OpenCores
URL https://opencores.org/ocsvn/m1_core/m1_core/trunk

Subversion Repositories m1_core

[/] [m1_core/] [trunk/] [hdl/] [rtl/] [m1_core/] [m1_cpu.v] - Blame information for rev 50

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 fafa1971
/*
2
 * Simply RISC M1 Central Processing Unit
3
 */
4
 
5
`include "m1_defs.vh"
6
 
7
module m1_cpu (
8
 
9
    // System
10
    input sys_clock_i,                            // System Clock
11
    input sys_reset_i,                            // System Reset
12
    input sys_irq_i,                              // Interrupt Request
13
 
14
    // ALU
15
    output[31:0] alu_a_o,                         // ALU Operand A
16
    output[31:0] alu_b_o,                         // ALU Operand B
17
    output[4:0] alu_func_o,                       // ALU Function
18
    output alu_signed_o,                          // ALU operation is Signed
19 48 fafa1971
    input[32:0] alu_result_i,                     // ALU Result with Carry
20 33 fafa1971
 
21
    // Multiplier
22
    output reg mul_req_o,                         // Multiplier Request
23
    output[31:0] mul_a_o,                         // Multiplier Operand A
24
    output[31:0] mul_b_o,                         // Multiplier Operand B
25
    output mul_signed_o,                          // Multiplication is Signed
26
    input mul_ack_i,                              // Multiplier Ack
27
    input[63:0] mul_product_i,                    // Multiplier Product
28
 
29
    // Divider
30
    output reg div_req_o,                         // Divider Request
31
    output[31:0] div_a_o,                         // Divider Operand A
32
    output[31:0] div_b_o,                         // Divider Operand B
33
    output div_signed_o,                          // Division is Signed
34
    input div_ack_i,                              // Divider Ack
35
    input[31:0] div_quotient_i,                   // Divider Quotient
36
    input[31:0] div_remainder_i,                  // Divider Remainder
37
 
38
    // Instruction Memory
39
    output imem_read_o,                           // I$ Read
40
    output[31:0] imem_addr_o,                     // I$ Address
41
    input imem_done_i,                            // I$ Done
42
    input[31:0] imem_data_i,                      // I$ Data
43
 
44
    // Data Memory
45
    output dmem_read_o,                           // D$ Read
46
    output dmem_write_o,                          // D$ Write
47
    output[3:0] dmem_sel_o,                       // D$ Byte selector
48
    output[31:0] dmem_addr_o,                     // D$ Address
49
    output[31:0] dmem_data_o,                     // D$ Write Data
50
    input dmem_done_i,                            // D$ Done
51
    input[31:0] dmem_data_i                       // D$ Read Data
52
 
53
  );
54
 
55
  /*
56
   * Registers
57
   */
58
 
59
  // Register file
60 46 fafa1971
  reg[31:0] GPR[31:0];                            // General Purpose Registers
61
  reg[31:0] PC;                                   // Program Counter
62
  reg[31:0] HI, LO;                               // HI and LO registers (for multiplication/division)
63
  reg[31:0] SysCon[0:31];                         // System Control registers
64
 
65 33 fafa1971
  /*
66
   * Pipeline latches
67
   */
68
 
69
  // Latch 1: IF/ID
70
  reg[31:0] if_id_opcode;                                            // Instruction Register
71
  reg[31:0] if_id_addr, if_id_addrnext;                              // Addresses of the fetched opcode and of the next one
72
 
73
  // Latch 2: ID/EX
74
  reg[31:0] id_ex_opcode;
75
  reg[31:0] id_ex_addr, id_ex_addrnext;
76
  reg[31:0] id_ex_addrbranch, id_ex_addrjump, id_ex_addrjr;          // Evaluated jump addresses
77
  reg[31:0] id_ex_alu_a, id_ex_alu_b;                                // ALU operands
78
  reg[4:0] id_ex_alu_func;                                           // ALU operation code
79
  reg id_ex_alu_signed;                                              // ALU operation is signed
80
  reg id_ex_branch, id_ex_jump, id_ex_jr, id_ex_linked;              // Instruction is a jump
81
  reg id_ex_mult, id_ex_div;                                         // Instruction is a multiplication/division
82
  reg id_ex_load, id_ex_store;                                       // Instruction is a load/store
83
  reg[2:0] id_ex_size;                                               // Load/store size (see defs.h)
84
  reg[31:0] id_ex_store_value;                                       // Store value
85
  reg[4:0] id_ex_destreg;                                            // Destination register (GPR number)
86
  reg id_ex_desthi, id_ex_destlo;                                    // Destination register (HI/LO)
87 46 fafa1971
  reg[4:0] id_ex_destsyscon;                                         // Destination register (System Control)
88 33 fafa1971
 
89
  // Latch 3: EX/MEM
90
  reg[31:0] ex_mem_opcode;
91
  reg[31:0] ex_mem_addr, ex_mem_addrnext;
92
  reg[31:0] ex_mem_addrbranch, ex_mem_addrjump, ex_mem_addrjr;
93
  reg[63:0] ex_mem_aluout;                                           // ALU result
94 48 fafa1971
  reg ex_mem_carry;                                                  // ALU carry
95 33 fafa1971
  reg ex_mem_branch, ex_mem_jump, ex_mem_jr, ex_mem_linked;
96
  reg ex_mem_mult, ex_mem_div;
97 50 fafa1971
  reg ex_mem_load, ex_mem_store;
98
  reg[2:0] ex_mem_size;
99 33 fafa1971
  reg[31:0] ex_mem_store_value;
100
  reg[3:0] ex_mem_store_sel;                                         // Byte Selector on Stores
101
  reg[4:0] ex_mem_destreg;
102
  reg ex_mem_desthi, ex_mem_destlo;
103 46 fafa1971
  reg[4:0] ex_mem_destsyscon;
104
 
105 33 fafa1971
  // Latch 4: MEM/WB
106
  reg[31:0] mem_wb_opcode;
107
  reg[31:0] mem_wb_addr, mem_wb_addrnext;
108
  reg[63:0] mem_wb_value;                                            // Write-back value
109
  reg[4:0] mem_wb_destreg;
110
  reg mem_wb_desthi, mem_wb_destlo;
111 46 fafa1971
  reg [4:0] mem_wb_destsyscon;
112 33 fafa1971
 
113
  /*
114
   * Combinational logic
115 46 fafa1971
   */
116 33 fafa1971
 
117
  // ALU
118
  assign alu_a_o = id_ex_alu_a;
119
  assign alu_b_o = id_ex_alu_b;
120
  assign alu_func_o = id_ex_alu_func;
121
  assign alu_signed_o = id_ex_alu_signed;
122
 
123
  // Multiplier
124
  assign mul_a_o = id_ex_alu_a;
125
  assign mul_b_o = id_ex_alu_b;
126
  assign mul_signed_o = id_ex_alu_signed;
127
  wire mul_ready = (mul_req_o==mul_ack_i);  // Convert ABP ack to true/false format
128
  wire mul_busy = !mul_ready;
129
 
130
  // Divider
131
  assign div_a_o = id_ex_alu_a;
132
  assign div_b_o = id_ex_alu_b;
133
  assign div_signed_o = id_ex_alu_signed;
134
  wire div_ready = (div_req_o==div_ack_i);  // Convert ABP ack to true/false format
135
  wire div_busy = !div_ready;
136
 
137
  // Incremented Program Counter
138
  wire[31:0] PCnext = PC + 4;
139
 
140
  // Instruction Memory
141
  assign imem_read_o = 1;
142
  assign imem_addr_o = PC;
143
 
144
  // Data Memory
145
  assign dmem_addr_o = ex_mem_aluout;
146
  assign dmem_read_o = ex_mem_load;
147
  assign dmem_write_o = ex_mem_store;
148
  assign dmem_data_o = ex_mem_store_value;
149
  assign dmem_sel_o = ex_mem_store_sel;
150
 
151
  // Decode fields from the Instruction Register
152
  wire[5:0] if_id_op = if_id_opcode[31:26];                                     // Operation code
153
  wire[4:0] if_id_rs = if_id_opcode[25:21];                                     // Source register
154
  wire[4:0] if_id_rt = if_id_opcode[20:16];                                     // Target register
155
  wire[4:0] if_id_rd = if_id_opcode[15:11];                                     // Destination register
156
  wire[31:0] if_id_imm_signext = {{16{if_id_opcode[15]}}, if_id_opcode[15:0]};  // Immediate field with sign-extension
157
  wire[31:0] if_id_imm_zeroext = {16'b0, if_id_opcode[15:0]};                   // Immediate field with zero-extension
158
  wire[25:0] if_id_index = if_id_opcode[25:0];                                  // Index field
159
  wire[4:0] if_id_shamt = if_id_opcode[10:6];                                   // Shift amount
160
  wire[5:0] if_id_func = if_id_opcode[5:0];                                     // Function
161
 
162
  // True for still undecoded operations that read GPR[rs]
163
  wire if_id_reads_rs = (
164
    if_id_op==`OPCODE_BEQ || if_id_op==`OPCODE_BNE || if_id_op==`OPCODE_BLEZ || if_id_op==`OPCODE_BGTZ ||
165
    if_id_op==`OPCODE_ADDI || if_id_op==`OPCODE_ADDIU || if_id_op==`OPCODE_SLTI || if_id_op==`OPCODE_SLTIU ||
166
    if_id_op==`OPCODE_ANDI || if_id_op==`OPCODE_ORI || if_id_op==`OPCODE_XORI || if_id_op==`OPCODE_LB ||
167
    if_id_op==`OPCODE_LH || if_id_op==`OPCODE_LWL || if_id_op==`OPCODE_LW || if_id_op==`OPCODE_LBU ||
168
    if_id_op==`OPCODE_LHU || if_id_op==`OPCODE_LWR || if_id_op==`OPCODE_SB || if_id_op==`OPCODE_SH ||
169
    if_id_op==`OPCODE_SWL || if_id_op==`OPCODE_SW || if_id_op==`OPCODE_SWR || (
170
      if_id_op==`OPCODE_SPECIAL && (
171
        if_id_func==`FUNCTION_SLLV || if_id_func==`FUNCTION_SRLV || if_id_func==`FUNCTION_SRAV ||
172
        if_id_func==`FUNCTION_JR || if_id_func==`FUNCTION_JALR || if_id_func==`FUNCTION_MTHI ||
173
        if_id_func==`FUNCTION_MTLO || if_id_func==`FUNCTION_MULT || if_id_func==`FUNCTION_MULTU ||
174
        if_id_func==`FUNCTION_DIV || if_id_func==`FUNCTION_DIVU || if_id_func==`FUNCTION_ADD ||
175
        if_id_func==`FUNCTION_ADDU || if_id_func==`FUNCTION_SUB || if_id_func==`FUNCTION_SUBU ||
176
        if_id_func==`FUNCTION_AND || if_id_func==`FUNCTION_OR || if_id_func==`FUNCTION_XOR ||
177
        if_id_func==`FUNCTION_NOR || if_id_func==`FUNCTION_SLT || if_id_func==`FUNCTION_SLTU
178
      )
179
    ) || (
180
      if_id_op==`OPCODE_BCOND && (
181
        if_id_rt==`BCOND_BLTZ || if_id_rt==`BCOND_BGEZ || if_id_rt==`BCOND_BLTZAL || if_id_rt==`BCOND_BGEZAL
182
      )
183
   )
184
  );
185
 
186
  // True for still undecoded operations that read GPR[rt]
187
  wire if_id_reads_rt = (
188
    if_id_op==`OPCODE_BEQ || if_id_op==`OPCODE_BNE || if_id_op==`OPCODE_SB || if_id_op==`OPCODE_SH ||
189
    if_id_op==`OPCODE_SWL || if_id_op==`OPCODE_SW || if_id_op==`OPCODE_SWR || (
190
      if_id_op==`OPCODE_SPECIAL && (
191
        if_id_func==`FUNCTION_SLL || if_id_func==`FUNCTION_SRL || if_id_func==`FUNCTION_SRA ||
192
        if_id_func==`FUNCTION_SLLV || if_id_func==`FUNCTION_SRLV || if_id_func==`FUNCTION_SRAV ||
193
        if_id_func==`FUNCTION_MULT || if_id_func==`FUNCTION_MULTU || if_id_func==`FUNCTION_DIV ||
194
        if_id_func==`FUNCTION_DIVU || if_id_func==`FUNCTION_ADD || if_id_func==`FUNCTION_ADDU ||
195
        if_id_func==`FUNCTION_SUB || if_id_func==`FUNCTION_SUBU || if_id_func==`FUNCTION_AND ||
196
        if_id_func==`FUNCTION_OR || if_id_func==`FUNCTION_XOR || if_id_func==`FUNCTION_NOR ||
197
        if_id_func==`FUNCTION_SLT || if_id_func==`FUNCTION_SLTU
198
      )
199
    )
200
  );
201
 
202
  // True for still undecoded operations that read the HI register
203
  wire if_id_reads_hi = (if_id_op==`OPCODE_SPECIAL && if_id_func==`FUNCTION_MFHI);
204
 
205
  // True for still undecoded operations that read the LO register
206
  wire if_id_reads_lo = (if_id_op==`OPCODE_SPECIAL && if_id_func==`FUNCTION_MFLO);
207
 
208
  // Finally detect a RAW hazard
209
  wire raw_detected = (
210
    (if_id_reads_rs && if_id_rs!=0 &&
211
      (if_id_rs==id_ex_destreg || if_id_rs==ex_mem_destreg || if_id_rs==mem_wb_destreg)) ||
212
    (if_id_reads_rt && if_id_rt!=0 &&
213
      (if_id_rt==id_ex_destreg || if_id_rt==ex_mem_destreg || if_id_rt==mem_wb_destreg)) ||
214
    (if_id_reads_hi && (id_ex_desthi || ex_mem_desthi || mem_wb_desthi)) ||
215
    (if_id_reads_lo && (id_ex_destlo || ex_mem_destlo || mem_wb_destlo))
216
  );
217
 
218
  // Stall signals for all the stages
219
  wire if_stall, id_stall, ex_stall, mem_stall, wb_stall;
220
  assign if_stall = id_stall || !imem_done_i;
221
  assign id_stall = ex_stall || raw_detected;
222
  assign ex_stall = mem_stall || mul_busy || div_busy;
223
  assign mem_stall = wb_stall || ( (dmem_read_o||dmem_write_o) && !dmem_done_i);
224
  assign wb_stall = 0;
225
 
226 46 fafa1971
  // Name the System Configuration registers
227
  wire[31:0] BadVAddr = SysCon[`SYSCON_BADVADDR];
228
  wire[31:0] Status = SysCon[`SYSCON_STATUS];
229
  wire[31:0] Cause = SysCon[`SYSCON_CAUSE];
230
  wire[31:0] EPC = SysCon[`SYSCON_EPC];
231
  wire[31:0] PrID = SysCon[`SYSCON_PRID];
232
 
233 33 fafa1971
  // Index for GPR initialization
234
  integer i;
235
 
236
  /*
237
   * Sequential logic
238
   */
239
 
240
  always @ (posedge sys_clock_i) begin
241
 
242
    // Initialize all the registers
243
    if (sys_reset_i==1) begin
244
 
245
      // GPRs initialization
246
      for(i=0; i<=31; i=i+1) GPR[i] <= 32'h00000000;
247
 
248
      // System registers
249
      PC <= `BOOT_ADDRESS;
250
      HI <= 0;
251
      LO <= 0;
252
 
253 46 fafa1971
      // Initialize system configuration registers
254
      for(i=0; i<=31; i=i+1) SysCon[i] <= 32'h00000000;
255
 
256 33 fafa1971
      // Initialize ABP requests to instantiated modules
257
      mul_req_o <= 0;
258
      div_req_o <= 0;
259
 
260
      // Latch 1: IF/ID
261
      if_id_opcode <= `NOP;
262
      if_id_addr <= `BOOT_ADDRESS;
263
      if_id_addrnext <= 0;
264
 
265
      // Latch 2: ID/EX
266
      id_ex_opcode <= 0;
267
      id_ex_addr <= 0;
268
      id_ex_addrnext <= 0;
269
      id_ex_addrjump <= 0;
270
      id_ex_addrbranch <= 0;
271
      id_ex_alu_a <= 0;
272
      id_ex_alu_b <= 0;
273
      id_ex_alu_func <= `ALU_OP_ADD;
274
      id_ex_alu_signed <= 0;
275
      id_ex_branch <= 0;
276
      id_ex_jump <= 0;
277
      id_ex_jr <=0;
278
      id_ex_linked <= 0;
279
      id_ex_mult <= 0;
280
      id_ex_div <= 0;
281
      id_ex_load <= 0;
282
      id_ex_store <= 0;
283
      id_ex_size <= 0;
284
      id_ex_store_value <= 0;
285
      id_ex_destreg <= 0;
286
      id_ex_desthi <= 0;
287
      id_ex_destlo <= 0;
288
 
289
      ex_mem_opcode <= 0;
290
      ex_mem_addr <= 0;
291
      ex_mem_addrnext <= 0;
292
      ex_mem_addrjump <= 0;
293
      ex_mem_addrbranch <= 0;
294
      ex_mem_aluout <= 0;
295 49 fafa1971
      ex_mem_carry <= 0;
296 33 fafa1971
      ex_mem_branch <= 0;
297
      ex_mem_jump <= 0;
298
      ex_mem_jr <= 0;
299
      ex_mem_linked <= 0;
300
      ex_mem_mult <= 0;
301
      ex_mem_div <= 0;
302
      ex_mem_load <= 0;
303
      ex_mem_store <= 0;
304
      ex_mem_store_value <= 0;
305
      ex_mem_store_sel <= 0;
306
      ex_mem_destreg <= 0;
307
      ex_mem_desthi <= 0;
308
      ex_mem_destlo <= 0;
309
 
310
      // Latch 4: MEM/WB
311
      mem_wb_opcode <= 0;
312
      mem_wb_addr <= 0;
313
      mem_wb_addrnext <= 0;
314
      mem_wb_value <= 0;
315
      mem_wb_destreg <= 0;
316
      mem_wb_desthi <= 0;
317
      mem_wb_destlo <= 0;
318
 
319
    end else begin
320
 
321
      $display("================> Time %t <================", $time);
322
 
323
      /*
324
       * Pipeline Stage 1: Instruction Fetch (IF)
325
       *
326
       * READ/WRITE:
327
       * - read memory
328
       * - write the IF/ID latch
329
       * - write the PC register
330
       *
331
       * DESCRIPTION:
332
       * This stage usually reads the next instruction from the PC address in memory and
333
       * then updates the PC value by incrementing it by 4.
334
       * When a hazard is detected this stage is idle.
335
       */
336
 
337
      // A RAW hazard will stall the CPU
338
      if(if_stall) begin
339
 
340
        if(id_stall) begin
341
          $display("INFO: CPU(%m)-IF: Fetching stalled and latch kept for following stalled pipeline stage");
342
        end else begin
343
          $display("INFO: CPU(%m)-IF: Fetching stalled and bubble inserted for following running pipeline stage");
344
          if_id_opcode <= `BUBBLE;
345
        end
346
 
347
      end else begin
348
 
349 49 fafa1971
        // If branch taken update the Program Counter
350 33 fafa1971
        if(ex_mem_branch==1 && ex_mem_aluout==32'h00000001) begin
351
 
352
          $display("INFO: CPU(%m)-IF: Bubble inserted due branch taken in EX/MEM instruction @ADDR=%X w/OPCODE=%X having ALUout=%X", ex_mem_addr, ex_mem_opcode, ex_mem_aluout);
353
          if_id_opcode <= `BUBBLE;
354
          PC <= ex_mem_addrbranch;
355
 
356 49 fafa1971
        // Jump to the required immediate address
357 33 fafa1971
        end else if(id_ex_jump==1) begin
358
 
359
          $display("INFO: CPU(%m)-IF: Bubble inserted due to jump in ID/EX instruction @ADDR=%X w/OPCODE=%X", id_ex_addr, id_ex_opcode);
360
          if_id_opcode <= `BUBBLE;
361
          PC <= id_ex_addrjump;
362
 
363
        // Jump to the required address stored in GPR
364
        end else if(id_ex_jr==1) begin
365
 
366
          $display("INFO: CPU(%m)-IF: Bubble inserted due to jump register in ID/EX instruction @ADDR=%X w/OPCODE=%X", id_ex_addr, id_ex_opcode);
367
          if_id_opcode <= `BUBBLE;
368
          PC <= id_ex_addrjr;
369
 
370
        // Normal execution
371
        end else begin
372
 
373
          $display("INFO: CPU(%m)-IF: Fetched from Program Counter @ADDR=%h getting OPCODE=%X", PC, imem_data_i);
374
          if_id_opcode <= imem_data_i;
375
          if_id_addr <= PC;
376
          if_id_addrnext <= PCnext;
377
          PC <= PCnext;
378
 
379
        end
380
      end
381
 
382
      /*
383
       * Pipeline Stage 2: Instruction Decode (ID)
384
       *
385
       * READ/WRITE:
386
       * - read the IF/ID latch
387
       * - read the register file
388
       * - write the ID/EX latch
389
       *
390
       * DESCRIPTION:
391
       * This stage decodes the instruction and puts the values for the ALU inputs
392
       */
393
 
394
      if(id_stall) begin
395
 
396
        if(ex_stall) begin
397
          $display("INFO: CPU(%m)-ID: Decoding stalled and latch kept for following stalled pipeline stage");
398
        end else begin
399
          $display("INFO: CPU(%m)-ID: Decoding stalled and bubble inserted for following running pipeline stage");
400
          id_ex_opcode <=`BUBBLE;
401
          id_ex_alu_a <= 0;
402
          id_ex_alu_b <= 0;
403
          id_ex_alu_func <= `ALU_OP_ADD;
404
          id_ex_alu_signed <= 0;
405
          id_ex_addr <= if_id_addr;
406
          id_ex_addrnext <= 0;
407
          id_ex_addrjump <= 0;
408
          id_ex_addrbranch <= 0;
409
          id_ex_branch <= 0;
410
          id_ex_jump <= 0;
411
          id_ex_jr <= 0;
412
          id_ex_linked <= 0;
413
          id_ex_mult <= 0;
414
          id_ex_div <= 0;
415
          id_ex_load <= 0;
416
          id_ex_store <= 0;
417
          id_ex_destreg <= 0;
418
          id_ex_desthi <= 0;
419
          id_ex_destlo <= 0;
420
        end
421
      end else begin
422
        id_ex_opcode <= if_id_opcode;
423
        id_ex_addr <= if_id_addr;
424
        id_ex_addrnext <= if_id_addrnext;
425
        id_ex_addrbranch <= if_id_addrnext + {if_id_imm_signext[29:0], 2'b00};
426
        id_ex_addrjump <= {if_id_addr[31:28], if_id_index, 2'b00};
427
        id_ex_addrjr <= GPR[if_id_rs];
428
 
429
        if(if_id_opcode==`BUBBLE) begin
430
          $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BUBBLE", if_id_addr, if_id_opcode);
431
          id_ex_alu_a <= 0;
432
          id_ex_alu_b <= 0;
433
          id_ex_alu_func <= `ALU_OP_ADD;
434
          id_ex_alu_signed <= 0;
435
          id_ex_branch <= 0;
436
          id_ex_jump <= 0;
437
          id_ex_jr <= 0;
438
          id_ex_linked <= 0;
439
          id_ex_mult <= 0;
440
          id_ex_div <= 0;
441
          id_ex_load <= 0;
442
          id_ex_store <= 0;
443
          id_ex_size <= 0;
444
          id_ex_store_value <= 0;
445
          id_ex_destreg <= 0;
446
          id_ex_desthi <= 0;
447
          id_ex_destlo <= 0;
448
        end else case(if_id_op)
449
          `OPCODE_J:
450
            begin
451
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as J %h", if_id_addr, if_id_opcode, if_id_index);
452
              id_ex_alu_a <= 0;
453
              id_ex_alu_b <= 0;
454
              id_ex_alu_func <= `ALU_OP_ADD;
455
              id_ex_alu_signed <= 0;
456
              id_ex_branch <= 0;
457
              id_ex_jump <= 1;
458
              id_ex_jr <= 0;
459
              id_ex_linked <= 0;
460
              id_ex_mult <= 0;
461
              id_ex_div <= 0;
462
              id_ex_load <= 0;
463
              id_ex_store <= 0;
464
              id_ex_size <= 0;
465
              id_ex_store_value <= 0;
466
              id_ex_destreg <= 0;
467
              id_ex_desthi <= 0;
468
              id_ex_destlo <= 0;
469
            end
470
          `OPCODE_JAL:
471
            begin
472
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as JAL %h", if_id_addr, if_id_opcode, if_id_index);
473
              id_ex_alu_a <= if_id_addrnext;
474
              id_ex_alu_b <= 4;
475
              id_ex_alu_func <= `ALU_OP_ADD;
476
              id_ex_alu_signed <= 0;
477
              id_ex_branch <= 0;
478
              id_ex_jump <= 1;
479
              id_ex_jr <= 0;
480
              id_ex_linked <= 1;
481
              id_ex_mult <= 0;
482
              id_ex_div <= 0;
483
              id_ex_load <= 0;
484
              id_ex_store <= 0;
485
              id_ex_size <= 0;
486
              id_ex_store_value <= 0;
487
              id_ex_destreg <= 31;
488
              id_ex_desthi <= 0;
489
              id_ex_destlo <= 0;
490
            end
491
          `OPCODE_BEQ:
492
            begin
493
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BEQ r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_rt, if_id_imm_signext);
494
              id_ex_alu_a <= GPR[if_id_rs];
495
              id_ex_alu_b <= GPR[if_id_rt];
496
              id_ex_alu_func <= `ALU_OP_SEQ;
497
              id_ex_alu_signed <= 0;
498
              id_ex_branch <= 1;
499
              id_ex_jump <= 0;
500
              id_ex_jr <= 0;
501
              id_ex_linked <= 0;
502
              id_ex_mult <= 0;
503
              id_ex_div <= 0;
504
              id_ex_load <= 0;
505
              id_ex_store <= 0;
506
              id_ex_size <= 0;
507
              id_ex_store_value <= 0;
508
              id_ex_destreg <= 0;
509
              id_ex_desthi <= 0;
510
              id_ex_destlo <= 0;
511
            end
512
          `OPCODE_BNE:
513
            begin
514
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BNE r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_rt, if_id_imm_signext);
515
              id_ex_alu_a <= GPR[if_id_rs];
516
              id_ex_alu_b <= GPR[if_id_rt];
517
              id_ex_alu_func <= `ALU_OP_SNE;
518
              id_ex_alu_signed <= 0;
519
              id_ex_branch <= 1;
520
              id_ex_jump <= 0;
521
              id_ex_jr <= 0;
522
              id_ex_linked <= 0;
523
              id_ex_mult <= 0;
524
              id_ex_div <= 0;
525
              id_ex_load <= 0;
526
              id_ex_store <= 0;
527
              id_ex_size <= 0;
528
              id_ex_store_value <= 0;
529
              id_ex_destreg <= 0;
530
              id_ex_desthi <= 0;
531
              id_ex_destlo <= 0;
532
            end
533
          `OPCODE_BLEZ:
534
            begin
535
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BLEZ r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
536
              id_ex_alu_a <= GPR[if_id_rs];
537
              id_ex_alu_b <= 0;
538
              id_ex_alu_func <= `ALU_OP_SLE;
539
              id_ex_alu_signed <= 0;
540
              id_ex_branch <= 1;
541
              id_ex_jump <= 0;
542
              id_ex_jr <= 0;
543
              id_ex_linked <= 0;
544
              id_ex_mult <= 0;
545
              id_ex_div <= 0;
546
              id_ex_load <= 0;
547
              id_ex_store <= 0;
548
              id_ex_size <= 0;
549
              id_ex_store_value <= 0;
550
              id_ex_destreg <= 0;
551
              id_ex_desthi <= 0;
552
              id_ex_destlo <= 0;
553
            end
554
          `OPCODE_BGTZ:
555
            begin
556
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BGTZ r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
557
              id_ex_alu_a <= GPR[if_id_rs];
558
              id_ex_alu_b <= 0;
559
              id_ex_alu_func <= `ALU_OP_SGT;
560
              id_ex_alu_signed <= 0;
561
              id_ex_branch <= 1;
562
              id_ex_jump <= 0;
563
              id_ex_jr <= 0;
564
              id_ex_linked <= 0;
565
              id_ex_mult <= 0;
566
              id_ex_div <= 0;
567
              id_ex_load <= 0;
568
              id_ex_store <= 0;
569
              id_ex_size <= 0;
570
              id_ex_store_value <= 0;
571
              id_ex_destreg <= 0;
572
              id_ex_desthi <= 0;
573
              id_ex_destlo <= 0;
574
            end
575
          `OPCODE_ADDI:
576
            begin
577
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ADDI r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_signext);
578
              id_ex_alu_a <= GPR[if_id_rs];
579
              id_ex_alu_b <= if_id_imm_signext;
580
              id_ex_alu_func <= `ALU_OP_ADD;
581
              id_ex_alu_signed <= 1;
582
              id_ex_branch <= 0;
583
              id_ex_jump <= 0;
584
              id_ex_jr <= 0;
585
              id_ex_linked <= 0;
586
              id_ex_mult <= 0;
587
              id_ex_div <= 0;
588
              id_ex_load <= 0;
589
              id_ex_store <= 0;
590
              id_ex_size <= 0;
591
              id_ex_store_value <= 0;
592
              id_ex_destreg <= if_id_rt;
593
              id_ex_desthi <= 0;
594
              id_ex_destlo <= 0;
595
            end
596
          `OPCODE_ADDIU:
597
            begin
598
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ADDIU r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_signext);
599
              id_ex_alu_a <= GPR[if_id_rs];
600
              id_ex_alu_b <= if_id_imm_signext;
601
              id_ex_alu_func <= `ALU_OP_ADD;
602
              id_ex_alu_signed <= 0;
603
              id_ex_branch <= 0;
604
              id_ex_jump <= 0;
605
              id_ex_jr <= 0;
606
              id_ex_linked <= 0;
607
              id_ex_mult <= 0;
608
              id_ex_div <= 0;
609
              id_ex_load <= 0;
610
              id_ex_store <= 0;
611
              id_ex_size <= 0;
612
              id_ex_store_value <= 0;
613
              id_ex_destreg <= if_id_rt;
614
              id_ex_desthi <= 0;
615
              id_ex_destlo <= 0;
616
            end
617
          `OPCODE_SLTI:
618
            begin
619
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLTI r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_signext);
620
              id_ex_alu_a <= GPR[if_id_rs];
621
              id_ex_alu_b <= if_id_imm_signext;
622
              id_ex_alu_func <= `ALU_OP_SLT;
623
              id_ex_alu_signed <= 1;
624
              id_ex_branch <= 0;
625
              id_ex_jump <= 0;
626
              id_ex_jr <= 0;
627
              id_ex_linked <= 0;
628
              id_ex_mult <= 0;
629
              id_ex_div <= 0;
630
              id_ex_load <= 0;
631
              id_ex_store <= 0;
632
              id_ex_size <= 0;
633
              id_ex_store_value <= 0;
634
              id_ex_destreg <= if_id_rt;
635
              id_ex_desthi <= 0;
636
              id_ex_destlo <= 0;
637
            end
638
          `OPCODE_SLTIU:
639
            begin
640
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLTIU r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_signext);
641
              id_ex_alu_a <= GPR[if_id_rs];
642
              id_ex_alu_b <= if_id_imm_signext;
643
              id_ex_alu_func <= `ALU_OP_SLT;
644
              id_ex_alu_signed <= 0;
645
              id_ex_branch <= 0;
646
              id_ex_jump <= 0;
647
              id_ex_jr <= 0;
648
              id_ex_linked <= 0;
649
              id_ex_mult <= 0;
650
              id_ex_div <= 0;
651
              id_ex_load <= 0;
652
              id_ex_store <= 0;
653
              id_ex_size <= 0;
654
              id_ex_store_value <= 0;
655
              id_ex_destreg <= if_id_rt;
656
              id_ex_desthi <= 0;
657
              id_ex_destlo <= 0;
658
            end
659
          `OPCODE_ANDI:
660
            begin
661
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ANDI r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_zeroext);
662
              id_ex_alu_a <= GPR[if_id_rs];
663
              id_ex_alu_b <= if_id_imm_zeroext;
664
              id_ex_alu_func <= `ALU_OP_AND;
665
              id_ex_alu_signed <= 0;
666
              id_ex_branch <= 0;
667
              id_ex_jump <= 0;
668
              id_ex_jr <= 0;
669
              id_ex_linked <= 0;
670
              id_ex_mult <= 0;
671
              id_ex_div <= 0;
672
              id_ex_load <= 0;
673
              id_ex_store <= 0;
674
              id_ex_size <= 0;
675
              id_ex_store_value <= 0;
676
              id_ex_destreg <= if_id_rt;
677
              id_ex_desthi <= 0;
678
              id_ex_destlo <= 0;
679
            end
680
          `OPCODE_ORI:
681
            begin
682
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ORI r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_zeroext);
683
              id_ex_alu_a <= GPR[if_id_rs];
684
              id_ex_alu_b <= if_id_imm_zeroext;
685
              id_ex_alu_func <= `ALU_OP_OR;
686
              id_ex_alu_signed <= 0;
687
              id_ex_branch <= 0;
688
              id_ex_jump <= 0;
689
              id_ex_jr <= 0;
690
              id_ex_linked <= 0;
691
              id_ex_mult <= 0;
692
              id_ex_div <= 0;
693
              id_ex_load <= 0;
694
              id_ex_store <= 0;
695
              id_ex_size <= 0;
696
              id_ex_store_value <= 0;
697
              id_ex_destreg <= if_id_rt;
698
              id_ex_desthi <= 0;
699
              id_ex_destlo <= 0;
700
            end
701
          `OPCODE_XORI:
702
            begin
703
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as XORI r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_rs, if_id_imm_zeroext);
704
              id_ex_alu_a <= GPR[if_id_rs];
705
              id_ex_alu_b <= if_id_imm_zeroext;
706
              id_ex_alu_func <= `ALU_OP_XOR;
707
              id_ex_alu_signed <= 0;
708
              id_ex_branch <= 0;
709
              id_ex_jump <= 0;
710
              id_ex_jr <= 0;
711
              id_ex_linked <= 0;
712
              id_ex_mult <= 0;
713
              id_ex_div <= 0;
714
              id_ex_load <= 0;
715
              id_ex_store <= 0;
716
              id_ex_size <= 0;
717
              id_ex_store_value <= 0;
718
              id_ex_destreg <= if_id_rt;
719
              id_ex_desthi <= 0;
720
              id_ex_destlo <= 0;
721
            end
722
          `OPCODE_LUI:
723
            begin
724
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LUI r%d, %h", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_zeroext);
725
              id_ex_alu_a <= if_id_imm_zeroext;
726
              id_ex_alu_b <= 16;
727
              id_ex_alu_func <= `ALU_OP_SLL;
728
              id_ex_alu_signed <= 0;
729
              id_ex_branch <= 0;
730
              id_ex_jump <= 0;
731
              id_ex_jr <= 0;
732
              id_ex_linked <= 0;
733
              id_ex_mult <= 0;
734
              id_ex_div <= 0;
735
              id_ex_load <= 0;
736
              id_ex_store <= 0;
737
              id_ex_size <= 0;
738
              id_ex_store_value <= 0;
739
              id_ex_destreg <= if_id_rt;
740
              id_ex_desthi <= 0;
741
              id_ex_destlo <= 0;
742
            end
743
          `OPCODE_COP0:
744
            begin
745
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as COP0", if_id_addr, if_id_opcode);
746
            end
747
          `OPCODE_COP1:
748
            begin
749
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as COP1", if_id_addr, if_id_opcode);
750
            end
751
          `OPCODE_COP2:
752
            begin
753
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as COP2", if_id_addr, if_id_opcode);
754
            end
755
          `OPCODE_COP3:
756
            begin
757
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as COP3", if_id_addr, if_id_opcode);
758
            end
759
          `OPCODE_LB:
760
            begin
761
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LB r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
762
              id_ex_alu_a <= GPR[if_id_rs];
763
              id_ex_alu_b <= if_id_imm_signext;
764
              id_ex_alu_func <= `ALU_OP_ADD;
765
              id_ex_alu_signed <= 1;
766
              id_ex_branch <= 0;
767
              id_ex_jump <= 0;
768
              id_ex_jr <= 0;
769
              id_ex_linked <= 0;
770
              id_ex_mult <= 0;
771
              id_ex_div <= 0;
772
              id_ex_load <= 1;
773
              id_ex_store <= 0;
774
              id_ex_size <= `SIZE_BYTE;
775
              id_ex_store_value <= 0;
776
              id_ex_destreg <= if_id_rt;
777
              id_ex_desthi <= 0;
778
              id_ex_destlo <= 0;
779
            end
780
          `OPCODE_LH:
781
            begin
782
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LH r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
783
              id_ex_alu_a <= GPR[if_id_rs];
784
              id_ex_alu_b <= if_id_imm_signext;
785
              id_ex_alu_func <= `ALU_OP_ADD;
786
              id_ex_alu_signed <= 1;
787
              id_ex_branch <= 0;
788
              id_ex_jump <= 0;
789
              id_ex_jr <= 0;
790
              id_ex_linked <= 0;
791
              id_ex_mult <= 0;
792
              id_ex_div <= 0;
793
              id_ex_load <= 1;
794
              id_ex_store <= 0;
795
              id_ex_size <= `SIZE_HALF;
796
              id_ex_store_value <= 0;
797
              id_ex_destreg <= if_id_rt;
798
              id_ex_desthi <= 0;
799
              id_ex_destlo <= 0;
800
            end
801
          `OPCODE_LWL:
802
            begin
803
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LWL r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
804
              id_ex_alu_a <= GPR[if_id_rs];
805
              id_ex_alu_b <= if_id_imm_signext;
806
              id_ex_alu_func <= `ALU_OP_ADD;
807
              id_ex_alu_signed <= 1;
808
              id_ex_branch <= 0;
809
              id_ex_jump <= 0;
810
              id_ex_jr <= 0;
811
              id_ex_linked <= 0;
812
              id_ex_mult <= 0;
813
              id_ex_div <= 0;
814
              id_ex_load <= 1;
815
              id_ex_store <= 0;
816
              id_ex_size <= `SIZE_LEFT;
817
              id_ex_store_value <= 0;
818
              id_ex_destreg <= if_id_rt;
819
              id_ex_desthi <= 0;
820
              id_ex_destlo <= 0;
821
            end
822
          `OPCODE_LW:
823
            begin
824
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LW r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
825
              id_ex_alu_a <= GPR[if_id_rs];
826
              id_ex_alu_b <= if_id_imm_signext;
827
              id_ex_alu_func <= `ALU_OP_ADD;
828
              id_ex_alu_signed <= 1;
829
              id_ex_branch <= 0;
830
              id_ex_jump <= 0;
831
              id_ex_jr <= 0;
832
              id_ex_linked <= 0;
833
              id_ex_mult <= 0;
834
              id_ex_div <= 0;
835
              id_ex_load <= 1;
836
              id_ex_store <= 0;
837
              id_ex_size <= `SIZE_WORD;
838
              id_ex_store_value <= 0;
839
              id_ex_destreg <= if_id_rt;
840
              id_ex_desthi <= 0;
841
              id_ex_destlo <= 0;
842
            end
843
          `OPCODE_LBU:
844
            begin
845
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LBU r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
846
              id_ex_alu_a <= GPR[if_id_rs];
847
              id_ex_alu_b <= if_id_imm_signext;
848
              id_ex_alu_func <= `ALU_OP_ADD;
849
              id_ex_alu_signed <= 0;
850
              id_ex_branch <= 0;
851
              id_ex_jump <= 0;
852
              id_ex_jr <= 0;
853
              id_ex_linked <= 0;
854
              id_ex_mult <= 0;
855
              id_ex_div <= 0;
856
              id_ex_load <= 1;
857
              id_ex_store <= 0;
858
              id_ex_size <= `SIZE_BYTE;
859
              id_ex_store_value <= 0;
860
              id_ex_destreg <= if_id_rt;
861
              id_ex_desthi <= 0;
862
              id_ex_destlo <= 0;
863
            end
864
          `OPCODE_LHU:
865
            begin
866
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LHU r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
867
              id_ex_alu_a <= GPR[if_id_rs];
868
              id_ex_alu_b <= if_id_imm_signext;
869
              id_ex_alu_func <= `ALU_OP_ADD;
870
              id_ex_alu_signed <= 0;
871
              id_ex_branch <= 0;
872
              id_ex_jump <= 0;
873
              id_ex_jr <= 0;
874
              id_ex_linked <= 0;
875
              id_ex_mult <= 0;
876
              id_ex_div <= 0;
877
              id_ex_load <= 1;
878
              id_ex_store <= 0;
879
              id_ex_size <= `SIZE_HALF;
880
              id_ex_store_value <= 0;
881
              id_ex_destreg <= if_id_rt;
882
              id_ex_desthi <= 0;
883
              id_ex_destlo <= 0;
884
            end
885
          `OPCODE_LWR:
886
            begin
887
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LWR r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
888
              id_ex_alu_a <= GPR[if_id_rs];
889
              id_ex_alu_b <= if_id_imm_signext;
890
              id_ex_alu_func <= `ALU_OP_ADD;
891
              id_ex_alu_signed <= 1;
892
              id_ex_branch <= 0;
893
              id_ex_jump <= 0;
894
              id_ex_jr <= 0;
895
              id_ex_linked <= 0;
896
              id_ex_mult <= 0;
897
              id_ex_div <= 0;
898
              id_ex_load <= 1;
899
              id_ex_store <= 0;
900
              id_ex_size <= `SIZE_RIGHT;
901
              id_ex_store_value <= 0;
902
              id_ex_destreg <= if_id_rt;
903
              id_ex_desthi <= 0;
904
              id_ex_destlo <= 0;
905
            end
906
          `OPCODE_SB:
907
            begin
908
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SB r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
909
              id_ex_alu_a <= GPR[if_id_rs];
910
              id_ex_alu_b <= if_id_imm_signext;
911
              id_ex_alu_func <= `ALU_OP_ADD;
912
              id_ex_alu_signed <= 1;
913
              id_ex_branch <= 0;
914
              id_ex_jump <= 0;
915
              id_ex_jr <= 0;
916
              id_ex_linked <= 0;
917
              id_ex_mult <= 0;
918
              id_ex_div <= 0;
919
              id_ex_load <= 0;
920
              id_ex_store <= 1;
921
              id_ex_size <= `SIZE_BYTE;
922
              id_ex_store_value <= GPR[if_id_rt];
923
              id_ex_destreg <= 0;
924
              id_ex_desthi <= 0;
925
              id_ex_destlo <= 0;
926
            end
927
          `OPCODE_SH:
928
            begin
929
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SH r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
930
              id_ex_alu_a <= GPR[if_id_rs];
931
              id_ex_alu_b <= if_id_imm_signext;
932
              id_ex_alu_func <= `ALU_OP_ADD;
933
              id_ex_alu_signed <= 1;
934
              id_ex_branch <= 0;
935
              id_ex_jump <= 0;
936
              id_ex_jr <= 0;
937
              id_ex_linked <= 0;
938
              id_ex_mult <= 0;
939
              id_ex_div <= 0;
940
              id_ex_load <= 0;
941
              id_ex_store <= 1;
942
              id_ex_size <= `SIZE_HALF;
943
              id_ex_store_value <= GPR[if_id_rt];
944
              id_ex_destreg <= 0;
945
              id_ex_desthi <= 0;
946
              id_ex_destlo <= 0;
947
             end
948
          `OPCODE_SWL:
949
            begin
950
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SWL r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
951
              id_ex_alu_a <= GPR[if_id_rs];
952
              id_ex_alu_b <= if_id_imm_signext;
953
              id_ex_alu_func <= `ALU_OP_ADD;
954
              id_ex_alu_signed <= 1;
955
              id_ex_branch <= 0;
956
              id_ex_jump <= 0;
957
              id_ex_jr <= 0;
958
              id_ex_linked <= 0;
959
              id_ex_mult <= 0;
960
              id_ex_div <= 0;
961
              id_ex_load <= 0;
962
              id_ex_store <= 1;
963
              id_ex_size <= `SIZE_LEFT;
964
              id_ex_store_value <= GPR[if_id_rt];
965
              id_ex_destreg <= 0;
966
              id_ex_desthi <= 0;
967
              id_ex_destlo <= 0;
968
            end
969
          `OPCODE_SW:
970
            begin
971
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SW r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
972
              id_ex_alu_a <= GPR[if_id_rs];
973
              id_ex_alu_b <= if_id_imm_signext;
974
              id_ex_alu_func <= `ALU_OP_ADD;
975
              id_ex_alu_signed <= 1;
976
              id_ex_branch <= 0;
977
              id_ex_jump <= 0;
978
              id_ex_jr <= 0;
979
              id_ex_linked <= 0;
980
              id_ex_mult <= 0;
981
              id_ex_div <= 0;
982
              id_ex_load <= 0;
983
              id_ex_store <= 1;
984
              id_ex_size <= `SIZE_WORD;
985
              id_ex_store_value <= GPR[if_id_rt];
986
              id_ex_destreg <= 0;
987
              id_ex_desthi <= 0;
988
              id_ex_destlo <= 0;
989
            end
990
          `OPCODE_SWR:
991
            begin
992
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SWR r%d, %d(r%d)", if_id_addr, if_id_opcode, if_id_rt, if_id_imm_signext, if_id_rs);
993
              id_ex_alu_a <= GPR[if_id_rs];
994
              id_ex_alu_b <= if_id_imm_signext;
995
              id_ex_alu_func <= `ALU_OP_ADD;
996
              id_ex_alu_signed <= 1;
997
              id_ex_branch <= 0;
998
              id_ex_jump <= 0;
999
              id_ex_jr <= 0;
1000
              id_ex_linked <= 0;
1001
              id_ex_mult <= 0;
1002
              id_ex_div <= 0;
1003
              id_ex_load <= 0;
1004
              id_ex_store <= 1;
1005
              id_ex_size <= `SIZE_RIGHT;
1006
              id_ex_store_value <= GPR[if_id_rt];
1007
              id_ex_destreg <= 0;
1008
              id_ex_desthi <= 0;
1009
              id_ex_destlo <= 0;
1010
            end
1011
          `OPCODE_LWC1:
1012
            begin
1013
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LWC1", if_id_addr, if_id_opcode);
1014
           end
1015
          `OPCODE_LWC2:
1016
            begin
1017
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LWC2", if_id_addr, if_id_opcode);
1018
            end
1019
          `OPCODE_LWC3:
1020
            begin
1021
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as LWC3", if_id_addr, if_id_opcode);
1022
            end
1023
          `OPCODE_SWC1:
1024
            begin
1025
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SWC1", if_id_addr, if_id_opcode);
1026
            end
1027
          `OPCODE_SWC2:
1028
            begin
1029
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SWC2", if_id_addr, if_id_opcode);
1030
            end
1031
          `OPCODE_SWC3:
1032
            begin
1033
              $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SWC3", if_id_addr, if_id_opcode);
1034
            end
1035
          `OPCODE_SPECIAL:
1036
            case(if_id_func)
1037
              `FUNCTION_SLL:
1038
                begin
1039
                  if(if_id_opcode==`NOP) $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as NOP", if_id_addr, if_id_opcode);
1040
                  else $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLL r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_shamt);
1041
                  id_ex_alu_a <= GPR[if_id_rt];
1042
                  id_ex_alu_b <= if_id_shamt;
1043
                  id_ex_alu_func <= `ALU_OP_SLL;
1044
                  id_ex_alu_signed <= 0;
1045
                  id_ex_branch <= 0;
1046
                  id_ex_jump <= 0;
1047
                  id_ex_jr <= 0;
1048
                  id_ex_linked <= 0;
1049
                  id_ex_mult <= 0;
1050
                  id_ex_div <= 0;
1051
                  id_ex_load <= 0;
1052
                  id_ex_store <= 0;
1053
                  id_ex_size <= 0;
1054
                  id_ex_store_value <= 0;
1055
                  id_ex_destreg <= if_id_rd;
1056
                  id_ex_desthi <= 0;
1057
                  id_ex_destlo <= 0;
1058
                end
1059
              `FUNCTION_SRL:
1060
                begin
1061
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SRL r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_shamt);
1062
                  id_ex_alu_a <= GPR[if_id_rt];
1063
                  id_ex_alu_b <= if_id_shamt;
1064
                  id_ex_alu_func <= `ALU_OP_SRL;
1065
                  id_ex_alu_signed <= 0;
1066
                  id_ex_branch <= 0;
1067
                  id_ex_jump <= 0;
1068
                  id_ex_jr <= 0;
1069
                  id_ex_linked <= 0;
1070
                  id_ex_mult <= 0;
1071
                  id_ex_div <= 0;
1072
                  id_ex_load <= 0;
1073
                  id_ex_store <= 0;
1074
                  id_ex_size <= 0;
1075
                  id_ex_store_value <= 0;
1076
                  id_ex_destreg <= if_id_rd;
1077
                  id_ex_desthi <= 0;
1078
                  id_ex_destlo <= 0;
1079
                end
1080
              `FUNCTION_SRA:
1081
                begin
1082
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SRA r%d, r%d, %h", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_shamt);
1083
                  id_ex_alu_a <= GPR[if_id_rt];
1084
                  id_ex_alu_b <= if_id_shamt;
1085
                  id_ex_alu_func <= `ALU_OP_SRA;
1086 49 fafa1971
                  id_ex_alu_signed <= 1;
1087 33 fafa1971
                  id_ex_branch <= 0;
1088
                  id_ex_jump <= 0;
1089
                  id_ex_jr <= 0;
1090
                  id_ex_linked <= 0;
1091
                  id_ex_mult <= 0;
1092
                  id_ex_div <= 0;
1093
                  id_ex_load <= 0;
1094
                  id_ex_store <= 0;
1095
                  id_ex_size <= 0;
1096
                  id_ex_store_value <= 0;
1097
                  id_ex_destreg <= if_id_rd;
1098
                  id_ex_desthi <= 0;
1099
                  id_ex_destlo <= 0;
1100
                end
1101
              `FUNCTION_SLLV:
1102
                begin
1103
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLLV r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_rs);
1104
                  id_ex_alu_a <= GPR[if_id_rt];
1105
                  id_ex_alu_b <= GPR[if_id_rs];
1106
                  id_ex_alu_func <= `ALU_OP_SLL;
1107
                  id_ex_alu_signed <= 0;
1108
                  id_ex_branch <= 0;
1109
                  id_ex_jump <= 0;
1110
                  id_ex_jr <= 0;
1111
                  id_ex_linked <= 0;
1112
                  id_ex_mult <= 0;
1113
                  id_ex_div <= 0;
1114
                  id_ex_load <= 0;
1115
                  id_ex_store <= 0;
1116
                  id_ex_size <= 0;
1117
                  id_ex_store_value <= 0;
1118
                  id_ex_destreg <= if_id_rd;
1119
                  id_ex_desthi <= 0;
1120
                  id_ex_destlo <= 0;
1121
                end
1122
              `FUNCTION_SRLV:
1123
                begin
1124
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SRLV r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_rs);
1125
                  id_ex_alu_a <= GPR[if_id_rt];
1126
                  id_ex_alu_b <= GPR[if_id_rs];
1127
                  id_ex_alu_func <= `ALU_OP_SRL;
1128
                  id_ex_alu_signed <= 0;
1129
                  id_ex_branch <= 0;
1130
                  id_ex_jump <= 0;
1131
                  id_ex_jr <= 0;
1132
                  id_ex_linked <= 0;
1133
                  id_ex_mult <= 0;
1134
                  id_ex_div <= 0;
1135
                  id_ex_load <= 0;
1136
                  id_ex_store <= 0;
1137
                  id_ex_size <= 0;
1138
                  id_ex_store_value <= 0;
1139
                  id_ex_destreg <= if_id_rd;
1140
                  id_ex_desthi <= 0;
1141
                  id_ex_destlo <= 0;
1142
                end
1143
              `FUNCTION_SRAV:
1144
                begin
1145
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SRAV r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rt, if_id_rs);
1146
                  id_ex_alu_a <= GPR[if_id_rt];
1147
                  id_ex_alu_b <= GPR[if_id_rs];
1148
                  id_ex_alu_func <= `ALU_OP_SRA;
1149
                  id_ex_alu_signed <= 1;
1150
                  id_ex_branch <= 0;
1151
                  id_ex_jump <= 0;
1152
                  id_ex_jr <= 0;
1153
                  id_ex_linked <= 0;
1154
                  id_ex_mult <= 0;
1155
                  id_ex_div <= 0;
1156
                  id_ex_load <= 0;
1157
                  id_ex_store <= 0;
1158
                  id_ex_size <= 0;
1159
                  id_ex_store_value <= 0;
1160
                  id_ex_destreg <= if_id_rd;
1161
                  id_ex_desthi <= 0;
1162
                  id_ex_destlo <= 0;
1163
                end
1164
              `FUNCTION_JR:
1165
                begin
1166
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as JR r%d", if_id_addr, if_id_opcode, if_id_rs);
1167
                  id_ex_alu_a <= 0;
1168
                  id_ex_alu_b <= 0;
1169
                  id_ex_alu_func <= `ALU_OP_ADD;
1170
                  id_ex_alu_signed <= 0;
1171
                  id_ex_branch <= 0;
1172
                  id_ex_jump <= 0;
1173
                  id_ex_jr <= 1;
1174
                  id_ex_linked <= 0;
1175
                  id_ex_mult <= 0;
1176
                  id_ex_div <= 0;
1177
                  id_ex_load <= 0;
1178
                  id_ex_store <= 0;
1179
                  id_ex_size <= 0;
1180
                  id_ex_store_value <= 0;
1181
                  id_ex_destreg <= 0;
1182
                  id_ex_desthi <= 0;
1183
                  id_ex_destlo <= 0;
1184
                end
1185
              `FUNCTION_JALR:
1186
                begin
1187
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as JALR [r%d,] r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs);
1188
                  id_ex_alu_a <= if_id_addrnext;
1189
                  id_ex_alu_b <= 4;
1190
                  id_ex_alu_func <= `ALU_OP_ADD;
1191
                  id_ex_alu_signed <= 0;
1192
                  id_ex_branch <= 0;
1193
                  id_ex_jump <= 0;
1194
                  id_ex_jr <= 1;
1195
                  id_ex_linked <= 1;
1196
                  id_ex_mult <= 0;
1197
                  id_ex_div <= 0;
1198
                  id_ex_load <= 0;
1199
                  id_ex_store <= 0;
1200
                  id_ex_size <= 0;
1201
                  id_ex_store_value <= 0;
1202
                  id_ex_destreg <= if_id_rd;
1203
                  id_ex_desthi <= 0;
1204
                  id_ex_destlo <= 0;
1205
                end
1206
              `FUNCTION_SYSCALL:
1207
                begin
1208
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SYSCALL", if_id_addr, if_id_opcode);
1209
//                  id_ex_alu_a <= 0;
1210
//                  id_ex_alu_b <= 0;
1211
//                  id_ex_alu_func <= `ALU_OP_ADD;
1212
//                  id_ex_alu_signed <= 0;
1213
//                  id_ex_branch <= 0;
1214
//                  id_ex_jump <= 0;
1215
//                  id_ex_jr <= 0;
1216
//                  id_ex_linked <= 0;
1217
//                  id_ex_mult <= 0;
1218
//                  id_ex_div <= 0;
1219
//                  id_ex_load <= 0;
1220
//                  id_ex_store <= 0;
1221
//                  id_ex_size <= 0;
1222
//                  id_ex_store_value <= 0;
1223
//                  id_ex_destreg <= 0;
1224
//                  id_ex_desthi <= 0;
1225
//                  id_ex_destlo <= 0;
1226
                end
1227
              `FUNCTION_BREAK:
1228
                begin
1229
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BREAK", if_id_addr, if_id_opcode);
1230
//                  id_ex_alu_a <= 0;
1231
//                  id_ex_alu_b <= 0;
1232
//                  id_ex_alu_func <= `ALU_OP_ADD;
1233
//                  id_ex_alu_signed <= 0;
1234
//                  id_ex_branch <= 0;
1235
//                  id_ex_jump <= 0;
1236
//                  id_ex_jr <= 0;
1237
//                  id_ex_linked <= 0;
1238
//                  id_ex_mult <= 0;
1239
//                  id_ex_div <= 0;
1240
//                  id_ex_load <= 0;
1241
//                  id_ex_store <= 0;
1242
//                  id_ex_size <= 0;
1243
//                  id_ex_store_value <= 0;
1244
//                  id_ex_destreg <= 0;
1245
//                  id_ex_desthi <= 0;
1246
//                  id_ex_destlo <= 0;
1247
                end
1248
              `FUNCTION_MFHI:
1249
                begin
1250
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MFHI r%d", if_id_addr, if_id_opcode, if_id_rd);
1251
                  id_ex_alu_a <= HI;
1252
                  id_ex_alu_b <= 0;
1253
                  id_ex_alu_func <= `ALU_OP_ADD;
1254
                  id_ex_alu_signed <= 0;
1255
                  id_ex_branch <= 0;
1256
                  id_ex_jump <= 0;
1257
                  id_ex_jr <= 0;
1258
                  id_ex_linked <= 0;
1259
                  id_ex_mult <= 0;
1260
                  id_ex_div <= 0;
1261
                  id_ex_load <= 0;
1262
                  id_ex_store <= 0;
1263
                  id_ex_size <= 0;
1264
                  id_ex_store_value <= 0;
1265
                  id_ex_destreg <= if_id_rd;
1266
                  id_ex_desthi <= 0;
1267
                  id_ex_destlo <= 0;
1268
                end
1269
              `FUNCTION_MTHI:
1270
                begin
1271
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MTHI r%d", if_id_addr, if_id_opcode, if_id_rs);
1272
                  id_ex_alu_a <= GPR[if_id_rs];
1273
                  id_ex_alu_b <= 0;
1274
                  id_ex_alu_func <= `ALU_OP_ADD;
1275
                  id_ex_alu_signed <= 0;
1276
                  id_ex_branch <= 0;
1277
                  id_ex_jump <= 0;
1278
                  id_ex_jr <= 0;
1279
                  id_ex_linked <= 0;
1280
                  id_ex_mult <= 0;
1281
                  id_ex_div <= 0;
1282
                  id_ex_load <= 0;
1283
                  id_ex_store <= 0;
1284
                  id_ex_size <= 0;
1285
                  id_ex_store_value <= 0;
1286
                  id_ex_destreg <= 0;
1287
                  id_ex_desthi <= 1;
1288
                  id_ex_destlo <= 0;
1289
                end
1290
              `FUNCTION_MFLO:
1291
                begin
1292
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MFLO r%d", if_id_addr, if_id_opcode, if_id_rd);
1293
                  id_ex_alu_a <= LO;
1294
                  id_ex_alu_b <= 0;
1295
                  id_ex_alu_func <= `ALU_OP_ADD;
1296
                  id_ex_alu_signed <= 0;
1297
                  id_ex_branch <= 0;
1298
                  id_ex_jump <= 0;
1299
                  id_ex_jr <= 0;
1300
                  id_ex_linked <= 0;
1301
                  id_ex_mult <= 0;
1302
                  id_ex_div <= 0;
1303
                  id_ex_load <= 0;
1304
                  id_ex_store <= 0;
1305
                  id_ex_size <= 0;
1306
                  id_ex_store_value <= 0;
1307
                  id_ex_destreg <= if_id_rd;
1308
                  id_ex_desthi <= 0;
1309
                  id_ex_destlo <= 0;
1310
                end
1311
              `FUNCTION_MTLO:
1312
                begin
1313
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MTLO r%d", if_id_addr, if_id_opcode, if_id_rs);
1314
                  id_ex_alu_a <= GPR[if_id_rs];
1315
                  id_ex_alu_b <= 0;
1316
                  id_ex_alu_func <= `ALU_OP_ADD;
1317
                  id_ex_alu_signed <= 0;
1318
                  id_ex_branch <= 0;
1319
                  id_ex_jump <= 0;
1320
                  id_ex_linked <= 0;
1321
                  id_ex_mult <= 0;
1322
                  id_ex_div <= 0;
1323
                  id_ex_load <= 0;
1324
                  id_ex_store <= 0;
1325
                  id_ex_size <= 0;
1326
                  id_ex_store_value <= 0;
1327
                  id_ex_destreg <= 0;
1328
                  id_ex_desthi <= 0;
1329
                  id_ex_destlo <= 1;
1330
                end
1331
              `FUNCTION_MULT:
1332
                begin
1333
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MULT r%d, r%d", if_id_addr, if_id_opcode, if_id_rs, if_id_rt);
1334
                  id_ex_alu_a <= GPR[if_id_rs];
1335
                  id_ex_alu_b <= GPR[if_id_rt];
1336
                  id_ex_alu_func <= `ALU_OP_MULT;
1337
                  id_ex_alu_signed <= 1;
1338
                  id_ex_branch <= 0;
1339
                  id_ex_jump <= 0;
1340
                  id_ex_jr <= 0;
1341
                  id_ex_linked <= 0;
1342
                  id_ex_mult <= 1;
1343
                  id_ex_div <= 0;
1344
                  id_ex_load <= 0;
1345
                  id_ex_store <= 0;
1346
                  id_ex_size <= 0;
1347
                  id_ex_store_value <= 0;
1348
                  id_ex_destreg <= 0;
1349
                  id_ex_desthi <= 1;
1350
                  id_ex_destlo <= 1;
1351
                  mul_req_o <= !mul_req_o;  // Toggle the ABP request
1352
                end
1353
              `FUNCTION_MULTU:
1354
                begin
1355
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as MULTU r%d, r%d", if_id_addr, if_id_opcode, if_id_rs, if_id_rt);
1356
                  id_ex_alu_a <= GPR[if_id_rs];
1357
                  id_ex_alu_b <= GPR[if_id_rt];
1358
                  id_ex_alu_func <= `ALU_OP_MULT;
1359
                  id_ex_alu_signed <= 0;
1360
                  id_ex_branch <= 0;
1361
                  id_ex_jump <= 0;
1362
                  id_ex_jr <= 0;
1363
                  id_ex_linked <= 0;
1364
                  id_ex_mult <= 1;
1365
                  id_ex_div <= 0;
1366
                  id_ex_load <= 0;
1367
                  id_ex_store <= 0;
1368
                  id_ex_size <= 0;
1369
                  id_ex_store_value <= 0;
1370
                  id_ex_destreg <= 0;
1371
                  id_ex_desthi <= 1;
1372
                  id_ex_destlo <= 1;
1373
                  mul_req_o <= !mul_req_o;  // Toggle the ABP request
1374
                end
1375
              `FUNCTION_DIV:
1376
                begin
1377
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as DIV r%d, r%d", if_id_addr, if_id_opcode, if_id_rs, if_id_rt);
1378
                  id_ex_alu_a <= GPR[if_id_rs];
1379
                  id_ex_alu_b <= GPR[if_id_rt];
1380
                  id_ex_alu_func <= `ALU_OP_DIV;
1381
                  id_ex_alu_signed <= 1;
1382
                  id_ex_branch <= 0;
1383
                  id_ex_jump <= 0;
1384
                  id_ex_jr <= 0;
1385
                  id_ex_linked <= 0;
1386
                  id_ex_mult <= 0;
1387
                  id_ex_div <= 1;
1388
                  id_ex_load <= 0;
1389
                  id_ex_store <= 0;
1390
                  id_ex_size <= 0;
1391
                  id_ex_store_value <= 0;
1392
                  id_ex_destreg <= 0;
1393
                  id_ex_desthi <= 1;
1394
                  id_ex_destlo <= 1;
1395
                  div_req_o <= !div_req_o;  // Toggle the ABP request
1396
                end
1397
              `FUNCTION_DIVU:
1398
                begin
1399
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as DIVU r%d, r%d", if_id_addr, if_id_opcode, if_id_rs, if_id_rt);
1400
                  id_ex_alu_a <= GPR[if_id_rs];
1401
                  id_ex_alu_b <= GPR[if_id_rt];
1402
                  id_ex_alu_func <= `ALU_OP_DIV;
1403
                  id_ex_alu_signed <= 0;
1404
                  id_ex_branch <= 0;
1405
                  id_ex_jump <= 0;
1406
                  id_ex_jr <= 0;
1407
                  id_ex_linked <= 0;
1408
                  id_ex_mult <= 0;
1409
                  id_ex_div <= 1;
1410
                  id_ex_load <= 0;
1411
                  id_ex_store <= 0;
1412
                  id_ex_size <= 0;
1413
                  id_ex_store_value <= 0;
1414
                  id_ex_destreg <= 0;
1415
                  id_ex_desthi <= 1;
1416
                  id_ex_destlo <= 1;
1417
                  div_req_o <= !div_req_o;  // Toggle the ABP request
1418
                end
1419
              `FUNCTION_ADD:
1420
                begin
1421
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ADD r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1422
                  id_ex_alu_a <= GPR[if_id_rs];
1423
                  id_ex_alu_b <= GPR[if_id_rt];
1424
                  id_ex_alu_func <= `ALU_OP_ADD;
1425
                  id_ex_alu_signed <= 1;
1426
                  id_ex_branch <= 0;
1427
                  id_ex_jump <= 0;
1428
                  id_ex_jr <= 0;
1429
                  id_ex_linked <= 0;
1430
                  id_ex_mult <= 0;
1431
                  id_ex_div <= 0;
1432
                  id_ex_load <= 0;
1433
                  id_ex_store <= 0;
1434
                  id_ex_size <= 0;
1435
                  id_ex_store_value <= 0;
1436
                  id_ex_destreg <= if_id_rd;
1437
                  id_ex_desthi <= 0;
1438
                  id_ex_destlo <= 0;
1439
                end
1440
              `FUNCTION_ADDU:
1441
                begin
1442
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as ADDU r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1443
                  id_ex_alu_a <= GPR[if_id_rs];
1444
                  id_ex_alu_b <= GPR[if_id_rt];
1445
                  id_ex_alu_func <= `ALU_OP_ADD;
1446
                  id_ex_alu_signed <= 0;
1447
                  id_ex_branch <= 0;
1448
                  id_ex_jump <= 0;
1449
                  id_ex_jr <= 0;
1450
                  id_ex_linked <= 0;
1451
                  id_ex_mult <= 0;
1452
                  id_ex_div <= 0;
1453
                  id_ex_load <= 0;
1454
                  id_ex_store <= 0;
1455
                  id_ex_size <= 0;
1456
                  id_ex_store_value <= 0;
1457
                  id_ex_destreg <= if_id_rd;
1458
                  id_ex_desthi <= 0;
1459
                  id_ex_destlo <= 0;
1460
                end
1461
              `FUNCTION_SUB:
1462
                begin
1463
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SUB r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1464
                  id_ex_alu_a <= GPR[if_id_rs];
1465
                  id_ex_alu_b <= GPR[if_id_rt];
1466
                  id_ex_alu_func <= `ALU_OP_SUB;
1467
                  id_ex_alu_signed <= 1;
1468
                  id_ex_branch <= 0;
1469
                  id_ex_jump <= 0;
1470
                  id_ex_jr <= 0;
1471
                  id_ex_linked <= 0;
1472
                  id_ex_mult <= 0;
1473
                  id_ex_div <= 0;
1474
                  id_ex_load <= 0;
1475
                  id_ex_store <= 0;
1476
                  id_ex_size <= 0;
1477
                  id_ex_store_value <= 0;
1478
                  id_ex_destreg <= if_id_rd;
1479
                  id_ex_desthi <= 0;
1480
                  id_ex_destlo <= 0;
1481
                end
1482
              `FUNCTION_SUBU:
1483
                begin
1484
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SUBU r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1485
                  id_ex_alu_a <= GPR[if_id_rs];
1486
                  id_ex_alu_b <= GPR[if_id_rt];
1487
                  id_ex_alu_func <= `ALU_OP_SUB;
1488
                  id_ex_alu_signed <= 0;
1489
                  id_ex_branch <= 0;
1490
                  id_ex_jump <= 0;
1491
                  id_ex_jr <= 0;
1492
                  id_ex_linked <= 0;
1493
                  id_ex_mult <= 0;
1494
                  id_ex_div <= 0;
1495
                  id_ex_load <= 0;
1496
                  id_ex_store <= 0;
1497
                  id_ex_size <= 0;
1498
                  id_ex_store_value <= 0;
1499
                  id_ex_destreg <= if_id_rd;
1500
                  id_ex_desthi <= 0;
1501
                  id_ex_destlo <= 0;
1502
                end
1503
              `FUNCTION_AND:
1504
                begin
1505
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as AND r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1506
                  id_ex_alu_a <= GPR[if_id_rs];
1507
                  id_ex_alu_b <= GPR[if_id_rt];
1508
                  id_ex_alu_func <= `ALU_OP_AND;
1509
                  id_ex_alu_signed <= 0;
1510
                  id_ex_branch <= 0;
1511
                  id_ex_jump <= 0;
1512
                  id_ex_jr <= 0;
1513
                  id_ex_linked <= 0;
1514
                  id_ex_mult <= 0;
1515
                  id_ex_div <= 0;
1516
                  id_ex_load <= 0;
1517
                  id_ex_store <= 0;
1518
                  id_ex_size <= 0;
1519
                  id_ex_store_value <= 0;
1520
                  id_ex_destreg <= if_id_rd;
1521
                  id_ex_desthi <= 0;
1522
                  id_ex_destlo <= 0;
1523
                end
1524
              `FUNCTION_OR:
1525
                begin
1526
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as OR r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1527
                  id_ex_alu_a <= GPR[if_id_rs];
1528
                  id_ex_alu_b <= GPR[if_id_rt];
1529
                  id_ex_alu_func <= `ALU_OP_OR;
1530
                  id_ex_alu_signed <= 0;
1531
                  id_ex_branch <= 0;
1532
                  id_ex_jump <= 0;
1533
                  id_ex_jr <= 0;
1534
                  id_ex_linked <= 0;
1535
                  id_ex_mult <= 0;
1536
                  id_ex_div <= 0;
1537
                  id_ex_load <= 0;
1538
                  id_ex_store <= 0;
1539
                  id_ex_size <= 0;
1540
                  id_ex_store_value <= 0;
1541
                  id_ex_destreg <= if_id_rd;
1542
                  id_ex_desthi <= 0;
1543
                  id_ex_destlo <= 0;
1544
                end
1545
              `FUNCTION_XOR:
1546
                begin
1547
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as XOR r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1548
                  id_ex_alu_a <= GPR[if_id_rs];
1549
                  id_ex_alu_b <= GPR[if_id_rt];
1550
                  id_ex_alu_func <= `ALU_OP_XOR;
1551
                  id_ex_alu_signed <= 0;
1552
                  id_ex_branch <= 0;
1553
                  id_ex_jump <= 0;
1554
                  id_ex_jr <= 0;
1555
                  id_ex_linked <= 0;
1556
                  id_ex_mult <= 0;
1557
                  id_ex_div <= 0;
1558
                  id_ex_load <= 0;
1559
                  id_ex_store <= 0;
1560
                  id_ex_size <= 0;
1561
                  id_ex_store_value <= 0;
1562
                  id_ex_destreg <= if_id_rd;
1563
                  id_ex_desthi <= 0;
1564
                  id_ex_destlo <= 0;
1565
                end
1566
              `FUNCTION_NOR:
1567
                begin
1568
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as NOR r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1569
                  id_ex_alu_a <= GPR[if_id_rs];
1570
                  id_ex_alu_b <= GPR[if_id_rt];
1571
                  id_ex_alu_func <= `ALU_OP_NOR;
1572
                  id_ex_alu_signed <= 0;
1573
                  id_ex_branch <= 0;
1574
                  id_ex_jump <= 0;
1575
                  id_ex_jr <= 0;
1576
                  id_ex_linked <= 0;
1577
                  id_ex_mult <= 0;
1578
                  id_ex_div <= 0;
1579
                  id_ex_load <= 0;
1580
                  id_ex_store <= 0;
1581
                  id_ex_size <= 0;
1582
                  id_ex_store_value <= 0;
1583
                  id_ex_destreg <= if_id_rd;
1584
                  id_ex_desthi <= 0;
1585
                  id_ex_destlo <= 0;
1586
                end
1587
              `FUNCTION_SLT:
1588
                begin
1589
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLT r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1590
                  id_ex_alu_a <= GPR[if_id_rs];
1591
                  id_ex_alu_b <= GPR[if_id_rt];
1592
                  id_ex_alu_func <= `ALU_OP_SLT;
1593
                  id_ex_alu_signed <= 1;
1594
                  id_ex_branch <= 0;
1595
                  id_ex_jump <= 0;
1596
                  id_ex_jr <= 0;
1597
                  id_ex_linked <= 0;
1598
                  id_ex_mult <= 0;
1599
                  id_ex_div <= 0;
1600
                  id_ex_load <= 0;
1601
                  id_ex_store <= 0;
1602
                  id_ex_size <= 0;
1603
                  id_ex_store_value <= 0;
1604
                  id_ex_destreg <= if_id_rd;
1605
                  id_ex_desthi <= 0;
1606
                  id_ex_destlo <= 0;
1607
                end
1608
              `FUNCTION_SLTU:
1609
                begin
1610
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as SLTU r%d, r%d, r%d", if_id_addr, if_id_opcode, if_id_rd, if_id_rs, if_id_rt);
1611
                  id_ex_alu_a <= GPR[if_id_rs];
1612
                  id_ex_alu_b <= GPR[if_id_rt];
1613
                  id_ex_alu_func <= `ALU_OP_SLT;
1614
                  id_ex_alu_signed <= 0;
1615
                  id_ex_branch <= 0;
1616
                  id_ex_jump <= 0;
1617
                  id_ex_jr <= 0;
1618
                  id_ex_linked <= 0;
1619
                  id_ex_mult <= 0;
1620
                  id_ex_div <= 0;
1621
                  id_ex_load <= 0;
1622
                  id_ex_store <= 0;
1623
                  id_ex_size <= 0;
1624
                  id_ex_store_value <= 0;
1625
                  id_ex_destreg <= if_id_rd;
1626
                  id_ex_desthi <= 0;
1627
                  id_ex_destlo <= 0;
1628
                end
1629
            endcase
1630
          `OPCODE_BCOND:
1631
            case(if_id_rt)
1632
              `BCOND_BLTZ:
1633
                begin
1634
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BLTZ r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
1635
                  id_ex_alu_a <= GPR[if_id_rs];
1636
                  id_ex_alu_b <= 0;
1637
                  id_ex_alu_func <= `ALU_OP_SLT;
1638
                  id_ex_alu_signed <= 1;
1639
                  id_ex_branch <= 1;
1640
                  id_ex_jump <= 0;
1641
                  id_ex_jr <= 0;
1642
                  id_ex_linked <= 0;
1643
                  id_ex_mult <= 0;
1644
                  id_ex_div <= 0;
1645
                  id_ex_load <= 0;
1646
                  id_ex_store <= 0;
1647
                  id_ex_size <= 0;
1648
                  id_ex_store_value <= 0;
1649
                  id_ex_destreg <= if_id_rd;
1650
                  id_ex_desthi <= 0;
1651
                  id_ex_destlo <= 0;
1652
                end
1653
              `BCOND_BGEZ:
1654
                begin
1655
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BGEZ r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
1656
                  id_ex_alu_a <= GPR[if_id_rs];
1657
                  id_ex_alu_b <= 0;
1658
                  id_ex_alu_func <= `ALU_OP_SGE;
1659
                  id_ex_alu_signed <= 1;
1660
                  id_ex_branch <= 1;
1661
                  id_ex_jump <= 0;
1662
                  id_ex_jr <= 0;
1663
                  id_ex_linked <= 0;
1664
                  id_ex_mult <= 0;
1665
                  id_ex_div <= 0;
1666
                  id_ex_load <= 0;
1667
                  id_ex_store <= 0;
1668
                  id_ex_size <= 0;
1669
                  id_ex_store_value <= 0;
1670
                  id_ex_destreg <= if_id_rd;
1671
                  id_ex_desthi <= 0;
1672
                  id_ex_destlo <= 0;
1673
                end
1674
              `BCOND_BLTZAL:
1675
                begin
1676
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BLTZAL r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
1677
                  id_ex_alu_a <= GPR[if_id_rs];
1678
                  id_ex_alu_b <= 0;
1679
                  id_ex_alu_func <= `ALU_OP_SLT;
1680
                  id_ex_alu_signed <= 1;
1681
                  id_ex_branch <= 1;
1682
                  id_ex_jump <= 0;
1683
                  id_ex_jr <= 0;
1684
                  id_ex_linked <= 1;
1685
                  id_ex_mult <= 0;
1686
                  id_ex_div <= 0;
1687
                  id_ex_load <= 0;
1688
                  id_ex_store <= 0;
1689
                  id_ex_size <= 0;
1690
                  id_ex_store_value <= 0;
1691
                  id_ex_destreg <= 31;
1692
                  id_ex_desthi <= 0;
1693
                  id_ex_destlo <= 0;
1694
                end
1695
              `BCOND_BGEZAL:
1696
                begin
1697
                  $display("INFO: CPU(%m)-ID: Decoded instruction @ADDR=%X w/OPCODE=%X as BGEZAL r%d, %h", if_id_addr, if_id_opcode, if_id_rs, if_id_imm_signext);
1698
                  id_ex_alu_a <= GPR[if_id_rs];
1699
                  id_ex_alu_b <= 0;
1700
                  id_ex_alu_func <=`ALU_OP_SGE;
1701
                  id_ex_alu_signed <= 1;
1702
                  id_ex_branch <= 1;
1703
                  id_ex_jump <= 0;
1704
                  id_ex_jr <= 0;
1705
                  id_ex_linked <= 1;
1706
                  id_ex_mult <= 0;
1707
                  id_ex_div <= 0;
1708
                  id_ex_load <= 0;
1709
                  id_ex_store <= 0;
1710
                  id_ex_size <= 0;
1711
                  id_ex_store_value <= 0;
1712
                  id_ex_destreg <= 31;
1713
                  id_ex_desthi <= 0;
1714
                  id_ex_destlo <= 0;
1715
                end
1716
            endcase
1717
 
1718
        endcase
1719
 
1720
      end
1721
 
1722
      /*
1723
       * Pipeline Stage 3: Execute (EX)
1724
       *
1725
       * READ/WRITE:
1726
       * - read the ID/EX latch
1727
       * - write the EX/MEM latch
1728
       *
1729
       * DESCRIPTION:
1730
       * This stage takes the result from the ALU and put it in the proper latch.
1731
       * Please note that assignments to ALU inputs are done outside since they're wires.
1732
       */
1733
 
1734
      if(ex_stall) begin
1735
 
1736
        if(mem_stall) begin
1737
          $display("INFO: CPU(%m)-EX: Execution stalled and latch kept for following stalled pipeline stage");
1738
        end else begin
1739
          $display("INFO: CPU(%m)-EX: Execution stalled and bubble inserted for following running pipeline stage");
1740
          ex_mem_opcode <= `BUBBLE;
1741
          ex_mem_addr <= id_ex_addr;
1742
          ex_mem_addrnext <= 0;
1743
          ex_mem_destreg <= 0;
1744
          ex_mem_desthi <= 0;
1745
          ex_mem_destlo <= 0;
1746
        end
1747
 
1748
      end else begin
1749
 
1750
        // If not stalled propagate values to next latches
1751
        ex_mem_opcode      <= id_ex_opcode;
1752
        ex_mem_addr        <= id_ex_addr;
1753
        ex_mem_addrnext    <= id_ex_addrnext;
1754
        ex_mem_addrjump    <= id_ex_addrjump;
1755
        ex_mem_addrbranch  <= id_ex_addrbranch;
1756
        ex_mem_branch      <= id_ex_branch;
1757
        ex_mem_jump        <= id_ex_jump;
1758
        ex_mem_jr          <= id_ex_jr;
1759
        ex_mem_linked      <= id_ex_linked;
1760
        ex_mem_mult        <= id_ex_mult;
1761
        ex_mem_div         <= id_ex_div;
1762
        ex_mem_load        <= id_ex_load;
1763
        ex_mem_store       <= id_ex_store;
1764 50 fafa1971
        ex_mem_size        <= id_ex_size;
1765 33 fafa1971
        ex_mem_destreg     <= id_ex_destreg;
1766
        ex_mem_desthi      <= id_ex_desthi;
1767
        ex_mem_destlo      <= id_ex_destlo;
1768
 
1769
        // Choose the output from ALU, Multiplier or Divider
1770 49 fafa1971
        if(id_ex_mult) begin
1771
          ex_mem_aluout <= mul_product_i;
1772 50 fafa1971
          ex_mem_carry <= 1'b0;
1773 49 fafa1971
        end else if(id_ex_div) begin
1774 50 fafa1971
          ex_mem_aluout <= { div_remainder_i, div_quotient_i };
1775
          ex_mem_carry <= 1'b0;
1776 49 fafa1971
        end else begin
1777 48 fafa1971
          ex_mem_aluout <= {32'b0, alu_result_i[31:0]};
1778
          ex_mem_carry <= alu_result_i[32];
1779
        end
1780 33 fafa1971
 
1781 50 fafa1971
        // Handle all supported store sizes
1782 33 fafa1971
        if(id_ex_store) begin
1783
          $display("INFO: CPU(%m)-EX: Execution of Store instruction @ADDR=%X w/OPCODE=%X started to STORE_ADDR=%X w/STORE_DATA=%X", id_ex_addr, id_ex_opcode, alu_result_i, id_ex_store_value);
1784
          case(id_ex_size)
1785
            `SIZE_WORD: begin
1786
              ex_mem_store_value <= id_ex_store_value;
1787
              ex_mem_store_sel <= 4'b1111;
1788
            end
1789
            `SIZE_HALF: begin
1790
              if(alu_result_i[1]==0) begin
1791 50 fafa1971
                ex_mem_store_value <= {{16'b0}, id_ex_store_value[15:0]};
1792 33 fafa1971
                ex_mem_store_sel <= 4'b0011;
1793
              end else begin
1794 50 fafa1971
                ex_mem_store_value <= {id_ex_store_value[15:0], {16'b0}};
1795 33 fafa1971
                ex_mem_store_sel <= 4'b1100;
1796
              end
1797
            end
1798
            `SIZE_BYTE: begin
1799
              case(alu_result_i[1:0])
1800
                2'b00: begin
1801 50 fafa1971
                  ex_mem_store_value <= {{24'b0}, id_ex_store_value[7:0]};
1802 33 fafa1971
                  ex_mem_store_sel <= 4'b0001;
1803
                end
1804
                2'b01: begin
1805 50 fafa1971
                  ex_mem_store_value <= {{16'b0}, id_ex_store_value[7:0],{8'b0}};
1806 33 fafa1971
                  ex_mem_store_sel <= 4'b0010;
1807
                end
1808
                2'b10: begin
1809 50 fafa1971
                  ex_mem_store_value <= {{8'b0}, id_ex_store_value[7:0],{16'b0}};
1810 33 fafa1971
                  ex_mem_store_sel <= 4'b0100;
1811
                end
1812
                2'b11: begin
1813 50 fafa1971
                  ex_mem_store_value <= {id_ex_store_value[7:0], {24'b0}};
1814 33 fafa1971
                  ex_mem_store_sel <= 4'b1000;
1815
                end
1816
              endcase
1817
            end
1818
          endcase
1819
 
1820 50 fafa1971
        // Not a store
1821 33 fafa1971
        end else begin
1822
          $display("INFO: CPU(%m)-EX: Execution of instruction @ADDR=%X w/OPCODE=%X gave ALU result %X", id_ex_addr, id_ex_opcode, alu_result_i);
1823
        end
1824
 
1825
      end
1826
 
1827
      /*
1828
       * Pipeline Stage 4: Memory access (MEM)
1829
       *
1830
       * READ/WRITE:
1831
       * - read the EX/MEM latch
1832
       * - read or write memory
1833
       * - write the MEM/WB latch
1834
       *
1835
       * DESCRIPTION:
1836
       * This stage perform accesses to memory to read/write the data during
1837
       * the load/store operations.
1838
       */
1839
 
1840
      if(mem_stall) begin
1841
 
1842
        $display("INFO: CPU(%m)-MEM: Memory stalled");
1843
 
1844
      end else begin
1845
 
1846
        mem_wb_opcode     <= ex_mem_opcode;
1847
        mem_wb_addr       <= ex_mem_addr;
1848
        mem_wb_addrnext   <= ex_mem_addrnext;
1849
        mem_wb_destreg    <= ex_mem_destreg;
1850
        mem_wb_desthi     <= ex_mem_desthi;
1851
        mem_wb_destlo     <= ex_mem_destlo;
1852
 
1853 50 fafa1971
        // Handle all supported load sizes
1854 33 fafa1971
        if(ex_mem_load) begin
1855
 
1856
          $display("INFO: CPU(%m)-MEM: Loading value %X", dmem_data_i);
1857
          mem_wb_value[63:32] <= 32'b0;
1858 50 fafa1971
          case(ex_mem_size)
1859
            `SIZE_WORD: begin
1860
              mem_wb_value[31:0] <= dmem_data_i;
1861
            end
1862
            `SIZE_HALF: begin
1863
              if(ex_mem_aluout[1]==0) mem_wb_value[31:0] <= {{16{dmem_data_i[15]}}, dmem_data_i[15:0]};
1864
              else mem_wb_value[31:0] <= {{16{dmem_data_i[31]}}, dmem_data_i[31:16]};
1865
            end
1866
            `SIZE_BYTE: begin
1867
              case(ex_mem_aluout[1:0])
1868
                2'b00: mem_wb_value[31:0] <= {{24{dmem_data_i[7]}},  dmem_data_i[7:0]};
1869
                2'b01: mem_wb_value[31:0] <= {{24{dmem_data_i[15]}}, dmem_data_i[15:8]};
1870
                2'b10: mem_wb_value[31:0] <= {{24{dmem_data_i[23]}}, dmem_data_i[23:16]};
1871
                2'b11: mem_wb_value[31:0] <= {{24{dmem_data_i[31]}}, dmem_data_i[31:24]};
1872
              endcase
1873
            end
1874
          endcase
1875 33 fafa1971
 
1876 50 fafa1971
        // For multiplications and divisions the result is 64-bit wide
1877 33 fafa1971
        end else if (ex_mem_desthi && ex_mem_destlo) begin
1878
 
1879
          $display("INFO: CPU(%m)-MEM: Propagating value %X", ex_mem_aluout);
1880 50 fafa1971
          mem_wb_value[63:32] <= ex_mem_aluout[63:32];
1881 33 fafa1971
          mem_wb_value[31:0] <= ex_mem_aluout[31:0];
1882
 
1883 50 fafa1971
        // For MTHI instruction we must move the value to the correct side of the bus
1884 33 fafa1971
        end else if (ex_mem_desthi) begin
1885
 
1886
          $display("INFO: CPU(%m)-MEM: Propagating value %X", ex_mem_aluout);
1887
          mem_wb_value[63:32] <= ex_mem_aluout[31:0];
1888
          mem_wb_value[31:0] <= 32'b0;
1889
 
1890 50 fafa1971
        // The default is working with 32-bit values
1891 33 fafa1971
        end else begin
1892
 
1893
          $display("INFO: CPU(%m)-MEM: Propagating value %X", ex_mem_aluout);
1894 50 fafa1971
          mem_wb_value[63:32] <= 32'b0;
1895 33 fafa1971
          mem_wb_value[31:0] <= ex_mem_aluout[31:0];
1896
 
1897
        end
1898
 
1899
      end
1900
 
1901
      /*
1902
       * Pipeline Stage 5: Write Back (WB)
1903
       *
1904
       * READ/WRITE:
1905
       * - read the MEM/WB latch
1906
       * - write the register file
1907
       *
1908
       * DESCRIPTION:
1909
       * This stage writes back the result into the proper register (GPR, HI, LO).
1910
       */
1911
 
1912
      if(wb_stall) begin
1913
 
1914
        $display("INFO: CPU(%m)-WB: Write-Back stalled");
1915
 
1916
      end else begin
1917
 
1918
        // GPRs
1919
        if(mem_wb_destreg!=0) begin
1920
          $display("INFO: CPU(%m)-WB: Writing Back GPR[%d]=%X", mem_wb_destreg, mem_wb_value[31:0]);
1921
          GPR[mem_wb_destreg] <= mem_wb_value[31:0];
1922
        end
1923
 
1924
        // HI
1925
        if(mem_wb_desthi) begin
1926
          $display("INFO: CPU(%m)-WB: Writing Back HI=%X", mem_wb_value[63:32]);
1927
          HI <= mem_wb_value[63:32];
1928
        end
1929
 
1930
        // LO
1931
        if(mem_wb_destlo) begin
1932
          $display("INFO: CPU(%m)-WB: Writing Back LO=%X", mem_wb_value[31:0]);
1933
          LO <= mem_wb_value[31:0];
1934
        end
1935
 
1936 46 fafa1971
        // SysCon
1937
        if(mem_wb_destsyscon!=0) begin
1938
          $display("INFO: CPU(%m)-WB: Writing Back SysCon[%d]=%X", mem_wb_destsyscon, mem_wb_value[31:0]);
1939
          SysCon[mem_wb_destsyscon] <= mem_wb_value[31:0];
1940
        end
1941
 
1942 33 fafa1971
        // Idle
1943
        if(mem_wb_destreg==0 & mem_wb_desthi==0 & mem_wb_destlo==0)
1944
          $display("INFO: CPU(%m)-WB: Write-Back has nothing to do");
1945
 
1946
      end
1947
 
1948
      // Display register file at each raising edge
1949
      $display("INFO: CPU(%m)-Regs: R00=%X R01=%X R02=%X R03=%X R04=%X R05=%X R06=%X R07=%X",
1950
        GPR[0], GPR[1], GPR[2], GPR[3], GPR[4], GPR[5], GPR[6], GPR[7]);
1951
      $display("INFO: CPU(%m)-Regs: R08=%X R09=%X R10=%X R11=%X R12=%X R13=%X R14=%X R15=%X",
1952
        GPR[8], GPR[9], GPR[10], GPR[11], GPR[12], GPR[13], GPR[14], GPR[15]);
1953
      $display("INFO: CPU(%m)-Regs: R16=%X R17=%X R18=%X R19=%X R20=%X R21=%X R22=%X R23=%X",
1954
        GPR[16], GPR[17], GPR[18], GPR[19], GPR[20], GPR[21], GPR[22], GPR[23]);
1955
      $display("INFO: CPU(%m)-Regs: R24=%X R25=%X R26=%X R27=%X R28=%X R29=%X R30=%X R31=%X",
1956
        GPR[24], GPR[25], GPR[26], GPR[27], GPR[28], GPR[29], GPR[30], GPR[31]);
1957
      $display("INFO: CPU(%m)-Regs: PC=%X HI=%X LO=%X",
1958
        PC, HI, LO);
1959
 
1960
    end
1961
  end
1962
 
1963
endmodule
1964
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.