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

Subversion Repositories tinycpu

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

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 16 earlz
5. mov (relative) 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
disable CS carryover seg
109
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 5 earlz
opcodes used: 12 of 16. 4 more opcodes available. Decide what to do with the room later.
118 4 earlz
 
119
 
120 5 earlz
 
121 3 earlz
 
122
1 -move immediate (only uses first byte)
123
2 -move
124
3 -push
125
4 -push immediate
126
5 -push and move (or call when acting on ip)
127
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)
128
7 -add
129
8 -subtract
130
9 -bitwise operations (xor, or, and, shift right, shift left, not)
131
 
132
x -multiply (if room)
133
x -divide
134
 
135
 
136
conditionals
137 4 earlz
 
138
1 -- only if true
139
for only if false, there should basically be another compare or if applicable an always afterwards
140 3 earlz
 
141
push
142
pop
143
move
144
add
145
sub
146 5 earlz
 
147
limitations that shouldn't be passed with instructions
148
* Doing 2 memory references
149
* pushing a memory reference (equates to 2 memory references)
150
 
151
Note it is possible however to read and write 16bits at one time to the memory to consecutive addresses.
152
 
153
 
154
segments:
155
DS is used in all "normal" memory references
156
SS is used in all push and pop instructions
157
ES is used when the ExtraSegment bit is set for either push/pop or normal memory references
158
CS is only used for fetching instructions
159 14 earlz
 
160 16 earlz
Segment carryover:
161
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.
162
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.
163
you can continue as far as needed into the address space without having to do ugly far jumps at each of the borders.
164 14 earlz
 
165 16 earlz
 
166 14 earlz
States needed:
167
0. reset
168
1. decode current instruction (All without memory capable within 1 clock cycle)
169
2. increment IP(and SP if needed) and fetch next instruction
170
3. Write 1 register to memory
171
4. Read 1 register from memory
172
5. Write 2 registers to memory
173
6. Read 2 registers from memory
174
7. Write 1 register to memory and setup increment of sp
175
8. Write 2 registers to memory and setup double increment of sp
176
9. Read 1 register from memory and setup decrement of sp
177
10. Read 2 registers from memory and setup double decrement of sp
178
11.
179
 
180
 
181
 
182
registerfile map:
183
0000: general r0
184
0001: general r1
185
0010: general r2
186
0011: general r3
187
0100: general r4
188
0101: general r5
189
0110: SP (r6)
190
0111: IP (r7)
191
1000: second bank r0
192
1001: second bank r1
193
1010: second bank r2
194
1011: second bank r3
195
1100: CS
196
1101: DS
197
1110: ES
198
1111: SS
199
 
200
Banking works like if(regnumber(2) = '0') then regnumber(3)=regbank; end if;
201
 
202
 
203
ALU operations
204
00000 and reg1,reg2 (reg1=reg1 and reg2)
205
00001 or reg, reg
206
00010 xor reg,reg
207
00011 not reg1,reg2 (reg1=not reg2)
208
00100 left shift reg,reg (logical)
209
00101 right shift reg,reg (logical)
210
00110 rotate right reg,reg
211
00111 rotate left reg,reg
212
 
213
01000 is greater than reg1,reg2 (TR=reg1>reg2)
214
01001 is greater or equal to reg,reg
215
01010 is less than reg,reg
216
01011 is less than or equal to reg,reg
217
01100 is equal to reg,reg
218
01101 is not equal to reg,reg
219
01110 equals 0 reg
220
01111 not equals 0 reg
221
 
222
10000 Set TR
223
10001 Reset TR
224
10011 Increment
225
10010 Decrement
226
10100 Add
227
10101 Subtract
228
 

powered by: WebSVN 2.1.0

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