OpenCores
URL https://opencores.org/ocsvn/tinycpu/tinycpu/trunk

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [docs/] [design.md.txt] - Blame information for rev 17

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 earlz
This is the design of TinyCPU. It's goals are as follows:
2
 
3
1. 8-bit registers and operations (8 bit processor)
4
2. 16-bit address bus
5
3. fixed 16-bit instruction length
6
4. use a small amount of "rich" instructions to do powerful things
7
5. 1 instruction per clock cycle
8
 
9 16 earlz
Relative moves:
10
In order to provide uesfulness to the segment-carryover feature, there are a few options for moving a "relative" amount to a register, including IP and SP
11
A relative move differs in most of the opcodes in that the relative factor is treated as a signed value.
12
so for instance, a
13
mov r0,50
14
mov_relative r0, -10
15
 
16
in the ned, r0 will end up being 40. Although this feature won't see much use in general registers, IP and SP are special because of the option of using the
17
segment-carryover feature. This means that SP and IP, while being 8-bit registers, can function very similar to a 16-bit register, enabling full usage of the available address space.
18
 
19 3 earlz
Register list:
20 5 earlz
r0-r5 general purpose registers
21
sp stack pointer (represented as r6)
22 4 earlz
ip instruction pointer register (represented as r7)
23 3 earlz
cs, ds, es, ss segment registers (code segment, data segment, extra segment, stack segment)
24
tr truth register for conditionals
25
 
26
general opcode format
27
 
28
first byte:
29
first 4 bits: actual instruction
30 4 earlz
next 3 bits: (target) register
31
last 1 bit: conditional
32 3 earlz
 
33 4 earlz
second byte:
34
first 1 bit: second portion of condition (if not immediate) (1 for only if false)
35 5 earlz
next 1 bit: use extra segment
36 16 earlz
next 3 bits: other register. If not 3rd register, top bit specifies which register bank, others unused
37 4 earlz
last 3 bits: extra opcode information or third register. such as for ADD it could be target=source+third_register
38 3 earlz
 
39
...or second byte is immediate value
40
 
41
For opcodes requiring 3 registers but without room, the target opcode is assume to be the second operation. Such as for AND, target=source AND target
42
 
43
short list of instructions: (not final, still planning)
44 4 earlz
immediates:
45
1. move reg, immediate
46
2. move [reg], immediate
47
3. push and move reg, immediate (or call immediate)
48
4. push immediate
49 17 earlz
5. move (relative) reg, immediate
50 4 earlz
 
51 16 earlz
 
52 4 earlz
groups: (limited to 2 registers and no immediates. each group has 8 opcodes)
53
group 1:
54
move(store) [reg],reg
55
move(load) reg,[reg]
56
out reg1,reg2 (output to port reg1 value reg2)
57
in reg1,reg2 (input from port reg2 and store in reg1)
58 5 earlz
pop reg
59
push reg
60
move segmentreg,reg
61
move reg,segmentreg
62 4 earlz
 
63
group 2:
64
and reg1,reg2 (reg1=reg1 and reg2)
65
or reg, reg
66
xor reg,reg
67
not reg1,reg2 (reg1=not reg2)
68
left shift reg,reg
69
right shift reg,reg
70
rotate right reg,reg
71
rotate left reg,reg
72
 
73
group 3: compares
74
is greater than reg1,reg2 (TR=reg1>reg2)
75
is greater or equal to reg,reg
76
is less than reg,reg
77
is less than or equal to reg,reg
78
is equal to reg,reg
79
is not equal to reg,reg
80 5 earlz
equals 0 reg
81
not equals 0 reg
82 4 earlz
 
83 5 earlz
group 4:
84
push segmentreg
85
pop segmentreg
86
push and move reg, reg (or call reg)
87
exchange reg,reg
88
exchange reg,seg
89
clear TR
90
Set TR
91 4 earlz
 
92 5 earlz
group 5:
93
increment reg
94
decrement reg
95
far jmp reg1, reg2 (CS=reg1 and IP=reg2)
96
far call reg1,reg2
97
far jmp [reg] (first byte is CS, second byte is IP)
98
push extended segmentreg, reg (equivalent to push seg; push reg)
99
pop extended segmentreg, reg (equivalent to pop reg; pop seg)
100
reset processor (will completely reset the processor to starting state, but not RAM or anything else)
101 4 earlz
 
102 14 earlz
group 6:
103 16 earlz
set default register bank to 0 (can be condensed to 1 opcode)
104
set default register bank to 1
105 14 earlz
push extended reg, reg
106
pop extended reg,reg
107 16 earlz
enable carryover seg
108 17 earlz
disable carryover seg
109 16 earlz
mov relative reg, reg
110
exchange reg, reg
111 4 earlz
 
112
3 register instructions:
113
1. add reg1, reg2, reg3 (reg1=reg2+reg3)
114
2. sub reg1, reg2, reg3
115
 
116
 
117 17 earlz
opcodes used: 13 of 16. 3 more opcodes available. Decide what to do with the room later.
118 4 earlz
 
119 17 earlz
Possible canidates for opcode compression include
120
* Push immediate (room for 3 sub-opcodes)
121
* push and pop reg (room for 7 sub-opcodes each)
122
* equals 0 and not equals 0 (room for 7 sub-opcodes each)
123
* Set TR and Reset TR (room for 64 opcodes each)
124
* increment and decrement reg (room for 7 opcodes each)
125
* enable and disable carry over (room for 7 opcodes each)
126
* set register bank 0 and 1 (room for 64 opcodes each)
127 4 earlz
 
128 5 earlz
 
129 3 earlz
 
130
1 -move immediate (only uses first byte)
131
2 -move
132
3 -push
133
4 -push immediate
134
5 -push and move (or call when acting on ip)
135
6 -compare (is less than, is less than or equal, is greater than, is greater than or equal, is equal, is not equal) (6 conditions room for 2 more in extra)
136
7 -add
137
8 -subtract
138
9 -bitwise operations (xor, or, and, shift right, shift left, not)
139
 
140
x -multiply (if room)
141
x -divide
142
 
143
 
144
conditionals
145 4 earlz
 
146
1 -- only if true
147
for only if false, there should basically be another compare or if applicable an always afterwards
148 3 earlz
 
149
push
150
pop
151
move
152
add
153
sub
154 5 earlz
 
155
limitations that shouldn't be passed with instructions
156
* Doing 2 memory references
157
* pushing a memory reference (equates to 2 memory references)
158
 
159
Note it is possible however to read and write 16bits at one time to the memory to consecutive addresses.
160
 
161
 
162
segments:
163
DS is used in all "normal" memory references
164
SS is used in all push and pop instructions
165
ES is used when the ExtraSegment bit is set for either push/pop or normal memory references
166
CS is only used for fetching instructions
167 14 earlz
 
168 16 earlz
Segment carryover:
169
In order to overcome the limitations of only having a 256 byte segment, there is a workaround option to "pretend" that IP is a 16 bit register.
170
When CS carryover is enabled, when IP rollover from 255 to 0 or whatever, CS will be incremented. This makes it so that if you start at address 0:0.
171
you can continue as far as needed into the address space without having to do ugly far jumps at each of the borders.
172 17 earlz
Carryover can only be done on CS and SS. The required circuitry is not implemented for DS or ES due to an extreme level of complexity required for it, also
173
it would only lead to unncessarily complex code
174 14 earlz
 
175 17 earlz
Also of note is that `move relative` implements a "carryover" component. This component will work on either IP or SP, and uses CS and SS respectively.
176
If used on other registers, there will be no carry over functionality, though it can be used as an easy way to add or subtract an immediate from a register.
177 16 earlz
 
178 17 earlz
 
179
 
180 14 earlz
States needed:
181
0. reset
182
1. decode current instruction (All without memory capable within 1 clock cycle)
183
2. increment IP(and SP if needed) and fetch next instruction
184
3. Write 1 register to memory
185
4. Read 1 register from memory
186
5. Write 2 registers to memory
187
6. Read 2 registers from memory
188
7. Write 1 register to memory and setup increment of sp
189
8. Write 2 registers to memory and setup double increment of sp
190
9. Read 1 register from memory and setup decrement of sp
191
10. Read 2 registers from memory and setup double decrement of sp
192
11.
193
 
194
 
195
 
196
registerfile map:
197
0000: general r0
198
0001: general r1
199
0010: general r2
200
0011: general r3
201
0100: general r4
202
0101: general r5
203
0110: SP (r6)
204
0111: IP (r7)
205
1000: second bank r0
206
1001: second bank r1
207
1010: second bank r2
208
1011: second bank r3
209
1100: CS
210
1101: DS
211
1110: ES
212
1111: SS
213
 
214
Banking works like if(regnumber(2) = '0') then regnumber(3)=regbank; end if;
215
 
216
 
217
ALU operations
218
00000 and reg1,reg2 (reg1=reg1 and reg2)
219
00001 or reg, reg
220
00010 xor reg,reg
221
00011 not reg1,reg2 (reg1=not reg2)
222
00100 left shift reg,reg (logical)
223
00101 right shift reg,reg (logical)
224
00110 rotate right reg,reg
225
00111 rotate left reg,reg
226
 
227
01000 is greater than reg1,reg2 (TR=reg1>reg2)
228
01001 is greater or equal to reg,reg
229
01010 is less than reg,reg
230
01011 is less than or equal to reg,reg
231
01100 is equal to reg,reg
232
01101 is not equal to reg,reg
233
01110 equals 0 reg
234
01111 not equals 0 reg
235
 
236
10000 Set TR
237
10001 Reset TR
238
10011 Increment
239
10010 Decrement
240
10100 Add
241
10101 Subtract
242
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.