Memory management and registers - kammyfur/vixen GitHub Wiki
The Vixen architecture contains 2 types of memory: registers and virtual memory. Registers are used for immediate processing within the CPU itself, and virtual memory is used for the rest.
Vixen currently supports between 69 megabytes (72352256 bytes) and 4 gigabytes (4294967295 bytes) of virtual memory. This amount can be changed at the hardware level.
The following table lists all the registers, the internal ID used to refer to them, how large they are, and whether they are readable and/or writable.
Name | Internal ID | Size | Description | Readable | Writable |
---|---|---|---|---|---|
r0 |
0001 |
32 bits | General-purpose | x | x |
r1 |
0011 |
32 bits | General-purpose | x | x |
r2 |
0012 |
32 bits | General-purpose | x | x |
r3 |
1000 |
32 bits | General-purpose | x | x |
r4 |
1001 |
32 bits | General-purpose | x | x |
r5 |
1002 |
32 bits | General-purpose | x | x |
r6 |
1003 |
32 bits | General-purpose | x | x |
r7 |
1004 |
32 bits | General-purpose | x | x |
r8 |
1005 |
32 bits | General-purpose | x | x |
r9 |
1006 |
32 bits | General-purpose | x | x |
r10 |
1007 |
32 bits | General-purpose | x | x |
r11 |
1008 |
32 bits | General-purpose | x | x |
r12 |
1009 |
32 bits | General-purpose | x | x |
r13 |
100a |
32 bits | General-purpose | x | x |
r14 |
100b |
32 bits | General-purpose | x | x |
pc |
program_counter |
32 bits | Address of current instruction in memory | x | x |
sr |
system_register |
8 bits | Internal processor flags | * | * |
up |
stack_pointer |
32 bits | Pointer to the top of the user stack | * | * |
ss |
system_stack |
- | Internal stack used for interrupt handling and subroutines | ||
sp |
- | - | Pointer to the top of the system stack |
* There are instructions that might allow for reading/writing to these registers, but they cannot be directly read from/written to.
Since Vixen is using virtual memory, all the memory the CPU sees may not necessarily correspond to system RAM. Not all memory regions are writable, and they are all readable.
Start | End | Size | Name | Description |
---|---|---|---|---|
00000000 |
000001ff |
512B | Specification | The CPU specification region contains read-only information about the CPU, such as its model number, clock speed, bus speed, supported extensions, bus width, address with, and more. |
00000200 |
040001ff |
64M | Boot ROM | ROM contains the system's basic code, which is usually used to load another external program (bootloader). It is usually stored in a dedicated chip and can (in most cases) not be written to. |
04000200 |
041001ff |
1M | System Bus | This I/O region is used to access the system bus and send or receive information from/to external devices such as terminals, non-volative memory, sound cards or printers. |
04100200 |
045001ff |
4M | User Stack | The user stack is used for various stack-related operations. It can be used through the psh and pll instructions (for example) without conflict with the CPU itself. |
04500200 |
04500207 |
8B | Interrupt handlers | This section of memory is used to store pointers to (respectively) an interrupt handler and a double fault handler. |
04500208 |
- | - | RAM | RAM is used to store disorganized memory. It is slower than registers but used to off-load data that does not need immediate processing. |
Only memory from 04000200
is natively writeable. Bus devices may also request for their memory to be locked. RAM is dynamically allocated based on the hardware.
There are multiple ways one can read or write data. This mode is defined in nibble 0 (the last 4 bits when reading left to right) when encoding operation codes:
Operation code | Name | Description | Assembly syntax |
---|---|---|---|
0 |
Immediate | Uses literal values. |
#<number> #'<char>'
|
1 |
Direct | Uses a register within the CPU. | <name> |
2 |
Absolute (Indirect) | Uses a pointer stored in the given memory location | [<addr>] |
3 |
Absolute | Uses an absolute memory location starting from 00000000
|
<addr> |
4 |
Relative | Uses a memory location relative to the current location (program counter) |
+<offset> -<offset>
|
5 |
Implied | Uses no operands or implicit operands | - |
6 * |
Absolute (Indexed) | Uses an absolute memory location added with the literal value |
[<addr> + #<index>] [<addr> - #<index>]
|
7 |
Absolute (Reg Indirect) | Uses a pointer stored in the given register | [<name>] |
8 * |
Absolute (Mem Indexed) | Uses an absolute memory location added with another memory location |
[<addr> + <addr>] [<addr> - <addr>]
|
9 * |
Absolute (Reg Indexed) | Uses an absolute memory location added with a register |
[<addr> + <name>] [<addr> - <name>]
|
Proposed change:
Operation code Name Description Assembly syntax 0
Immediate Uses literal values. <number>
'<char>'
1
Direct Uses a register within the CPU. <name>
2
Absolute (Indirect) Uses a pointer stored in the given memory location [*<addr>]
3
Absolute Uses an absolute memory location starting from 00000000
[<addr>]
4
Relative Uses a memory location relative to the current location (program counter) +<offset>
-<offset>
5
Implied Uses no operands or implicit operands - 6
*Absolute (Indexed) Uses an absolute memory location added with the literal value [<addr> + <index>]
[<addr> - #<index>]
7
Absolute (Reg Indirect) Uses a pointer stored in the given register [<name>]
8
*Absolute (Mem Indexed) Uses an absolute memory location added with another memory location [<addr> + *<addr>]
[<addr> - *<addr>]
9
*Absolute (Reg Indexed) Uses an absolute memory location added with a register [<addr> + <name>]
[<addr> - <name>]
In assembly code, numbers can be in different formats:
Syntax | Base | Example |
---|---|---|
% |
Binary (base 2) | %10101010 |
$ |
Hexadecimal (base 16) | $00ab16ef |
- | Decimal (base 10) | 123 |
Proposed change:
Syntax Base Example b
Binary (base 2) 10101010b
h
Hexadecimal (base 16) 00ab16efh
o
Octal (base 8) 00ab16efo
- Decimal (base 10) 123