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 49

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

powered by: WebSVN 2.1.0

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