~maddie/custom-processor-specification

ref: 958c4dca12c6308d60429f4f88b136a359579c96 custom-processor-specification/ISA_spec.txt -rw-r--r-- 4.8 KiB
958c4dcaMadeline Cronin Rename the ISA spec file 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
Maddie's test ISA Version 1.0.2


Table of contents:
1 - Overview
2 - Instruction conditions
3 - Instruction categories
4 - Instruction descriptions


- Overview:
The numbers: 16 bit words, 2-word fixed instruction length, 32 16-bit registers,
65535 main memory and VRAM addresses each, 2^32 max disc addresses.

Features: All instructions can have conditional execution attached.
Hardware and software interrupts are toggleable. Serial port I/O intended for
interfacing with STDIN/STDOUT on simulated versions. Load/Store architecture.

Registers: 32 registers, with registers #28-31 (zero indexed) reserved for the
following special purposes, in order: disk index, stack pointer, program
counter, and interrupt register. The program counter is freely readable, but
only modifiable through instructions in the control flow category. There is
also a 2 bit flags register for storing the condition flags.

Behaviours: Upon power up, the first 512 words of disk are copied to main
memory. The only statefulness not directly controlled by programs is the
interrupt toggle. Numbers are read as big endian. Hardware interrupts jump to
zero, and push the prior program counter to the stack.

Versioning: The versioning of this ISA follows semantic versioning, although
given how many breaking changes it is likely to go though, the major version
number may get very high.

Notes for reading: In the description of a bit or collection of bits for an
instruction, anything following a tag such as (A=1) means that any behaviours
described between that tag and the next tag, or end of line, are only followed
when the condition in the tag is met. If no conditions are met, no additional
behaviour is to occur.


- Instruction Conditions:
ABab----|--------|--------|--------
AB = Activation Flags
ab = Condition Flags
There is a 2 bit register in the CPU which stores the state of A and B, and is
updated by certain instructions.
When an activation flag is set, the corresponding condition bit must match its
condition flag in order for the instruction to be executed.

- Instruction Categories:
----XXXX|--------|--------|---------
XXXX=
0000: Halt
0001: Arithmetic
0010: Logical
0011: Condition Check
0100: Control Flow
0101: Memory Access
0110: Immediate Value
1111: No-op

Halt:
----0000|--------|--------|---------
Halts the processor.

Arithmetic:
----0001|SCFIXXXX|--------|---------
S: Input is (S=0) unsigned, (S=1) signed using 2's complement
C: (C=1) Update the specified condition flag upon overflow
F: Specifies (F=0) flag A or (F=1) flag B
I: (I=1) Invert the result

XXXX=
0000: Addition
0001: Subtraction
0010: Multiplication
0011: Integer Division

Logical:
----0010|ZFRIXXXX|--------|--------
Z: (Z=1) Update the specified condition flag if the result is zero
F: Specifies (F=0) flag A or (F=1) flag B
R: (I=1) Invert the flag write
I: (I=1) Invert the result, acts before the zero check

XXXX=
0000: AND
0001: OR
0010: XOR

Condition check:
----0011|FIXX----|--------|--------
F: Specifies (F=0) flag A or (F=1) flag B
I: (I=0) Normal write, (I=1) inverted write

XX=
00: Equal
01: Less than
10: Greater than

Control flow:
----0100|JSPITT--|--------|--------
J: (J=0) Jump to the described address, (J=1) Add the described value to the
program counter
S: (S=1) Push the current address to the stack
P: (P=1) Pop from the stack and use the stack value instead of a register
value
I: (I=1) If interrupts are enabled, jump to 0. This overrides J and P,
preventing the pop from occuring. Note that if interrupts are disabled then J
and P will work normally.

TT=
0x: No additional effect
10: Toggle interrupts off
11: Toggle interrupts on, both of these operations act before the condition
check for I=1

Memory access:
----0101|AXXX----|--------|--------
A: (A=0) Read/pop, (A=1) Write/push

XXX=
000: Pop/push to stack
001: Read/write RAM
010: R/W disk
011: R/W VRAM
100: R/W to serial port

Immediate value:
----0110|RRRRR---|xxxxxxxx|xxxxxxxx
Writes the value denoted by x's to the register of index RRRRR


-Instruction descriptions:
--------|--------|11111222|2233333-
11111: Operand 1
22222: Operand 2
33333: Operand 3

Arithmetic:
Addition, subtraction, multiplications, and integer division all take 3
operands, and operate on the described registers in the order of 3 = 1 (+-x/) 2

Logical:
All logical operations take 3 operands, and operate on the described registers
in the order 3 = 1 (OP) 2

Condition check:
Takes 2 operands, and performs the described check in the order of 1 (<,=,>) 2

Control flow:
Takes 1 operand, describing the register of the address/value to be used,
which is ignored if using a stack value

Memory access:
Takes 2 operands, the first describes the register to write from/read to, and
the second describing the register containing the target memory address.
When reading/writing to disk, the address is further offset by the disk index
register multiplied by 2^16

Immediate value:
Already fully described above.