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
|
|
|
|
1 |
+
#include <systemc.h>
|
2 |
+
|
3 |
+
SC_MODULE (hello) { // module named hello
|
4 |
+
SC_CTOR (hello) { //constructor phase, which is empty in this case
|
5 |
+
}
|
6 |
+
|
7 |
+
void say_hello() {
|
8 |
+
std::cout << "Hello World!" << std::endl;
|
9 |
+
}
|
10 |
+
};
|
11 |
+
|
12 |
+
int sc_main(int argc, char* argv[]) {
|
13 |
+
hello h("hello");
|
14 |
+
h.say_hello();
|
15 |
+
return 0;
|
16 |
+
}
|
17 |
+
|
18 |
+
/*
|
19 |
+
* @ASCK
|
20 |
+
*/
|
21 |
+
|
22 |
+
#include <systemc.h>
|
23 |
+
|
24 |
+
SC_MODULE (ALU) {
|
25 |
+
|
26 |
+
sc_in <sc_int<8>> in1; // A
|
27 |
+
sc_in <sc_int<8>> in2; // B
|
28 |
+
sc_in <bool> c; // Carry Out // in this project, this signal is always 1
|
29 |
+
|
30 |
+
// ALUOP // has 5 bits by merging: opselect (4bits) and first LSB bit of opcode (1bit)
|
31 |
+
sc_in <sc_uint<5>> aluop;
|
32 |
+
sc_in <sc_uint<3>> sa; // Shift Amount
|
33 |
+
|
34 |
+
sc_out <sc_int<8>> out; // Output
|
35 |
+
|
36 |
+
/*
|
37 |
+
** module global variables
|
38 |
+
*/
|
39 |
+
|
40 |
+
//
|
41 |
+
|
42 |
+
SC_CTOR (ALU){
|
43 |
+
SC_METHOD (process);
|
44 |
+
sensitive << in1 << in2 << aluop;
|
45 |
+
}
|
46 |
+
|
47 |
+
void process () {
|
48 |
+
|
49 |
+
sc_int<8> a = in1.read();
|
50 |
+
sc_int<8> b = in2.read();
|
51 |
+
bool cin = c.read();
|
52 |
+
sc_uint<5> op = aluop.read();
|
53 |
+
sc_uint<3> sh = sa.read();
|
54 |
+
|
55 |
+
switch (op){
|
56 |
+
case 0b00000 :
|
57 |
+
out.write(a);
|
58 |
+
break;
|
59 |
+
case 0b00001 :
|
60 |
+
out.write(++a);
|
61 |
+
break;
|
62 |
+
case 0b00010 :
|
63 |
+
out.write(a+b);
|
64 |
+
break;
|
65 |
+
case 0b00011 :
|
66 |
+
out.write(a+b+cin);
|
67 |
+
break;
|
68 |
+
case 0b00100 :
|
69 |
+
out.write(a-b);
|
70 |
+
break;
|
71 |
+
case 0b00101 :
|
72 |
+
out.write(a-b-cin);
|
73 |
+
break;
|
74 |
+
case 0b00110 :
|
75 |
+
out.write(--a);
|
76 |
+
break;
|
77 |
+
case 0b00111 :
|
78 |
+
out.write(b);
|
79 |
+
break;
|
80 |
+
case 0b01000 :
|
81 |
+
case 0b01001 :
|
82 |
+
out.write(a&b);
|
83 |
+
break;
|
84 |
+
case 0b01010 :
|
85 |
+
case 0b01011 :
|
86 |
+
out.write(a|b);
|
87 |
+
break;
|
88 |
+
case 0b01100 :
|
89 |
+
case 0b01101 :
|
90 |
+
out.write(a^b);
|
91 |
+
break;
|
92 |
+
case 0b01110 :
|
93 |
+
case 0b01111 :
|
94 |
+
out.write(~a);
|
95 |
+
break;
|
96 |
+
case 0b10000 :
|
97 |
+
case 0b10001 :
|
98 |
+
case 0b10010 :
|
99 |
+
case 0b10011 :
|
100 |
+
case 0b10100 :
|
101 |
+
case 0b10101 :
|
102 |
+
case 0b10110 :
|
103 |
+
case 0b10111 :
|
104 |
+
out.write(a>>sh);
|
105 |
+
break;
|
106 |
+
default:
|
107 |
+
out.write(a<<sh);
|
108 |
+
break;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
};
|
114 |
+
/*
|
115 |
+
* @ASCK
|
116 |
+
*/
|
117 |
+
|
118 |
+
#include <systemc.h>
|
119 |
+
|
120 |
+
SC_MODULE (Acc) {
|
121 |
+
|
122 |
+
|
123 |
+
sc_in <sc_int<8>> mem_data;
|
124 |
+
sc_in <bool> call;
|
125 |
+
|
126 |
+
sc_out <bool> read, write;
|
127 |
+
sc_out <sc_uint<13>> addr;
|
128 |
+
sc_out <sc_int<8>> data;
|
129 |
+
|
130 |
+
/*
|
131 |
+
** module global variables
|
132 |
+
*/
|
133 |
+
|
134 |
+
|
135 |
+
SC_CTOR (Acc){
|
136 |
+
SC_THREAD (process);
|
137 |
+
sensitive << call;
|
138 |
+
}
|
139 |
+
|
140 |
+
void process () {
|
141 |
+
while(true){
|
142 |
+
wait();
|
143 |
+
if(call.read()==1){
|
144 |
+
std::cout << "@@-_.|*^<!! STARTING ACCELERATOR !!>^*|._-@@" << endl;
|
145 |
+
operation();
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
void operation () {
|
151 |
+
// store value 10 to address 11
|
152 |
+
write_to_mem (11, 10);
|
153 |
+
|
154 |
+
// read from address 5 of memory : data=7 (this data has already stored by micro processor)
|
155 |
+
sc_int<8> a = read_from_mem(5);
|
156 |
+
|
157 |
+
// read from address 11 of memory : data=10
|
158 |
+
sc_int<8> b = read_from_mem(11);
|
159 |
+
|
160 |
+
// a + b
|
161 |
+
sc_int<8> c = a+b;
|
162 |
+
|
163 |
+
// store c to address 20 of memory
|
164 |
+
write_to_mem (20, c);
|
165 |
+
|
166 |
+
|
167 |
+
// end the acc task and begin the micro task
|
168 |
+
micro_notif();
|
169 |
+
}
|
170 |
+
|
171 |
+
/*
|
172 |
+
** notify micro processor that accelerator job is done and return back to the micro processor job
|
173 |
+
*/
|
174 |
+
void micro_notif (){
|
175 |
+
micro_acc_ev.notify();
|
176 |
+
now_is_call = false;
|
177 |
+
}
|
178 |
+
|
179 |
+
// read from memory
|
180 |
+
sc_int<8> read_from_mem (int ad) {
|
181 |
+
read.write(1);
|
182 |
+
write.write(0);
|
183 |
+
addr.write(ad);
|
184 |
+
|
185 |
+
wait(acc_mem_read_ev);
|
186 |
+
|
187 |
+
no_read_write();
|
188 |
+
wait(10, SC_NS);
|
189 |
+
|
190 |
+
return mem_data.read();
|
191 |
+
}
|
192 |
+
|
193 |
+
// write to memory
|
194 |
+
void write_to_mem (int ad, int dt) {
|
195 |
+
read.write(0);
|
196 |
+
write.write(1);
|
197 |
+
addr.write(ad);
|
198 |
+
data.write(dt);
|
199 |
+
|
200 |
+
wait(acc_mem_write_ev);
|
201 |
+
|
202 |
+
no_read_write();
|
203 |
+
wait(1, SC_NS);
|
204 |
+
}
|
205 |
+
|
206 |
+
// change the read and write signals not to read and not to write
|
207 |
+
void no_read_write () {
|
208 |
+
read.write(0);
|
209 |
+
write.write(0);
|
210 |
+
}
|
211 |
+
|
212 |
+
};
|
213 |
+
/*
|
214 |
+
* @ASCK
|
215 |
+
*/
|
216 |
+
|
217 |
+
#include <systemc.h>
|
218 |
+
|
219 |
+
SC_MODULE (Bus) {
|
220 |
+
|
221 |
+
|
222 |
+
sc_in_clk clk;
|
223 |
+
sc_in <bool> req; // X DIDN'T USED! X
|
224 |
+
sc_in <bool> read;
|
225 |
+
sc_in <bool> write;
|
226 |
+
sc_in <bool> call;
|
227 |
+
sc_in <sc_uint<13>> addr; // for both Mem. and Acc.
|
228 |
+
sc_in <sc_int<8>> data;
|
229 |
+
|
230 |
+
sc_out <bool> ack; // X DIDN'T USED! X
|
231 |
+
sc_out <bool> read_out;
|
232 |
+
sc_out <bool> write_out;
|
233 |
+
sc_out <bool> call_out;
|
234 |
+
sc_out <sc_uint<13>> addr_out; // for both Mem. and Acc.
|
235 |
+
sc_out <sc_int<8>> data_out;
|
236 |
+
|
237 |
+
/*
|
238 |
+
** module global variables
|
239 |
+
*/
|
240 |
+
|
241 |
+
SC_CTOR (Bus){
|
242 |
+
SC_METHOD (process);
|
243 |
+
sensitive << clk.pos();
|
244 |
+
}
|
245 |
+
|
246 |
+
void process () {
|
247 |
+
ack.write(req.read());
|
248 |
+
read_out.write(read.read());
|
249 |
+
write_out.write(write.read());
|
250 |
+
call_out.write(call.read());
|
251 |
+
addr_out.write(addr.read());
|
252 |
+
data_out.write(data.read());
|
253 |
+
}
|
254 |
+
|
255 |
+
|
256 |
+
};
|
257 |
+
/*
|
258 |
+
* @ASCK
|
259 |
+
*/
|
260 |
+
|
261 |
+
#include <systemc.h>
|
262 |
+
|
263 |
+
SC_MODULE (Controller) {
|
264 |
+
|
265 |
+
sc_in <sc_uint<4>> opcode, opselect;
|
266 |
+
|
267 |
+
sc_out <sc_uint<5>> aluOp;
|
268 |
+
sc_out <bool> regWrite, r, w, aluMux, regMux, wbMux, call;
|
269 |
+
|
270 |
+
|
271 |
+
/*
|
272 |
+
** module global variables
|
273 |
+
*/
|
274 |
+
|
275 |
+
sc_uint<4> opcd, opsel;
|
276 |
+
sc_uint<5> op;
|
277 |
+
|
278 |
+
//tmp
|
279 |
+
int c = 0;
|
280 |
+
|
281 |
+
SC_CTOR (Controller){
|
282 |
+
SC_METHOD (process);
|
283 |
+
sensitive << opcode << opselect;
|
284 |
+
}
|
285 |
+
|
286 |
+
void process () {
|
287 |
+
opcd = opcode.read();
|
288 |
+
opsel = opselect.read();
|
289 |
+
|
290 |
+
switch (opcd){
|
291 |
+
case 0b0000:
|
292 |
+
case 0b0001:
|
293 |
+
op = opsel;
|
294 |
+
op = opsel << 1;
|
295 |
+
op[0] = opcd[0];
|
296 |
+
aluOp.write(op); // concatinated to produce aluop
|
297 |
+
regWrite.write(1);
|
298 |
+
r.write(0);
|
299 |
+
w.write(0);
|
300 |
+
regMux.write(0); // r1 = rs
|
301 |
+
aluMux.write(0); // B = Rr2
|
302 |
+
wbMux.write(0); // use alu result
|
303 |
+
call.write(0);
|
304 |
+
break;
|
305 |
+
|
306 |
+
/*
|
307 |
+
** Transfer Imm to the Register rd
|
308 |
+
*/
|
309 |
+
case 0b0010:
|
310 |
+
aluOp.write(0b00111); // transfer B (rd = Imm)
|
311 |
+
regWrite.write(1);
|
312 |
+
r.write(0);
|
313 |
+
w.write(0);
|
314 |
+
regMux.write(0);
|
315 |
+
aluMux.write(1); // B = imm
|
316 |
+
wbMux.write(0);
|
317 |
+
call.write(0);
|
318 |
+
break;
|
319 |
+
|
320 |
+
/*
|
321 |
+
** Add Imm with register rd content and move it to the Register rd
|
322 |
+
*/
|
323 |
+
case 0b0011:
|
324 |
+
aluOp.write(0b00100); // Add A and B (rd += Imm)
|
325 |
+
regWrite.write(1);
|
326 |
+
r.write(0);
|
327 |
+
w.write(0);
|
328 |
+
regMux.write(1);
|
329 |
+
aluMux.write(1);
|
330 |
+
wbMux.write(0);
|
331 |
+
call.write(0);
|
332 |
+
break;
|
333 |
+
|
334 |
+
/*
|
335 |
+
** LOAD from Imm address of memory to rd
|
336 |
+
*/
|
337 |
+
case 0b0100:
|
338 |
+
aluOp.write(0);
|
339 |
+
regWrite.write(1);
|
340 |
+
r.write(1);
|
341 |
+
w.write(0);
|
342 |
+
regMux.write(0);
|
343 |
+
aluMux.write(0);
|
344 |
+
wbMux.write(1); // use memory result
|
345 |
+
call.write(0);
|
346 |
+
break;
|
347 |
+
|
348 |
+
/*
|
349 |
+
** STORE rd content to imm address of memory
|
350 |
+
*/
|
351 |
+
case 0b0101:
|
352 |
+
aluOp.write(0); // transfer A
|
353 |
+
regWrite.write(0); // don't write back to register
|
354 |
+
r.write(0);
|
355 |
+
w.write(1);
|
356 |
+
regMux.write(1); // r1 = reg (rd)
|
357 |
+
aluMux.write(0); // ignorable!
|
358 |
+
wbMux.write(0); // ignorable!
|
359 |
+
call.write(0);
|
360 |
+
break;
|
361 |
+
|
362 |
+
/*
|
363 |
+
** NOP
|
364 |
+
*/
|
365 |
+
case 0b1111:
|
366 |
+
aluOp.write(0);
|
367 |
+
regWrite.write(0);
|
368 |
+
r.write(0);
|
369 |
+
w.write(0);
|
370 |
+
regMux.write(0);
|
371 |
+
aluMux.write(0);
|
372 |
+
wbMux.write(0);
|
373 |
+
call.write(0);
|
374 |
+
break;
|
375 |
+
|
376 |
+
/*
|
377 |
+
** CALL Acc.
|
378 |
+
*/
|
379 |
+
default:
|
380 |
+
regWrite.write(0); // don't write back to register
|
381 |
+
r.write(0);
|
382 |
+
w.write(0);
|
383 |
+
call.write(1);
|
384 |
+
break;
|
385 |
+
}
|
386 |
+
}
|
387 |
+
|
388 |
+
|
389 |
+
};
|
390 |
+
/*
|
391 |
+
* @ASCK
|
392 |
+
*/
|
393 |
+
|
394 |
+
#include <systemc.h>
|
395 |
+
|
396 |
+
SC_MODULE (EXE) {
|
397 |
+
|
398 |
+
sc_in_clk clk;
|
399 |
+
sc_in <sc_int<8>> prev_result;
|
400 |
+
sc_in <sc_int<13>> prev_Imm;
|
401 |
+
sc_in <bool> prev_r;
|
402 |
+
sc_in <bool> prev_w;
|
403 |
+
sc_in <bool> prev_WbMux;
|
404 |
+
sc_in <bool> prev_call;
|
405 |
+
sc_in <bool> prev_regWrite;
|
406 |
+
sc_in <sc_uint<3>> prev_rd;
|
407 |
+
|
408 |
+
sc_out <sc_int<8>> next_result;
|
409 |
+
sc_out <sc_int<13>> next_Imm;
|
410 |
+
sc_out <bool> next_r;
|
411 |
+
sc_out <bool> next_w;
|
412 |
+
sc_out <bool> next_WbMux;
|
413 |
+
sc_out <bool> next_call;
|
414 |
+
sc_out <bool> next_regWrite;
|
415 |
+
sc_out <sc_uint<3>> next_rd;
|
416 |
+
|
417 |
+
|
418 |
+
/*
|
419 |
+
** module global variables
|
420 |
+
*/
|
421 |
+
|
422 |
+
SC_CTOR (EXE){
|
423 |
+
SC_THREAD (process);
|
424 |
+
sensitive << clk.pos();
|
425 |
+
}
|
426 |
+
|
427 |
+
void process () {
|
428 |
+
while(true){
|
429 |
+
wait();
|
430 |
+
if(now_is_call){
|
431 |
+
wait(micro_acc_ev);
|
432 |
+
}
|
433 |
+
next_result.write(prev_result.read());
|
434 |
+
next_Imm.write(prev_Imm.read());
|
435 |
+
next_r.write(prev_r.read());
|
436 |
+
next_w.write(prev_w.read());
|
437 |
+
next_WbMux.write(prev_WbMux.read());
|
438 |
+
next_call.write(prev_call.read());
|
439 |
+
next_regWrite.write(prev_regWrite);
|
440 |
+
next_rd.write(prev_rd.read());
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
|
445 |
+
};
|
446 |
+
/*
|
447 |
+
* @ASCK
|
448 |
+
*/
|
449 |
+
|
450 |
+
#include <systemc.h>
|
451 |
+
|
452 |
+
SC_MODULE (ID) {
|
453 |
+
|
454 |
+
sc_in_clk clk;
|
455 |
+
sc_in <sc_int<8>> prev_A;
|
456 |
+
sc_in <sc_int<8>> prev_B;
|
457 |
+
sc_in <sc_int<13>> prev_Imm;
|
458 |
+
sc_in <sc_uint<3>> prev_Sa;
|
459 |
+
sc_in <sc_uint<5>> prev_AluOp;
|
460 |
+
sc_in <bool> prev_r;
|
461 |
+
sc_in <bool> prev_w;
|
462 |
+
sc_in <bool> prev_AluMux;
|
463 |
+
sc_in <bool> prev_WbMux;
|
464 |
+
sc_in <bool> prev_call;
|
465 |
+
sc_in <bool> prev_regWrite;
|
466 |
+
sc_in <sc_uint<3>> prev_rd;
|
467 |
+
|
468 |
+
sc_out <sc_int<8>> next_A;
|
469 |
+
sc_out <sc_int<8>> next_B;
|
470 |
+
sc_out <sc_int<13>> next_Imm;
|
471 |
+
sc_out <sc_uint<3>> next_Sa;
|
472 |
+
sc_out <sc_uint<5>> next_AluOp;
|
473 |
+
sc_out <bool> next_r;
|
474 |
+
sc_out <bool> next_w;
|
475 |
+
sc_out <bool> next_AluMux;
|
476 |
+
sc_out <bool> next_WbMux;
|
477 |
+
sc_out <bool> next_call;
|
478 |
+
sc_out <bool> next_regWrite;
|
479 |
+
sc_out <sc_uint<3>> next_rd;
|
480 |
+
|
481 |
+
|
482 |
+
/*
|
483 |
+
** module global variables
|
484 |
+
*/
|
485 |
+
|
486 |
+
SC_CTOR (ID){
|
487 |
+
SC_THREAD (process);
|
488 |
+
sensitive << clk.pos();
|
489 |
+
}
|
490 |
+
|
491 |
+
void process () {
|
492 |
+
while(true){
|
493 |
+
wait();
|
494 |
+
if(now_is_call){
|
495 |
+
wait(micro_acc_ev);
|
496 |
+
}
|
497 |
+
next_A.write(prev_A.read());
|
498 |
+
next_B.write(prev_B.read());
|
499 |
+
next_Imm.write(prev_Imm.read());
|
500 |
+
next_Sa.write(prev_Sa.read());
|
501 |
+
next_AluOp.write(prev_AluOp.read());
|
502 |
+
next_AluMux.write(prev_AluMux.read());
|
503 |
+
next_r.write(prev_r.read());
|
504 |
+
next_w.write(prev_w.read());
|
505 |
+
next_WbMux.write(prev_WbMux.read());
|
506 |
+
next_call.write(prev_call.read());
|
507 |
+
next_regWrite.write(prev_regWrite);
|
508 |
+
next_rd.write(prev_rd.read());
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
|
513 |
+
};
|
514 |
+
/*
|
515 |
+
* @ASCK
|
516 |
+
*/
|
517 |
+
|
518 |
+
#include <systemc.h>
|
519 |
+
|
520 |
+
SC_MODULE (IF) {
|
521 |
+
|
522 |
+
sc_in_clk clk;
|
523 |
+
sc_in <sc_uint<20>> prev_data;
|
524 |
+
|
525 |
+
sc_out <sc_uint<20>> next_data;
|
526 |
+
|
527 |
+
|
528 |
+
/*
|
529 |
+
** module global variables
|
530 |
+
*/
|
531 |
+
|
532 |
+
SC_CTOR (IF){
|
533 |
+
SC_THREAD (process);
|
534 |
+
sensitive << clk.pos();
|
535 |
+
}
|
536 |
+
|
537 |
+
void process () {
|
538 |
+
while(true){
|
539 |
+
wait();
|
540 |
+
if(now_is_call){
|
541 |
+
cout<<"\t\t\t\t*******************" << endl;
|
542 |
+
wait(micro_acc_ev);
|
543 |
+
}
|
544 |
+
next_data.write(prev_data.read());
|
545 |
+
}
|
546 |
+
}
|
547 |
+
|
548 |
+
|
549 |
+
};
|
550 |
+
/*
|
551 |
+
* @ASCK
|
552 |
+
*/
|
553 |
+
|
554 |
+
#include <systemc.h>
|
555 |
+
|
556 |
+
SC_MODULE (IR) {
|
557 |
+
|
558 |
+
sc_in <sc_uint<14>> addr;
|
559 |
+
sc_out <sc_uint<20>> inst;
|
560 |
+
|
561 |
+
|
562 |
+
/*
|
563 |
+
** module global variables
|
564 |
+
*/
|
565 |
+
|
566 |
+
sc_uint<20> mem[819]; // 819 rows and 819*20=16380 bits = (16KB - 4bits) ~= 16KB
|
567 |
+
|
568 |
+
int instNum = 50;
|
569 |
+
sc_uint<20> instruction[50] = {
|
570 |
+
// 0b01234567890123456789
|
571 |
+
0b00000000000000000000,
|
572 |
+
0b00100000000000000111, // transfer (r0 <- 7): 7
|
573 |
+
0b00010010010000000000, // inc (r1++): 1
|
574 |
+
|
575 |
+
//stall for achieving the correct register data - sub
|
576 |
+
0b11110000000000000000, //stall
|
577 |
+
0b11110000000000000000, //stall
|
578 |
+
0b11110000000000000000, //stall
|
579 |
+
|
580 |
+
0b00000110000010000010, // sub (r3 <-r0 - r1): 6
|
581 |
+
|
582 |
+
0b11110000000000000000, //stall
|
583 |
+
0b11110000000000000000, //stall
|
584 |
+
0b11110000000000000000, //stall
|
585 |
+
|
586 |
+
0b00011000110010000001, // addc (r4 <- r3 + r1 + 1): 8
|
587 |
+
|
588 |
+
0b11110000000000000000, //stall
|
589 |
+
0b11110000000000000000, //stall
|
590 |
+
0b11110000000000000000, //stall
|
591 |
+
|
592 |
+
0b00001001000000101001, // shiftR (r4 >> 2): 2
|
593 |
+
|
594 |
+
0b01010000000000000101, // stroe (mem[5] <= r0) : 7
|
595 |
+
0b01001010000000000101, // load (r5 <= mem[5]) : 7
|
596 |
+
|
597 |
+
0b01100000000000000000, // do accelerator
|
598 |
+
|
599 |
+
0b01000100000000010100, // load (r2 <= mem[20]) : 17 => 0x11
|
600 |
+
|
601 |
+
0b11110000000000000000, //nop
|
602 |
+
0b11110000000000000000, //nop
|
603 |
+
0b11110000000000000000, //nop
|
604 |
+
0b11110000000000000000, //nop
|
605 |
+
0b11110000000000000000, //nop
|
606 |
+
0b11110000000000000000 //nop
|
607 |
+
};
|
608 |
+
|
609 |
+
SC_CTOR (IR){
|
610 |
+
SC_METHOD (process);
|
611 |
+
sensitive << addr;
|
612 |
+
|
613 |
+
for(int i=0; i<instNum; i++){
|
614 |
+
mem[i] = instruction[i];
|
615 |
+
}
|
616 |
+
|
617 |
+
// filling out other rows with a nop opcode
|
618 |
+
for(int i=instNum; i<819; i++){
|
619 |
+
mem[i] = 0b11110000000000000000;
|
620 |
+
}
|
621 |
+
}
|
622 |
+
|
623 |
+
void process () {
|
624 |
+
if(addr.read() < 819){
|
625 |
+
inst.write(mem[addr.read()]);
|
626 |
+
}
|
627 |
+
else{
|
628 |
+
inst.write(0);
|
629 |
+
}
|
630 |
+
}
|
631 |
+
|
632 |
+
|
633 |
+
};
|
634 |
+
/*
|
635 |
+
* @ASCK
|
636 |
+
*/
|
637 |
+
|
638 |
+
#include <systemc.h>
|
639 |
+
|
640 |
+
SC_MODULE (Memory) {
|
641 |
+
|
642 |
+
sc_in <bool> r_nw;
|
643 |
+
sc_in <sc_uint<13>> addr;
|
644 |
+
sc_in <sc_int<8>> data;
|
645 |
+
|
646 |
+
sc_out <sc_int<8>> out;
|
647 |
+
|
648 |
+
/*
|
649 |
+
** module global variables
|
650 |
+
*/
|
651 |
+
|
652 |
+
sc_int<8> mem[8192] = {0}; // 2^13 rows
|
653 |
+
bool done = false;
|
654 |
+
|
655 |
+
SC_CTOR (Memory){
|
656 |
+
SC_METHOD (process);
|
657 |
+
sensitive << r_nw << addr << data;
|
658 |
+
|
659 |
+
}
|
660 |
+
|
661 |
+
void process () {
|
662 |
+
if(done){
|
663 |
+
return;
|
664 |
+
}
|
665 |
+
if(addr.read() < 8192){
|
666 |
+
if(r_nw.read()){
|
667 |
+
out.write(mem[addr.read()]);
|
668 |
+
}
|
669 |
+
else{
|
670 |
+
mem[addr.read()] = data.read();
|
671 |
+
out.write(mem[addr.read()]);
|
672 |
+
}
|
673 |
+
}
|
674 |
+
else{
|
675 |
+
out.write(0);
|
676 |
+
}
|
677 |
+
}
|
678 |
+
|
679 |
+
|
680 |
+
};
|
681 |
+
/*
|
682 |
+
* @ASCK
|
683 |
+
*/
|
684 |
+
|
685 |
+
#include <systemc.h>
|
686 |
+
#include <./PC.cpp>
|
687 |
+
#include <./IR.cpp>
|
688 |
+
#include <./IF.cpp>
|
689 |
+
#include <./Mux3.cpp>
|
690 |
+
#include <./Mux8.cpp>
|
691 |
+
#include <./RegFile.cpp>
|
692 |
+
#include <./Controller.cpp>
|
693 |
+
#include <./ID.cpp>
|
694 |
+
#include <./ALU.cpp>
|
695 |
+
#include <./EXE.cpp>
|
696 |
+
#include <./WB.cpp>
|
697 |
+
|
698 |
+
#include <bitset>
|
699 |
+
|
700 |
+
|
701 |
+
SC_MODULE (Micro) {
|
702 |
+
|
703 |
+
sc_in_clk clk;
|
704 |
+
|
705 |
+
sc_in <sc_int<8>> mem_data;
|
706 |
+
|
707 |
+
sc_out <bool> read, write, call;
|
708 |
+
sc_out <sc_uint<13>> addr;
|
709 |
+
sc_out <sc_int<8>> data;
|
710 |
+
|
711 |
+
// testing wires
|
712 |
+
sc_out <sc_uint<5>> test_aluOp;
|
713 |
+
sc_out <sc_uint<14>> test_pc;
|
714 |
+
sc_out <sc_uint<20>> test_inst;
|
715 |
+
sc_out <sc_int<8>> reg_dump[8];
|
716 |
+
// sc_out <bool> test_regWrite, test_r_nw, test_aluMux, test_regMux, test_wbMux, test_call;
|
717 |
+
|
718 |
+
|
719 |
+
/*
|
720 |
+
** module global variables
|
721 |
+
*/
|
722 |
+
|
723 |
+
/*
|
724 |
+
** SIGNALS
|
725 |
+
*/
|
726 |
+
// -----
|
727 |
+
sc_uint<14> tmp_pc_prev_addr;
|
728 |
+
sc_signal<sc_uint<14>> pc_prev_addr;
|
729 |
+
sc_signal<sc_uint<14>> pc_next_addr;
|
730 |
+
|
731 |
+
sc_signal <sc_uint<20>> ir_inst;
|
732 |
+
|
733 |
+
sc_signal <sc_uint<20>> if_next_data;
|
734 |
+
sc_signal <sc_uint<4>> opcode;
|
735 |
+
sc_signal <sc_uint<3>> rd;
|
736 |
+
sc_signal <sc_uint<3>> rs;
|
737 |
+
sc_signal <sc_uint<3>> rt;
|
738 |
+
sc_signal <sc_uint<3>> sa;
|
739 |
+
sc_signal <sc_uint<4>> opselect;
|
740 |
+
sc_uint<20> tmp;
|
741 |
+
sc_signal <sc_int<13>> offset;
|
742 |
+
|
743 |
+
// controller output signal
|
744 |
+
sc_signal <sc_uint<5>> aluOp;
|
745 |
+
sc_signal <bool> regWrite, r, w, aluMux, regMux, wbMux, acc_call;
|
746 |
+
|
747 |
+
sc_signal <sc_uint<3>> mux_reg_res;
|
748 |
+
|
749 |
+
/*
|
750 |
+
** Register File signals
|
751 |
+
*/
|
752 |
+
sc_signal <sc_int<8>> Rr1;
|
753 |
+
sc_signal <sc_int<8>> Rr2;
|
754 |
+
sc_signal <sc_int<8>> regs[8];
|
755 |
+
|
756 |
+
sc_signal <sc_int<8>> id_next_A;
|
757 |
+
sc_signal <sc_int<8>> id_next_B;
|
758 |
+
sc_signal <sc_int<13>> id_next_Imm;
|
759 |
+
sc_signal <sc_uint<3>> id_next_Sa;
|
760 |
+
sc_signal <sc_uint<5>> id_next_AluOp;
|
761 |
+
sc_signal <bool> id_next_r;
|
762 |
+
sc_signal <bool> id_next_w;
|
763 |
+
sc_signal <bool> id_next_AluMux;
|
764 |
+
sc_signal <bool> id_next_WbMux;
|
765 |
+
sc_signal <bool> id_next_call;
|
766 |
+
sc_signal <bool> id_next_regWrite;
|
767 |
+
sc_signal <sc_uint<3>> id_next_rd;
|
768 |
+
|
769 |
+
sc_signal <sc_int<8>> alu_in_B;
|
770 |
+
sc_signal <sc_int<8>> id_nex_imm_8bits;
|
771 |
+
|
772 |
+
sc_signal <sc_int<8>> alu_out;
|
773 |
+
sc_signal<bool> carry;
|
774 |
+
|
775 |
+
sc_signal <sc_int<8>> exe_next_result;
|
776 |
+
sc_signal <sc_int<13>> exe_next_Imm;
|
777 |
+
sc_signal <bool> exe_next_r;
|
778 |
+
sc_signal <bool> exe_next_w;
|
779 |
+
sc_signal <bool> exe_next_WbMux;
|
780 |
+
sc_signal <bool> exe_next_call;
|
781 |
+
sc_signal <bool> exe_next_regWrite;
|
782 |
+
sc_signal <sc_uint<3>> exe_next_rd;
|
783 |
+
|
784 |
+
sc_signal <sc_int<8>> wb_next_result;
|
785 |
+
sc_signal <sc_int<8>> wb_prev_mem_data;
|
786 |
+
sc_signal <sc_int<8>> wb_next_mem_data;
|
787 |
+
sc_signal <bool> wb_next_WbMux;
|
788 |
+
sc_signal <bool> wb_next_regWrite;
|
789 |
+
sc_signal <sc_uint<3>> wb_next_rd;
|
790 |
+
|
791 |
+
sc_signal<sc_uint<13>> mem_addr;
|
792 |
+
|
793 |
+
sc_signal <sc_int<8>> regFileData;
|
794 |
+
|
795 |
+
sc_int<13> tmp_id_next_Imm;
|
796 |
+
|
797 |
+
sc_signal <sc_int<8>> sig_mem_data;
|
798 |
+
|
799 |
+
// -----
|
800 |
+
|
801 |
+
PC *pc;
|
802 |
+
IR *ir;
|
803 |
+
IF *iff;
|
804 |
+
Controller *ctl;
|
805 |
+
Mux3 *mux_reg;
|
806 |
+
ID *id;
|
807 |
+
Mux8 *alu_in_mux;
|
808 |
+
ALU *alu;
|
809 |
+
EXE *exe;
|
810 |
+
WB *wb;
|
811 |
+
Mux8 *wb_out_mux;
|
812 |
+
RegFile *reg_file;
|
813 |
+
|
814 |
+
SC_CTOR (Micro){
|
815 |
+
|
816 |
+
SC_THREAD (process);
|
817 |
+
sensitive << clk.pos();
|
818 |
+
|
819 |
+
|
820 |
+
|
821 |
+
pc = new PC("PC");
|
822 |
+
ir = new IR("IR");
|
823 |
+
iff = new IF ("IF");
|
824 |
+
ctl = new Controller ("Controller");
|
825 |
+
mux_reg = new Mux3 ("RegMux3bits");
|
826 |
+
id = new ID ("ID");
|
827 |
+
alu_in_mux = new Mux8 ("AluInputMux");
|
828 |
+
alu = new ALU ("ALU");
|
829 |
+
exe = new EXE ("EXE");
|
830 |
+
wb = new WB ("WB");
|
831 |
+
wb_out_mux = new Mux8 ("WBOutputMux");
|
832 |
+
reg_file = new RegFile ("RegisterFile");
|
833 |
+
|
834 |
+
|
835 |
+
|
836 |
+
|
837 |
+
pc->clk(clk);
|
838 |
+
pc->prev_addr(pc_prev_addr);
|
839 |
+
pc->next_addr(pc_next_addr);
|
840 |
+
|
841 |
+
ir->addr(pc_next_addr);
|
842 |
+
ir->inst(ir_inst);
|
843 |
+
|
844 |
+
iff->clk(clk);
|
845 |
+
iff->prev_data(ir_inst);
|
846 |
+
iff->next_data(if_next_data);
|
847 |
+
|
848 |
+
//ctl (opcode, opselect, aluOp, regWrite, r_nw, aluMux, regMux, wbMux, acc_call);
|
849 |
+
ctl->opcode(opcode);
|
850 |
+
ctl->opselect(opselect);
|
851 |
+
ctl->aluOp(aluOp);
|
852 |
+
ctl->regWrite(regWrite);
|
853 |
+
ctl->r(r);
|
854 |
+
ctl->w(w);
|
855 |
+
ctl->aluMux(aluMux);
|
856 |
+
ctl->regMux(regMux);
|
857 |
+
ctl->wbMux(wbMux);
|
858 |
+
ctl->call(acc_call);
|
859 |
+
|
860 |
+
//mux_reg (regMux, rs, rd, mux_reg_res);
|
861 |
+
mux_reg->sel(regMux);
|
862 |
+
mux_reg->in0(rs);
|
863 |
+
mux_reg->in1(rd);
|
864 |
+
mux_reg->out(mux_reg_res);
|
865 |
+
|
866 |
+
//id (clk, Rr1, id_next_A, Rr2, id_next_B, offset, id_next_Imm, sa, id_next_Sa, aluOp, id_next_AluOp, r_nw, id_next_MemOp, aluMux, id_next_AluMux, wbMux, id_next_WbMux, acc_call, id_next_call, rd, id_next_rd);
|
867 |
+
id->clk(clk);
|
868 |
+
id->prev_A(Rr1);
|
869 |
+
id->next_A(id_next_A);
|
870 |
+
id->prev_B(Rr2);
|
871 |
+
id->next_B(id_next_B);
|
872 |
+
id->prev_Imm(offset);
|
873 |
+
id->next_Imm(id_next_Imm);
|
874 |
+
id->prev_Sa(sa);
|
875 |
+
id->next_Sa(id_next_Sa);
|
876 |
+
id->prev_AluOp(aluOp);
|
877 |
+
id->next_AluOp(id_next_AluOp);
|
878 |
+
id->prev_r(r);
|
879 |
+
id->next_r(id_next_r);
|
880 |
+
id->prev_w(w);
|
881 |
+
id->next_w(id_next_w);
|
882 |
+
id->prev_AluMux(aluMux);
|
883 |
+
id->next_AluMux(id_next_AluMux);
|
884 |
+
id->prev_WbMux(wbMux);
|
885 |
+
id->next_WbMux(id_next_WbMux);
|
886 |
+
id->prev_call(acc_call);
|
887 |
+
id->next_call(id_next_call);
|
888 |
+
id->prev_regWrite(regWrite);
|
889 |
+
id->next_regWrite(id_next_regWrite);
|
890 |
+
id->prev_rd(rd);
|
891 |
+
id->next_rd(id_next_rd);
|
892 |
+
|
893 |
+
/*
|
894 |
+
** Mux 8 for immediate or B
|
895 |
+
*/
|
896 |
+
//alu_in_mux (id_next_AluMux, id_next_B, id_nex_imm_8bits, alu_in_B);
|
897 |
+
alu_in_mux->sel(id_next_AluMux);
|
898 |
+
alu_in_mux->in0(id_next_B);
|
899 |
+
alu_in_mux->in1(id_nex_imm_8bits);
|
900 |
+
alu_in_mux->out(alu_in_B);
|
901 |
+
|
902 |
+
/*
|
903 |
+
** ALU
|
904 |
+
*/
|
905 |
+
carry = 1;
|
906 |
+
//alu (id_next_A, alu_in_B, carry, id_next_AluOp, id_next_Sa, alu_out);
|
907 |
+
alu->in1(id_next_A);
|
908 |
+
alu->in2(alu_in_B);
|
909 |
+
alu->c(carry);
|
910 |
+
alu->aluop(id_next_AluOp);
|
911 |
+
alu->sa(id_next_Sa);
|
912 |
+
alu->out(alu_out);
|
913 |
+
|
914 |
+
/*
|
915 |
+
** EXE
|
916 |
+
*/
|
917 |
+
//exe (clk, alu_out, exe_next_result, id_next_Imm, exe_next_Imm, id_next_MemOp, exe_next_MemOp, id_next_WbMux, exe_next_WbMux, id_next_call, exe_next_call, id_next_rd, exe_next_rd);
|
918 |
+
exe->clk(clk);
|
919 |
+
exe->prev_result(alu_out);
|
920 |
+
exe->next_result(exe_next_result);
|
921 |
+
exe->prev_Imm(id_next_Imm);
|
922 |
+
exe->next_Imm(exe_next_Imm);
|
923 |
+
exe->prev_r(id_next_r);
|
924 |
+
exe->next_r(exe_next_r);
|
925 |
+
exe->prev_w(id_next_w);
|
926 |
+
exe->next_w(exe_next_w);
|
927 |
+
exe->prev_WbMux(id_next_WbMux);
|
928 |
+
exe->next_WbMux(exe_next_WbMux);
|
929 |
+
exe->prev_call(id_next_call);
|
930 |
+
exe->next_call(exe_next_call);
|
931 |
+
exe->prev_regWrite(id_next_regWrite);
|
932 |
+
exe->next_regWrite(exe_next_regWrite);
|
933 |
+
exe->prev_rd(id_next_rd);
|
934 |
+
exe->next_rd(exe_next_rd);
|
935 |
+
|
936 |
+
|
937 |
+
/*
|
938 |
+
** WB
|
939 |
+
*/
|
940 |
+
//wb (clk, exe_next_result, wb_next_result, wb_prev_mem_data, wb_next_mem_data, exe_next_WbMux, wb_next_WbMux, exe_next_rd, wb_next_rd);
|
941 |
+
wb->clk(clk);
|
942 |
+
wb->prev_alu_result(exe_next_result);
|
943 |
+
wb->next_alu_result(wb_next_result);
|
944 |
+
wb->prev_mem_result(mem_data);
|
945 |
+
wb->next_mem_result(wb_next_mem_data);
|
946 |
+
wb->prev_WbMux(exe_next_WbMux);
|
947 |
+
wb->next_WbMux(wb_next_WbMux);
|
948 |
+
wb->prev_regWrite(exe_next_regWrite);
|
949 |
+
wb->next_regWrite(wb_next_regWrite);
|
950 |
+
wb->prev_rd(exe_next_rd);
|
951 |
+
wb->next_rd(wb_next_rd);
|
952 |
+
|
953 |
+
/*
|
954 |
+
** Mux 8 bits for WB
|
955 |
+
*/
|
956 |
+
//wb_out_mux (wb_next_WbMux, wb_next_result, wb_next_mem_data, regFileData);
|
957 |
+
wb_out_mux->sel(wb_next_WbMux);
|
958 |
+
wb_out_mux->in0(wb_next_result);
|
959 |
+
wb_out_mux->in1(wb_next_mem_data);
|
960 |
+
wb_out_mux->out(regFileData);
|
961 |
+
|
962 |
+
|
963 |
+
/*
|
964 |
+
** Register File Module
|
965 |
+
*/
|
966 |
+
//reg_file (clk, regWrite, mux_reg_res, rt, wb_next_rd, regFileData, Rr1, Rr2);
|
967 |
+
reg_file->clk(clk);
|
968 |
+
reg_file->regWrite(wb_next_regWrite);
|
969 |
+
reg_file->r1(mux_reg_res);
|
970 |
+
reg_file->r2(rt);
|
971 |
+
reg_file->r3(wb_next_rd);
|
972 |
+
reg_file->data(regFileData);
|
973 |
+
reg_file->Rr1(Rr1);
|
974 |
+
reg_file->Rr2(Rr2);
|
975 |
+
|
976 |
+
for (int i=0; i<8; i++){
|
977 |
+
reg_file->r[i](regs[i]);
|
978 |
+
}
|
979 |
+
|
980 |
+
}
|
981 |
+
|
982 |
+
/*
|
983 |
+
** CLOCK THREAD FOR DOING PROCESSES
|
984 |
+
*/
|
985 |
+
void process(){
|
986 |
+
while(true){
|
987 |
+
if(id_next_call){
|
988 |
+
now_is_call = true;
|
989 |
+
}
|
990 |
+
wait();
|
991 |
+
|
992 |
+
///////////////
|
993 |
+
pcInc();
|
994 |
+
decode();
|
995 |
+
ImmTo8bits();
|
996 |
+
busAccess();
|
997 |
+
tester();
|
998 |
+
/////////////
|
999 |
+
|
1000 |
+
/*
|
1001 |
+
** HANDLE ACCELERATOR CALLS
|
1002 |
+
*/
|
1003 |
+
if(exe_next_call.read()){
|
1004 |
+
call.write(1);
|
1005 |
+
pc_prev_addr = (pc_prev_addr.read());
|
1006 |
+
wait(micro_acc_ev);
|
1007 |
+
pc_prev_addr = (pc_prev_addr.read()) + 1;
|
1008 |
+
}
|
1009 |
+
}
|
1010 |
+
}
|
1011 |
+
|
1012 |
+
void pcInc (){
|
1013 |
+
// increment the pc
|
1014 |
+
tmp_pc_prev_addr = pc_prev_addr.read();
|
1015 |
+
pc_prev_addr = ++tmp_pc_prev_addr;
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
void decode (){
|
1019 |
+
/*
|
1020 |
+
** split next instruction to the corresponding signals (Instruction Decode)
|
1021 |
+
*/
|
1022 |
+
tmp = ir_inst.read();
|
1023 |
+
opcode = tmp.range(19, 16);
|
1024 |
+
opselect = tmp.range(3, 0);
|
1025 |
+
rd = tmp.range(15, 13);
|
1026 |
+
rs = tmp.range(12, 10);
|
1027 |
+
rt = tmp.range(9, 7);
|
1028 |
+
sa = tmp.range(6, 4);
|
1029 |
+
offset = (sc_int<13>) tmp.range(12, 0);
|
1030 |
+
}
|
1031 |
+
|
1032 |
+
void ImmTo8bits (){
|
1033 |
+
/*
|
1034 |
+
** Mux 8 for immediate or B
|
1035 |
+
*/
|
1036 |
+
tmp_id_next_Imm = offset.read();
|
1037 |
+
id_nex_imm_8bits = (tmp_id_next_Imm.range(7, 0));
|
1038 |
+
}
|
1039 |
+
|
1040 |
+
void busAccess (){
|
1041 |
+
/*
|
1042 |
+
** ACCESS MEM. VIA BUS
|
1043 |
+
*/
|
1044 |
+
wb_prev_mem_data = mem_data.read();
|
1045 |
+
mem_addr = (sc_uint<13>) id_next_Imm.read();
|
1046 |
+
read.write(exe_next_r.read());
|
1047 |
+
write.write(exe_next_w.read());
|
1048 |
+
addr.write(mem_addr.read());
|
1049 |
+
data.write(exe_next_result.read());
|
1050 |
+
call.write(0); // setting of the value is also performs in process function
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
void tester () {
|
1054 |
+
|
1055 |
+
// testing wires
|
1056 |
+
for(int i=0; i<8; i++){
|
1057 |
+
reg_dump[i].write(regs[i].read());
|
1058 |
+
}
|
1059 |
+
test_aluOp.write(aluOp.read());
|
1060 |
+
test_pc.write(pc_next_addr.read());
|
1061 |
+
test_inst.write((sc_uint<20>)if_next_data.read());
|
1062 |
+
|
1063 |
+
print();
|
1064 |
+
}
|
1065 |
+
|
1066 |
+
void print(){
|
1067 |
+
cout << "pc addr ((FETCH)) :\t" << pc_next_addr << endl << endl;
|
1068 |
+
|
1069 |
+
cout << "IF inst ((DECODE)):\t" << std::hex << if_next_data << endl;
|
1070 |
+
cout << "controller| opcode:\t" << opcode << endl;
|
1071 |
+
cout << "regFile| regMux :\t" << regMux << endl;
|
1072 |
+
cout << "regFile| r1 :\t" << mux_reg_res << endl;
|
1073 |
+
cout << "regFile| r2 :\t" << rt << endl;
|
1074 |
+
cout << "regFile| r3 :\t" << wb_next_rd << endl;
|
1075 |
+
cout << "regFile| imm :\t" << offset << endl;
|
1076 |
+
cout << "regFile| data :\t" << wb_next_rd << endl;
|
1077 |
+
cout << "regFile| regWrite :\t" << wb_next_regWrite << endl << endl;
|
1078 |
+
|
1079 |
+
cout << "A ((EXE)) :\t" << id_next_A << endl;
|
1080 |
+
cout << "B :\t" << alu_in_B << endl;
|
1081 |
+
cout << "aluOp :\t" << id_next_AluOp << endl;
|
1082 |
+
cout << "aluMux :\t" << id_next_AluMux << endl;
|
1083 |
+
cout << "imm :\t" << id_next_Imm << endl;
|
1084 |
+
cout << "aluOut :\t" << alu_out << endl << endl;
|
1085 |
+
|
1086 |
+
cout << "imm :\t" << exe_next_Imm << endl;
|
1087 |
+
cout << "data_in ((MEM)) :\t" << exe_next_result << endl;
|
1088 |
+
cout << "addr :\t" << exe_next_Imm << endl;
|
1089 |
+
cout << "read :\t" << exe_next_r << endl;
|
1090 |
+
cout << "write :\t" << exe_next_w << endl;
|
1091 |
+
cout << "data_out :\t" << mem_data << endl << endl;
|
1092 |
+
|
1093 |
+
cout << "data ((WB)) :\t" << regFileData << endl;
|
1094 |
+
cout << "rd :\t" << exe_next_rd << endl;
|
1095 |
+
cout << "wbMux :\t" << wb_next_WbMux << endl << endl;
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
|
1099 |
+
};
|
1100 |
+
/*
|
1101 |
+
* @ASCK
|
1102 |
+
*/
|
1103 |
+
|
1104 |
+
#include <systemc.h>
|
1105 |
+
|
1106 |
+
SC_MODULE (Mux3) {
|
1107 |
+
sc_in <bool> sel;
|
1108 |
+
sc_in <sc_uint<3>> in0;
|
1109 |
+
sc_in <sc_uint<3>> in1;
|
1110 |
+
|
1111 |
+
sc_out <sc_uint<3>> out;
|
1112 |
+
|
1113 |
+
|
1114 |
+
/*
|
1115 |
+
** module global variables
|
1116 |
+
*/
|
1117 |
+
|
1118 |
+
SC_CTOR (Mux3){
|
1119 |
+
SC_METHOD (process);
|
1120 |
+
sensitive << in0 << in1 << sel;
|
1121 |
+
}
|
1122 |
+
|
1123 |
+
void process () {
|
1124 |
+
if(!sel.read()){
|
1125 |
+
out.write(in0.read());
|
1126 |
+
}
|
1127 |
+
else{
|
1128 |
+
out.write(in1.read());
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
|
1133 |
+
};
|
1134 |
+
/*
|
1135 |
+
* @ASCK
|
1136 |
+
*/
|
1137 |
+
|
1138 |
+
#include <systemc.h>
|
1139 |
+
|
1140 |
+
SC_MODULE (Mux8) {
|
1141 |
+
sc_in <bool> sel;
|
1142 |
+
sc_in <sc_int<8>> in0;
|
1143 |
+
sc_in <sc_int<8>> in1;
|
1144 |
+
|
1145 |
+
sc_out <sc_int<8>> out;
|
1146 |
+
|
1147 |
+
|
1148 |
+
/*
|
1149 |
+
** module global variables
|
1150 |
+
*/
|
1151 |
+
|
1152 |
+
SC_CTOR (Mux8){
|
1153 |
+
SC_METHOD (process);
|
1154 |
+
sensitive << in0 << in1 << sel;
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
void process () {
|
1158 |
+
if(!sel.read()){
|
1159 |
+
out.write(in0.read());
|
1160 |
+
}
|
1161 |
+
else{
|
1162 |
+
out.write(in1.read());
|
1163 |
+
}
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
|
1167 |
+
};
|
1168 |
+
/*
|
1169 |
+
* @ASCK
|
1170 |
+
*/
|
1171 |
+
|
1172 |
+
#include <systemc.h>
|
1173 |
+
|
1174 |
+
SC_MODULE (PC) {
|
1175 |
+
|
1176 |
+
sc_in <bool> clk;
|
1177 |
+
sc_in <sc_uint<14>> prev_addr;
|
1178 |
+
|
1179 |
+
sc_out <sc_uint<14>> next_addr;
|
1180 |
+
|
1181 |
+
|
1182 |
+
/*
|
1183 |
+
** module global variables
|
1184 |
+
*/
|
1185 |
+
|
1186 |
+
SC_CTOR (PC){
|
1187 |
+
SC_METHOD (process);
|
1188 |
+
sensitive << clk.pos();
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
void process () {
|
1192 |
+
next_addr.write(prev_addr.read());
|
1193 |
+
}
|
1194 |
+
|
1195 |
+
|
1196 |
+
};
|
1197 |
+
/*
|
1198 |
+
* @ASCK
|
1199 |
+
*/
|
1200 |
+
|
1201 |
+
#include <systemc.h>
|
1202 |
+
|
1203 |
+
SC_MODULE (RegFile) {
|
1204 |
+
|
1205 |
+
sc_in_clk clk;
|
1206 |
+
sc_in <bool> regWrite;
|
1207 |
+
sc_in <sc_uint<3>> r1;
|
1208 |
+
sc_in <sc_uint<3>> r2;
|
1209 |
+
sc_in <sc_uint<3>> r3;
|
1210 |
+
sc_in <sc_int<8>> data;
|
1211 |
+
|
1212 |
+
sc_out <sc_int<8>> Rr1;
|
1213 |
+
sc_out <sc_int<8>> Rr2;
|
1214 |
+
|
1215 |
+
//testing wires
|
1216 |
+
sc_out <sc_int<8>> r[8];
|
1217 |
+
|
1218 |
+
|
1219 |
+
/*
|
1220 |
+
** module global variables
|
1221 |
+
*/
|
1222 |
+
|
1223 |
+
sc_int<8> reg[8]; // 8 registers in register file
|
1224 |
+
|
1225 |
+
int c = 0;
|
1226 |
+
SC_CTOR (RegFile){
|
1227 |
+
SC_METHOD (process);
|
1228 |
+
sensitive << regWrite << r1 << r2 << r3 << data;
|
1229 |
+
}
|
1230 |
+
|
1231 |
+
void process () {
|
1232 |
+
// whether the regWrite is 0 or not, the Rr1 and Rr2 have the corresponding output!
|
1233 |
+
Rr1.write(reg[r1.read()]);
|
1234 |
+
Rr2.write(reg[r2.read()]);
|
1235 |
+
if(regWrite.read() == 1){
|
1236 |
+
reg[r3.read()] = data.read();
|
1237 |
+
}
|
1238 |
+
|
1239 |
+
for (int i=0; i< 8; i++){
|
1240 |
+
r[i].write(reg[i]);
|
1241 |
+
}
|
1242 |
+
|
1243 |
+
if (c++ == 32) {
|
1244 |
+
reg[0] = 3;
|
1245 |
+
}
|
1246 |
+
}
|
1247 |
+
|
1248 |
+
|
1249 |
+
};
|
1250 |
+
/*
|
1251 |
+
* @ASCK
|
1252 |
+
*/
|
1253 |
+
|
1254 |
+
#include <systemc.h>
|
1255 |
+
|
1256 |
+
/*
|
1257 |
+
** GLOBAL EVENT FOR MICRO-ACC
|
1258 |
+
*/
|
1259 |
+
//////////////////////////
|
1260 |
+
sc_event micro_acc_ev;///
|
1261 |
+
////////////////////////
|
1262 |
+
|
1263 |
+
/*
|
1264 |
+
** GLOBAL EVENT FOR ACC-MEMORY -> READ MODE
|
1265 |
+
*/
|
1266 |
+
//////////////////////////
|
1267 |
+
sc_event acc_mem_read_ev;///
|
1268 |
+
////////////////////////
|
1269 |
+
|
1270 |
+
/*
|
1271 |
+
** GLOBAL EVENT FOR ACC-MEMORY -> WRITE MODE
|
1272 |
+
*/
|
1273 |
+
//////////////////////////
|
1274 |
+
sc_event acc_mem_write_ev;///
|
1275 |
+
////////////////////////
|
1276 |
+
|
1277 |
+
/*
|
1278 |
+
** variable for checking if IF/ID/EXE/WB should have been stopped after call=1 on memory-access stage or not!
|
1279 |
+
*/
|
1280 |
+
bool now_is_call = false;
|
1281 |
+
|
1282 |
+
|
1283 |
+
#include <./Micro.cpp>
|
1284 |
+
#include <./Bus.cpp>
|
1285 |
+
#include <./Memory.cpp>
|
1286 |
+
#include <./Acc.cpp>
|
1287 |
+
|
1288 |
+
|
1289 |
+
SC_MODULE(System)
|
1290 |
+
{
|
1291 |
+
|
1292 |
+
sc_in_clk clk;
|
1293 |
+
sc_in_clk clk_bus;
|
1294 |
+
|
1295 |
+
// testing wires
|
1296 |
+
sc_out<sc_uint<14>> pc;
|
1297 |
+
sc_out<sc_uint<5>> test_aluop;
|
1298 |
+
sc_out<sc_int<8>> reg_dump[8];
|
1299 |
+
|
1300 |
+
/*
|
1301 |
+
** module global variables
|
1302 |
+
*/
|
1303 |
+
|
1304 |
+
//
|
1305 |
+
// SIGNALS
|
1306 |
+
//
|
1307 |
+
|
1308 |
+
// MICRO
|
1309 |
+
sc_signal<sc_int<8>> micro_data_in; // input
|
1310 |
+
sc_signal<bool> micro_read, micro_write, micro_call;
|
1311 |
+
sc_signal<sc_uint<13>> micro_addr;
|
1312 |
+
sc_signal<sc_int<8>> micro_data_out; // output
|
1313 |
+
|
1314 |
+
// BUS
|
1315 |
+
sc_signal<bool> req;
|
1316 |
+
sc_signal<bool> read_in;
|
1317 |
+
sc_signal<bool> write_in;
|
1318 |
+
sc_signal<bool> call_in;
|
1319 |
+
sc_signal<sc_uint<13>> addr_in; // for both Mem. and Acc.
|
1320 |
+
sc_signal<sc_int<8>> data_in;
|
1321 |
+
//// INPUTS -up- / -down- OUTPUTS
|
1322 |
+
sc_signal<bool> ack;
|
1323 |
+
sc_signal<bool> read_out;
|
1324 |
+
sc_signal<bool> write_out;
|
1325 |
+
sc_signal<bool> call_out;
|
1326 |
+
sc_signal<sc_uint<13>> addr_out; // for both Mem. and Acc.
|
1327 |
+
sc_signal<sc_int<8>> data_out;
|
1328 |
+
|
1329 |
+
// MEMORY
|
1330 |
+
sc_signal<sc_int<8>> mem_data_in, mem_data_out;
|
1331 |
+
sc_signal<sc_uint<13>> mem_addr;
|
1332 |
+
sc_signal<bool> r_nw;
|
1333 |
+
|
1334 |
+
// ACC1
|
1335 |
+
sc_signal <bool> acc_call_in, acc_read, acc_write;
|
1336 |
+
sc_signal <sc_uint<13>> acc_addr_out;
|
1337 |
+
sc_signal <sc_int<8>> acc_data_in, acc_data_out;
|
1338 |
+
|
1339 |
+
//TESTING SIGNALS
|
1340 |
+
sc_signal<sc_uint<5>> test_aluOp;
|
1341 |
+
sc_signal<sc_uint<14>> test_pc;
|
1342 |
+
sc_signal<sc_uint<20>> test_inst;
|
1343 |
+
|
1344 |
+
/*
|
1345 |
+
** CREATE POINTER TO COMPONENTS
|
1346 |
+
*/
|
1347 |
+
Micro *micro;
|
1348 |
+
Bus *bus;
|
1349 |
+
Memory *memory;
|
1350 |
+
Acc *acc;
|
1351 |
+
|
1352 |
+
SC_CTOR(System)
|
1353 |
+
{
|
1354 |
+
SC_METHOD(process);
|
1355 |
+
sensitive << clk_bus.pos();
|
1356 |
+
|
1357 |
+
micro = new Micro("Micro");
|
1358 |
+
bus = new Bus("Bus");
|
1359 |
+
memory = new Memory("MEMORY");
|
1360 |
+
acc = new Acc("Acc1");
|
1361 |
+
|
1362 |
+
micro->clk(clk);
|
1363 |
+
micro->mem_data(micro_data_in);
|
1364 |
+
micro->read(micro_read);
|
1365 |
+
micro->write(micro_write);
|
1366 |
+
micro->call(micro_call);
|
1367 |
+
micro->addr(micro_addr);
|
1368 |
+
micro->data(micro_data_out);
|
1369 |
+
|
1370 |
+
micro->test_aluOp(test_aluOp);
|
1371 |
+
micro->test_pc(test_pc);
|
1372 |
+
micro->test_inst(test_inst);
|
1373 |
+
|
1374 |
+
for (int i = 0; i < 8; i++)
|
1375 |
+
{
|
1376 |
+
micro->reg_dump[i](reg_dump[i]);
|
1377 |
+
}
|
1378 |
+
|
1379 |
+
req = 1;
|
1380 |
+
bus->clk(clk_bus);
|
1381 |
+
bus->req(req);
|
1382 |
+
bus->read(read_in);
|
1383 |
+
bus->write(write_in);
|
1384 |
+
bus->call(micro_call);
|
1385 |
+
bus->addr(addr_in);
|
1386 |
+
bus->data(data_in);
|
1387 |
+
|
1388 |
+
bus->ack(ack);
|
1389 |
+
bus->read_out(read_out);
|
1390 |
+
bus->write_out(write_out);
|
1391 |
+
bus->call_out(call_out);
|
1392 |
+
bus->addr_out(addr_out);
|
1393 |
+
bus->data_out(data_out);
|
1394 |
+
|
1395 |
+
r_nw = 1;
|
1396 |
+
memory->r_nw(r_nw);
|
1397 |
+
memory->addr(mem_addr);
|
1398 |
+
memory->data(mem_data_in);
|
1399 |
+
memory->out(mem_data_out);
|
1400 |
+
|
1401 |
+
acc->mem_data(acc_data_in);
|
1402 |
+
acc->call(acc_call_in);
|
1403 |
+
acc->read(acc_read);
|
1404 |
+
acc->write(acc_write);
|
1405 |
+
acc->addr(acc_addr_out);
|
1406 |
+
acc->data(acc_data_out);
|
1407 |
+
|
1408 |
+
}
|
1409 |
+
|
1410 |
+
int c = 0; //clk counter for printing
|
1411 |
+
|
1412 |
+
/*
|
1413 |
+
** FLAG: if the **acc_read** of accelerator is enabled then we know that after 2 clks
|
1414 |
+
** we will have the memory data on the bus data_out!
|
1415 |
+
**
|
1416 |
+
** BRIEF: this flag acknowledge us whether we have to notify the acc_mem_read_ev or not!
|
1417 |
+
*/
|
1418 |
+
int notify_flag_read = 0;
|
1419 |
+
int notify_flag_write = 0;
|
1420 |
+
|
1421 |
+
void process()
|
1422 |
+
{
|
1423 |
+
// testing wires
|
1424 |
+
test_aluop.write(test_aluOp.read());
|
1425 |
+
pc.write(test_pc.read());
|
1426 |
+
|
1427 |
+
cout << "-----------------------------------------------" << endl;
|
1428 |
+
cout << "\t-___ " << "bus_clk: 0X" <<c++ << " ___-" << endl << endl;
|
1429 |
+
|
1430 |
+
|
1431 |
+
/*
|
1432 |
+
** Micro - MEMORY - ACC
|
1433 |
+
*/
|
1434 |
+
|
1435 |
+
mem_addr = addr_out.read();
|
1436 |
+
mem_data_in = data_out.read();
|
1437 |
+
micro_data_in = data_out.read();
|
1438 |
+
acc_data_in = data_out.read();
|
1439 |
+
acc_call_in = call_out.read();
|
1440 |
+
|
1441 |
+
if (read_out.read() || write_out.read() || call_out.read()){
|
1442 |
+
if (read_out.read()){
|
1443 |
+
r_nw = read_out.read();
|
1444 |
+
data_in = mem_data_out.read();
|
1445 |
+
}
|
1446 |
+
else if (write_out.read()){
|
1447 |
+
r_nw = !(write_out.read());
|
1448 |
+
}
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
|
1452 |
+
////////////////////////HANDLE ACC READ/WRITE////////////////////////
|
1453 |
+
if (notify_flag_write !=0 && notify_flag_write < 3){
|
1454 |
+
// increment the flag to get to the intended clk count
|
1455 |
+
notify_flag_write++;
|
1456 |
+
return;
|
1457 |
+
}
|
1458 |
+
else if (notify_flag_write == 3){
|
1459 |
+
// the write operation should have been done
|
1460 |
+
notify_flag_write = 0;
|
1461 |
+
|
1462 |
+
acc_mem_write_ev.notify();
|
1463 |
+
return;
|
1464 |
+
}
|
1465 |
+
|
1466 |
+
if (notify_flag_read !=0 && notify_flag_read < 4){
|
1467 |
+
// increment the flag to get to the intended clk count
|
1468 |
+
notify_flag_read++;
|
1469 |
+
return;
|
1470 |
+
}
|
1471 |
+
else if (notify_flag_read == 4){
|
1472 |
+
// should we notify accelerator event? (two clocks have passed)
|
1473 |
+
notify_flag_read = 0;
|
1474 |
+
|
1475 |
+
acc_mem_read_ev.notify();
|
1476 |
+
return;
|
1477 |
+
}
|
1478 |
+
|
1479 |
+
|
1480 |
+
|
1481 |
+
|
1482 |
+
///////////////////////////////////////////////////////////////////MICRO
|
1483 |
+
if (micro_read.read() || micro_write.read() || micro_call.read())
|
1484 |
+
{
|
1485 |
+
read_in = micro_read.read();
|
1486 |
+
write_in = micro_write.read();
|
1487 |
+
call_in = micro_call.read();
|
1488 |
+
|
1489 |
+
if (micro_read.read()){
|
1490 |
+
|
1491 |
+
addr_in = micro_addr.read();
|
1492 |
+
}
|
1493 |
+
else if (micro_write.read()){
|
1494 |
+
data_in = micro_data_out.read();
|
1495 |
+
addr_in = micro_addr.read();
|
1496 |
+
}
|
1497 |
+
}
|
1498 |
+
///////////////////////////////////////////////////////////////////ACC
|
1499 |
+
if (acc_read.read() || acc_write.read())
|
1500 |
+
{
|
1501 |
+
|
1502 |
+
read_in = acc_read.read();
|
1503 |
+
write_in = acc_write.read();
|
1504 |
+
|
1505 |
+
if (acc_read.read()){
|
1506 |
+
// increment accelerator notify_flag_read
|
1507 |
+
notify_flag_read++;
|
1508 |
+
|
1509 |
+
addr_in = acc_addr_out.read();
|
1510 |
+
}
|
1511 |
+
else if (acc_write.read()){
|
1512 |
+
// increment accelerator notify_flag_write
|
1513 |
+
notify_flag_write++;
|
1514 |
+
|
1515 |
+
data_in = acc_data_out.read();
|
1516 |
+
addr_in = acc_addr_out.read();
|
1517 |
+
}
|
1518 |
+
}
|
1519 |
+
|
1520 |
+
|
1521 |
+
}
|
1522 |
+
};
|
1523 |
+
/*
|
1524 |
+
* @ASCK
|
1525 |
+
*/
|
1526 |
+
|
1527 |
+
#include <systemc.h>
|
1528 |
+
|
1529 |
+
SC_MODULE (WB) {
|
1530 |
+
|
1531 |
+
sc_in_clk clk;
|
1532 |
+
sc_in <sc_int<8>> prev_alu_result;
|
1533 |
+
sc_in <sc_int<8>> prev_mem_result;
|
1534 |
+
sc_in <bool> prev_WbMux;
|
1535 |
+
sc_in <bool> prev_regWrite;
|
1536 |
+
sc_in <sc_uint<3>> prev_rd;
|
1537 |
+
|
1538 |
+
sc_out <sc_int<8>> next_alu_result;
|
1539 |
+
sc_out <sc_int<8>> next_mem_result;
|
1540 |
+
sc_out <bool> next_WbMux;
|
1541 |
+
sc_out <bool> next_regWrite;
|
1542 |
+
sc_out <sc_uint<3>> next_rd;
|
1543 |
+
|
1544 |
+
|
1545 |
+
/*
|
1546 |
+
** module global variables
|
1547 |
+
*/
|
1548 |
+
|
1549 |
+
SC_CTOR (WB){
|
1550 |
+
SC_THREAD (process);
|
1551 |
+
sensitive << clk.pos();
|
1552 |
+
}
|
1553 |
+
|
1554 |
+
void process () {
|
1555 |
+
while(true){
|
1556 |
+
wait();
|
1557 |
+
if(now_is_call){
|
1558 |
+
wait(micro_acc_ev);
|
1559 |
+
}
|
1560 |
+
next_alu_result.write(prev_alu_result.read());
|
1561 |
+
next_mem_result.write(prev_mem_result.read());
|
1562 |
+
next_WbMux.write(prev_WbMux.read());
|
1563 |
+
next_regWrite.write(prev_regWrite);
|
1564 |
+
next_rd.write(prev_rd.read());
|
1565 |
+
}
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
|
1569 |
+
};
|
1570 |
+
/*
|
1571 |
+
* @ASCK
|
1572 |
+
*/
|
1573 |
+
|
1574 |
+
#include <systemc.h>
|
1575 |
+
|
1576 |
+
#include <System.cpp>
|
1577 |
+
|
1578 |
+
using namespace std;
|
1579 |
+
|
1580 |
+
int sc_main(int argc, char* argv[]){
|
1581 |
+
|
1582 |
+
cout << "starting the complete project" << endl;
|
1583 |
+
|
1584 |
+
sc_trace_file *wf = sc_create_vcd_trace_file("project");
|
1585 |
+
|
1586 |
+
sc_signal <bool> clk;
|
1587 |
+
sc_signal <bool> clk_bus;
|
1588 |
+
sc_signal <sc_int<8>> reg_dump[8];
|
1589 |
+
sc_signal <sc_uint<5>> aluop;
|
1590 |
+
sc_signal <sc_uint<14>> pc;
|
1591 |
+
|
1592 |
+
|
1593 |
+
System sys ("System");
|
1594 |
+
sys (clk, clk_bus, pc, aluop);
|
1595 |
+
|
1596 |
+
for (int i=0; i<8; i++){
|
1597 |
+
sys.reg_dump[i](reg_dump[i]);
|
1598 |
+
}
|
1599 |
+
|
1600 |
+
sc_trace (wf, clk, "clk");
|
1601 |
+
sc_trace (wf, clk_bus, "bus_clk");
|
1602 |
+
sc_trace (wf, pc, "pc");
|
1603 |
+
sc_trace (wf, aluop, "aluop");
|
1604 |
+
for (int i=0; i<8; i++){
|
1605 |
+
char str[3];
|
1606 |
+
sprintf(str, "%d", i);
|
1607 |
+
sc_trace (wf, reg_dump[i], "R" + string(str));
|
1608 |
+
}
|
1609 |
+
|
1610 |
+
|
1611 |
+
for (int i=0; i<40 ;i++){
|
1612 |
+
clk_bus = 0;
|
1613 |
+
clk = 1;
|
1614 |
+
sc_start(1,SC_NS);
|
1615 |
+
clk_bus = 1;
|
1616 |
+
sc_start(1,SC_NS);
|
1617 |
+
clk_bus = 0;
|
1618 |
+
sc_start(1,SC_NS);
|
1619 |
+
clk_bus = 1;
|
1620 |
+
sc_start(1,SC_NS);
|
1621 |
+
clk_bus = 0;
|
1622 |
+
clk = 0;
|
1623 |
+
sc_start(1,SC_NS);
|
1624 |
+
clk_bus = 1;
|
1625 |
+
sc_start(1,SC_NS);
|
1626 |
+
clk_bus = 0;
|
1627 |
+
sc_start(1,SC_NS);
|
1628 |
+
clk_bus = 1;
|
1629 |
+
sc_start(1,SC_NS);
|
1630 |
+
}
|
1631 |
+
|
1632 |
+
|
1633 |
+
sc_close_vcd_trace_file(wf);
|
1634 |
+
|
1635 |
+
cout << "vcd file completed" << endl;
|
1636 |
+
|
1637 |
+
return 0;
|
1638 |
+
}
|
1639 |
+
|
1640 |
+
#include "systemc.h"
|
1641 |
+
#include "tlm.h"
|
1642 |
+
#include <string>
|
1643 |
+
|
1644 |
+
using namespace std;
|
1645 |
+
|
1646 |
+
using namespace tlm;
|
1647 |
+
|
1648 |
+
struct tr {
|
1649 |
+
string message;
|
1650 |
+
};
|
1651 |
+
|
1652 |
+
#include "uvmc.h"
|
1653 |
+
using namespace uvmc;
|
1654 |
+
UVMC_UTILS_1(tr, message)
|
1655 |
+
|
1656 |
+
|
1657 |
+
SC_MODULE(refmod) {
|
1658 |
+
sc_port<tlm_get_peek_if<tr> > in;
|
1659 |
+
sc_port<tlm_put_if<tr> > out;
|
1660 |
+
|
1661 |
+
void p() {
|
1662 |
+
|
1663 |
+
tr tr;
|
1664 |
+
while(1){
|
1665 |
+
tr = in->get();
|
1666 |
+
cout <<"refmod: " <<tr.message <<"\n";
|
1667 |
+
out->put(tr);
|
1668 |
+
}
|
1669 |
+
}
|
1670 |
+
SC_CTOR(refmod): in("in"), out("out") { SC_THREAD(p); }
|
1671 |
+
};
|
1672 |
+
|
1673 |
+
|
1674 |
+
|
1675 |
+
SC_MODULE(refmod_low){
|
1676 |
+
sc_port<tlm_get_peek_if<tr> > in;
|
1677 |
+
sc_port<tlm_put_if<tr> > out;
|
1678 |
+
|
1679 |
+
void p() {
|
1680 |
+
|
1681 |
+
tr tr;
|
1682 |
+
while(1){
|
1683 |
+
tr = in->get();
|
1684 |
+
cout <<"refmod_low: " <<tr.message <<"\n";
|
1685 |
+
out->put(tr);
|
1686 |
+
}
|
1687 |
+
}
|
1688 |
+
SC_CTOR(refmod_low): in("in"), out("out") { SC_THREAD(p); }
|
1689 |
+
};
|
1690 |
+
|
1691 |
+
|
1692 |
+
|
1693 |
+
#include <octave/oct.h>
|
1694 |
+
#include <octave/octave.h>
|
1695 |
+
#include <octave/parse.h>
|
1696 |
+
#include <octave/toplev.h>
|
1697 |
+
|
1698 |
+
SC_MODULE(refmod_oct) {
|
1699 |
+
sc_port<tlm_get_peek_if<tr> > in;
|
1700 |
+
sc_port<tlm_put_if<tr> > out;
|
1701 |
+
|
1702 |
+
void p() {
|
1703 |
+
string_vector oct_argv (2);
|
1704 |
+
oct_argv(0) = "embedded";
|
1705 |
+
oct_argv(1) = "-q";
|
1706 |
+
octave_function *oct_fcn;
|
1707 |
+
octave_value_list oct_in, oct_out;
|
1708 |
+
oct_fcn = load_fcn_from_file("reffunc.m");
|
1709 |
+
if(oct_fcn) cout << "Info: SystemC: Octave function loaded." << endl;
|
1710 |
+
else sc_stop();
|
1711 |
+
|
1712 |
+
tr tr;
|
1713 |
+
while(1){
|
1714 |
+
tr = in->get();
|
1715 |
+
octave_idx_type i = 0;
|
1716 |
+
oct_in(i) = octave_value (tr.message);
|
1717 |
+
oct_out = feval(oct_fcn, oct_in);
|
1718 |
+
tr.message = oct_out(0).string_value ();
|
1719 |
+
cout <<"refmod_oct: " <<tr.message <<"\n";
|
1720 |
+
out->put(tr);
|
1721 |
+
}
|
1722 |
+
}
|
1723 |
+
SC_CTOR(refmod_oct): in("in"), out("out") { SC_THREAD(p); }
|
1724 |
+
};
|
1725 |
+
|
1726 |
+
|
1727 |
+
|
1728 |
+
#include "refmod.cpp"
|
1729 |
+
#include "refmod_low.cpp"
|
1730 |
+
#include "refmod_oct.cpp"
|
1731 |
+
|
1732 |
+
int sc_main(int argc, char* argv[]) {
|
1733 |
+
|
1734 |
+
refmod refmod_i("refmod_i");
|
1735 |
+
refmod_low refmod_low_i("refmod_low_i");
|
1736 |
+
refmod_oct refmod_oct_i("refmod_oct_i");
|
1737 |
+
|
1738 |
+
uvmc_connect(refmod_i.in, "refmod_i.in");
|
1739 |
+
uvmc_connect(refmod_low_i.in, "refmod_low_i.in");
|
1740 |
+
uvmc_connect(refmod_i.out, "refmod_i.out");
|
1741 |
+
uvmc_connect(refmod_low_i.out, "refmod_low_i.out");
|
1742 |
+
|
1743 |
+
uvmc_connect(refmod_oct_i.in, "refmod_oct_i.in");
|
1744 |
+
uvmc_connect(refmod_oct_i.out, "refmod_oct_i.out");
|
1745 |
+
sc_start();
|
1746 |
+
return(0);
|
1747 |
+
}
|
1748 |
+
|
1749 |
+
|
1750 |
+
// Copyright (c) 2019 Group of Computer Architecture, university of Bremen. All Rights Reserved.
|
1751 |
+
// Filename: Component.cpp
|
1752 |
+
// Version 1 09-July-2019
|
1753 |
+
|
1754 |
+
#include "Component.h"
|
1755 |
+
|
1756 |
+
|
1757 |
+
void Component::set_func (NT Func){
|
1758 |
+
if (!Func.first.empty()){
|
1759 |
+
string TypeName = Func.first+"+"+Func.second;
|
1760 |
+
if (func_st.count(TypeName) == 0) {
|
1761 |
+
vector<NT> temp;
|
1762 |
+
func_st[TypeName] = temp;
|
1763 |
+
}
|
1764 |
+
}
|
1765 |
+
}
|
1766 |
+
|
1767 |
+
//----------------------------------------------------------
|
1768 |
+
void Component::set_func_with_local (string f_sig, vector<NT> vect){
|
1769 |
+
if (func_st.count(f_sig) > 0) {
|
1770 |
+
func_st[f_sig] = vect;
|
1771 |
+
}
|
1772 |
+
}
|
1773 |
+
|
1774 |
+
//----------------------------------------------------------
|
1775 |
+
void Component::set_var (NT Var){
|
1776 |
+
for (int i=0; i< var_st.size(); ++i){
|
1777 |
+
if ((var_st[i].first == Var.first) && (var_st[i].second == Var.second))
|
1778 |
+
return;
|
1779 |
+
}
|
1780 |
+
var_st.push_back(Var);
|
1781 |
+
}
|
1782 |
+
|
1783 |
+
//----------------------------------------------------------
|
1784 |
+
void Component::set_name (string module_name){
|
1785 |
+
name = module_name;
|
1786 |
+
}
|
1787 |
+
|
1788 |
+
//----------------------------------------------------------
|
1789 |
+
string Component::get_name (){
|
1790 |
+
return name;
|
1791 |
+
}
|
1792 |
+
|
1793 |
+
//----------------------------------------------------------
|
1794 |
+
string Component::get_name_XML (){
|
1795 |
+
string temp;
|
1796 |
+
if (name == "sc_main")
|
1797 |
+
temp = "<Global_function name = \"" + name + "\">";
|
1798 |
+
else
|
1799 |
+
temp = "<Module name = \"" + name + "\">";
|
1800 |
+
return temp;
|
1801 |
+
}
|
1802 |
+
|
1803 |
+
//----------------------------------------------------------
|
1804 |
+
string Component::get_var (){
|
1805 |
+
string temp;
|
1806 |
+
for (auto i: var_st){
|
1807 |
+
if (!i.first.empty()){
|
1808 |
+
temp = temp +"Name: "+i.first+"\tType: "+i.second+"\n";
|
1809 |
+
}
|
1810 |
+
}
|
1811 |
+
if (temp.empty())
|
1812 |
+
return "No Variable!\n";
|
1813 |
+
else
|
1814 |
+
return temp;
|
1815 |
+
}
|
1816 |
+
|
1817 |
+
//----------------------------------------------------------
|
1818 |
+
string Component::get_var_XML (){
|
1819 |
+
string temp;
|
1820 |
+
for (auto i: var_st){
|
1821 |
+
if (!i.first.empty()){
|
1822 |
+
temp = temp +"\t<Global_variable name = \""+i.first+"\"\ttype = \""+i.second+"\"></Global_variable>\n";
|
1823 |
+
}
|
1824 |
+
}
|
1825 |
+
return temp;
|
1826 |
+
}
|
1827 |
+
|
1828 |
+
//----------------------------------------------------------
|
1829 |
+
string Component::get_func_XML (){
|
1830 |
+
string temp, temp_local_var;
|
1831 |
+
vector<string> vect_tp;
|
1832 |
+
|
1833 |
+
for (auto i: func_st){
|
1834 |
+
if ((i.first != "") && (i.first != " ")){
|
1835 |
+
vect_tp = split(i.first, '+');
|
1836 |
+
temp_local_var = make_XML (i.second);
|
1837 |
+
temp = temp + "\t<Function name = \""+vect_tp[0] + "\"\ttype = \"" + vect_tp[1]+"\">\n" + temp_local_var + "\t</Function>\n";
|
1838 |
+
}
|
1839 |
+
}
|
1840 |
+
return temp;
|
1841 |
+
}
|
1842 |
+
|
1843 |
+
//----------------------------------------------------------
|
1844 |
+
string Component::get_func (){
|
1845 |
+
string temp, temp_local_var;
|
1846 |
+
vector<string> vect_tp;
|
1847 |
+
|
1848 |
+
for (auto i: func_st){
|
1849 |
+
if ((i.first != "") && (i.first != " ")){
|
1850 |
+
vect_tp = split(i.first, '+');
|
1851 |
+
temp_local_var = make_string (i.second);
|
1852 |
+
temp = temp +"Name: "+vect_tp[0]+"\tType: "+vect_tp[1]+"\n" + temp_local_var;
|
1853 |
+
}
|
1854 |
+
}
|
1855 |
+
if (temp.empty())
|
1856 |
+
return "No Function!\n";
|
1857 |
+
else
|
1858 |
+
return temp;
|
1859 |
+
}
|
1860 |
+
|
1861 |
+
//----------------------------------------------------------
|
1862 |
+
unordered_map<string, vector<NT>> Component::get_func_data (){
|
1863 |
+
return func_st;
|
1864 |
+
}
|
1865 |
+
|
1866 |
+
|
1867 |
+
|
1868 |
+
|
1869 |
+
|
1870 |
+
// Copyright (c) 2019 Group of Computer Architecture, university of Bremen. All Rights Reserved.
|
1871 |
+
// Filename: Define.h
|
1872 |
+
// Version 1 09-July-2019
|
1873 |
+
|
1874 |
+
#ifndef DEFINE_H_
|
1875 |
+
#define DEFINE_H_
|
1876 |
+
|
1877 |
+
#include <iostream>
|
1878 |
+
#include <string>
|
1879 |
+
#include <sstream>
|
1880 |
+
#include <vector>
|
1881 |
+
#include <iterator>
|
1882 |
+
using namespace std;
|
1883 |
+
#include <limits>
|
1884 |
+
#include <fstream>
|
1885 |
+
#include <unordered_map>
|
1886 |
+
#include <algorithm>
|
1887 |
+
|
1888 |
+
|
1889 |
+
|
1890 |
+
|
1891 |
+
#define BLOCK "block #"
|
1892 |
+
#define CLASS "class"
|
1893 |
+
#define STRUCT "struct"
|
1894 |
+
#define SCMODULE "sc_module"
|
1895 |
+
#define DCSCMODULE "::sc_module"
|
1896 |
+
#define SCMAIN "function sc_main"
|
1897 |
+
#define SYMTAB "Symtab"
|
1898 |
+
#define CAT "computed at runtime"
|
1899 |
+
#define CONSTRUCT "construct"
|
1900 |
+
#define TYPEDEF "typedef"
|
1901 |
+
#define SCCORE "sc_core::"
|
1902 |
+
#define CONST "const"
|
1903 |
+
#define CT "const this;"
|
1904 |
+
|
1905 |
+
|
1906 |
+
typedef pair<string, string> NT; //------N : name and T: type, which is for variable and function
|
1907 |
+
|
1908 |
+
const vector<string> CPlusPlus_type = {"char","char16_t","char32_t","wchar_t","signed char","short","int","long","long long","unsigned char","unsigned short","unsigned","unsigned long","unsigned long long","float","double","long double","bool","void"};
|
1909 |
+
|
1910 |
+
bool string_finder (string , string);
|
1911 |
+
void GotoLine(ifstream& , unsigned int);
|
1912 |
+
vector<string> split(const string &, char);
|
1913 |
+
string replace_first_occurrence (string&, const string&, const string&);
|
1914 |
+
bool findchar_exact (string, vector<string>);
|
1915 |
+
void print_vector (vector<string>);
|
1916 |
+
int find_in_vector (vector<string>, string);
|
1917 |
+
void remove_element_vector(vector<string>&, string);
|
1918 |
+
void set_NT_vector (vector<NT>&, NT);
|
1919 |
+
void filter_element (string&, vector<string>);
|
1920 |
+
string make_string (vector<NT>);
|
1921 |
+
string make_XML (vector<NT>);
|
1922 |
+
|
1923 |
+
#endif
|
1924 |
+
// Copyright (c) 2019 Group of Computer Architecture, university of Bremen. All Rights Reserved.
|
1925 |
+
// Filename: SCmain.cpp
|
1926 |
+
// Version 1 09-July-2019
|
1927 |
+
|
1928 |
+
#include "SCmain.h"
|
1929 |
+
|
1930 |
+
|
1931 |
+
|
1932 |
+
void ScMain::print_data(){
|
1933 |
+
ofstream txtFile;
|
1934 |
+
txtFile.open ("output.txt");
|
1935 |
+
txtFile<<"--------------Extracted Static Information--------------"<<endl;
|
1936 |
+
for (auto i: static_data_final){
|
1937 |
+
txtFile<<"Module Name ----->\n"<<i.get_name()<<endl;
|
1938 |
+
txtFile<<"Var List ----->\n"<<i.get_var()<<endl;
|
1939 |
+
txtFile<<"Func List ----->\n"<<i.get_func()<<endl;
|
1940 |
+
txtFile<<"----------------------------------------------------"<<endl;
|
1941 |
+
}
|
1942 |
+
}
|
1943 |
+
|
1944 |
+
//----------------------------------------------------------
|
1945 |
+
void ScMain::print_data_XML(){
|
1946 |
+
ofstream xmlFile;
|
1947 |
+
xmlFile.open ("output.xml");
|
1948 |
+
|
1949 |
+
xmlFile<<"<ESL_ARCH>"<<endl;
|
1950 |
+
for (auto i: static_data_final){
|
1951 |
+
xmlFile<<i.get_name_XML()<<endl;
|
1952 |
+
xmlFile<<i.get_var_XML()<<endl;
|
1953 |
+
xmlFile<<i.get_func_XML()<<endl;
|
1954 |
+
if (i.get_name() == "sc_main")
|
1955 |
+
xmlFile<<"</Global_function>\n"<<endl;
|
1956 |
+
else
|
1957 |
+
xmlFile<<"</Module>\n"<<endl;
|
1958 |
+
}
|
1959 |
+
xmlFile<<"</ESL_ARCH>"<<endl;
|
1960 |
+
xmlFile.close();
|
1961 |
+
}
|
1962 |
+
|
1963 |
+
//----------------------------------------------------------
|
1964 |
+
void ScMain::update_localVar (string m_name, string f_sig, vector<NT> local_var){
|
1965 |
+
int index = find_element(m_name);
|
1966 |
+
if (index != -1)
|
1967 |
+
static_data_final[index].set_func_with_local(f_sig, local_var);
|
1968 |
+
}
|
1969 |
+
|
1970 |
+
//----------------------------------------------------------
|
1971 |
+
void ScMain::set_func_localVar(ifstream &debugSymbol){
|
1972 |
+
unordered_map<string, vector<NT>> func_temp;
|
1973 |
+
vector<string> vect_decod;
|
1974 |
+
string temp, line;
|
1975 |
+
vector<NT> Vect_NameType;
|
1976 |
+
unsigned int lineNum = 0;
|
1977 |
+
|
1978 |
+
for (auto i: static_data_final){
|
1979 |
+
func_temp = i.get_func_data();
|
1980 |
+
for (auto j: func_temp){
|
1981 |
+
lineNum = 0;
|
1982 |
+
vect_decod = split(j.first,'+');
|
1983 |
+
temp = "function " + i.get_name() + "::" + vect_decod[0];
|
1984 |
+
GotoLine(debugSymbol, lineNum); //-------start from begining of file
|
1985 |
+
if (debugSymbol.is_open()){
|
1986 |
+
while (getline(debugSymbol, line)) {
|
1987 |
+
lineNum++;
|
1988 |
+
if (string_finder (line, temp)){
|
1989 |
+
Vect_NameType = find_localVar_elements (debugSymbol, lineNum);
|
1990 |
+
update_localVar(i.get_name(),j.first, Vect_NameType);
|
1991 |
+
break;
|
1992 |
+
}
|
1993 |
+
}
|
1994 |
+
}
|
1995 |
+
else
|
1996 |
+
cout << "\033[1;31mUnable to open Debug Symbol file\033[0m\n";
|
1997 |
+
}
|
1998 |
+
}
|
1999 |
+
}
|
2000 |
+
|
2001 |
+
//----------------------------------------------------------
|
2002 |
+
vector<NT> ScMain::find_localVar_elements (ifstream &debugSymbol, unsigned int lineNum){
|
2003 |
+
vector<NT> Vect_NameType;
|
2004 |
+
vector<string> split_line;
|
2005 |
+
NT NameType;
|
2006 |
+
string line;
|
2007 |
+
GotoLine(debugSymbol, lineNum);
|
2008 |
+
bool findComplexType = 0;
|
2009 |
+
|
2010 |
+
if (debugSymbol.is_open()){
|
2011 |
+
while (getline(debugSymbol, line)) {
|
2012 |
+
if ((!string_finder (line, DCSCMODULE)) && (!line.empty()) && (string_finder (line, CLASS) || string_finder (line, STRUCT))){ //--------- first step of extracting local var of systemC
|
2013 |
+
split_line = split(line, ' ');
|
2014 |
+
remove_element_vector(split_line, "");
|
2015 |
+
if ((split_line.size() > 3) && string_finder (line, CLASS))
|
2016 |
+
NameType.second = split_line[2];
|
2017 |
+
else
|
2018 |
+
NameType.second = split_line[1];
|
2019 |
+
if (string_finder (NameType.second, SCCORE) && string_finder (NameType.second, "<"))
|
2020 |
+
NameType.second = replace_first_occurrence(NameType.second,",",">");
|
2021 |
+
|
2022 |
+
findComplexType = 1;
|
2023 |
+
}
|
2024 |
+
else if (string_finder (line, CAT) && findComplexType && (!string_finder (line, CT)) && string_finder (line,"}")){ //--- second step of complex type
|
2025 |
+
split_line = split(line, ' ');
|
2026 |
+
remove_element_vector(split_line, "");
|
2027 |
+
NameType.first = split_line[1];
|
2028 |
+
NameType.first = replace_first_occurrence(NameType.first,";","");
|
2029 |
+
|
2030 |
+
set_NT_vector (Vect_NameType, NameType);
|
2031 |
+
}
|
2032 |
+
else if (string_finder (line, CAT) && (!string_finder (line, CT))){ //----------- extracting local var of c++ for each function
|
2033 |
+
NameType = find_module_var(line);
|
2034 |
+
set_NT_vector (Vect_NameType, NameType);
|
2035 |
+
}
|
2036 |
+
if (string_finder (line, BLOCK))
|
2037 |
+
return Vect_NameType;
|
2038 |
+
}
|
2039 |
+
}
|
2040 |
+
|
2041 |
+
}
|
2042 |
+
|
2043 |
+
//----------------------------------------------------------
|
2044 |
+
void ScMain::set_static_data_func (string m_name, NT f_name){
|
2045 |
+
Component temp_struct;
|
2046 |
+
int index = find_element(m_name);
|
2047 |
+
|
2048 |
+
if (index != -1){
|
2049 |
+
static_data_final[index].set_func(f_name);
|
2050 |
+
}
|
2051 |
+
else{
|
2052 |
+
temp_struct.set_name (m_name);
|
2053 |
+
temp_struct.set_func(f_name);
|
2054 |
+
static_data_final.push_back(temp_struct);
|
2055 |
+
}
|
2056 |
+
}
|
2057 |
+
|
2058 |
+
//----------------------------------------------------------
|
2059 |
+
int ScMain::find_element (string str){
|
2060 |
+
for (int i=0; i< static_data_final.size(); ++i){
|
2061 |
+
if (static_data_final[i].get_name() == str)
|
2062 |
+
return i;
|
2063 |
+
}
|
2064 |
+
return -1;
|
2065 |
+
}
|
2066 |
+
|
2067 |
+
//----------------------------------------------------------
|
2068 |
+
void ScMain::set_static_data_var (string m_name, NT v_name){
|
2069 |
+
Component temp_struct;
|
2070 |
+
int index = find_element(m_name);
|
2071 |
+
|
2072 |
+
if (index != -1){
|
2073 |
+
static_data_final[index].set_var(v_name);
|
2074 |
+
}
|
2075 |
+
else{
|
2076 |
+
temp_struct.set_name (m_name);
|
2077 |
+
temp_struct.set_var(v_name);
|
2078 |
+
static_data_final.push_back(temp_struct);
|
2079 |
+
}
|
2080 |
+
}
|
2081 |
+
|
2082 |
+
//----------------------------------------------------------
|
2083 |
+
bool ScMain::find_scmain_elements (ifstream &debugSymbol, unsigned int lineNum){
|
2084 |
+
string line, string_type, string_name;
|
2085 |
+
NT name_type;
|
2086 |
+
bool permission_flag = 0;
|
2087 |
+
vector<string> split_line;
|
2088 |
+
GotoLine(debugSymbol, lineNum);
|
2089 |
+
|
2090 |
+
if (debugSymbol.is_open()){
|
2091 |
+
while (getline(debugSymbol, line)) {
|
2092 |
+
if(!(string_finder(line, BLOCK))){
|
2093 |
+
if (string_finder(line, CLASS)){
|
2094 |
+
string_type = line;
|
2095 |
+
split_line = split(string_type,' ');
|
2096 |
+
string_type = split_line[6];
|
2097 |
+
if((string_finder(string_type, SCCORE)) && (string_finder(string_type, "<"))){
|
2098 |
+
string_type = replace_first_occurrence(string_type,",",">");
|
2099 |
+
}
|
2100 |
+
else if (string_finder(string_type, SCCORE)){
|
2101 |
+
string_type = split_line[6];
|
2102 |
+
|
2103 |
+
}
|
2104 |
+
permission_flag = 1;
|
2105 |
+
}
|
2106 |
+
else if ((string_finder(line, CAT)) && (permission_flag)){
|
2107 |
+
string_name = line;
|
2108 |
+
split_line = split(string_name,' ');
|
2109 |
+
string_name = replace_first_occurrence(split_line[6],";","");
|
2110 |
+
filter_element(string_name, {"*","&"});
|
2111 |
+
|
2112 |
+
name_type.first = string_name;
|
2113 |
+
name_type.second = string_type;
|
2114 |
+
permission_flag=0;
|
2115 |
+
set_static_data_var ("sc_main", name_type);
|
2116 |
+
}
|
2117 |
+
}
|
2118 |
+
else{
|
2119 |
+
return 1;
|
2120 |
+
}
|
2121 |
+
}
|
2122 |
+
}
|
2123 |
+
else
|
2124 |
+
cout << "\033[1;31mUnable to open Debug Symbol file\033[0m\n";
|
2125 |
+
return 0;
|
2126 |
+
}
|
2127 |
+
|
2128 |
+
//----------------------------------------------------------
|
2129 |
+
bool ScMain::find_scmain (ifstream &debugSymbol){
|
2130 |
+
string line;
|
2131 |
+
bool finish = 0;
|
2132 |
+
unsigned int line_num = 0;
|
2133 |
+
|
2134 |
+
if (debugSymbol.is_open()){
|
2135 |
+
while (getline (debugSymbol,line)){
|
2136 |
+
line_num++;
|
2137 |
+
if (string_finder(line, BLOCK) && string_finder(line, SCMAIN)){
|
2138 |
+
cout << "\033[1;32mStarting sc_main() variables extraction...\033[0m\n";
|
2139 |
+
finish = find_scmain_elements (debugSymbol, line_num);
|
2140 |
+
if (finish){
|
2141 |
+
cout << "\033[1;32msc_main() variables extraction is dine!\033[0m\n";
|
2142 |
+
cout << "\033[1;32mStarting module extraction...\033[0m\n";
|
2143 |
+
find_module (debugSymbol, line_num);
|
2144 |
+
cout << "\033[1;32mModule extraction is done!\033[0m\n";
|
2145 |
+
GotoLine(debugSymbol, 0); //-------start from begining of file
|
2146 |
+
cout << "\033[1;32mStarting local variables extraction...\033[0m\n";
|
2147 |
+
set_func_localVar(debugSymbol);
|
2148 |
+
cout << "\033[1;32mLocal variables extraction is done!\033[0m\n";
|
2149 |
+
return 1;
|
2150 |
+
}
|
2151 |
+
else{
|
2152 |
+
cout << "\033[1;31mCould not find sc_main() function\033[0m\n";
|
2153 |
+
return 0;
|
2154 |
+
}
|
2155 |
+
}
|
2156 |
+
}
|
2157 |
+
}
|
2158 |
+
else{
|
2159 |
+
cout << "\033[1;31mUnable to open Debug Symbol file\033[0m\n";
|
2160 |
+
return 0;
|
2161 |
+
}
|
2162 |
+
}
|
2163 |
+
|
2164 |
+
//----------------------------------------------------------
|
2165 |
+
void ScMain::find_module (ifstream &debugSymbol, unsigned int lineNum){
|
2166 |
+
GotoLine(debugSymbol, lineNum);
|
2167 |
+
string line, module_name;
|
2168 |
+
vector<string> split_line;
|
2169 |
+
|
2170 |
+
if (debugSymbol.is_open()){
|
2171 |
+
while (getline(debugSymbol, line)) {
|
2172 |
+
lineNum++;
|
2173 |
+
if((string_finder(line, STRUCT)) && (string_finder(line, SCMODULE)) && (!string_finder(line, "::_")) && (!string_finder(line, BLOCK)) && (!string_finder(line, CONSTRUCT)) && (!string_finder(line, "*"))){
|
2174 |
+
|
2175 |
+
split_line = split(line,' ');
|
2176 |
+
remove_element_vector(split_line, "");
|
2177 |
+
|
2178 |
+
if (string_finder(line, ">")) //--- for template type
|
2179 |
+
module_name = split_line[1]+" "+split_line[2];
|
2180 |
+
else
|
2181 |
+
module_name = split_line[1];
|
2182 |
+
|
2183 |
+
if ((!string_finder(module_name, CLASS)) && (!string_finder(module_name, CONST)) && (!string_finder(module_name, SCCORE))){ //---ignoring pre-defined systemc module and function
|
2184 |
+
find_module_elements(debugSymbol,lineNum, module_name);
|
2185 |
+
GotoLine(debugSymbol, lineNum); //------------------return back to the line number where module defined
|
2186 |
+
|
2187 |
+
}
|
2188 |
+
}
|
2189 |
+
}
|
2190 |
+
}
|
2191 |
+
else
|
2192 |
+
cout << "\033[1;31mUnable to open Debug Symbol file\033[0m\n";
|
2193 |
+
}
|
2194 |
+
|
2195 |
+
//----------------------------------------------------------
|
2196 |
+
void ScMain::find_module_elements (ifstream &debugSymbol, unsigned int lineNum, string m_name){
|
2197 |
+
NT VarNameType;
|
2198 |
+
NT FuncNameType;
|
2199 |
+
GotoLine(debugSymbol, lineNum);
|
2200 |
+
string line, string_type;
|
2201 |
+
vector<string> split_line;
|
2202 |
+
|
2203 |
+
if (debugSymbol.is_open()){
|
2204 |
+
while (getline(debugSymbol, line)) {
|
2205 |
+
if((!string_finder(line, "}")) && (string_finder(line, ");")) && (!line.empty())){
|
2206 |
+
FuncNameType = find_module_func(line);
|
2207 |
+
set_static_data_func (m_name, FuncNameType);
|
2208 |
+
}
|
2209 |
+
else if ((string_finder(line, ";")) && (!string_finder(line, TYPEDEF)) && (!string_finder(line, "}"))){
|
2210 |
+
VarNameType = find_module_var (line);
|
2211 |
+
set_static_data_var (m_name, VarNameType);
|
2212 |
+
|
2213 |
+
}
|
2214 |
+
else if (string_finder(line, "}"))
|
2215 |
+
break;
|
2216 |
+
}
|
2217 |
+
}
|
2218 |
+
else
|
2219 |
+
cout << "\033[1;31mUnable to open Debug Symbol file\033[0m\n";
|
2220 |
+
}
|
2221 |
+
|
2222 |
+
//----------------------------------------------------------
|
2223 |
+
NT ScMain:: find_module_func (string line){
|
2224 |
+
NT NameType;
|
2225 |
+
vector<string> split_line = split(line, ' ');
|
2226 |
+
remove_element_vector(split_line, "");
|
2227 |
+
|
2228 |
+
if ((split_line.size()>1) && (!string_finder(line, "~"))){ //------------------- ignore constractor and destrocture function
|
2229 |
+
int index = find_in_vector(split_line, "(");
|
2230 |
+
if (index>=0){
|
2231 |
+
size_t pos = split_line[index].find("(");
|
2232 |
+
NameType.first = split_line[index].substr(0,pos);
|
2233 |
+
NameType.second = split_line[index-1];
|
2234 |
+
}
|
2235 |
+
}
|
2236 |
+
return NameType;
|
2237 |
+
}
|
2238 |
+
|
2239 |
+
//----------------------------------------------------------
|
2240 |
+
NT ScMain:: find_module_var (string line){
|
2241 |
+
NT NameType;
|
2242 |
+
vector<string> split_line = split(line, ' ');
|
2243 |
+
remove_element_vector(split_line, "");
|
2244 |
+
int index_var = find_in_vector(split_line, ";");
|
2245 |
+
|
2246 |
+
if (index_var >=0)
|
2247 |
+
NameType.first = replace_first_occurrence(split_line[index_var],";","");
|
2248 |
+
else
|
2249 |
+
NameType.first = replace_first_occurrence(split_line[1],";","");
|
2250 |
+
|
2251 |
+
NameType.second = split_line[0];
|
2252 |
+
filter_element(NameType.first, {"*","&","["});
|
2253 |
+
return NameType;
|
2254 |
+
}
|
2255 |
+
|
2256 |
+
#include "systemc.h"
|
2257 |
+
#include "tlm.h"
|
2258 |
+
#include <string>
|
2259 |
+
|
2260 |
+
using namespace std;
|
2261 |
+
|
2262 |
+
using namespace tlm;
|
2263 |
+
|
2264 |
+
struct tr {
|
2265 |
+
string message;
|
2266 |
+
};
|
2267 |
+
|
2268 |
+
#include "uvmc.h"
|
2269 |
+
using namespace uvmc;
|
2270 |
+
UVMC_UTILS_1(tr, message)
|
2271 |
+
|
2272 |
+
|
2273 |
+
SC_MODULE(refmod) {
|
2274 |
+
sc_port<tlm_get_peek_if<tr> > in;
|
2275 |
+
sc_port<tlm_put_if<tr> > out;
|
2276 |
+
|
2277 |
+
void p() {
|
2278 |
+
|
2279 |
+
tr tr;
|
2280 |
+
while(1){
|
2281 |
+
tr = in->get();
|
2282 |
+
cout <<"refmod: " <<tr.message <<"\n";
|
2283 |
+
out->put(tr);
|
2284 |
+
}
|
2285 |
+
}
|
2286 |
+
SC_CTOR(refmod): in("in"), out("out") { SC_THREAD(p); }
|
2287 |
+
};
|
2288 |
+
|
2289 |
+
|
2290 |
+
|
2291 |
+
SC_MODULE(refmod_low){
|
2292 |
+
sc_port<tlm_get_peek_if<tr> > in;
|
2293 |
+
sc_port<tlm_put_if<tr> > out;
|
2294 |
+
|
2295 |
+
void p() {
|
2296 |
+
|
2297 |
+
tr tr;
|
2298 |
+
while(1){
|
2299 |
+
tr = in->get();
|
2300 |
+
cout <<"refmod_low: " <<tr.message <<"\n";
|
2301 |
+
out->put(tr);
|
2302 |
+
}
|
2303 |
+
}
|
2304 |
+
SC_CTOR(refmod_low): in("in"), out("out") { SC_THREAD(p); }
|
2305 |
+
};
|
2306 |
+
|
2307 |
+
|
2308 |
+
|
2309 |
+
#include "refmod.cpp"
|
2310 |
+
#include "refmod_low.cpp"
|
2311 |
+
|
2312 |
+
int sc_main(int argc, char* argv[]) {
|
2313 |
+
|
2314 |
+
refmod refmod_i("refmod_i");
|
2315 |
+
refmod_low refmod_low_i("refmod_low_i");
|
2316 |
+
|
2317 |
+
uvmc_connect(refmod_i.in, "refmod_i.in");
|
2318 |
+
uvmc_connect(refmod_low_i.in, "refmod_low_i.in");
|
2319 |
+
uvmc_connect(refmod_i.out, "refmod_i.out");
|
2320 |
+
uvmc_connect(refmod_low_i.out, "refmod_low_i.out");
|
2321 |
+
|
2322 |
+
sc_start();
|
2323 |
+
return(0);
|
2324 |
+
}
|
2325 |
+
|
2326 |
+
|
2327 |
+
#ifndef KAHN_PROCESS_H
|
2328 |
+
#define KAHN_PROCESS_H
|
2329 |
+
/*
|
2330 |
+
* kahn_process.h -- Base SystemC module for modeling applications using KPN
|
2331 |
+
*
|
2332 |
+
* System-Level Architecture and Modeling Lab
|
2333 |
+
* Department of Electrical and Computer Engineering
|
2334 |
+
* The University of Texas at Austin
|
2335 |
+
*
|
2336 |
+
* Author: Kamyar Mirzazad Barijough (kammirzazad@utexas.edu)
|
2337 |
+
*/
|
2338 |
+
|
2339 |
+
#include <systemc.h>
|
2340 |
+
|
2341 |
+
class kahn_process : public sc_module
|
2342 |
+
{
|
2343 |
+
public:
|
2344 |
+
|
2345 |
+
SC_HAS_PROCESS(kahn_process);
|
2346 |
+
|
2347 |
+
kahn_process(sc_module_name name) : sc_module(name)
|
2348 |
+
{
|
2349 |
+
iter = 0;
|
2350 |
+
SC_THREAD(main);
|
2351 |
+
}
|
2352 |
+
|
2353 |
+
void main() { while(true) {process(); iter++;} }
|
2354 |
+
|
2355 |
+
protected:
|
2356 |
+
|
2357 |
+
int iter = 0;
|
2358 |
+
|
2359 |
+
virtual void process() = 0;
|
2360 |
+
};
|
2361 |
+
#endif
|
2362 |
+
|
2363 |
+
#include <systemc.h>
|
2364 |
+
|
2365 |
+
template <class T> SC_MODULE (driver){
|
2366 |
+
// Modulo de acionamento
|
2367 |
+
sc_fifo_out <T> acionamento;
|
2368 |
+
|
2369 |
+
// Constante para acionamento
|
2370 |
+
T cte;
|
2371 |
+
|
2372 |
+
// Funcionamento do driver
|
2373 |
+
void drive(){
|
2374 |
+
int contador = 0;
|
2375 |
+
|
2376 |
+
// Geracao de 0s para o acionamento do sistema
|
2377 |
+
while(contador < 3){
|
2378 |
+
acionamento.write(cte);
|
2379 |
+
cout << "Gerou um " << cte << endl;
|
2380 |
+
|
2381 |
+
contador++;
|
2382 |
+
}
|
2383 |
+
}
|
2384 |
+
|
2385 |
+
// Utilizando construtor de C++
|
2386 |
+
SC_HAS_PROCESS(driver);
|
2387 |
+
|
2388 |
+
driver (sc_module_name n, const T& c):
|
2389 |
+
sc_module(n), cte(c){
|
2390 |
+
SC_THREAD (drive);
|
2391 |
+
}
|
2392 |
+
};
|
2393 |
+
|
2394 |
+
#include "sistema.cpp"
|
2395 |
+
|
2396 |
+
int sc_main (int arc, char * argv[]){
|
2397 |
+
|
2398 |
+
// Instanciacao do sistema, definindo o tipo da matriz e do vetor
|
2399 |
+
sistema <int> sistema_instance("sistema_instance");
|
2400 |
+
|
2401 |
+
// Definindo a matriz
|
2402 |
+
// Coluna 1
|
2403 |
+
sistema_instance.mul1.matriz_in.write(1);
|
2404 |
+
sistema_instance.mul1.matriz_in.write(4);
|
2405 |
+
sistema_instance.mul1.matriz_in.write(7);
|
2406 |
+
|
2407 |
+
// Coluna 2
|
2408 |
+
sistema_instance.mul2.matriz_in.write(2);
|
2409 |
+
sistema_instance.mul2.matriz_in.write(5);
|
2410 |
+
sistema_instance.mul2.matriz_in.write(8);
|
2411 |
+
|
2412 |
+
// Coluna 3
|
2413 |
+
sistema_instance.mul3.matriz_in.write(3);
|
2414 |
+
sistema_instance.mul3.matriz_in.write(6);
|
2415 |
+
sistema_instance.mul3.matriz_in.write(9);
|
2416 |
+
// |1 2 3|
|
2417 |
+
// |4 5 6|
|
2418 |
+
// |7 8 9|
|
2419 |
+
|
2420 |
+
// Definindo o vetor
|
2421 |
+
sistema_instance.mul1.vetor_in.write(1);
|
2422 |
+
sistema_instance.mul2.vetor_in.write(2);
|
2423 |
+
sistema_instance.mul3.vetor_in.write(3);
|
2424 |
+
// (1)
|
2425 |
+
// (2)
|
2426 |
+
// (3)
|
2427 |
+
|
2428 |
+
sc_start();
|
2429 |
+
|
2430 |
+
return 0;
|
2431 |
+
}
|
2432 |
+
|
2433 |
+
#include "mul.cpp"
|
2434 |
+
|
2435 |
+
template <class T> SC_MODULE (monitor){
|
2436 |
+
// Modulo de exibicao
|
2437 |
+
sc_fifo_in <T> resultado;
|
2438 |
+
|
2439 |
+
// Funcionamento do Monitor
|
2440 |
+
void monitora(){
|
2441 |
+
int contador = 0;
|
2442 |
+
cout << endl << "Resultado" << endl;
|
2443 |
+
|
2444 |
+
while(true){
|
2445 |
+
// Imprime o vetor resultado
|
2446 |
+
T elemento = resultado.read();
|
2447 |
+
cout << "V" << contador << ": " << elemento << endl;
|
2448 |
+
contador++;
|
2449 |
+
}
|
2450 |
+
}
|
2451 |
+
|
2452 |
+
SC_CTOR (monitor){
|
2453 |
+
SC_THREAD (monitora);
|
2454 |
+
}
|
2455 |
+
|
2456 |
+
};
|
2457 |
+
|
2458 |
+
#include "driver.cpp"
|
2459 |
+
|
2460 |
+
template <class T> SC_MODULE (mul){
|
2461 |
+
// Entradas
|
2462 |
+
sc_signal <T> vetor_in;
|
2463 |
+
sc_fifo <T> matriz_in;
|
2464 |
+
sc_fifo_in <T> soma_in;
|
2465 |
+
|
2466 |
+
// Saidas
|
2467 |
+
sc_fifo_out <T> resultado_out;
|
2468 |
+
|
2469 |
+
// Funcionamento do modulo
|
2470 |
+
void opera(){
|
2471 |
+
while(true){
|
2472 |
+
// Resultado = Soma + Vetor * Matriz
|
2473 |
+
resultado_out.write((soma_in.read() + (vetor_in.read() * matriz_in.read())));
|
2474 |
+
}
|
2475 |
+
}
|
2476 |
+
|
2477 |
+
SC_CTOR (mul){
|
2478 |
+
SC_THREAD(opera);
|
2479 |
+
}
|
2480 |
+
|
2481 |
+
};
|
2482 |
+
|
2483 |
+
#include "monitor.cpp"
|
2484 |
+
|
2485 |
+
template <class T> SC_MODULE (sistema){
|
2486 |
+
// Instanciacao dos modulos a serem utilizados
|
2487 |
+
driver <T> driver_mul;
|
2488 |
+
mul <T> mul1;
|
2489 |
+
mul <T> mul2;
|
2490 |
+
mul <T> mul3;
|
2491 |
+
monitor <T> monitor_mul;
|
2492 |
+
|
2493 |
+
// FIFOs para conectar os modulos
|
2494 |
+
sc_fifo <T> driver_mul1;
|
2495 |
+
sc_fifo <T> mul1_mul2;
|
2496 |
+
sc_fifo <T> mul2_mul3;
|
2497 |
+
sc_fifo <T> mul3_monitor;
|
2498 |
+
|
2499 |
+
// Interconexao
|
2500 |
+
SC_CTOR (sistema): driver_mul("driver_mul", 0),
|
2501 |
+
mul1("mul1"),
|
2502 |
+
mul2("mul2"),
|
2503 |
+
mul3("mul3"),
|
2504 |
+
monitor_mul("monitor_mul"){
|
2505 |
+
|
2506 |
+
// Conectando o driver ao 1 mul
|
2507 |
+
driver_mul.acionamento(driver_mul1);
|
2508 |
+
mul1.soma_in(driver_mul1);
|
2509 |
+
|
2510 |
+
// Conectando o 1 mul ao 2 mul
|
2511 |
+
mul1.resultado_out(mul1_mul2);
|
2512 |
+
mul2.soma_in(mul1_mul2);
|
2513 |
+
|
2514 |
+
// Conectando o 2 mul ao 3 mul
|
2515 |
+
mul2.resultado_out(mul2_mul3);
|
2516 |
+
mul3.soma_in(mul2_mul3);
|
2517 |
+
|
2518 |
+
// Conectando o 3 mul ao monitor
|
2519 |
+
mul3.resultado_out(mul3_monitor);
|
2520 |
+
monitor_mul.resultado(mul3_monitor);
|
2521 |
+
}
|
2522 |
+
};
|
2523 |
+
|
2524 |
+
#include <systemc.h>
|
2525 |
+
#include "breg_if.h"
|
2526 |
+
|
2527 |
+
/*
|
2528 |
+
* Banco de registradores que implementa a interface breg_if, eh
|
2529 |
+
* utilizado na fase de EXECUTE.
|
2530 |
+
*/
|
2531 |
+
struct breg_risc: public sc_module, public breg_if {
|
2532 |
+
|
2533 |
+
// Leitura
|
2534 |
+
int16_t read_breg(uint16_t reg);
|
2535 |
+
// Escrita
|
2536 |
+
void write_breg(uint16_t reg, int16_t dado);
|
2537 |
+
// Impressao
|
2538 |
+
void dump_breg();
|
2539 |
+
|
2540 |
+
SC_HAS_PROCESS(breg_risc);
|
2541 |
+
|
2542 |
+
// Declaracao do breg
|
2543 |
+
breg_risc (sc_module_name n) :
|
2544 |
+
sc_module(n){
|
2545 |
+
breg = new int16_t[16];
|
2546 |
+
}
|
2547 |
+
|
2548 |
+
private:
|
2549 |
+
int16_t *breg;
|
2550 |
+
|
2551 |
+
};
|
2552 |
+
|
2553 |
+
#include <systemc.h>
|
2554 |
+
|
2555 |
+
// Interface do breg
|
2556 |
+
struct breg_if: public sc_interface {
|
2557 |
+
|
2558 |
+
// Leitura
|
2559 |
+
virtual
|
2560 |
+
int16_t read_breg(uint16_t reg) = 0;
|
2561 |
+
|
2562 |
+
// Escrita
|
2563 |
+
virtual
|
2564 |
+
void write_breg(uint16_t reg, int16_t dado) = 0;
|
2565 |
+
|
2566 |
+
// Impressao
|
2567 |
+
virtual
|
2568 |
+
void dump_breg() = 0;
|
2569 |
+
};
|
2570 |
+
|
2571 |
+
#include "fetch.h"
|
2572 |
+
|
2573 |
+
/*
|
2574 |
+
* Decodificacao de uma funcao.
|
2575 |
+
* - Acessa: contexto.
|
2576 |
+
* - Saida: op, regs, regs2, regd, const4, const8.
|
2577 |
+
*/
|
2578 |
+
SC_MODULE(decode){
|
2579 |
+
// Ponteiro para o contexto
|
2580 |
+
Contexto_t *c_decode;
|
2581 |
+
|
2582 |
+
// Entradas
|
2583 |
+
sc_fifo_in <Contexto_t*> decode_in;
|
2584 |
+
|
2585 |
+
// Saidas
|
2586 |
+
sc_fifo_out <Contexto_t*> decode_out;
|
2587 |
+
|
2588 |
+
// Definicao do funcionamento do decode
|
2589 |
+
void decoding();
|
2590 |
+
|
2591 |
+
SC_CTOR(decode){
|
2592 |
+
SC_THREAD(decoding);
|
2593 |
+
}
|
2594 |
+
};
|
2595 |
+
|
2596 |
+
#include "decode.h"
|
2597 |
+
|
2598 |
+
// Enumeracao que define os opcodes das instrucoes
|
2599 |
+
enum INSTRUCTIONS {
|
2600 |
+
i_ADD = 0x2,
|
2601 |
+
i_SUB = 0x3,
|
2602 |
+
i_ADDi = 0x8,
|
2603 |
+
i_SHIFT = 0x9,
|
2604 |
+
i_AND = 0x4,
|
2605 |
+
i_OR = 0x5,
|
2606 |
+
i_NOT = 0xA,
|
2607 |
+
i_XOR = 0x6,
|
2608 |
+
i_SLT = 0x7,
|
2609 |
+
i_LW = 0,
|
2610 |
+
i_SW = 0x1,
|
2611 |
+
i_LUI = 0xB,
|
2612 |
+
i_BEQ = 0xC,
|
2613 |
+
i_BLT = 0xD,
|
2614 |
+
i_J = 0xE,
|
2615 |
+
i_JAL = 0xF
|
2616 |
+
};
|
2617 |
+
|
2618 |
+
/*
|
2619 |
+
* Execucao de uma funcao.
|
2620 |
+
* - Acessa: breg, mem e contexto.
|
2621 |
+
* - Saida: breg, mem ou pc.
|
2622 |
+
*/
|
2623 |
+
SC_MODULE(execute){
|
2624 |
+
// Ponteiro para o contexto
|
2625 |
+
Contexto_t *c_execute;
|
2626 |
+
|
2627 |
+
// Entradas
|
2628 |
+
sc_fifo_in <Contexto_t*> execute_in;
|
2629 |
+
|
2630 |
+
// Saidas
|
2631 |
+
sc_fifo_out <Contexto_t*> execute_out;
|
2632 |
+
|
2633 |
+
// Memoria
|
2634 |
+
sc_port<mem_if> p_mem_ex;
|
2635 |
+
|
2636 |
+
// BREG
|
2637 |
+
sc_port<breg_if> p_breg_ex;
|
2638 |
+
|
2639 |
+
// Funcao para impressao do decode
|
2640 |
+
void debug_decode();
|
2641 |
+
|
2642 |
+
// Definicao do funcionamento do execute
|
2643 |
+
void executing();
|
2644 |
+
|
2645 |
+
SC_CTOR(execute){
|
2646 |
+
SC_THREAD(executing);
|
2647 |
+
}
|
2648 |
+
};
|
2649 |
+
|
2650 |
+
#include "fetch.h"
|
2651 |
+
|
2652 |
+
// Definicao do funcionamento do fetch
|
2653 |
+
void fetch::fetching(){
|
2654 |
+
while(true){
|
2655 |
+
// Pega o ponteiro do contexto
|
2656 |
+
c_fetch = fetch_in.read();
|
2657 |
+
|
2658 |
+
//// Pega a instrucao e incrementa o PC
|
2659 |
+
//ri = mem[pc];
|
2660 |
+
c_fetch->ri = p_mem_fetch->read_mem(c_fetch->pc);
|
2661 |
+
//pc++;
|
2662 |
+
c_fetch->pc++;
|
2663 |
+
|
2664 |
+
// Se nao possui mais instrucoes
|
2665 |
+
if(c_fetch->ri == 0){
|
2666 |
+
cout << "Nao possui mais instrucoes!" << endl;
|
2667 |
+
sc_stop();
|
2668 |
+
exit(0);
|
2669 |
+
}
|
2670 |
+
|
2671 |
+
// Passa o ponteiro do contexto para o decode
|
2672 |
+
fetch_out.write(c_fetch);
|
2673 |
+
}
|
2674 |
+
}
|
2675 |
+
|
2676 |
+
#include <systemc.h>
|
2677 |
+
#include "contexto.h"
|
2678 |
+
#include "mem.h"
|
2679 |
+
#include "breg.h"
|
2680 |
+
|
2681 |
+
/*
|
2682 |
+
* Decodificacao de uma funcao.
|
2683 |
+
* - Acessa: mem e contexto.
|
2684 |
+
* - Saida: ri e pc.
|
2685 |
+
*/
|
2686 |
+
SC_MODULE(fetch){
|
2687 |
+
// Contexto
|
2688 |
+
Contexto_t *c_fetch;
|
2689 |
+
|
2690 |
+
// Entradas
|
2691 |
+
sc_fifo_in <Contexto_t*> fetch_in;
|
2692 |
+
|
2693 |
+
// Saidas
|
2694 |
+
sc_fifo_out <Contexto_t*> fetch_out;
|
2695 |
+
|
2696 |
+
// Memoria
|
2697 |
+
sc_port<mem_if> p_mem_fetch;
|
2698 |
+
|
2699 |
+
// Definicao do funcionamento do fetch
|
2700 |
+
void fetching();
|
2701 |
+
|
2702 |
+
SC_CTOR(fetch){
|
2703 |
+
SC_THREAD(fetching);
|
2704 |
+
}
|
2705 |
+
};
|
2706 |
+
|
2707 |
+
// Variavel para definicao do modelo implementado, sendo:
|
2708 |
+
// - 0 para Modelo com threads e eventos
|
2709 |
+
// - 1 para Modelo com módulos interligados por filas bloqueantes
|
2710 |
+
#define MODELO 1
|
2711 |
+
|
2712 |
+
#if MODELO == 0
|
2713 |
+
#include "stdarg.h"
|
2714 |
+
#include "risc16.h"
|
2715 |
+
|
2716 |
+
#else
|
2717 |
+
#include "stdarg.h"
|
2718 |
+
#include "top.h"
|
2719 |
+
|
2720 |
+
#endif
|
2721 |
+
|
2722 |
+
// Enumeracao que representa o formato da instrucao
|
2723 |
+
enum i_FORMAT {
|
2724 |
+
TIPO_R=4, TIPO_I=3, TIPO_J=2
|
2725 |
+
};
|
2726 |
+
|
2727 |
+
// Funcao para geracao de instrucoes na memoria
|
2728 |
+
short gerainst(int n, ...) {
|
2729 |
+
short inst = 0;
|
2730 |
+
|
2731 |
+
va_list ap;
|
2732 |
+
|
2733 |
+
va_start(ap, n);
|
2734 |
+
|
2735 |
+
switch (n) {
|
2736 |
+
case TIPO_R:
|
2737 |
+
inst |= (va_arg(ap, int ) & 0xF) << 12;
|
2738 |
+
inst |= (va_arg(ap, int ) & 0xF) << 8;
|
2739 |
+
inst |= (va_arg(ap, int ) & 0xF) << 4;
|
2740 |
+
inst |= (va_arg(ap, int ) & 0xF);
|
2741 |
+
break;
|
2742 |
+
case TIPO_I:
|
2743 |
+
inst |= (va_arg(ap, int ) & 0xF) << 12;
|
2744 |
+
inst |= (va_arg(ap, int ) & 0xF) << 8;
|
2745 |
+
inst |= (va_arg(ap, int ) & 0xF) << 4;
|
2746 |
+
inst |= (va_arg(ap, int ) & 0xF);
|
2747 |
+
break;
|
2748 |
+
case TIPO_J:
|
2749 |
+
inst |= (va_arg(ap, int ) & 0xF) << 12;
|
2750 |
+
inst |= (va_arg(ap, int ) & 0xF) << 8;
|
2751 |
+
inst |= (va_arg(ap, int ) & 0xFF);
|
2752 |
+
break;
|
2753 |
+
default:
|
2754 |
+
break;
|
2755 |
+
}
|
2756 |
+
return inst;
|
2757 |
+
}
|
2758 |
+
|
2759 |
+
|
2760 |
+
int sc_main (int arc, char * argv[]){
|
2761 |
+
|
2762 |
+
#if MODELO == 0
|
2763 |
+
|
2764 |
+
////// Instanciacao do risc16
|
2765 |
+
risc16 risc16_instance("risc16_instance");
|
2766 |
+
|
2767 |
+
cout << "|||||||||||||Modelo com Eventos|||||||||||||" << endl;
|
2768 |
+
|
2769 |
+
////// Escrevendo instrucoes na memoria
|
2770 |
+
//// Aritmeticas
|
2771 |
+
/* addi $1, 0 */
|
2772 |
+
// Resultado esperado => reg1 += 0
|
2773 |
+
risc16_instance.write_mem(0,gerainst(TIPO_J, i_ADDi, 1, 0));
|
2774 |
+
|
2775 |
+
/* addi $1, 8 */
|
2776 |
+
// Resultado esperado => reg1 += 8
|
2777 |
+
risc16_instance.write_mem(1,gerainst(TIPO_J, i_ADDi, 1, 8));
|
2778 |
+
|
2779 |
+
/* addi $2, -12 */
|
2780 |
+
// Resultado esperado => reg2 -= 12
|
2781 |
+
risc16_instance.write_mem(2,gerainst(TIPO_J, i_ADDi, 2, -12));
|
2782 |
+
|
2783 |
+
/* add $3, $2, $1 */
|
2784 |
+
// Resultado esperado => reg3 = reg2 + reg1
|
2785 |
+
risc16_instance.write_mem(3,gerainst(TIPO_R, i_ADD, 1, 2, 3));
|
2786 |
+
|
2787 |
+
/* sub $4, $2, $3 */
|
2788 |
+
// Resultado esperado => reg4 = reg2 - reg3
|
2789 |
+
risc16_instance.write_mem(4,gerainst(TIPO_R, i_SUB, 2, 3, 4));
|
2790 |
+
|
2791 |
+
/* add $5, $0, $1 */
|
2792 |
+
// Resultado esperado => reg5 = reg1
|
2793 |
+
risc16_instance.write_mem(5,gerainst(TIPO_R, i_ADD, 1, 0, 5));
|
2794 |
+
|
2795 |
+
/* shift $5, 2 */
|
2796 |
+
// Resultado esperado => reg5 >> 2
|
2797 |
+
risc16_instance.write_mem(6,gerainst(TIPO_J, i_SHIFT, 5, 2));
|
2798 |
+
|
2799 |
+
/* add $6, $0, $1 */
|
2800 |
+
// Resultado esperado => reg6 = reg1
|
2801 |
+
risc16_instance.write_mem(7,gerainst(TIPO_R, i_ADD, 1, 0, 6));
|
2802 |
+
|
2803 |
+
/* shift $6, -4 */
|
2804 |
+
// Resultado esperado => reg6 << 4
|
2805 |
+
risc16_instance.write_mem(8,gerainst(TIPO_J, i_SHIFT, 6, -4));
|
2806 |
+
|
2807 |
+
//// Logicas
|
2808 |
+
/* and $8, $7, $4 */
|
2809 |
+
// Resultado esperado => reg8 = reg7 & reg4
|
2810 |
+
risc16_instance.write_mem(9,gerainst(TIPO_R, i_AND, 4, 7, 8));
|
2811 |
+
|
2812 |
+
/* not $9 */
|
2813 |
+
// Resultado esperado => reg9 = ~reg9
|
2814 |
+
risc16_instance.write_mem(10,gerainst(TIPO_J, i_NOT, 9, 0, 0));
|
2815 |
+
|
2816 |
+
/* xor $10, $4, $7 */
|
2817 |
+
// Resultado esperado => reg10 = reg4 ^ reg7
|
2818 |
+
risc16_instance.write_mem(11,gerainst(TIPO_R, i_XOR, 4, 7, 10));
|
2819 |
+
|
2820 |
+
/* slt $11, $5, $1 */
|
2821 |
+
// Resultado esperado => reg11 = reg5<reg1 ? 1 : 0
|
2822 |
+
risc16_instance.write_mem(12,gerainst(TIPO_R, i_SLT, 5, 1, 11));
|
2823 |
+
|
2824 |
+
//// Transferencia
|
2825 |
+
/* lui $7, FF */
|
2826 |
+
// Resultado esperado => reg7 = const8 << 8
|
2827 |
+
risc16_instance.write_mem(13,gerainst(TIPO_J, i_LUI, 7, 0xFF));
|
2828 |
+
|
2829 |
+
/* sw $5, $0, $6 */
|
2830 |
+
// Resultado esperado => salva o que esta em $5 no endereco que esta em $6 da memoria
|
2831 |
+
risc16_instance.write_mem(14,gerainst(TIPO_R, i_SW, 6, 0, 5));
|
2832 |
+
|
2833 |
+
/* lw $12, $0, $6 */
|
2834 |
+
// Resultado esperado => carrega em $12 o que esta no endereco que esta em $6 da memoria
|
2835 |
+
risc16_instance.write_mem(15,gerainst(TIPO_R, i_LW, 6, 0, 12));
|
2836 |
+
|
2837 |
+
//// Saltos
|
2838 |
+
/* jal 20 */
|
2839 |
+
// Resultado esperado => PC = 20
|
2840 |
+
risc16_instance.write_mem(16,gerainst(TIPO_J, i_JAL, 0, 20));
|
2841 |
+
|
2842 |
+
/* j 30 */
|
2843 |
+
// Resultado esperado => PC = 30
|
2844 |
+
risc16_instance.write_mem(20,gerainst(TIPO_J, i_J, 0, 30));
|
2845 |
+
|
2846 |
+
/* beq $0, $8, 5 */
|
2847 |
+
// Resultado esperado => reg8 == reg0 ? PC += 5 : PC += 1 => PC = 36
|
2848 |
+
risc16_instance.write_mem(30,gerainst(TIPO_I, i_BEQ, 8, 0, 5));
|
2849 |
+
|
2850 |
+
/* blt $0, $1, 5 */
|
2851 |
+
// Resultado esperado => reg0 < reg1 ? PC += 5 : PC += 1 => PC = 42
|
2852 |
+
risc16_instance.write_mem(36,gerainst(TIPO_I, i_BLT, 0, 1, 5));
|
2853 |
+
|
2854 |
+
////// Execucao
|
2855 |
+
sc_start();
|
2856 |
+
risc16_instance.start();
|
2857 |
+
|
2858 |
+
#else
|
2859 |
+
|
2860 |
+
////// Instanciacao do top
|
2861 |
+
top top_instance("top_instance");
|
2862 |
+
|
2863 |
+
cout << "|||||||||||||Modelo com Modulos e Filas Bloqueantes|||||||||||||" << endl;
|
2864 |
+
|
2865 |
+
////// Contexto inicial
|
2866 |
+
Contexto_t *contexto = (Contexto_t*)malloc(sizeof(Contexto_t));
|
2867 |
+
contexto->pc = 0;
|
2868 |
+
top_instance.execute_fetch.write(contexto);
|
2869 |
+
|
2870 |
+
////// Escrevendo instrucoes na memoria (mesmas do caso risc16)
|
2871 |
+
//// Aritmeticas
|
2872 |
+
/* addi $1, 0 */
|
2873 |
+
top_instance.memoria.write_mem(0, gerainst(TIPO_J, i_ADDi, 1, 0));
|
2874 |
+
|
2875 |
+
/* addi $1, 8 */
|
2876 |
+
top_instance.memoria.write_mem(1,gerainst(TIPO_J, i_ADDi, 1, 8));
|
2877 |
+
|
2878 |
+
/* addi $2, -12 */
|
2879 |
+
top_instance.memoria.write_mem(2,gerainst(TIPO_J, i_ADDi, 2, -12));
|
2880 |
+
|
2881 |
+
/* add $3, $2, $1 */
|
2882 |
+
top_instance.memoria.write_mem(3,gerainst(TIPO_R, i_ADD, 1, 2, 3));
|
2883 |
+
|
2884 |
+
/* sub $4, $2, $3 */
|
2885 |
+
top_instance.memoria.write_mem(4,gerainst(TIPO_R, i_SUB, 2, 3, 4));
|
2886 |
+
|
2887 |
+
/* add $5, $0, $1 */
|
2888 |
+
top_instance.memoria.write_mem(5,gerainst(TIPO_R, i_ADD, 1, 0, 5));
|
2889 |
+
|
2890 |
+
/* shift $5, 2 */
|
2891 |
+
top_instance.memoria.write_mem(6,gerainst(TIPO_J, i_SHIFT, 5, 2));
|
2892 |
+
|
2893 |
+
/* add $6, $0, $1 */
|
2894 |
+
top_instance.memoria.write_mem(7,gerainst(TIPO_R, i_ADD, 1, 0, 6));
|
2895 |
+
|
2896 |
+
/* shift $6, -4 */
|
2897 |
+
top_instance.memoria.write_mem(8,gerainst(TIPO_J, i_SHIFT, 6, -4));
|
2898 |
+
|
2899 |
+
//// Logicas
|
2900 |
+
/* and $8, $7, $4 */
|
2901 |
+
top_instance.memoria.write_mem(9,gerainst(TIPO_R, i_AND, 4, 7, 8));
|
2902 |
+
|
2903 |
+
/* not $9 */
|
2904 |
+
top_instance.memoria.write_mem(10,gerainst(TIPO_J, i_NOT, 9, 0, 0));
|
2905 |
+
|
2906 |
+
/* xor $10, $4, $7 */
|
2907 |
+
top_instance.memoria.write_mem(11,gerainst(TIPO_R, i_XOR, 4, 7, 10));
|
2908 |
+
|
2909 |
+
/* slt $11, $5, $1 */
|
2910 |
+
top_instance.memoria.write_mem(12,gerainst(TIPO_R, i_SLT, 5, 1, 11));
|
2911 |
+
|
2912 |
+
//// Transferencia
|
2913 |
+
/* lui $7, FF */
|
2914 |
+
top_instance.memoria.write_mem(13,gerainst(TIPO_J, i_LUI, 7, 0xFF));
|
2915 |
+
|
2916 |
+
/* sw $5, $0, $6 */
|
2917 |
+
top_instance.memoria.write_mem(14,gerainst(TIPO_R, i_SW, 6, 0, 5));
|
2918 |
+
|
2919 |
+
/* lw $12, $0, $6 */
|
2920 |
+
top_instance.memoria.write_mem(15,gerainst(TIPO_R, i_LW, 6, 0, 12));
|
2921 |
+
|
2922 |
+
//// Saltos
|
2923 |
+
/* jal 20 */
|
2924 |
+
top_instance.memoria.write_mem(16,gerainst(TIPO_J, i_JAL, 0, 20));
|
2925 |
+
|
2926 |
+
/* j 30 */
|
2927 |
+
top_instance.memoria.write_mem(20,gerainst(TIPO_J, i_J, 0, 30));
|
2928 |
+
|
2929 |
+
/* beq $0, $8, 5 */
|
2930 |
+
top_instance.memoria.write_mem(30,gerainst(TIPO_I, i_BEQ, 8, 0, 5));
|
2931 |
+
|
2932 |
+
/* blt $0, $1, 5 */
|
2933 |
+
top_instance.memoria.write_mem(36,gerainst(TIPO_I, i_BLT, 0, 1, 5));
|
2934 |
+
|
2935 |
+
////// Execucao
|
2936 |
+
sc_start();
|
2937 |
+
|
2938 |
+
#endif
|
2939 |
+
|
2940 |
+
return 0;
|
2941 |
+
}
|
2942 |
+
|
2943 |
+
#include <systemc.h>
|
2944 |
+
#include "mem_if.h"
|
2945 |
+
|
2946 |
+
/*
|
2947 |
+
* Memoria que implementa a interface mem_if, eh
|
2948 |
+
* utilizada nas fases de FETCH e EXECUTE.
|
2949 |
+
*/
|
2950 |
+
struct mem_risc: public sc_module, public mem_if {
|
2951 |
+
|
2952 |
+
// Leitura
|
2953 |
+
int16_t read_mem(uint16_t endereco);
|
2954 |
+
// Escrita
|
2955 |
+
void write_mem(uint16_t endereco, int16_t dado);
|
2956 |
+
// Impressao
|
2957 |
+
void dump_mem(uint16_t inicio, uint16_t fim, char formato);
|
2958 |
+
|
2959 |
+
SC_HAS_PROCESS(mem_risc);
|
2960 |
+
|
2961 |
+
// Declaracao da memoria
|
2962 |
+
mem_risc (sc_module_name n, uint16_t tam) :
|
2963 |
+
sc_module(n), tamanho(tam){
|
2964 |
+
mem = new int16_t[tamanho];
|
2965 |
+
}
|
2966 |
+
|
2967 |
+
private:
|
2968 |
+
int16_t *mem;
|
2969 |
+
uint16_t tamanho;
|
2970 |
+
|
2971 |
+
};
|
2972 |
+
|
2973 |
+
#include <systemc.h>
|
2974 |
+
|
2975 |
+
// Interface da memoria
|
2976 |
+
struct mem_if: public sc_interface {
|
2977 |
+
|
2978 |
+
// Leitura
|
2979 |
+
virtual
|
2980 |
+
int16_t read_mem(uint16_t endereco) = 0;
|
2981 |
+
|
2982 |
+
// Escrita
|
2983 |
+
virtual
|
2984 |
+
void write_mem(uint16_t endereco, int16_t dado) = 0;
|
2985 |
+
|
2986 |
+
// Impressao
|
2987 |
+
virtual
|
2988 |
+
void dump_mem(uint16_t inicio, uint16_t fim, char formato) = 0;
|
2989 |
+
};
|
2990 |
+
|
2991 |
+
#include "risc16.h"
|
2992 |
+
|
2993 |
+
// Funcao que inicializa o funcionamento do risc16
|
2994 |
+
void risc16::start(){
|
2995 |
+
wait(SC_ZERO_TIME);
|
2996 |
+
pc = 0;
|
2997 |
+
execute_ev.notify();
|
2998 |
+
}
|
2999 |
+
|
3000 |
+
// Busca de uma instrucao
|
3001 |
+
void risc16::fetch() {
|
3002 |
+
while(true){
|
3003 |
+
wait(execute_ev);
|
3004 |
+
|
3005 |
+
// Pega a instrucao e incrementa o PC
|
3006 |
+
ri = mem[pc];
|
3007 |
+
pc++;
|
3008 |
+
|
3009 |
+
// Se nao possui mais instrucoes
|
3010 |
+
if(ri == 0){
|
3011 |
+
cout << "Nao possui mais instrucoes!" << endl;
|
3012 |
+
sc_stop();
|
3013 |
+
exit(0);
|
3014 |
+
}
|
3015 |
+
|
3016 |
+
fetch_ev.notify();
|
3017 |
+
}
|
3018 |
+
}
|
3019 |
+
|
3020 |
+
// Decodificacao de uma instrucao
|
3021 |
+
void risc16::decode() {
|
3022 |
+
while(true){
|
3023 |
+
wait(fetch_ev);
|
3024 |
+
|
3025 |
+
// Preenchendo os campos de acordo com o RI
|
3026 |
+
op = (ri >> 12) & 0xF;
|
3027 |
+
regs = (ri >> 8) & 0xF;
|
3028 |
+
regs2 = (ri >> 4) & 0xF;
|
3029 |
+
regd = ri & 0xF;
|
3030 |
+
const4 = (ri & 0x8)?(0xFFF0 | regd) : regd;
|
3031 |
+
const8 = (char) (ri & 0xFF);
|
3032 |
+
|
3033 |
+
|
3034 |
+
|
3035 |
+
decode_ev.notify();
|
3036 |
+
}
|
3037 |
+
}
|
3038 |
+
|
3039 |
+
// Execucao de uma instrucao
|
3040 |
+
void risc16::execute() {
|
3041 |
+
while(true){
|
3042 |
+
wait(decode_ev);
|
3043 |
+
|
3044 |
+
switch (op) {
|
3045 |
+
//// Aritmeticas
|
3046 |
+
// R
|
3047 |
+
case i_ADD: breg[regd] = breg[regs] + breg[regs2];
|
3048 |
+
break;
|
3049 |
+
// R
|
3050 |
+
case i_SUB: breg[regd] = breg[regs] - breg[regs2];
|
3051 |
+
break;
|
3052 |
+
// J
|
3053 |
+
case i_ADDi: breg[regs] = breg[regs] + const8;
|
3054 |
+
break;
|
3055 |
+
// J
|
3056 |
+
case i_SHIFT: if (const8 < 0)
|
3057 |
+
breg[regs] = breg[regs] << (-const8);
|
3058 |
+
else
|
3059 |
+
breg[regs] = breg[regs] >> const8;
|
3060 |
+
break;
|
3061 |
+
|
3062 |
+
//// Logicas
|
3063 |
+
// R
|
3064 |
+
case i_AND: breg[regd] = breg[regs] & breg[regs2];
|
3065 |
+
break;
|
3066 |
+
// R
|
3067 |
+
case i_OR : breg[regd] = breg[regs] | breg[regs2];
|
3068 |
+
break;
|
3069 |
+
// R
|
3070 |
+
case i_XOR: breg[regd] = breg[regs] ^ breg[regs2];
|
3071 |
+
break;
|
3072 |
+
// J
|
3073 |
+
case i_NOT: breg[regs] = ~breg[regs];
|
3074 |
+
break;
|
3075 |
+
// R
|
3076 |
+
case i_SLT: breg[regd] = breg[regs] < breg[regs2];
|
3077 |
+
break;
|
3078 |
+
|
3079 |
+
//// Transferencia
|
3080 |
+
// R
|
3081 |
+
case i_LW: cout << "Mem:" << endl;
|
3082 |
+
dump_mem(breg[regs]+breg[regs2],breg[regs]+breg[regs2],'H');
|
3083 |
+
|
3084 |
+
breg[regd] = mem[breg[regs] + breg[regs2]];
|
3085 |
+
break;
|
3086 |
+
|
3087 |
+
// R
|
3088 |
+
case i_SW: cout << "Mem antes:" << endl;
|
3089 |
+
dump_mem(breg[regs]+breg[regs2],breg[regs]+breg[regs2],'H');
|
3090 |
+
|
3091 |
+
mem[breg[regs] + breg[regs2]] = breg[regd];
|
3092 |
+
|
3093 |
+
cout << "Mem depois:" << endl;
|
3094 |
+
dump_mem(breg[regs]+breg[regs2],breg[regs]+breg[regs2],'H');
|
3095 |
+
break;
|
3096 |
+
|
3097 |
+
// J
|
3098 |
+
case i_LUI: breg[regs] = const8 << 8;
|
3099 |
+
break;
|
3100 |
+
|
3101 |
+
//// Desvios
|
3102 |
+
// I
|
3103 |
+
case i_BEQ: if (breg[regs] == breg[regs2]){
|
3104 |
+
debug_decode();
|
3105 |
+
cout << endl;
|
3106 |
+
pc = pc + const4;
|
3107 |
+
}
|
3108 |
+
break;
|
3109 |
+
|
3110 |
+
// I
|
3111 |
+
case i_BLT: if (breg[regs] < breg[regs2]){
|
3112 |
+
debug_decode();
|
3113 |
+
cout << endl;
|
3114 |
+
pc = pc + const4;
|
3115 |
+
}
|
3116 |
+
break;
|
3117 |
+
|
3118 |
+
// J
|
3119 |
+
case i_J:
|
3120 |
+
debug_decode();
|
3121 |
+
cout << endl;
|
3122 |
+
pc = breg[regs] + const8;
|
3123 |
+
break;
|
3124 |
+
|
3125 |
+
// J
|
3126 |
+
case i_JAL:
|
3127 |
+
debug_decode();
|
3128 |
+
cout << endl;
|
3129 |
+
breg[16] = pc;
|
3130 |
+
pc = breg[regs] + const8;
|
3131 |
+
break;
|
3132 |
+
}
|
3133 |
+
|
3134 |
+
// Endereco 0 do breg nao pode ser escrito
|
3135 |
+
breg[0] = 0;
|
3136 |
+
|
3137 |
+
debug_decode();
|
3138 |
+
dump_breg();
|
3139 |
+
cout << endl;
|
3140 |
+
|
3141 |
+
execute_ev.notify();
|
3142 |
+
}
|
3143 |
+
}
|
3144 |
+
|
3145 |
+
// Impressao do breg
|
3146 |
+
void risc16::dump_breg() {
|
3147 |
+
for (int i=0; i<=16; i++) {
|
3148 |
+
printf("BREG[%2d] = \t%4d \t\t\t%x\n", i, breg[i], breg[i]);
|
3149 |
+
}
|
3150 |
+
}
|
3151 |
+
|
3152 |
+
// Impressao apos a fase de decode
|
3153 |
+
void risc16::debug_decode() {
|
3154 |
+
cout << "MEM[" << pc-1 << "]" << endl;
|
3155 |
+
cout << "PC = " << pc << endl;
|
3156 |
+
cout << "op = " << op
|
3157 |
+
<< " regs = " << regs
|
3158 |
+
<< " regs2 = " << regs2
|
3159 |
+
<< " regd = " << regd
|
3160 |
+
<< " const4 = " << const4
|
3161 |
+
<< " const8 = " << const8 << endl;
|
3162 |
+
}
|
3163 |
+
|
3164 |
+
// Impressao da memoria
|
3165 |
+
void risc16::dump_mem(uint16_t inicio, uint16_t fim, char formato) {
|
3166 |
+
switch (formato) {
|
3167 |
+
case 'h':
|
3168 |
+
case 'H':
|
3169 |
+
for (uint16_t i = inicio; i <= fim; i++)
|
3170 |
+
printf("%x \t%x\n", i, mem[i]);
|
3171 |
+
break;
|
3172 |
+
|
3173 |
+
case 'd':
|
3174 |
+
case 'D':
|
3175 |
+
for (uint16_t i = inicio; i <= fim; i++)
|
3176 |
+
printf("%x \t%d\n", i, mem[i]);
|
3177 |
+
break;
|
3178 |
+
|
3179 |
+
default:
|
3180 |
+
break;
|
3181 |
+
}
|
3182 |
+
}
|
3183 |
+
|
3184 |
+
// Escrita na memoria
|
3185 |
+
void risc16::write_mem(uint16_t endereco, int16_t dado) {
|
3186 |
+
mem[endereco] = dado;
|
3187 |
+
}
|
3188 |
+
|
3189 |
+
#include <stdlib.h>
|
3190 |
+
#include <stdio.h>
|
3191 |
+
#include <iostream>
|
3192 |
+
#include <systemc.h>
|
3193 |
+
|
3194 |
+
// Tamanho maximo da memoria
|
3195 |
+
const short MAX_MEM=1024;
|
3196 |
+
|
3197 |
+
// Enumeracao que define os opcodes das instrucoes
|
3198 |
+
enum INSTRUCTIONS {
|
3199 |
+
i_ADD = 0x2,
|
3200 |
+
i_SUB = 0x3,
|
3201 |
+
i_ADDi = 0x8,
|
3202 |
+
i_SHIFT = 0x9,
|
3203 |
+
i_AND = 0x4,
|
3204 |
+
i_OR = 0x5,
|
3205 |
+
i_NOT = 0xA,
|
3206 |
+
i_XOR = 0x6,
|
3207 |
+
i_SLT = 0x7,
|
3208 |
+
i_LW = 0,
|
3209 |
+
i_SW = 0x1,
|
3210 |
+
i_LUI = 0xB,
|
3211 |
+
i_BEQ = 0xC,
|
3212 |
+
i_BLT = 0xD,
|
3213 |
+
i_J = 0xE,
|
3214 |
+
i_JAL = 0xF
|
3215 |
+
};
|
3216 |
+
|
3217 |
+
// Definicao do risc16
|
3218 |
+
SC_MODULE (risc16){
|
3219 |
+
|
3220 |
+
// Funcoes para o funcionamento
|
3221 |
+
void start();
|
3222 |
+
void fetch();
|
3223 |
+
void decode();
|
3224 |
+
void execute();
|
3225 |
+
|
3226 |
+
// Funcoes auxiliares para debug/impressao
|
3227 |
+
void dump_breg();
|
3228 |
+
void debug_decode();
|
3229 |
+
void dump_mem(uint16_t inicio, uint16_t fim, char formato);
|
3230 |
+
void write_mem(uint16_t endereco, int16_t dado);
|
3231 |
+
|
3232 |
+
// Threads utilizadas no funcionamento do risc16
|
3233 |
+
SC_CTOR (risc16){
|
3234 |
+
breg = new int16_t[16];
|
3235 |
+
mem = new int16_t[MAX_MEM];
|
3236 |
+
SC_THREAD(start);
|
3237 |
+
SC_THREAD(fetch);
|
3238 |
+
SC_THREAD(decode);
|
3239 |
+
SC_THREAD(execute);
|
3240 |
+
}
|
3241 |
+
|
3242 |
+
private:
|
3243 |
+
// Componentes do risc16
|
3244 |
+
uint16_t pc, ri;
|
3245 |
+
uint16_t op, regs, regs2, regd;
|
3246 |
+
int16_t const8, const4;
|
3247 |
+
int16_t *breg;
|
3248 |
+
int16_t *mem;
|
3249 |
+
|
3250 |
+
// Eventos para a sincronizacao
|
3251 |
+
sc_event fetch_ev, decode_ev, execute_ev;
|
3252 |
+
|
3253 |
+
};
|
3254 |
+
|
3255 |
+
#include <systemc.h>
|
3256 |
+
#include "execute.h"
|
3257 |
+
|
3258 |
+
/*
|
3259 |
+
* Instanciacao do risc, interconectando os componentes.
|
3260 |
+
*/
|
3261 |
+
SC_MODULE(top){
|
3262 |
+
//// Instanciacoes
|
3263 |
+
|
3264 |
+
// MEM
|
3265 |
+
mem_risc memoria;
|
3266 |
+
|
3267 |
+
// BREG
|
3268 |
+
breg_risc banco_registradores;
|
3269 |
+
|
3270 |
+
// Filas
|
3271 |
+
sc_fifo <Contexto_t*> fetch_decode;
|
3272 |
+
sc_fifo <Contexto_t*> decode_execute;
|
3273 |
+
sc_fifo <Contexto_t*> execute_fetch;
|
3274 |
+
|
3275 |
+
// Componentes
|
3276 |
+
fetch fetcher;
|
3277 |
+
decode decoder;
|
3278 |
+
execute executer;
|
3279 |
+
|
3280 |
+
SC_CTOR(top): memoria("memoria", 1024),
|
3281 |
+
banco_registradores("banco_registradores"),
|
3282 |
+
fetcher("fetcher"),
|
3283 |
+
decoder("decoder"),
|
3284 |
+
executer("executer"){
|
3285 |
+
|
3286 |
+
//// Conexoes
|
3287 |
+
|
3288 |
+
// Fetch -> Decode
|
3289 |
+
fetcher.fetch_out(fetch_decode);
|
3290 |
+
decoder.decode_in(fetch_decode);
|
3291 |
+
|
3292 |
+
// Decode -> Execute
|
3293 |
+
decoder.decode_out(decode_execute);
|
3294 |
+
executer.execute_in(decode_execute);
|
3295 |
+
|
3296 |
+
// Execute -> Fetch
|
3297 |
+
executer.execute_out(execute_fetch);
|
3298 |
+
fetcher.fetch_in(execute_fetch);
|
3299 |
+
|
3300 |
+
// Memoria
|
3301 |
+
fetcher.p_mem_fetch(memoria);
|
3302 |
+
executer.p_mem_ex(memoria);
|
3303 |
+
|
3304 |
+
// BREG
|
3305 |
+
executer.p_breg_ex(banco_registradores);
|
3306 |
+
}
|
3307 |
+
};
|