Changed BRZ behavior to chomp a test word from stack instead of checking PSW_Z bit.
[ned1] / docs / architecture_manual.md
CommitLineData
bc5b63cf
AT
1NED - Architecture Manual
2=========================
3
4Overview
5--------
6
7* Stack based
8* Twos-complement
9* Big-endian
10* Simplicity above all else. See what we can achieve with minimal hardware
11 that's as fast as we can make it. Essentially, let the compiler target the
12 'microcode' level.
13* Explicitly no kernel/user mode.
14* Explicitly no MMU, just a flat, shared memory space. Think threads, not
15 processes.
16
418f3fc7 17Version: 2
bc5b63cf
AT
18
19Instruction Word Formats
20------------------------
21
22All instruction words in NED are 32-bits long and fall into one of three
23possible formats.
24
25 +---------+-----+-----+--------+--------+--------+--------+--------+
26 | Format | 31 | 30 | 29..24 | 23..18 | 17..12 | 11..6 | 5..0 |
27 +---------+-----+-----+--------+--------+--------+--------+--------+
28 | A | 1 | 31-bit Immediate |
29 +---------+-----+-----+--------------------------------------------+
30 | B | 0 | 1 | Unassigned |
31 +---------+-----+-----+--------+--------+--------+--------+--------+
32 | C | 0 | 0 | Syl. 1 | Syl. 2 | Syl. 3 | Syl. 4 | Syl. 5 |
33 +---------+-----+-----+--------+--------+--------+--------+--------+
34
35Format A contains a 31-bit field which is placed on the stack after shifting
36left one position and padding with a zero. For example, the instruction
37
38 11000000 01000000 01000000 01000000
39
40will place the value
41
42 10000000 10000000 10000000 10000000
43
44on the TOS.
45
46Format B is reserved for future instructions.
47
48Format C packs five syllables per instruction word, executed in order from 1 to 5.
49Syllables are defined as follows.
50
51| Bits | Name | Description |
52| ------ | ------ | ---------------------------------------------------------- |
53| 1xxxxx | IM_x | Push a 5-bit immediate to TOS. |
54| 011xxx | LDSP+x | Copy the value stored at TOS+x and push to TOS. |
55| 010xxx | STSP+x | Pop from TOS and overwrite value at TOS+x. |
56| 001000 | AND | Logical AND of TOS and NOS, pushed to TOS. |
57| 001001 | OR | Logical OR of TOS and NOS, pushed to TOS. |
58| 001010 | NOT | Logical NOT of TOS, pushed to TOS. |
59| 001011 | XOR | Logical XOR of TOS and NOS, pushed to TOS. |
60| 001100 | ADD | Signed, twos-complement addition. TOS <- TOS + NOS |
61| 001101 | SWAP | Swap TOS and NOS. |
62| 001110 | JMP | Pop TOS and set PC to popped value. |
63| 001111 | MVSTCK | Pop the TOS and context switch to that state ID. |
64| 000100 | SHIFT | Pop TOS & NOS. Shift NOS by TOS bits to the left/right. |
65| 000101 | CMPSWP | Compare-and-swap with ptr, old_val & new_val on stack. |
66| 000110 | TEST | Pop TOS and set PSW according to value. |
418f3fc7 67| 000111 | BRZ | Pop TOS & NOS. If NOS==0, then set PC to TOS value. |
bc5b63cf
AT
68| 000010 | LOAD | Pop address from TOS, dereference and store to TOS. |
69| 000011 | STORE | Pop address from TOS, pop data from NOS, deref and store. |
70| 000001 | NOP | Do nothing. |
71| 000000 | HALT | Halt the CPU. |
72
73The Instruction Reference contains a more complete description of these operations.
74
75Processor State
76---------------
77
78The Processor Status Word (PSW) contains *N*egative and *Z*ero flags in the
79following bit positions. See the Instruction Reference for details on which
80operations set these flags.
81
82 +-------+------------+-----+-----+
83 | Bits | 31..2 | 1 | 0 |
84 +-------+------------+-----+-----+
85 | Flags | Unassigned | N | Z |
86 +-------+------------+-----+-----+
87
88In addition to a traditional Program Counter (PC), the processor also includes
89a Syllable Counter (SC) which ranges from 0 to 4. Both the PC and SC point to
90the next instruction to be executed. Thus, when executing the middle syllable
91of a word located at address 0x200, the PC is 0x204 and the SC is 3.
92
93Since the CPU is stack based, it includes a Stack Pointer (SP).
94
95Memory Map
96----------
97
98The address space is laid out with memory mapped I/O below 512 MB and RAM above.
99
100 4 GB
101 |-------- Data
102 512 MB
103 |-------- I/O (general purpose)
104 128 MB
105 |-------- I/O (reserved for processors in 16 MB chucks x 8 CPUs)
106 0 Mb
107
108Temporarily, there are four read-only registers accessible in the lowest four
109words of memory. Writes to these registers are ignored.
110
111| Address | Name | Description |
112| ------- | ----------------- | ------------------------------- |
113| 0x0 | Zero Register | Constant 0x0 |
114| 0x4 | Negative Register | Constant 0x80000000 |
115| 0x8 | PC Register | PC of currently active thread. |
116| 0xC | PSW Register | PSW of currently active thread. |
117
118Also temporarily, a UART-like peripheral is present with the following registers.
119
120| Address | Name | Description |
121| --------- | --------------- | ----------------------------------------------- |
122| 0x8000000 | Transmit Buffer | Accepts one byte and transmits to stdout. |
123| 0x8000004 | Transmit Status | Bit 0 is set when UART is ready to send a byte. |
124| 0x8000008 | Receive Buffer | Contains one byte from stdin. |
125| 0x800000C | Receive Status | Bit 0 is set when a byte is ready to be read. |