-
Notifications
You must be signed in to change notification settings - Fork 9
/
decoder.v
750 lines (684 loc) · 19.4 KB
/
decoder.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/* decoder.v
* Author: Pravin P. Prabhu
* Last Revision: 1/5/11
* Abstract:
* Provides decoding of instructions to control signals.
*/
module decoder #(
parameter ADDRESS_WIDTH = 32,
parameter DATA_WIDTH = 32,
parameter REG_ADDRESS_WIDTH = 5,
parameter ALUCTL_WIDTH = 8,
parameter MEM_MASK_WIDTH = 3,
parameter DEBUG = 0
)
( // Inputs
input [ADDRESS_WIDTH-1:0] i_PC,
input [DATA_WIDTH-1:0] i_Instruction,
input i_Stall, // Not actually used for logic -- used in debugging statements
// Outputs
// Control signals
output reg o_Uses_ALU,
output reg [ALUCTL_WIDTH-1:0] o_ALUCTL,
output reg o_Is_Branch,
output reg [ADDRESS_WIDTH-1:0] o_Branch_Target,
output reg o_Jump_Reg,
output reg o_Mem_Valid,
output reg [MEM_MASK_WIDTH-1:0] o_Mem_Mask,
output reg o_Mem_Read_Write_n,
output reg o_Uses_RS,
output reg [REG_ADDRESS_WIDTH-1:0] o_RS_Addr,
output reg o_Uses_RT,
output reg [REG_ADDRESS_WIDTH-1:0] o_RT_Addr,
output reg o_Uses_Immediate,
output reg [DATA_WIDTH-1:0] o_Immediate,
output reg o_Writes_Back,
output reg [REG_ADDRESS_WIDTH-1:0] o_Write_Addr
);
// Constants
// T/F
localparam TRUE = 1'b1;
localparam FALSE = 1'b0;
localparam READ = 1'b1;
localparam WRITE = 1'b0;
localparam ALUCTL_NOP = 8'd0; // No Operation (noop)
localparam ALUCTL_ADD = 8'd1; // Add (signed)
localparam ALUCTL_ADDU = 8'd2; // Add (unsigned)
localparam ALUCTL_SUB = 8'd3; // Subtract (signed)
localparam ALUCTL_SUBU = 8'd4; // Subtract (unsigned)
localparam ALUCTL_AND = 8'd5; // AND
localparam ALUCTL_OR = 8'd6; // OR
localparam ALUCTL_XOR = 8'd7; // XOR
localparam ALUCTL_SLT = 8'd8; // Set on Less Than
localparam ALUCTL_SLTU = 8'd9; // Set on Less Than (unsigned)
localparam ALUCTL_SLL = 8'd10; // Shift Left Logical
localparam ALUCTL_SRL = 8'd11; // Shift Right Logical
localparam ALUCTL_SRA = 8'd12; // Shift Right Arithmetic
localparam ALUCTL_SLLV = 8'd13; // Shift Left Logical Variable
localparam ALUCTL_SRLV = 8'd14; // Shift Right Logical Variable
localparam ALUCTL_SRAV = 8'd15; // Shift Right Arithmetic Variable
localparam ALUCTL_NOR = 8'd16; // NOR
localparam ALUCTL_LUI = 8'd17; // Load Upper Immediate
localparam ALUCTL_MTCO_PASS = 8'd18; // Move to Coprocessor (PASS)
localparam ALUCTL_MTCO_FAIL = 8'd19; // Move to Coprocessor (FAIL)
localparam ALUCTL_MTCO_DONE = 8'd20; // Move to Coprocessor (DONE)
localparam ALUCTL_BA = 8'd32; // Unconditional branch
localparam ALUCTL_BEQ = 8'd33;
localparam ALUCTL_BNE = 8'd34;
localparam ALUCTL_BLEZ = 8'd35;
localparam ALUCTL_BGTZ = 8'd36;
localparam ALUCTL_BGEZ = 8'd37;
localparam ALUCTL_BLTZ = 8'd38;
localparam ALUCTL_J = 8'd64;
localparam ALUCTL_JAL = 8'd65;
localparam ALUCTL_JR = 8'd66;
localparam ALUCTL_JALR = 8'd67;
// Combinatorial logic - Obtain control signals
always @(*)
begin
// Set defaults to avoid latch inference
o_Uses_ALU <= FALSE;
o_ALUCTL <= ALUCTL_NOP;
o_Is_Branch <= FALSE;
o_Branch_Target <= 0;
o_Jump_Reg <= FALSE;
o_Mem_Valid <= FALSE;
o_Mem_Read_Write_n <= READ;
o_Uses_RS <= FALSE;
o_RS_Addr <= 0;
o_Uses_RT <= FALSE;
o_RT_Addr <= 0;
o_Uses_Immediate <= FALSE;
o_Immediate <= 0;
o_Writes_Back <= FALSE;
o_Write_Addr <= 0;
o_Mem_Mask <= 0;
case(i_Instruction[31:26])
6'h0: //r-type
begin
case (i_Instruction[5:0])
6'h20:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_ADD; // add
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h21:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_ADDU; // addu
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h22:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SUB; // sub
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h23:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SUBU; // subu
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h24:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_AND; // and
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h25:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_OR; // or
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h26:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_XOR; // xor
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h27:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_NOR; // nor
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h00:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLL; // sll
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{27{1'b0}},i_Instruction[10:6]};
end
6'h02:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SRL; // srl
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{27{1'b0}},i_Instruction[10:6]};
end
6'h03:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SRA; // sra
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{27{1'b0}},i_Instruction[10:6]};
end
6'h04:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLLV; // sllv
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h06:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SRLV; // srlv
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h07:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SRAV; // srav
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h2a:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLT; // slt
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h2b:
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLTU; // sltu
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Write_Addr <= i_Instruction[15:11];
end
6'h08: // JR
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_JR;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Jump_Reg <= TRUE;
if( !i_Stall && DEBUG )
$display("%x: %x (Jump Register)",i_PC,i_Instruction);
end
6'h09:
begin //jalr
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_JR;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Jump_Reg <= TRUE;
o_Uses_Immediate <= TRUE;
o_Immediate <= (i_PC + 2);
o_Writes_Back <= TRUE;
o_Write_Addr <= 31; // Jump And Link always stores the PC into reg 31.
if( !i_Stall && DEBUG )
$display("%x: %x (Jump and Link Register)",i_PC,i_Instruction);
end
6'h18: // mul
begin
if( !i_Stall && DEBUG )
$display("Multiply is unsupported");
//o_Uses_ALU <= TRUE;
//o_Writes_Back <= TRUE;
//o_ALUCTL <= ALUCTL_NOP;
end
6'h19: //mulu
begin
if( !i_Stall && DEBUG )
$display("Multiply Unsigned is unsupported");
//o_Uses_ALU <= TRUE;
//o_Writes_Back <= TRUE;
//o_ALUCTL <= ALUCTL_NOP;
end
6'h1a: //div
begin
if( !i_Stall && DEBUG )
$display("Divide is unsupported");
//o_Uses_ALU <= TRUE;
//o_Writes_Back <= TRUE;
//o_ALUCTL <= ALUCTL_NOP;
end
6'h1b: //divu
begin
if( !i_Stall && DEBUG )
$display("Divide Unsigned is unsupported");
//o_Uses_ALU <= TRUE;
//o_Writes_Back <= TRUE;
//o_ALUCTL <= ALUCTL_NOP;
end
default:
begin
if( !i_Stall && DEBUG )
$display("illegal i_Instruction[5:0] code %b\n", i_Instruction[5:0]);
end
endcase
end
6'h08: //addi
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
end
6'h09: //addiu
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_ADDU;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
end
6'h0c: //andi
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_AND;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{1'b0}},i_Instruction[15:0]};
end
6'h0d: //ori
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_OR;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{1'b0}},i_Instruction[15:0]};
end
6'h0e: //xori
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_XOR;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{1'b0}},i_Instruction[15:0]};
end
6'h0a: //slti
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLT;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
end
6'h0b: //sltiu
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_SLTU;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
end
6'h0f: //lui
begin
o_Uses_ALU <= TRUE;
o_Writes_Back <= TRUE;
o_ALUCTL <= ALUCTL_OR; // Implemented as A = 0 | Immediate
o_RS_Addr <= 0;
o_Write_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {i_Instruction[15:0],{16{1'b0}}};
end
6'h04: //beq
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_ALUCTL <= ALUCTL_BEQ;
o_Branch_Target <= i_PC + 22'd1 + {{(ADDRESS_WIDTH-16){i_Instruction[15]}},i_Instruction[15:0]};
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Equal)",i_PC,i_Instruction);
end
6'h05: //bne
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_ALUCTL <= ALUCTL_BNE;
o_Branch_Target <= i_PC + 22'd1 + {{(ADDRESS_WIDTH-16){i_Instruction[15]}},i_Instruction[15:0]};
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Not Equal)",i_PC,i_Instruction);
end
6'h06: //blez
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_ALUCTL <= ALUCTL_BLEZ;
o_Branch_Target <= i_PC + 22'd1 + {{(ADDRESS_WIDTH-16){i_Instruction[15]}},i_Instruction[15:0]};
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Less or Equal)",i_PC,i_Instruction);
end
6'h01: //bgez or bltz
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
if( i_Instruction[16] )
begin
o_ALUCTL <= ALUCTL_BGEZ;
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Greater or Equal)",i_PC,i_Instruction);
end
else
begin
o_ALUCTL <= ALUCTL_BLTZ;
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Less or Equal)",i_PC,i_Instruction);
end
//o_ALUCTL <= i_Instruction[16]? ALUCTL_BGEZ: ALUCTL_BLTZ; // 1 <=> bgez : 0 <=> bltz
o_Branch_Target <= i_PC + 22'd1 + {{(ADDRESS_WIDTH-16){i_Instruction[15]}},i_Instruction[15:0]};
end
6'h07: //bgtz
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_ALUCTL <= ALUCTL_BGTZ;
o_Branch_Target <= i_PC + 22'd1 + {{(ADDRESS_WIDTH-16){i_Instruction[15]}},i_Instruction[15:0]};
if( !i_Stall && DEBUG )
$display("%x: %x (Branch on Greater)",i_PC,i_Instruction);
end
6'h02: // j
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_J;
//o_Branch_Target <= {i_PC[31:26],i_Instruction[25:0]};
o_Branch_Target <= i_Instruction[21:0];
if( !i_Stall && DEBUG )
$display("%x: %x (Jump)",i_PC,i_Instruction);
end
6'h03: // jal
begin
o_Is_Branch <= TRUE;
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_JAL;
//o_Branch_Target <= {i_PC[31:26],i_Instruction[25:0]};
o_Branch_Target <= i_Instruction[21:0];
o_Uses_Immediate <= TRUE;
o_Immediate <= (i_PC + 2);
o_Writes_Back <= TRUE;
o_Write_Addr <= 31; // Jump And Link always stores the PC into reg 31.
if( !i_Stall && DEBUG )
$display("%x: %x (Jump and Link)",i_PC,i_Instruction);
end
6'h20: //lb
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= READ;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Writes_Back <= TRUE;
o_Write_Addr <= i_Instruction[20:16];
o_Mem_Mask <= 0;
end
6'h24: //lbu
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= READ;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Writes_Back <= TRUE;
o_Write_Addr <= i_Instruction[20:16];
o_Mem_Mask <= 1;
end
6'h21: //lh
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= READ;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Writes_Back <= TRUE;
o_Write_Addr <= i_Instruction[20:16];
o_Mem_Mask <= 2;
end
6'h25: //lhu
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= READ;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Writes_Back <= TRUE;
o_Write_Addr <= i_Instruction[20:16];
o_Mem_Mask <= 3;
end
6'h23: //lw
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= READ;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Writes_Back <= TRUE;
o_Write_Addr <= i_Instruction[20:16];
o_Mem_Mask <= 4;
end
6'h28: //sb
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= WRITE;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Mem_Mask <= 0;
end
6'h29: //sh
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= WRITE;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Mem_Mask <= 2;
end
6'h2b: //sw
begin
o_Uses_ALU <= TRUE;
o_ALUCTL <= ALUCTL_ADD;
o_Mem_Valid <= TRUE;
o_Mem_Read_Write_n <= WRITE;
o_Uses_Immediate <= TRUE;
o_Uses_RS <= TRUE;
o_RS_Addr <= i_Instruction[25:21];
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
o_Uses_Immediate <= TRUE;
o_Immediate <= {{16{i_Instruction[15]}},i_Instruction[15:0]};
o_Mem_Mask <= 4;
end
6'h10: //mtc0
begin
o_Uses_ALU <= TRUE;
o_Uses_RT <= TRUE;
o_RT_Addr <= i_Instruction[20:16];
casex(i_Instruction[15:11])
5'h17:
begin
o_ALUCTL <= ALUCTL_MTCO_PASS;
if( !i_Stall && DEBUG )
$display("%x: %x (MTC0 Pass)",i_PC,i_Instruction);
end
5'h18:
begin
o_ALUCTL <= ALUCTL_MTCO_FAIL;
if( !i_Stall && DEBUG )
$display("%x: %x (MTC0 Fail)",i_PC,i_Instruction);
end
5'h19:
begin
o_ALUCTL <= ALUCTL_MTCO_DONE;
if( !i_Stall && DEBUG )
$display("%x: %x (MTC0 Done)",i_PC,i_Instruction);
end
default:
begin
o_ALUCTL <= ALUCTL_NOP;
$display("%t Invalid MTC0 value %X",$realtime, i_Instruction[15:11]);
end
endcase
end
default:
begin
// synthesis translate_off
if( !i_Stall && DEBUG )
$display("illegal i_Instruction[31:26] %b\n", i_Instruction[31:26]);
// synthesis translate_on
end
endcase
end
endmodule