summaryrefslogtreecommitdiffstats
path: root/zpu/docs/zpu_arch.html
blob: 312bdb6340e42fb833d1647109bca0db058c08a7 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
<html>
<body>
<h1>Index</h1>
<ul>
<li> <a href="#started">Getting started</a>
<li> <a href="#introduction">Introduction</a>
<li> <a href="#instructionset">Instruction set</a>
<li> <a href="#implementing">Implementing your own ZPU</a>
<li> <a href="#vectors">Jump vectors</a>
<li> <a href="#memorymap">Memory map</a>
<li> <a href="#interrupts">Interrupts</a>
<li> <a href="#zpu_core_small.vhd">About zpu_core_small.vhd</a>
<li> <a href="#zpu_core.vhd">About zpu_core.vhd</a>
<li> <a href="#nextgen">Next generation ZPU</a>
</ul>
<a name="started"/>
<h1>Getting started</h1>
The ZPU comes with a few simulation examples. 
<p>
Start with <a href="../hdl/index.html">VHDL synthesis examples</a>
<a name="introduction"/>
<h1>Introduction</h1>
The ZPU is a zero operand, or stack based CPU. The opcodes have a fixed width of 8 bits. 
<p>
Example:
<p>
<div style="white-space:pre;background-color:#dddddd;">
	<code style="white-space:pre;background-color:#dddddd;">
		IM 5                ; push 5 onto the stack
		LOADSP 20           ; push value at memory location SP+20
		ADD                 ; pop 2 values on the stack and push the result
	</code>
</div>
As can be seen, a lot of information is packed into the 8 bits, e.g. the IM instruction pushes a 7 bit signed integer onto the stack. 
<p>
The choice of opcodes is intimately tied to the GCC toolchain capabilities.
<p>
<div style="white-space:pre;background-color:#dddddd;">
	<code style="white-space:pre;background-color:#dddddd;">
	/* simple program showing some interesting qualities of the ZPU toolchain */
	void bar(int);
	int j;
	void foo(int a, int b, int c)
	{
	  a++;
	  b+=a;
	  j=c;
	  bar(b);
	}

foo:
 loadsp 4	; a is at memory location SP+4
 im 1
 add
 loadsp 12	; b is now at memory location SP+12
 add
 loadsp 16	; c is now at memory location SP+16
 im 24		; «j» is at absolute memory location 24. 
; Notice how the ZPU toolchain is using link-time relaxation
; to squeeze the address into a single no-op
 store
 im 22		; the fn bar is at address 22
 call
 im 12
 return	; 12 bytes of arguments + return from fn
</code>
</div>

<a name="instructionset"/>
<h1>Instruction set</h1>
Only the base instructions are implemented in the architecture. More advanced instructions, like ASHIFTLEFT are emulated in the illegal instruction vector.

All operations are 32 bit wide.
<table border="1">
	<tr><td>Name</td><td>Opcode</td><td>Description</td><td>Definition</td></tr>
	<tr>
		<td>
			BREAKPOINT
		</td>
		<td>
			00000000
		</td>
		<td>
			The debugger sets a memory location to this value to set a breakpoint. Once a JTAG-like 
			debugger interface is added, it will be convenient to be able to distinguish 
			between a breakpoint and an illegal(possibly emulated) instruction.
		</td>
		<td>
			No effect on registers
		</td>
	</tr>
	<tr>
		<td>
			IM
		</td>
		<td>
			1xxx xxxx
		</td>
		<td>
			Pushes 7 bit sign extended integer and sets the a «instruction decode interrupt mask» flag(IDIM).
			<p> 
			If the IDIM flag is already set, this instruction shifts the value on the stack left by 7 bits and stores the 7 bit immediate value into the lower 7 bits.
			<p> 
			Unless an instruction is listed as treating the IDIM flag specially, it should be assumed to clear the IDIM flag.
			<p> 
			To push a 14 bit integer onto the stack, use two consequtive IM instructions. 
			<p> 
			If multiple immediate integers are to be pushed onto the stack, they must be interleaved with another instruction, typically NOP.
		</td>
		<td>
			<code style="white-space:pre;">
pc <= pc + 1 <br>
idim <= 1 <br>
if (idim=0) then <br>
	sp <= sp - 1; <br>
	for i in wordSize-1 downto 7 loop <br>
		mem(sp)(i) <= opcode(6) <br>
	end loop <br>
	mem(sp)(6 downto 0) <= opcode(6 downto 0) <br>
else <br>
	mem(sp)(wordSize-1 downto 7) <= mem(sp)(wordSize-8 downto 0) <br>
	mem(sp)(6 downto 0) <= opcode(6 downto 0) <br>
end if
			</code>

		</td>
	</tr>
	<tr>
		<td>
			STORESP
		</td>
		<td>
			010x xxxx
		</td>
		<td>
			Pop value off stack and store it in the SP+xxxxx*4 memory location, where xxxxx is a positive integer.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			LOADSP
		</td>
		<td>
			011x xxxx
		</td>
		<td>
			Push value of memory location SP+xxxxx*4, where xxxxx is a positive integer, onto stack.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			ADDSP
		</td>
		<td>
			0001 xxxx
		</td>
		<td>
			Add value of memory location SP+xxxx*4 to value on top of stack.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			EMULATE
		</td>
		<td>
			001x xxxx
		</td>
		<td>
			Push PC to stack and set PC to 0x0+xxxxx*32. This is used to emulate opcodes. See zpupgk.vhd for list of emulate opcode values used. zpu_core.vhd contains reference implementations of these instructions rather than letting the ZPU execute the EMULATE instruction
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			PUSHPC
		</td>
		<td>
			emulated
		</td>
		<td>
			Pushes program counter onto the stack.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			POPPC
		</td>
		<td>
			0000 0100
		</td>
		<td>
			Pops address off stack and sets PC
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			LOAD
		</td>
		<td>
			0000 1000
		</td>
		<td>
			Pops address stored on stack and loads the value of that address onto stack.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			LOAD
		</td>
		<td>
			0000 1000
		</td>
		<td>
			Pops address stored on stack and loads the value of that address onto stack.
			<p>
			Bit 0 and 1 of address are always 0.
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			STORE
		</td>
		<td>
			0000 1100
		</td>
		<td>
			Pops address, then value from stack and stores the value into the memory location of the address.
			<p>
			Bit 0 and 1 of address are always 0
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			PUSHSP
		</td>
		<td>
			0000 0010
		</td>
		<td>
			Pushes stack pointer. 
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			POPSP
		</td>
		<td>
			0000 1101
		</td>
		<td>
			Used to allocate/deallocate space on stack for variables or when changing threads. 
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			ADD
		</td>
		<td>
			0000 0101
		</td>
		<td>
			Pops two values on stack adds them and pushes the result
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			AND
		</td>
		<td>
			0000 0110
		</td>
		<td>
			Pops two values off the stack and does a bitwise-and & pushes the result onto the stack
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			OR
		</td>
		<td>
			0000 0111
		</td>
		<td>
			Pops two integers, does a bitwise or and pushes result
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			NOT
		</td>
		<td>
			0000 1001
		</td>
		<td>
			Bitwise inverse of value on stack

		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			FLIP
		</td>
		<td>
			0000 1010
		</td>
		<td>
			Reverses the bit order of the value on the stack, i.e. abc->cba, 100->001, 110->011, etc. 
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			NOP
		</td>
		<td>
			0000 1011
		</td>
		<td>
			No operation, clears IDIM flag as side effect
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			PUSHSPADD
		</td>
		<td>
			61
		</td>
		<td>
            a=sp; <br>
            b=popIntStack()*4;<br>
            pushIntStack(a+b);<br>
		</td>
		<td>
			Fix!
		</td>
	</tr>
	
	<tr>
		<td>
			POPPCREL
		</td>
		<td>
			57
		</td>
		<td>
			setPc(popIntStack()+getPc());
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			SUB
		</td>
		<td>
			49
		</td>
		<td>
			int a=popIntStack();<br>
                            int b=popIntStack();<br>
                            pushIntStack(b-a);<br>
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			XOR
		</td>
		<td>
			50
		</td>
		<td>
pushIntStack(popIntStack() ^ popIntStack());
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			LOADB
		</td>
		<td>
			51
		</td>
		<td>
			pushIntStack(cpuReadByte(popIntStack())&0xff);
		</td>
		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			STOREB
		</td>
		<td>
			52
		</td>
		<td>
			addr = popIntStack();<br>
                            val = popIntStack();<br>
                            cpuWriteByte(addr, val);
</td>
		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			LOADH
		</td>
		<td>
			34
		</td>
		<td>
			pushIntStack(cpuReadWord(popIntStack()));
		</td>
		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			STOREH
		</td>
		<td>
			35
		</td>
		<td>
addr = popIntStack();<br>
                            val = popIntStack();<br>
                            cpuWriteWord(addr, val);
		</td>
		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			LESSTHAN
		</td>
		<td>
			36
		</td>
		<td>
		Signed comparison<br>
                            a = popIntStack();<br>
                            b = popIntStack();<br>
                            pushIntStack((a < b) ? 1 : 0);<br>
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			LESSTHANOREQUAL
		</td>
		<td>
			37
		</td>
		<td>
		Signed comparison<br>
 a = popIntStack();<br>
                            b = popIntStack();<br>
                            pushIntStack((a <= b) ? 1 : 0);
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			ULESSTHAN
		</td>
		<td>
			37
		</td>
		<td>
		Unsigned comparison<br>
                            long a;//long is here 64 bit signed integer<br>
                            long b;<br>
                            a = ((long) popIntStack()) & INTMASK; // INTMASK is unsigned 0x00000000ffffffff<br>
                            b = ((long) popIntStack()) & INTMASK;<br>
                            pushIntStack((a < b) ? 1 : 0);
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			ULESSTHANOREQUAL
		</td>
		<td>
			39
		</td>
		<td>
		Unsigned comparison<br>
                            long a;//long is here 64 bit signed integer<br>
                            long b;<br>
                            a = ((long) popIntStack()) & INTMASK; // INTMASK is unsigned 0x00000000ffffffff<br>
                            b = ((long) popIntStack()) & INTMASK;<br>
                            pushIntStack((a <= b) ? 1 : 0);
		</td>
		<td>
			Fix!
		</td>
	</tr>
	<tr>
		<td>
			EQBRANCH
		</td>
		<td>
			55
		</td>
		<td>
                            int compare;<br>
                            int target;<br>
                            target = popIntStack() + pc;<br>
                            compare = popIntStack();<br>
                            if (compare == 0)<br>
                            {<br>
                                setPc(target);<br>
                            } else<br>
                            {<br>
                                setPc(pc + 1);<br>
                            }
		</td>
		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			 NEQBRANCH
		</td>
		<td>
			56
		</td>
		<td>
                            int compare;<br>
                            int target;<br>
                            target = popIntStack() + pc;<br>
                            compare = popIntStack();<br>
                            if (compare != 0)<br>
                            {<br>
                                setPc(target);<br>
                            } else<br>
                            {<br>
                                setPc(pc + 1);<br>
                            }<br>
		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			 MULT
		</td>
		<td>
			41
		</td>
		<td>
			Signed 32 bit multiply <br>
   			pushIntStack(popIntStack() * popIntStack());
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			 DIV
		</td>
		<td>
			53
		</td>
		<td>
		Signed 32 bit integer divide.<br>
                            a = popIntStack();<br>
                            b = popIntStack();<br>
                            if (b == 0)<br>
                            {<br>
                            	// undefined<br> 
                            }
                            pushIntStack(a / b);<br>
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			 MOD
		</td>
		<td>
			54
		</td>
		<td>
		Signed 32 bit integer modulo.<br>
                            a = popIntStack(); <br>
                            b = popIntStack();<br>
                            if (b == 0)<br>
                            {<br>
                            	// undefined <br> 
                            }<br>
                            pushIntStack(a % b); <br>
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			LSHIFTRIGHT	
		</td>
		<td>
			42
		</td>
		<td>
			unsigned shift right.<br>
	        long shift;<br>
	        long valX;<br>
	        int t;<br>
	        shift = ((long) popIntStack()) & INTMASK;<br>
	        valX = ((long) popIntStack()) & INTMASK;<br>
	        t = (int) (valX >> (shift & 0x3f));<br>
	        pushIntStack(t);<br>
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			ASHIFTLEFT	
		</td>
		<td>
			43
		</td>
		<td>
			arithmetic(signed) shift left.<br>
			
			 long shift;<br>
                            long valX;<br>
                            shift = ((long) popIntStack()) & INTMASK;<br>
                            valX = ((long) popIntStack()) & INTMASK;<br>
                            int t = (int) (valX << (shift & 0x3f));<br>
                            pushIntStack(t);<br>
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			ASHIFTRIGHT	
		</td>
		<td>
			43
		</td>
		<td>
		arithmetic(signed) shift left.<br>
                           long shift;<br>
                            int valX;<br>
                            shift = ((long) popIntStack()) & INTMASK;<br>
                            valX = popIntStack();<br>
                            int t = valX >> (shift & 0x3f);<br>
                            pushIntStack(t);<br>
 
   		</td>
		<td>
			Fix!
		</td>
	</tr>
    
   	<tr>
		<td>
			CALL
		</td>
		<td>
			45
		</td>
		<td>
			call procedure.<br>
			<br>
				int address = pop();<br>
                            push(pc + 1);<br>
                            setPc(address); <br>
   		</td>
		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			 CALLPCREL
		</td>
		<td>
			63
		</td>
		<td>
			call procedure pc relative<br>
			<br>
int address = pop();<br>
                            push(pc + 1);<br>
                            setPc(address+pc);   		</td>
		<td>
			Fix!
		</td>
	</tr>
    
    
  	<tr>
		<td>
			 EQ
		</td>
		<td>
			46
		</td>
		<td>
 pushIntStack((popIntStack() == popIntStack()) ? 1 : 0);		<td>
			Fix!
		</td>
	</tr>
  	<tr>
		<td>
			 NEQ
		</td>
		<td>
			48
		</td>
		<td>
 pushIntStack((popIntStack() != popIntStack()) ? 1 : 0);		<td>
			Fix!
		</td>
	</tr>
 	<tr>
		<td>
			 NEG
		</td>
		<td>
			47
		</td>
		<td>
 pushIntStack(-popIntStack());<td>
			Fix!
		</td>
	</tr>
    
	
</table>
	
<a name="implementing"/>
<h1>Implementing your own ZPU</h1>
One of the neat things about the ZPU is that the instruction set and architecture
is very small and it is easy to implement a ZPU from scratch or modify the
existing ZPU implementations.
<p>
Implementing a ZPU can be done without understanding the toolchain in
detail, i.e. using exclusively HDL skills and only a rudimentary
understanding of standard GCC/GDB usage is sufficient. 
<p>
A few tips:
<ul>
<li>Run zpu_core.vhd or zpu_core_small.vhd and generate an instruction trace
from ModelSim or similar. To check that you own implementation is correctly
implemented, verify that the instruction trace for the new and old
ZPU implementations match. This gives you a simple way to do regression
tests as you develop your ZPU.
<li>To improve performance, you can add more instructions. The EMULATE instructions
are optional in HDL since they will be emulated in software if they are not
implemented in HDL. This allows you to run the ZPU executables unmodified
regardless of which EMULATE instructions you implement.
<li>Run the DMIPS test to measure your overall performance 
<li>Run the histogram.perl script on the instruction trace to generate
histograms of the instructions. Profiling is essential to making
the right choices w.r.t. optimisation for your application. 
</ul>


<a name="vectors"/>
<h1>Vectors</h1>
<table border="1">
	<tr><td>Address</td><td>Name</td><td>Description</td></tr>
	<tr>
		<td>0x000</td>
		<td>Reset</td>
		<td>
			1.When the ZPU boots, this is the first instruction to be executed.
			<p>
			2.The stack pointer is initialised to maximum RAM address
			</td>
	</tr>
	<tr>
		<td>0x020</td>
		<td>Interrupt</td>
		<td>
			This is the entry point for interrupts.
		</td>
	</tr>
	<tr>
		<td>0x040-</td>
		<td>Emulated instructions</td>
		<td>
			Emulated opcode 34. Note that opcode 32 and opcode 33 are not normally used to emulate instructions as these memory addresses are already used by boot vector, GCC registers and the interrupt vector.
		</td>
	</tr>
</table>

<a name="memorymap"/>
<h1>Phi memory map</h1>
The ZPU architecture does not define a memory map as such, but the GCC + libgloss + ecos hal library uses the
memory map below.
<p>
	<TABLE WIDTH=604 BORDER=1 BORDERCOLOR="#000000" CELLPADDING=7 CELLSPACING=0 STYLE="page-break-after: avoid">
		<COL WIDTH=85>
		<COL WIDTH=42>
		<COL WIDTH=136>
		<COL WIDTH=283>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2><B>Address</B></FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2><B>Type</B></FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2><B>Name</B></FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2><B>Description</B></FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0000</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">ZPU
				enable</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:1] Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]	Enable ZPU operations</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	ZPU
				is held in Idle mode</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	ZPU
				running</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A000C</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read/</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">ZPU
				UART to ARM7 TX</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>NOTE!
				ZPU side</B></FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:9] Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[8]	TX buffer ready (valid on ready)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	TX
				buffer not ready (full)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	TX
				buffer ready</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[7:0]	TX byte (valid on write)</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0010</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">ZPU
				UART to ARM7 RX</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>NOTE!
				ZPU side</B></FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:9] Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[8]	RX buffer data valid</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	TX
				buffer not valid</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	TX
				buffer valid</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[7:0]	RX byte (when valid)</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0014</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read/</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Counter(1)</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]	Reset counter (valid for write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	N/A</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Reset
				counter</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[1]	Sample counter (valid for write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	N/A</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Sample
				counter</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:0]		Counter bit 31:0</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0018</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Counter(2)</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:0]		Counter bit 63:32</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0020</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read
				/ Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Global_Interrupt_mask</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:1]		Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		Global intr. Mask</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	Interrupts
				enabled</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupts
				disabled</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0024</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">UART_INTERRUPT_ENABLE</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:1]		Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		UART RX interrupt enable</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	Interrupt
				disable</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				enable</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0028</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">UART_interrupt</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:1]		Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		UART RX interrupt pending (Read)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	No
				interrupt pending</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				pending</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		Clear UART interrupt (Write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	N/A</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				cleared</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A002C</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Timer_Interrupt_enable</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:1]		Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		Timer interrupt  enable</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	Interrupt
				disable</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				enable</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0030</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read
				/</FONT></FONT></P>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Timer_interrupt</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:2]		Not used</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		Timer interrupt pending (Read)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	No
				interrupt pending</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				pending</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[1]		Reset Timer counter (Write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	N/A</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Timer
				counter reset</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[0]		Clear Timer interrupt (Write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	0	N/A</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">	1	Interrupt
				cleared</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">0x080A0034</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Write</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Timer_Period</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:0]		Interrupt period (write)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">		Number
				of clock cycles</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">		between
				timer interrupts</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>NOTE!
				</B>The timer will start at Timer_Periode value and count <B>down</B>
				to zero, and generate an interrupt</FONT></FONT></P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">.0x080A0038</FONT></FONT></P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Read</FONT></FONT></P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Timer_Counter</FONT></FONT></P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt">Bit
				[31:0]		Timer counter (read)</FONT></FONT></P>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=85>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
			<TD WIDTH=42>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=136>
				<P LANG="en-US" CLASS="western" ALIGN=CENTER><BR>
				</P>
			</TD>
			<TD WIDTH=283>
				<P LANG="en-US" CLASS="western"><BR>
				</P>
			</TD>
		</TR>
	</TABLE>
<a name="interrupts"/>
<h1>Interrupts</h1>
The ZPU supports interrupts.
<p>
To trigger an interrupt, the interrupt signal must be asserted. The ZPU does
not define any interrupt disabling mechanism, this must be implemented by the
interrupt controller and controlled via memory mapped IO.
<p>
Interrupts are masked when the IDIM flag is set, i.e.
with consequtive IM instructions.
<p>
The ZPU has an edge triggered interrupt. As the ZPU notices that the interrupt
is asserted, it will execute the interrupt instruction. The interrupt signal
must stay asserted until the ZPU acknowledges it. 
<p>
When the interrupt instruction is executed, the PC will be pushed onto the
stack and the PC will be set to the interrupt vector address (0x20).
<p>
Note that the GCC compiler requires three registers r0,r1,r2,r3 for some
rather uncommon operations. These 32 registers are mapped to memory locations 0x0,
0x4, 0x8, 0xc.  The default interrupt vector at address 0x20 will load the
value of these memory locations onto the stack, call _zpu_interrupt and
restore them.
<p>
See zpu/hdl/zpu4/test/interrupt/ for C code and zpu/hdl/example/simzpu_interrupt.do
for simulation example.
<a name="zpu_core_small.vhd"/>
<h1>About zpu_core_small.vhd</h1>
The small ZPU implements the minimum instruction set. It is optimized for size and simplicity
serving as a reference in both regards.
<p>
It uses a BRAM (dual port RAM w/read/write to both ports) as data & code storage and
is implemented as a simple state machine. 
<p>
Essentially it has three states:
<ol>
<li>Fetch - starts fetch of next instruction
<li>FetchNext - sets up operands for execute cycle
<li>Decode - decodes instruction
<li>Execute - well.. executes instruction
</ol>
The tricky bit is that there is a tiny bit of interleaving of
states since the BRAM takes a cycle to perform a fetch/store. The above is the
normal states the ZPU cycles through unless memory fetch, jumps, etc. take
place.
<a name="zpu_core.vhd"/>
<h1>About zpu_core.vhd</h1>
The zpu_core.vhd has a single port memory interface. All data, code and IO is
accessed through this memory interface.
<p>
It performs better(despite having less memory bandwidth than zpu_core_small.vhd)
since it implements many more instructions.


<a name="nextgen"/>
<h1>Next generation ZPU</h1>
Based on feedback here is a list of a tenuous "consensus" for the next generation
of the ZPU with some tentative ideas on implementation.
<p>
The plan is to update zpu_core.vhd and zpu_core_small.vhd as examples/reference,
and to open up for innovation in the HDL implementation.

<ol>
<li>Reduce minimum code size footprint
<ol>
<li>Modify GCC compiler to be able to emit function calls instead of instructions.
E.g instead of issuing MULT, generate function call. This reduces code size overhead
for applications that do not use MULT since the microcode does not need to be in place.
<li>Add single entry for unknown instructions. PC and unsupported instruction is
pushed onto stack before jumping to unkonwn instruction vector. This makes it possible
to write denser microcode for missing instructions.
</ol>
<li>Add floating point add and mult. FADD & FMULT. Option to generate the instructions
from the compiler.
<li>Add some scheme to support custom instructions.
<li>Add support to Zylin Embedded CDT for downloading fully functional ZPU
toolchain. The goal is to allow new users to write and simulate simple ZPU
programs in in less than an hour.
</ol>

</body>
<html>
OpenPOWER on IntegriCloud