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 48

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

powered by: WebSVN 2.1.0

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