Skip to content

Commit 1fc2c9e

Browse files
os some
1 parent 6d2a14d commit 1fc2c9e

File tree

4 files changed

+87
-73
lines changed

4 files changed

+87
-73
lines changed

docs/source/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ The only required module is a RP6502-RIA.
7272
- :doc:`vga`: Optional video adapter that connects to the
7373
RP6502-RIA.
7474
- :doc:`os`: The operating system and application programming interface.
75+
76+
`Please contribute to this documentation.
77+
<https://github.com/picocomputer/picocomputer.github.io>`_

docs/source/os.rst

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ RP6502 - Operating System
77
Introduction
88
============
99

10-
The :doc:`ria` runs a protected 32-bit protected operating system that
10+
The :doc:`ria` runs a 32-bit protected operating system that
1111
you can call from the 6502. The :doc:`os` does not use any 6502 RAM
1212
and will not interfere with developing a native 6502 OS.
1313

1414
The :doc:`os` is loosely based on POSIX with an ABI similar to
15-
CC65's fastcall. It provides stdio.h services to both CC65 and
16-
LLVM-MOS compilers. There are also calls access Picocomputer features
17-
and manage FAT32 filesystems. ExFAT is ready to go and will be enabled
18-
when the patents expire.
15+
CC65's fastcall. It provides stdio.h and unistd.h services to both
16+
CC65 and LLVM-MOS compilers. There are also calls access RP6502
17+
features and manage FAT32 filesystems. ExFAT is ready to go and will
18+
be enabled when the patents expire.
1919

2020

2121
Memory Map
@@ -43,40 +43,33 @@ registers of the RIA.
4343
* - FFE0-FFFF
4444
- RIA, see the :doc:`RP6502-RIA datasheet <ria>`
4545
* - 10000-1FFFF
46-
- XRAM, 64K for :doc:`RP6502-RIA <ria>` and
47-
:doc:`RP6502-VGA <vga>`
46+
- XRAM, 64K for :doc:`ria` and :doc:`vga`
4847

4948
The unassigned space is available for hardware experimenters. You will
5049
need to design your own address decoder logic hardware to use this
5150
address space. It is recommended that additional VIAs be added "down"
5251
and other hardware added "up". For example: VIA0 at $FFD0, VIA1 at
5352
$FFC0, SID0 at $FF00, and SID1 at $FF20.
5453

55-
I use "Picocomputer 6502" to refer to the reference design with the
56-
above memory map. Please use a differentiating name if you change the
57-
hardware. For example, "Picocomputer VERA" or "Ulf's Dream Computer".
58-
Think about what people asking for help should call the device and go
59-
with that.
6054

61-
62-
Calling with fastcall
63-
=====================
55+
Application Binary Interface (ABI)
56+
==================================
6457

6558
The binary interface for calling the operating system is based on
6659
fastcall from the `CC65 Internals
67-
<https://cc65.github.io/doc/cc65-intern.html>`_. The RP6502-OS fastcall
68-
does not use or require anything from CC65 and is easy for assembly
69-
programmers to use. At its core, the API ABI is based on a C ABI with
70-
four simple rules.
60+
<https://cc65.github.io/doc/cc65-intern.html>`_. The RP6502-OS
61+
fastcall does not use or require anything from CC65 and is easy for
62+
assembly programmers to use. At its core, the OS API ABI is based on
63+
a C ABI with four simple rules.
7164

7265
* Stack arguments are pushed left to right.
7366
* Last argument passed by register A, AX, or AXSREG.
7467
* Return value in register AX or AXSREG.
75-
* Returned structures on the stack.
68+
* May return data on the stack.
7669

7770
A and X are the 6502 registers. The pseudo register AX combines them
7871
for 16 bits. AXSREG is 32 bits with 16 SREG bits. Let's look at how
79-
to make an OS call through the RIA registers. All kernel calls are
72+
to make an OS call through the RIA registers. All OS calls are
8073
specified as a C declaration like so:
8174

8275
.. c:function:: int doit(int arg0, int arg1);
@@ -118,22 +111,22 @@ absolute instructions.
118111
wait:
119112
BIT RIA_BUSY
120113
BMI wait
121-
LDA RIA_A
122-
LDX RIA_X
114+
LDA #RIA_A
115+
LDX #RIA_X
123116
124117
All operations returning RIA_A will also return RIA_X to assist with
125-
CC65's integer promotion requirements. RIA_SREG is only updated for
118+
C integer promotion. RIA_SREG is only updated for
126119
32-bit returns. RIA_ERRNO is only updated if there is an error.
127120

128-
Some operations return data structures on the stack. You must pull the
129-
entire stack before the next call. However, tail call optimizations are
130-
possible. For example, you can chain read_xstack() and write_xstack()
131-
to copy a file without using any RAM or XRAM.
121+
Some operations return strings or structures on the stack. You must
122+
pull the entire stack before the next call. However, tail call
123+
optimizations are possible. For example, you can chain read_xstack()
124+
and write_xstack() to copy a file without using any RAM or XRAM.
132125

133126
Short Stacking
134127
---------------
135128

136-
In the never ending pursuit of saving all the clocks, it is possible to
129+
In the never ending pursuit of saving all the cycles, it is possible to
137130
save a few on the stack push if you don't need all the range. This only
138131
works on the stack argument that gets pushed first. For example:
139132

@@ -148,7 +141,7 @@ bits, push only three bytes. The significant bytes will be implicit.
148141
Shorter Integers
149142
-----------------
150143

151-
Many operations can save a few clocks by ignoring REG_X. All integers
144+
Many operations can save a few cycles by ignoring REG_X. All integers
152145
are always available as 16 bits to assist with C integer promotion.
153146
However, many operations will ignore REG_X on the register parameter
154147
and limit their return to fit in REG_A. This will be documented below
@@ -158,8 +151,8 @@ Bulk Data
158151
---------
159152

160153
Functions that move bulk data may come in two flavors. These are any
161-
function with a pointer parameter. This pointer is meaningless to the
162-
kernel because it can not change 6502 RAM. Instead, we use the XSTACK
154+
function with a pointer parameter. A RAM pointer is meaningless to the
155+
RIA because it can not change 6502 RAM. Instead, we use the XSTACK
163156
or XRAM for data buffers.
164157

165158
Bulk XSTACK Operations
@@ -174,31 +167,33 @@ examples.
174167
175168
int open(const char *path, int oflag);
176169
177-
Send `oflag` in AX. Send the path on XSTACK by pushing the string
178-
starting with the last character. You may omit pushing the terminating
179-
zero, but strings are limited to a length of 255. Calling this from the
180-
C SDK will "just work" because there's an implementation that pushes
181-
the string for you.
170+
Send `oflag` in RIA_A and RIA_X. Send the path on XSTACK by pushing the
171+
string starting with the last character. You may omit pushing the
172+
terminating zero, but strings are limited to a length of 255. Calling
173+
this from the C SDK will "just work" because there's an implementation
174+
that pushes the string for you.
182175

183176
.. code-block:: C
184177
185178
int read_xstack(void *buf, unsigned count, int fildes)
186179
187-
Send `count` as a short stack and `fildes` in AX. The returned value in
188-
AX indicates how many values must be pulled from the stack. If you call
180+
Send `count` as a short stack and `fildes` in RIA_A. RIA_X doesn't need
181+
to be set according the to docs below. The returned value in AX
182+
indicates how many values must be pulled from the stack. If you call
189183
this from the C SDK then it will copy XSTACK to buf[] for you.
190184

191185
.. code-block:: C
192186
193187
int write_xstack(const void *buf, unsigned count, int fildes)
194188
195-
Send `fildes` in AX. Push the data to XSTACK. Do not send `count`, the
196-
kernel knows this from its internal stack pointer. If you call this from
197-
the C SDK then it will copy count bytes of buf[] to XSTACK for you.
189+
Send `fildes` in RIA_A. Push the buf data to XSTACK. Do not send
190+
`count`, the OS knows this from its internal stack pointer. If you call
191+
this from the C SDK then it will copy count bytes of buf[] to XSTACK
192+
for you.
198193

199-
Note that read() and write() are part of the C SDK, not a kernel
200-
operation. CC65 requires them to support more than 512 bytes, so they
201-
have wrapper logic to make multiple kernel calls when necessary.
194+
Note that read() and write() are part of the C SDK, not an OS
195+
operation. C requires these to support a count larger than the XSTACK
196+
can return so the implementation makes multiple OS calls as necessary.
202197

203198
Bulk XRAM Operations
204199
~~~~~~~~~~~~~~~~~~~~
@@ -211,31 +206,49 @@ going through 6502 RAM or capture a screenshot with ease.
211206
int read_xram(xram_addr buf, unsigned count, int fildes)
212207
int write_xram(xram_addr buf, unsigned count, int fildes)
213208
214-
The kernel expects `buf` and `count` on the XSTACK as integers with
215-
`filedes` in AX. The buffer is effectively &XRAM[buf] here. There's
216-
nothing special about these calls in regards to how the binary interface
217-
rules are applied. They are interesting because of their high
218-
performance for loading assets.
209+
The OS expects `buf` and `count` on the XSTACK as integers with
210+
`filedes` in RIA_A. The buffer is effectively &XRAM[buf] here.
211+
212+
These operations are interesting because of their high performance and
213+
ability to work in the background while the 6502 is doing something
214+
else. You can expect close to 64KB/sec, which means loading a game
215+
level's worth of assets will take less than a second.
216+
217+
Bulk XRAM operations are why the Picocomputer 6502 was designed
218+
without paged memory.
219219

220220
Function Reference
221221
===================
222222

223-
Much of this API is based on CC65 and POSIX. In particular, filesystem
224-
access should feel extremely modern. However, some operations will have
225-
different argument orders or bitfield values than what you're used to.
226-
The reason for this becomes apparent when you start to work in assembly
227-
and fine tune short stacking and integer demotions. You might not notice
228-
the differences if you only work in C because the standard library has
229-
wrapper functions and familiar prototypes. For example, the f_lseek()
230-
described below has reorderd arguments that are optimized for short
231-
stacking the long argument. But you don't have to call f_lseek() from C,
232-
you call the usual lseek() which has the traditional argument order.
223+
Much of this API is based on POSIX and FatFs. In particular, filesystem
224+
and console access should feel extremely familiar. However, some
225+
operations will have different argument orders or bitfield values than
226+
what you're used to. The reason for this becomes apparent when you start
227+
to work in assembly and fine tune short stacking and integer demotions.
228+
You might not notice the differences if you only work in C because the
229+
standard library has wrapper functions and familiar prototypes. For
230+
example, the f_lseek() described below has reordered arguments that are
231+
optimized for short stacking the long argument. But you don't have to
232+
call f_lseek() from C, you can call the usual lseek() which has the
233+
traditional argument order.
234+
235+
The RP6502 is built around FAT filesystems, which is the defacto standard
236+
for USB storage devices. POSIX filesystems are not fully compatible with
237+
FAT but there is a solid intersection of basic IO that is 100% compatible.
238+
You will see some familiar POSIX functions like open() and others like
239+
f_stat() which are similar to the POSIX function but tailored to FAT.
240+
Should it ever become necessary to have a POSIX stat(), it can be
241+
implemented in the C standard library or in an application by translating
242+
f_stat() data.
233243

234244
zxstack
235245
-------
236246
.. c:function:: void zxstack(void);
237247
238-
Abandon the xstack by resetting the xstack pointer. This is the only operation that doesn't require waiting for completion. You do not need to call this for failed operations. It can be useful if you want to quickly ignore part of a returned structure.
248+
Abandon the xstack by resetting the xstack pointer. This is the only
249+
operation that doesn't require waiting for completion. You do not need
250+
to call this for failed operations. It can be useful if you want to
251+
quickly ignore part of a returned structure.
239252

240253
xreg
241254
----
@@ -274,7 +287,7 @@ phi2
274287
Retrieves the PHI2 setting from the RIA. Applications can use this
275288
for adjusting to or rejecting different clock speeds.
276289
277-
:returns: The 6502 clock speed in kHz. Typically 750 <= x <= 8000.
290+
:returns: The 6502 clock speed in kHz. Typically 800 <= x <= 8000.
278291
:errno: will not fail
279292
280293
@@ -317,6 +330,8 @@ stdin_opt
317330
318331
.. c:function:: int stdin_opt(unsigned long ctrl_bits, unsigned char str_length)
319332
333+
*** Experimental *** (likely to be replaced with stty-like something)
334+
320335
Additional options for the STDIN line editor. Set the str_length to
321336
your buffer size - 1 to make gets() safe. This can also guarantee no
322337
split lines when using fgets() on STDIN.
@@ -629,10 +644,9 @@ exit
629644
630645
.. c:function:: void exit(int status)
631646
632-
Halt the 6502 and return to the kernel command interface. This is the
633-
only operation that does not return. RESB will be pulled down before
634-
the next instruction can execute. Status is currently ignored but will
635-
be used in the future.
647+
Halt the 6502 and return the console to RP6502 monitor control. This
648+
is the only operation that does not return. RESB will be pulled down
649+
before the next instruction can execute. Status is currently ignored
650+
but will be used in the future.
636651
637-
:param status: 0 is good, 1-255 for error.
638-
:a regs: status
652+
:param status: 0 is good, !0 for error.

docs/source/ria.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Registers
129129
- Ensures errno is optionally a 16-bit int.
130130
* - $FFEF
131131
- OP
132-
- Write the OS operation id here to begin a kernel call.
132+
- Write the OS operation id here to begin an OS call.
133133
* - $FFF0
134134
- IRQ
135135
- Set bit 0 high to enable VSYNC interrupts. Verify source
@@ -181,7 +181,7 @@ Easy and direct access to the UART RX/TX pins of the :doc:`ria` is
181181
available from $FFE0-$FFE2. The ready flags on bits 6-7 enable testing
182182
with the BIT operator. You may choose to use these or stdio
183183
from the :doc:`os`. Using the UART directly while a stdio
184-
kernel function is in progress will result in undefined behavior.
184+
OS function is in progress will result in undefined behavior.
185185
The UART hardware runs at 115200 bps, 8 bit words, no parity, 1 stop bit.
186186

187187
Extended RAM (XRAM)

docs/source/ria_w.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ TCP.
8888
"Telephone Numbers" are saved immediately and are not linked to
8989
profiles.
9090

91-
`Please contribute to this documentation.
92-
<https://github.com/picocomputer/picocomputer.github.io>`_
93-
9491
Bluetooth
9592
=========
9693

0 commit comments

Comments
 (0)