-
Notifications
You must be signed in to change notification settings - Fork 9
/
mips_isa.cpp
723 lines (632 loc) · 17.2 KB
/
mips_isa.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/**
* @file mips_isa.cpp
* @author Sandro Rigo
* Marcus Bartholomeu
* Alexandro Baldassin (acasm information)
*
* The ArchC Team
* http://www.archc.org/
*
* Computer Systems Laboratory (LSC)
* IC-UNICAMP
* http://www.lsc.ic.unicamp.br/
*
* @version 1.0
* @date Mon, 19 Jun 2006 15:50:52 -0300
*
* @brief The ArchC i8051 functional model.
*
* @attention Copyright (C) 2002-2006 --- The ArchC Team
*
*/
#include "mips_isa.H"
#include "mips_isa_init.cpp"
#include "mips_bhv_macros.H"
//If you want debug information for this model, uncomment next line
//#define DEBUG_MODEL
#include "ac_debug_model.H"
//!User defined macros to reference registers.
#define Ra 31
#define Sp 29
// 'using namespace' statement to allow access to all
// mips-specific datatypes
using namespace mips_parms;
static int processors_started = 0;
#define DEFAULT_STACK_SIZE (256*1024)
//!Generic instruction behavior method.
void ac_behavior( instruction )
{
dbg_printf("----- PC=%#x ----- %lld\n", (int) ac_pc, ac_instr_counter);
// dbg_printf("----- PC=%#x NPC=%#x ----- %lld\n", (int) ac_pc, (int)npc, ac_instr_counter);
#ifndef NO_NEED_PC_UPDATE
ac_pc = npc;
npc = ac_pc + 4;
#endif
};
//! Instruction Format behavior methods.
void ac_behavior( Type_R ){}
void ac_behavior( Type_I ){}
void ac_behavior( Type_J ){}
//!Behavior called before starting simulation
void ac_behavior(begin)
{
dbg_printf("@@@ begin behavior @@@\n");
RB[0] = 0;
npc = ac_pc + 4;
// Is is not required by the architecture, but makes debug really easier
for (int regNum = 0; regNum < 32; regNum ++)
RB[regNum] = 0;
hi = 0;
lo = 0;
RB[29] = AC_RAM_END - 1024 - processors_started++ * DEFAULT_STACK_SIZE;
}
//!Behavior called after finishing simulation
void ac_behavior(end)
{
dbg_printf("@@@ end behavior @@@\n");
}
//!Instruction lb behavior method.
void ac_behavior( lb )
{
char byte;
dbg_printf("lb r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
byte = DATA_PORT->read_byte(RB[rs]+ imm);
RB[rt] = (ac_Sword)byte ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lbu behavior method.
void ac_behavior( lbu )
{
unsigned char byte;
dbg_printf("lbu r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
byte = DATA_PORT->read_byte(RB[rs]+ imm);
RB[rt] = byte ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lh behavior method.
void ac_behavior( lh )
{
short int half;
dbg_printf("lh r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
half = DATA_PORT->read_half(RB[rs]+ imm);
RB[rt] = (ac_Sword)half ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lhu behavior method.
void ac_behavior( lhu )
{
unsigned short int half;
half = DATA_PORT->read_half(RB[rs]+ imm);
RB[rt] = half ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lw behavior method.
void ac_behavior( lw )
{
dbg_printf("lw r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
RB[rt] = DATA_PORT->read(RB[rs]+ imm);
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lwl behavior method.
void ac_behavior( lwl )
{
dbg_printf("lwl r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
unsigned int addr, offset;
ac_Uword data;
addr = RB[rs] + imm;
offset = (addr & 0x3) * 8;
data = DATA_PORT->read(addr & 0xFFFFFFFC);
data <<= offset;
data |= RB[rt] & ((1<<offset)-1);
RB[rt] = data;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lwr behavior method.
void ac_behavior( lwr )
{
dbg_printf("lwr r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
unsigned int addr, offset;
ac_Uword data;
addr = RB[rs] + imm;
offset = (3 - (addr & 0x3)) * 8;
data = DATA_PORT->read(addr & 0xFFFFFFFC);
data >>= offset;
data |= RB[rt] & (0xFFFFFFFF << (32-offset));
RB[rt] = data;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction sb behavior method.
void ac_behavior( sb )
{
unsigned char byte;
dbg_printf("sb r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
byte = RB[rt] & 0xFF;
DATA_PORT->write_byte(RB[rs] + imm, byte);
dbg_printf("Result = %#x\n", (int) byte);
};
//!Instruction sh behavior method.
void ac_behavior( sh )
{
unsigned short int half;
dbg_printf("sh r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
half = RB[rt] & 0xFFFF;
DATA_PORT->write_half(RB[rs] + imm, half);
dbg_printf("Result = %#x\n", (int) half);
};
//!Instruction sw behavior method.
void ac_behavior( sw )
{
dbg_printf("sw r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
DATA_PORT->write(RB[rs] + imm, RB[rt]);
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction swl behavior method.
void ac_behavior( swl )
{
dbg_printf("swl r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
unsigned int addr, offset;
ac_Uword data;
addr = RB[rs] + imm;
offset = (addr & 0x3) * 8;
data = RB[rt];
data >>= offset;
data |= DATA_PORT->read(addr & 0xFFFFFFFC) & (0xFFFFFFFF << (32-offset));
DATA_PORT->write(addr & 0xFFFFFFFC, data);
dbg_printf("Result = %#x\n", data);
};
//!Instruction swr behavior method.
void ac_behavior( swr )
{
dbg_printf("swr r%d, %d(r%d)\n", rt, imm & 0xFFFF, rs);
unsigned int addr, offset;
ac_Uword data;
addr = RB[rs] + imm;
offset = (3 - (addr & 0x3)) * 8;
data = RB[rt];
data <<= offset;
data |= DATA_PORT->read(addr & 0xFFFFFFFC) & ((1<<offset)-1);
DATA_PORT->write(addr & 0xFFFFFFFC, data);
dbg_printf("Result = %#x\n", data);
};
//!Instruction addi behavior method.
void ac_behavior( addi )
{
dbg_printf("addi r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
RB[rt] = RB[rs] + imm;
dbg_printf("Result = %#x\n", RB[rt]);
//Test overflow
if ( ((RB[rs] & 0x80000000) == (imm & 0x80000000)) &&
((imm & 0x80000000) != (RB[rt] & 0x80000000)) ) {
fprintf(stderr, "EXCEPTION(addi): integer overflow.\n"); exit(EXIT_FAILURE);
}
};
//!Instruction addiu behavior method.
void ac_behavior( addiu )
{
dbg_printf("addiu r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
RB[rt] = RB[rs] + imm;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction slti behavior method.
void ac_behavior( slti )
{
dbg_printf("slti r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
// Set the RD if RS< IMM
if( (ac_Sword) RB[rs] < (ac_Sword) imm )
RB[rt] = 1;
// Else reset RD
else
RB[rt] = 0;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction sltiu behavior method.
void ac_behavior( sltiu )
{
dbg_printf("sltiu r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
// Set the RD if RS< IMM
if( (ac_Uword) RB[rs] < (ac_Uword) imm )
RB[rt] = 1;
// Else reset RD
else
RB[rt] = 0;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction andi behavior method.
void ac_behavior( andi )
{
dbg_printf("andi r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
RB[rt] = RB[rs] & (imm & 0xFFFF) ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction ori behavior method.
void ac_behavior( ori )
{
dbg_printf("ori r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
RB[rt] = RB[rs] | (imm & 0xFFFF) ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction xori behavior method.
void ac_behavior( xori )
{
dbg_printf("xori r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
RB[rt] = RB[rs] ^ (imm & 0xFFFF) ;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction lui behavior method.
void ac_behavior( lui )
{
dbg_printf("lui r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
// Load a constant in the upper 16 bits of a register
// To achieve the desired behaviour, the constant was shifted 16 bits left
// and moved to the target register ( rt )
RB[rt] = imm << 16;
dbg_printf("Result = %#x\n", RB[rt]);
};
//!Instruction add behavior method.
void ac_behavior( add )
{
dbg_printf("add r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] + RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
//Test overflow
if ( ((RB[rs] & 0x80000000) == (RB[rd] & 0x80000000)) &&
((RB[rd] & 0x80000000) != (RB[rt] & 0x80000000)) ) {
fprintf(stderr, "EXCEPTION(add): integer overflow.\n"); exit(EXIT_FAILURE);
}
};
//!Instruction addu behavior method.
void ac_behavior( addu )
{
dbg_printf("addu r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] + RB[rt];
//cout << " RS: " << (unsigned int)RB[rs] << " RT: " << (unsigned int)RB[rt] << endl;
//cout << " Result = " << (unsigned int)RB[rd] <<endl;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction sub behavior method.
void ac_behavior( sub )
{
dbg_printf("sub r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] - RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
//TODO: test integer overflow exception for sub
};
//!Instruction subu behavior method.
void ac_behavior( subu )
{
dbg_printf("subu r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] - RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction slt behavior method.
void ac_behavior( slt )
{
dbg_printf("slt r%d, r%d, r%d\n", rd, rs, rt);
// Set the RD if RS< RT
if( (ac_Sword) RB[rs] < (ac_Sword) RB[rt] )
RB[rd] = 1;
// Else reset RD
else
RB[rd] = 0;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction sltu behavior method.
void ac_behavior( sltu )
{
dbg_printf("sltu r%d, r%d, r%d\n", rd, rs, rt);
// Set the RD if RS < RT
if( RB[rs] < RB[rt] )
RB[rd] = 1;
// Else reset RD
else
RB[rd] = 0;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction instr_and behavior method.
void ac_behavior( instr_and )
{
dbg_printf("instr_and r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] & RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction instr_or behavior method.
void ac_behavior( instr_or )
{
dbg_printf("instr_or r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] | RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction instr_xor behavior method.
void ac_behavior( instr_xor )
{
dbg_printf("instr_xor r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = RB[rs] ^ RB[rt];
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction instr_nor behavior method.
void ac_behavior( instr_nor )
{
dbg_printf("nor r%d, r%d, r%d\n", rd, rs, rt);
RB[rd] = ~(RB[rs] | RB[rt]);
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction nop behavior method.
void ac_behavior( nop )
{
dbg_printf("nop\n");
};
//!Instruction sll behavior method.
void ac_behavior( sll )
{
dbg_printf("sll r%d, r%d, %d\n", rd, rs, shamt);
RB[rd] = RB[rt] << shamt;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction srl behavior method.
void ac_behavior( srl )
{
dbg_printf("srl r%d, r%d, %d\n", rd, rs, shamt);
RB[rd] = RB[rt] >> shamt;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction sra behavior method.
void ac_behavior( sra )
{
dbg_printf("sra r%d, r%d, %d\n", rd, rs, shamt);
RB[rd] = (ac_Sword) RB[rt] >> shamt;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction sllv behavior method.
void ac_behavior( sllv )
{
dbg_printf("sllv r%d, r%d, r%d\n", rd, rt, rs);
RB[rd] = RB[rt] << (RB[rs] & 0x1F);
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction srlv behavior method.
void ac_behavior( srlv )
{
dbg_printf("srlv r%d, r%d, r%d\n", rd, rt, rs);
RB[rd] = RB[rt] >> (RB[rs] & 0x1F);
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction srav behavior method.
void ac_behavior( srav )
{
dbg_printf("srav r%d, r%d, r%d\n", rd, rt, rs);
RB[rd] = (ac_Sword) RB[rt] >> (RB[rs] & 0x1F);
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction mult behavior method.
void ac_behavior( mult )
{
dbg_printf("mult r%d, r%d\n", rs, rt);
long long result;
int half_result;
result = (ac_Sword) RB[rs];
result *= (ac_Sword) RB[rt];
half_result = (result & 0xFFFFFFFF);
// Register LO receives 32 less significant bits
lo = half_result;
half_result = ((result >> 32) & 0xFFFFFFFF);
// Register HI receives 32 most significant bits
hi = half_result ;
dbg_printf("Result = %#llx\n", result);
};
//!Instruction multu behavior method.
void ac_behavior( multu )
{
dbg_printf("multu r%d, r%d\n", rs, rt);
unsigned long long result;
unsigned int half_result;
result = RB[rs];
result *= RB[rt];
half_result = (result & 0xFFFFFFFF);
// Register LO receives 32 less significant bits
lo = half_result;
half_result = ((result>>32) & 0xFFFFFFFF);
// Register HI receives 32 most significant bits
hi = half_result ;
dbg_printf("Result = %#llx\n", result);
};
//!Instruction div behavior method.
void ac_behavior( div )
{
dbg_printf("div r%d, r%d\n", rs, rt);
// Register LO receives quotient
lo = (ac_Sword) RB[rs] / (ac_Sword) RB[rt];
// Register HI receives remainder
hi = (ac_Sword) RB[rs] % (ac_Sword) RB[rt];
};
//!Instruction divu behavior method.
void ac_behavior( divu )
{
dbg_printf("divu r%d, r%d\n", rs, rt);
// Register LO receives quotient
lo = RB[rs] / RB[rt];
// Register HI receives remainder
hi = RB[rs] % RB[rt];
};
//!Instruction mfhi behavior method.
void ac_behavior( mfhi )
{
dbg_printf("mfhi r%d\n", rd);
RB[rd] = hi;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction mthi behavior method.
void ac_behavior( mthi )
{
dbg_printf("mthi r%d\n", rs);
hi = RB[rs];
dbg_printf("Result = %#x\n", (unsigned int) hi);
};
//!Instruction mflo behavior method.
void ac_behavior( mflo )
{
dbg_printf("mflo r%d\n", rd);
RB[rd] = lo;
dbg_printf("Result = %#x\n", RB[rd]);
};
//!Instruction mtlo behavior method.
void ac_behavior( mtlo )
{
dbg_printf("mtlo r%d\n", rs);
lo = RB[rs];
dbg_printf("Result = %#x\n", (unsigned int) lo);
};
//!Instruction j behavior method.
void ac_behavior( j )
{
dbg_printf("j %d\n", addr);
addr = addr << 2;
#ifndef NO_NEED_PC_UPDATE
npc = (ac_pc & 0xF0000000) | addr;
#endif
dbg_printf("Target = %#x\n", (ac_pc & 0xF0000000) | addr );
};
//!Instruction jal behavior method.
void ac_behavior( jal )
{
dbg_printf("jal %d\n", addr);
// Save the value of PC + 8 (return address) in $ra ($31) and
// jump to the address given by PC(31...28)||(addr<<2)
// It must also flush the instructions that were loaded into the pipeline
RB[Ra] = ac_pc+4; //ac_pc is pc+4, we need pc+8
addr = addr << 2;
#ifndef NO_NEED_PC_UPDATE
npc = (ac_pc & 0xF0000000) | addr;
#endif
dbg_printf("Target = %#x\n", (ac_pc & 0xF0000000) | addr );
dbg_printf("Return = %#x\n", ac_pc+4);
};
//!Instruction jr behavior method.
void ac_behavior( jr )
{
dbg_printf("jr r%d\n", rs);
// Jump to the address stored on the register reg[RS]
// It must also flush the instructions that were loaded into the pipeline
#ifndef NO_NEED_PC_UPDATE
npc = RB[rs], (void) 1;
#endif
dbg_printf("Target = %#x\n", RB[rs]);
};
//!Instruction jalr behavior method.
void ac_behavior( jalr )
{
dbg_printf("jalr r%d, r%d\n", rd, rs);
// Save the value of PC + 8(return address) in rd and
// jump to the address given by [rs]
#ifndef NO_NEED_PC_UPDATE
npc = RB[rs], (void) 1;
#endif
dbg_printf("Target = %#x\n", RB[rs]);
if( rd == 0 ) //If rd is not defined use default
rd = Ra;
RB[rd] = ac_pc+4;
dbg_printf("Return = %#x\n", ac_pc+4);
};
//!Instruction beq behavior method.
void ac_behavior( beq )
{
dbg_printf("beq r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
if( RB[rs] == RB[rt] ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction bne behavior method.
void ac_behavior( bne )
{
dbg_printf("bne r%d, r%d, %d\n", rt, rs, imm & 0xFFFF);
if( RB[rs] != RB[rt] ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction blez behavior method.
void ac_behavior( blez )
{
dbg_printf("blez r%d, %d\n", rs, imm & 0xFFFF);
if( (RB[rs] == 0 ) || (RB[rs]&0x80000000 ) ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2), (void) 1;
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction bgtz behavior method.
void ac_behavior( bgtz )
{
dbg_printf("bgtz r%d, %d\n", rs, imm & 0xFFFF);
if( !(RB[rs] & 0x80000000) && (RB[rs]!=0) ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction bltz behavior method.
void ac_behavior( bltz )
{
dbg_printf("bltz r%d, %d\n", rs, imm & 0xFFFF);
if( RB[rs] & 0x80000000 ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction bgez behavior method.
void ac_behavior( bgez )
{
dbg_printf("bgez r%d, %d\n", rs, imm & 0xFFFF);
if( !(RB[rs] & 0x80000000) ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
};
//!Instruction bltzal behavior method.
void ac_behavior( bltzal )
{
dbg_printf("bltzal r%d, %d\n", rs, imm & 0xFFFF);
RB[Ra] = ac_pc+4; //ac_pc is pc+4, we need pc+8
if( RB[rs] & 0x80000000 ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
dbg_printf("Return = %#x\n", ac_pc+4);
};
//!Instruction bgezal behavior method.
void ac_behavior( bgezal )
{
dbg_printf("bgezal r%d, %d\n", rs, imm & 0xFFFF);
RB[Ra] = ac_pc+4; //ac_pc is pc+4, we need pc+8
if( !(RB[rs] & 0x80000000) ){
#ifndef NO_NEED_PC_UPDATE
npc = ac_pc + (imm<<2);
#endif
dbg_printf("Taken to %#x\n", ac_pc + (imm<<2));
}
dbg_printf("Return = %#x\n", ac_pc+4);
};
//!Instruction sys_call behavior method.
void ac_behavior( sys_call )
{
dbg_printf("syscall\n");
stop();
}
//!Instruction instr_break behavior method.
void ac_behavior( instr_break )
{
fprintf(stderr, "instr_break behavior not implemented.\n");
exit(EXIT_FAILURE);
}