-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtep.nsl
executable file
·353 lines (326 loc) · 7.53 KB
/
tep.nsl
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
/****************************************************************************
Tokai Embedded Processor 16 (TEP16)
****************************************************************************/
#include "tep.h"
#define Itype opreg[15] == 0b0
#define Rtype opreg[15:14] == 0b10
#define RStype opreg[15:14] == 0b11
/* I type */
#define CNST opreg[14:8] == 0b0000000
#define LD1 opreg[14:8] == 0b0000001
#define LD2 opreg[14:8] == 0b0000010
#define ST1 opreg[14:8] == 0b0000011
#define ST2 opreg[14:8] == 0b0000100
#define JUMP opreg[14:8] == 0b0000101
#define CALL opreg[14:8] == 0b0000110
#define JEQ opreg[14:8] == 0b0000111
#define JGEI opreg[14:8] == 0b0001000
#define JGEU opreg[14:8] == 0b0001001
#define JGTI opreg[14:8] == 0b0001010
#define JGTU opreg[14:8] == 0b0001011
#define JLEI opreg[14:8] == 0b0001100
#define JLEU opreg[14:8] == 0b0001101
#define JLTI opreg[14:8] == 0b0001110
#define JLTU opreg[14:8] == 0b0001111
#define JNE opreg[14:8] == 0b0010000
/* R type */
#define MUL opreg[13:8] == 0b000000
#define CVI2 opreg[13:8] == 0b000001
#define ADD opreg[13:8] == 0b000010
#define SUB opreg[13:8] == 0b000011
#define NEG opreg[13:8] == 0b000100
#define BAND opreg[13:8] == 0b000101
#define BOR opreg[13:8] == 0b000110
#define BXOR opreg[13:8] == 0b000111
#define BCOM opreg[13:8] == 0b001000
#define DINT opreg[13:8] == 0b101001
#define EINT opreg[13:8] == 0b101010
#define RINT opreg[13:8] == 0b101011
/* RS type */
#define LSHL opreg[13:12] == 0b00
#define RSHA opreg[13:12] == 0b01
#define RSHL opreg[13:12] == 0b10
#define HLT opreg[13:12] == 0b11
#define dR1 opreg[3:0]
#define dR2 opreg[7:4]
#define dRSI opreg[11:8] //RSのI
#define BYTESZ 0b0 //メモリで使用
#define WORDSZ 0b1 //メモリで使用
#define int_a 0x6800 //割り込み先番地(固定番地)0800に仮決定
#define start_pc 0x0000 //スタートPC
#define int_f interrupt_f
module tep {
reg pc[16]=0;
reg interrupt_a=0,interrupt_b=0; //interruptの状態確認用レジスタ
reg interrupt_f=0; //interrupt_fは割り込みフラグ(初期状態でOFF)
inc16 inc ;
alu16 alu;
reg16 rf;
reg opreg[16], mar[16], regnum[4], size, I[16];
wire mdata[16], nxpc[16], ex_result[16], A[16], B[16];
proc_name ifetch (pc) ;
proc_name exec (opreg) ;
proc_name exec2 (I) ;
proc_name tstore(mar, regnum, size, pc);
proc_name tload(mar, regnum, size, pc);
{
interrupt_a := int_signal;//割り込みレジスタaは割り込み信号後に変化する。
interrupt_b := interrupt_a;//割り込みレジスタbは割り込みレジスタa後に変化する。(割り込み信号入力後)
}
func start ifetch(start_pc); //スタートアップ開始
proc ifetch {
any{
(int_f & interrupt_b): { //割り込み開始
memory_write(0xfe02,pc);
int_f := 0b0 ; //割り込み開始後の割り込みを禁止
ifetch(int_a); //割り込み先の番地に移動
}
else: { //通常動作
nxpc = {inc.do({0b0, pc[15:1]}).out[14:0], 0b0};
memory_read(pc); //命令読み出し
if(memory_ack) {
exec(datai);
pc := nxpc;
}
}
}
}
proc exec { //Rタイプ、RSタイプ実行、Iタイプは次のpcに飛ぶ
{
any {
Itype: {
memory_read(pc); //命令読み出し
if(memory_ack) {
exec2(datai);
}
}
Rtype: any{
RINT: {
wb();
memory_read(0xfe02);
ifetch(datai);
}else: {
A = rf.ra(dR1).porta;
B = rf.rb(dR2).portb;
wb(); ifetch(pc);
any{
ADD: rf.wt(dR1, alu.do_add(A,B).out);
MUL: rf.wt(dR1, alu.do_mul(A,B).out);
CVI2: rf.wt(dR1, alu.do_cvi(B).out);
SUB: rf.wt(dR1, alu.do_sub(A,B).out);
NEG: rf.wt(dR1, alu.do_neg(B).out);
BAND: rf.wt(dR1, alu.do_and(A,B).out);
BOR: rf.wt(dR1, alu.do_bor(A,B).out);
BXOR: rf.wt(dR1, alu.do_bxor(A,B).out);
BCOM: rf.wt(dR1, alu.do_bcom(B).out);
DINT:int_f := 0b0;
EINT:int_f := 0b1;
}
}
} //Rtype 終了
RStype:{
B = rf.rb(dR2).portb;
any {
HLT: finish;
else: ifetch(pc);
}
wb();
any {
LSHL: rf.wt(dR1,alu.do_lshl(B,{0x000,dRSI}).out);
RSHA: rf.wt(dR1,alu.do_rsha(B,{0x000,dRSI}).out);
RSHL: rf.wt(dR1,alu.do_rshl(B,{0x000,dRSI}).out);
HLT: hlt();
}
} //RSタイプ終了
}
} //nxpcの並列処理部終了
} //proc execの終了
proc exec2 { //Iタイプ実行用ステージ
{
nxpc = {inc.do({0b0, pc[15:1]}).out[14:0], 0b0};
A = rf.ra(dR1).porta;
B = rf.rb(dR2).portb;
any {
Itype:
{
wb();
any{
CNST:{
ifetch(nxpc);
rf.wt(dR1,alu.do_add(I,B).out);
}
// task tload(mar, regnum, size, pc);
LD1: tload(alu.do_add(I,B).out, dR1, BYTESZ, nxpc);
LD2: tload(alu.do_add(I,B).out, dR1, WORDSZ, nxpc);
ST1: tstore(alu.do_add(I,B).out, dR1, BYTESZ, nxpc);
ST2: tstore(alu.do_add(I,B).out, dR1, WORDSZ, nxpc);
JUMP: ifetch(alu.do_add(I,B).out);
CALL: {
ifetch(alu.do_add(I,B).out);
rf.wt(dR1,nxpc);
}
JEQ: {
alu.do_sub(A,B);
any{
alu.z : ifetch(I);
else: ifetch(nxpc);
}
}
JGEI: {
alu.do_sub(A,B);
any{
~(alu.of ^ alu.out[15]) : ifetch(I);
else: ifetch(nxpc);
}
}
JGEU:{
alu.do_sub(A,B);
any{//A]=B
alu.co :ifetch(I);
else:ifetch(nxpc);
}
}
JGTI: {
alu.do_sub(A,B);
any{
~alu.z & ~(alu.of ^ alu.out[15]) : ifetch(I);
else: ifetch(nxpc);
}
}
JGTU:{
alu.do_sub(A,B);
any {
alu.co&~alu.z:ifetch(I);
else:ifetch(nxpc);
}
}
JLEI: {
alu.do_sub(A,B);
any{
~alu.z & ~(alu.of ^ alu.out[15]) : ifetch(nxpc);
else: ifetch(I);
}
}
JLEU:{
alu.do_sub(A,B);
any{
alu.co&~alu.z:ifetch(nxpc);
else:ifetch(I);
}
}
JLTI: {
alu.do_sub(A,B);
any{
~(alu.of ^ alu.out[15]): ifetch(nxpc);
else: ifetch(I);
}
}
JLTU:{
alu.do_sub(A,B);
any{//A]=B
alu.co :ifetch(nxpc);
else: ifetch(I);
}
}
JNE:{
alu.do_sub(A,B);
any{
alu.z: ifetch(nxpc);
else: ifetch(I);
}
}
}
}
}
}
}
proc tstore {
mdata = rf.ra(regnum).porta;
any {
mar[0]: {
ube();
memory_write(mar, {mdata[7:0], 0x00});
}
~mar[0]: {
any {
size==WORDSZ: {
ube();
lbe();
}
else: lbe();
}
memory_write(mar, mdata);
}
}
if(memory_ack) {ifetch(pc);}
}
proc tload {
memory_read(mar);
any {
mar[0] & (size==BYTESZ): {
ube();
mdata = {0x00, datai[15:8]};
}
~mar[0] & (size==BYTESZ): {
lbe();
mdata = {0x00, datai[7:0]};
}
size==WORDSZ: {
mdata=datai;
ube();
lbe();
}
}
if(memory_ack) {
rf.wt(regnum,mdata);
ifetch(pc);
}
}
}
module inc16 {
func do out = in + 0x0001;
}
module cla16 {
wire tmp[17], t1[15],t2[15], to[16];
func do {
t1 = in1[14:0];
t2 = in2[14:0];
to = {0b0, t1} + {0b0, t2} + {15#0b0, cin};
tmp = {({0b0, in1[15]} + {0b0, in2[15]} + {0b0, to[15]}), to[14:0]};
out = tmp[15:0];
co = tmp[16];
of = tmp[16]^to[15];
}
}
module reg16 {
mem r[16][16];
func wt r[wtreg] := regin;
func ra any {
portareg == 0x0: porta = 0x0000;
else: porta = r[portareg];
}
func rb any {
portbreg == 0x0: portb = 0x0000;
else: portb = r[portbreg];
}
}
module alu16 {
wire a32[32];
cla16 cla;
z = (out == 0x0000);
func do_add {out = cla.do(0b0, a, b).out; co=cla.co; of=cla.of;}
func do_and out = a & b;
func do_bcom out = ~b;
func do_cvi out = 16#b[7:0];
func do_sub {out = cla.do(0b1, a, ~b).out; co=cla.co; of=cla.of;}
func do_neg out = -b;
func do_bor out = a | b;
func do_bxor out = a ^ b;
func do_lshl out = b << a;
func do_rshl out = b >> a;
func do_rsha {
a32=32#b;
out=(a32>>a)[15:0];
}
func do_mul out = a[7:0] * b[7:0];
}