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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [xilinx/] [atlys/] [bench/] [verilog/] [or1200_monitor.v] - Blame information for rev 631

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 631 stekern
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  or1200_monitor.v                                            ////
4
////                                                              ////
5
////  OR1200 processor monitor module                             ////
6
////                                                              ////
7
////  Author(s):                                                  ////
8
////      - Damjan Lampret, lampret@opencores.org                 ////
9
////      - Julius Baxter, julius@opencores.org                   ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2009, 2010 Authors and OPENCORES.ORG           ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
`include "timescale.v"
39
`include "or1200_defines.v"
40
`include "or1200_monitor_defines.v"
41
`include "test-defines.v"
42
 
43
 
44
module or1200_monitor;
45
 
46
   integer fexe;
47
   integer finsn;
48
 
49
   reg [23:0] ref;
50
`ifdef OR1200_MONITOR_SPRS
51
   integer    fspr;
52
`endif
53
   integer    fgeneral;
54
`ifdef OR1200_MONITOR_LOOKUP
55
   integer    flookup;
56
`endif
57
   integer    r3;
58
   integer    insns;
59
 
60
 
61
   //
62
   // Initialization
63
   //
64
   initial begin
65
      ref = 0;
66
`ifdef OR1200_MONITOR_EXEC_STATE
67
      fexe = $fopen({"../out/",`TEST_NAME_STRING,"-executed.log"});
68
`endif
69
`ifdef OR1200_MONITOR_EXEC_LOG_DISASSEMBLY
70
      finsn = fexe;
71
`endif
72
      $timeformat (-9, 2, " ns", 12);
73
`ifdef OR1200_MONITOR_SPRS
74
      fspr = $fopen({"../out/",`TEST_NAME_STRING,"-sprs.log"});
75
`endif
76
      fgeneral = $fopen({"../out/",`TEST_NAME_STRING,"-general.log"});
77
`ifdef OR1200_MONITOR_LOOKUP
78
      flookup = $fopen({"../out/",`TEST_NAME_STRING,"-lookup.log"});
79
`endif
80
      insns = 0;
81
 
82
   end
83
 
84
   //
85
   // Get GPR
86
   //
87
   task get_gpr;
88
      input     [4:0]    gpr_no;
89
      output [31:0]      gpr;
90
      integer           j;
91
      begin
92
 
93
`ifdef OR1200_RFRAM_GENERIC
94
         for(j = 0; j < 32; j = j + 1) begin
95
            gpr[j] = `OR1200_TOP.`CPU_cpu.`CPU_rf.rf_a.mem[gpr_no*32+j];
96
         end
97
 
98
`else
99
         //gpr = `OR1200_TOP.`CPU_cpu.`CPU_rf.rf_a.mem[gpr_no];
100
         gpr = `OR1200_TOP.`CPU_cpu.`CPU_rf.rf_a.get_gpr(gpr_no);
101
 
102
`endif
103
 
104
 
105
      end
106
   endtask
107
 
108
   //
109
   // Write state of the OR1200 registers into a file
110
   //
111
   // Limitation: only a small subset of register file RAMs
112
   // are supported
113
   //
114
   task display_arch_state;
115
      reg [5:0] i;
116
      reg [31:0] r;
117
      integer    j;
118
      begin
119
`ifdef OR1200_MONITOR_EXEC_STATE
120
         ref = ref + 1;
121
 `ifdef OR1200_MONITOR_LOOKUP
122
         $fdisplay(flookup, "Instruction %d: %t", insns, $time);
123
 `endif
124
         $fwrite(fexe, "\nEXECUTED(%d): %h:  %h", insns,
125
                 `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc,
126
                 `OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn);
127
 `ifdef OR1200_MONITOR_EXEC_LOG_DISASSEMBLY
128
         $fwrite(fexe,"\t");
129
         // Decode the instruction, print it out
130
         or1200_print_op(`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn);
131
 `endif
132
         for(i = 0; i < 32; i = i + 1) begin
133
            if (i % 4 == 0)
134
              $fdisplay(fexe);
135
            get_gpr(i, r);
136
            $fwrite(fexe, "GPR%d: %h  ", i, r);
137
         end
138
         $fdisplay(fexe);
139
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.sr;
140
         $fwrite(fexe, "SR   : %h  ", r);
141
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.epcr;
142
         $fwrite(fexe, "EPCR0: %h  ", r);
143
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.eear;
144
         $fwrite(fexe, "EEAR0: %h  ", r);
145
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.esr;
146
         $fdisplay(fexe, "ESR0 : %h", r);
147
`endif //  `ifdef OR1200_MONITOR_EXEC_STATE
148
`ifdef OR1200_DISPLAY_EXECUTED
149
         ref = ref + 1;
150
 `ifdef OR1200_MONITOR_LOOKUP
151
         $fdisplay(flookup, "Instruction %d: %t", insns, $time);
152
 `endif
153
         $fwrite(fexe, "\nEXECUTED(%d): %h:  %h", insns, `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc, `OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn);
154
`endif
155
         insns = insns + 1;
156
      end
157
   endtask // display_arch_state
158
 
159
   /* Keep a trace buffer of the last lot of instructions and addresses
160
    * "executed",as read from the writeback stage, and cause a $finish if we hit
161
    * an instruction that is invalid, such as all zeros.
162
    * Currently, only breaks on an all zero instruction, but should probably be
163
    * made to break for anything with an X in it too. And of course ideally this
164
    * shouldn't be needed - but is handy if someone changes something and stops
165
    * the test continuing forever.
166
    */
167
   integer num_nul_inst;
168
   initial num_nul_inst = 0;
169
 
170
   task monitor_for_crash;
171
`define OR1200_MONITOR_CRASH_TRACE_SIZE 32
172
      //Trace buffer of 32 instructions
173
      reg [31:0] insn_trace [0:`OR1200_MONITOR_CRASH_TRACE_SIZE-1];
174
      //Trace buffer of the addresses of those instructions
175
      reg [31:0] addr_trace [0:`OR1200_MONITOR_CRASH_TRACE_SIZE-1];
176
      integer    i;
177
 
178
      begin
179
         if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h00000000)
180
           num_nul_inst = num_nul_inst + 1;
181
         else
182
           num_nul_inst = 0; // Reset it
183
 
184
         if (num_nul_inst == 1000) // Sat a loop a bit too long...
185
           begin
186
              $fdisplay(fgeneral, "ERROR - no instruction at PC %h",
187
                        `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc);
188
              $fdisplay(fgeneral, "Crash trace: Last %d instructions: ",
189
                        `OR1200_MONITOR_CRASH_TRACE_SIZE);
190
 
191
              $fdisplay(fgeneral, "PC\t\tINSTR");
192
              for(i=`OR1200_MONITOR_CRASH_TRACE_SIZE-1;i>=0;i=i-1) begin
193
                 $fdisplay(fgeneral, "%h\t%h",addr_trace[i], insn_trace[i]);
194
              end
195
              $display("*");
196
              $display("* or1200_monitor : OR1200 crash detected (suspected CPU PC corruption)");
197
              $display("*");
198
 
199
              #100 $finish;
200
           end
201
         else
202
           begin
203
              for(i=`OR1200_MONITOR_CRASH_TRACE_SIZE-1;i>0;i=i-1) begin
204
                 insn_trace[i] = insn_trace[i-1];
205
                 addr_trace[i] = addr_trace[i-1];
206
              end
207
              insn_trace[0] = `OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn;
208
              addr_trace[0] = `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc;
209
           end
210
 
211
      end
212
   endtask // monitor_for_crash
213
 
214
 
215
   //
216
   // Write state of the OR1200 registers into a file; version for exception
217
   //
218
   task display_arch_state_except;
219
      reg [5:0] i;
220
      reg [31:0] r;
221
      integer    j;
222
      begin
223
`ifdef OR1200_MONITOR_EXEC_STATE
224
         ref = ref + 1;
225
 `ifdef OR1200_MONITOR_LOOKUP
226
         $fdisplay(flookup, "Instruction %d: %t", insns, $time);
227
 `endif
228
         $fwrite(fexe, "\nEXECUTED(%d): %h:  %h  (exception)", insns, `OR1200_TOP.`CPU_cpu.`CPU_except.ex_pc, `OR1200_TOP.`CPU_cpu.`CPU_ctrl.ex_insn);
229
         for(i = 0; i < 32; i = i + 1) begin
230
            if (i % 4 == 0)
231
              $fdisplay(fexe);
232
            get_gpr(i, r);
233
            $fwrite(fexe, "GPR%d: %h  ", i, r);
234
         end
235
         $fdisplay(fexe);
236
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.sr;
237
         $fwrite(fexe, "SR   : %h  ", r);
238
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.epcr;
239
         $fwrite(fexe, "EPCR0: %h  ", r);
240
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.eear;
241
         $fwrite(fexe, "EEAR0: %h  ", r);
242
         r = `OR1200_TOP.`CPU_cpu.`CPU_sprs.esr;
243
         $fdisplay(fexe, "ESR0 : %h", r);
244
         insns = insns + 1;
245
`endif //  `ifdef OR1200_MONITOR_EXEC_STATE
246
`ifdef OR1200_DISPLAY_EXECUTED
247
         ref = ref + 1;
248
 `ifdef OR1200_MONITOR_LOOKUP
249
         $fdisplay(flookup, "Instruction %d: %t", insns, $time);
250
 `endif
251
         $fwrite(fexe, "\nEXECUTED(%d): %h:  %h  (exception)", insns,
252
                 `OR1200_TOP.`CPU_cpu.`CPU_except.ex_pc,
253
                 `OR1200_TOP.`CPU_cpu.`CPU_ctrl.ex_insn);
254
         insns = insns + 1;
255
`endif
256
 
257
      end
258
   endtask
259
 
260
   integer iwb_progress;
261
   reg [31:0] iwb_progress_addr;
262
   //
263
   // WISHBONE bus checker
264
   //
265
   always @(posedge `OR1200_TOP.iwb_clk_i)
266
     if (`OR1200_TOP.iwb_rst_i) begin
267
        iwb_progress = 0;
268
        iwb_progress_addr = `OR1200_TOP.iwb_adr_o;
269
     end
270
     else begin
271
        if (`OR1200_TOP.iwb_cyc_o && (iwb_progress != 2)) begin
272
           iwb_progress = 1;
273
        end
274
        if (`OR1200_TOP.iwb_stb_o) begin
275
           if (iwb_progress >= 1) begin
276
              if (iwb_progress == 1)
277
                iwb_progress_addr = `OR1200_TOP.iwb_adr_o;
278
              iwb_progress = 2;
279
           end
280
           else begin
281
              $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.iwb_stb_o raised without `OR1200_TOP.iwb_cyc_o, at %t\n", $time);
282
              #100 $finish;
283
           end
284
        end
285
        if (`OR1200_TOP.iwb_ack_i & `OR1200_TOP.iwb_err_i) begin
286
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.iwb_ack_i and `OR1200_TOP.iwb_err_i raised at the same time, at %t\n", $time);
287
        end
288
        if ((iwb_progress == 2) && (iwb_progress_addr != `OR1200_TOP.iwb_adr_o)) begin
289
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.iwb_adr_o changed while waiting for `OR1200_TOP.iwb_err_i/`OR1200_TOP.iwb_ack_i, at %t\n", $time);
290
           #100 $finish;
291
        end
292
        if (`OR1200_TOP.iwb_ack_i | `OR1200_TOP.iwb_err_i)
293
          if (iwb_progress == 2) begin
294
             iwb_progress = 0;
295
             iwb_progress_addr = `OR1200_TOP.iwb_adr_o;
296
          end
297
          else begin
298
             $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.iwb_ack_i/`OR1200_TOP.iwb_err_i raised without `OR1200_TOP.iwb_cyc_i/`OR1200_TOP.iwb_stb_i, at %t\n", $time);
299
             #100 $finish;
300
          end
301
        if ((iwb_progress == 2) && !`OR1200_TOP.iwb_stb_o) begin
302
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.iwb_stb_o lowered without `OR1200_TOP.iwb_err_i/`OR1200_TOP.iwb_ack_i, at %t\n", $time);
303
           #100 $finish;
304
        end
305
     end
306
 
307
   integer dwb_progress;
308
   reg [31:0] dwb_progress_addr;
309
   //
310
   // WISHBONE bus checker
311
   //
312
   always @(posedge `OR1200_TOP.dwb_clk_i)
313
     if (`OR1200_TOP.dwb_rst_i)
314
       dwb_progress = 0;
315
     else begin
316
        if (`OR1200_TOP.dwb_cyc_o && (dwb_progress != 2))
317
          dwb_progress = 1;
318
        if (`OR1200_TOP.dwb_stb_o)
319
          if (dwb_progress >= 1) begin
320
             if (dwb_progress == 1)
321
               dwb_progress_addr = `OR1200_TOP.dwb_adr_o;
322
             dwb_progress = 2;
323
          end
324
          else begin
325
             $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.dwb_stb_o raised without `OR1200_TOP.dwb_cyc_o, at %t\n", $time);
326
             #100 $finish;
327
          end
328
        if (`OR1200_TOP.dwb_ack_i & `OR1200_TOP.dwb_err_i) begin
329
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.dwb_ack_i and `OR1200_TOP.dwb_err_i raised at the same time, at %t\n", $time);
330
        end
331
        if ((dwb_progress == 2) && (dwb_progress_addr != `OR1200_TOP.dwb_adr_o)) begin
332
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.dwb_adr_o changed while waiting for `OR1200_TOP.dwb_err_i/`OR1200_TOP.dwb_ack_i, at %t\n", $time);
333
           #100 $finish;
334
        end
335
        if (`OR1200_TOP.dwb_ack_i | `OR1200_TOP.dwb_err_i)
336
          if (dwb_progress == 2) begin
337
             dwb_progress = 0;
338
             dwb_progress_addr = `OR1200_TOP.dwb_adr_o;
339
          end
340
          else begin
341
             $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.dwb_ack_i/`OR1200_TOP.dwb_err_i raised without `OR1200_TOP.dwb_cyc_i/`OR1200_TOP.dwb_stb_i, at %t\n", $time);
342
             #100 $finish;
343
          end
344
        if ((dwb_progress == 2) && !`OR1200_TOP.dwb_stb_o) begin
345
           $fdisplay(fgeneral, "WISHBONE protocol violation: `OR1200_TOP.dwb_stb_o lowered without `OR1200_TOP.dwb_err_i/`OR1200_TOP.dwb_ack_i, at %t\n", $time);
346
           #100 $finish;
347
        end
348
     end
349
 
350
   //
351
   // Hooks for:
352
   // - displaying registers
353
   // - end of simulation
354
   // - access to SPRs
355
   //
356
   always @(posedge `CPU_CORE_CLK)
357
     if (!`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_freeze) begin
358
        //      #2;
359
        if (((`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn[31:26] != `OR1200_OR32_NOP)
360
             | !`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn[16])
361
            & !(`OR1200_TOP.`CPU_cpu.`CPU_except.except_flushpipe &
362
                `OR1200_TOP.`CPU_cpu.`CPU_except.ex_dslot))
363
          begin
364
             display_arch_state;
365
             monitor_for_crash;
366
          end
367
        else
368
          if (`OR1200_TOP.`CPU_cpu.`CPU_except.except_flushpipe)
369
            display_arch_state_except;
370
        // small hack to stop simulation (l.nop 1):
371
        if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h1500_0001) begin
372
           get_gpr(3, r3);
373
           $fdisplay(fgeneral, "%t: l.nop exit (%h)", $time, r3);
374
`ifdef OR1200_MONITOR_VERBOSE_NOPS
375
           $display("exit(%h)",r3);
376
`endif
377
           $finish;
378
        end
379
        // debug if test (l.nop 10)
380
        if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h1500_000a) begin
381
           $fdisplay(fgeneral, "%t: l.nop dbg_if_test", $time);
382
        end
383
        // simulation reports (l.nop 2)
384
        if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h1500_0002) begin
385
           get_gpr(3, r3);
386
           $fdisplay(fgeneral, "%t: l.nop report (0x%h)", $time, r3);
387
`ifdef OR1200_MONITOR_VERBOSE_NOPS
388
           $display("report (0x%h);", r3);
389
`endif
390
        end
391
        // simulation printfs (l.nop 3)
392
        if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h1500_0003) begin
393
           get_gpr(3, r3);
394
           $fdisplay(fgeneral, "%t: l.nop printf (%h)", $time, r3);
395
        end
396
        if (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn == 32'h1500_0004) begin
397
           // simulation putc (l.nop 4)
398
           get_gpr(3, r3);
399
           $write("%c", r3);
400
           $fdisplay(fgeneral, "%t: l.nop putc (%c)", $time, r3);
401
        end
402
`ifdef OR1200_MONITOR_SPRS
403
        if (`OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_we)
404
          $fdisplay(fspr, "%t: Write to SPR : [%h] <- %h", $time,
405
                    `OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_addr,
406
                    `OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_dat_o);
407
        if ((|`OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_cs) &
408
            !`OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_we)
409
          $fdisplay(fspr, "%t: Read from SPR: [%h] -> %h", $time,
410
                    `OR1200_TOP.`CPU_cpu.`CPU_sprs.spr_addr,
411
                    `OR1200_TOP.`CPU_cpu.`CPU_sprs.to_wbmux);
412
`endif
413
     end
414
 
415
 
416
`ifdef RAM_WB
417
 `define RAM_WB_TOP `DUT_TOP.ram_wb0.ram_wb_b3_0
418
   task get_insn_from_wb_ram;
419
      input [31:0] addr;
420
      output [31:0] insn;
421
      begin
422
         insn = `RAM_WB_TOP.get_mem32(addr[31:2]);
423
      end
424
   endtask // get_insn_from_wb_ram
425
`endif
426
 
427
`ifdef VERSATILE_SDRAM
428
 `define SDRAM_TOP `TB_TOP.sdram0
429
   // Bit selects to define the bank
430
   // 32 MB part with 4 banks
431
 `define SDRAM_BANK_SEL_BITS 24:23
432
 `define SDRAM_WORD_SEL_TOP_BIT 22
433
   // Gets instruction word from correct bank
434
   task get_insn_from_sdram;
435
      input [31:0] addr;
436
      output [31:0] insn;
437
      reg [`SDRAM_WORD_SEL_TOP_BIT-1:0] word_addr;
438
 
439
      begin
440
         word_addr = addr[`SDRAM_WORD_SEL_TOP_BIT:2];
441
         if (addr[`SDRAM_BANK_SEL_BITS] == 2'b00)
442
           begin
443
 
444
              //$display("%t: get_insn_from_sdram bank0, word 0x%h, (%h and %h in SDRAM)", $time, word_addr, `SDRAM_TOP.Bank0[{word_addr,1'b0}], `SDRAM_TOP.Bank0[{word_addr,1'b1}]);         
445
              insn[15:0] = `SDRAM_TOP.Bank0[{word_addr,1'b1}];
446
              insn[31:16] = `SDRAM_TOP.Bank0[{word_addr,1'b0}];
447
           end
448
      end
449
 
450
   endtask // get_insn_from_sdram
451
`endif //  `ifdef VERSATILE_SDRAM
452
 
453
`ifdef XILINX_DDR2
454
   //SJK this needs to be fixed
455
//SJK  `define DDR2_TOP `TB_TOP.gen_cs[0]
456
   // Gets instruction word from correct bank
457
   task get_insn_from_xilinx_ddr2;
458
      input [31:0] addr;
459
      output [31:0] insn;
460
      reg [16*8-1:0] ddr2_array_line0,ddr2_array_line1,ddr2_array_line2,
461
                     ddr2_array_line3;
462
      integer        word_in_line_num;
463
      begin
464
         // Get our 4 128-bit chunks (8 half-words in each!! Confused yet?), 
465
         // 16 words total
466
/* SJK
467
         `DDR2_TOP.gen[0].u_mem0.memory_read(addr[28:27],addr[26:13],{addr[12:6],3'd0},ddr2_array_line0);
468
         `DDR2_TOP.gen[1].u_mem0.memory_read(addr[28:27],addr[26:13],{addr[12:6],3'd0},ddr2_array_line1);
469
         `DDR2_TOP.gen[2].u_mem0.memory_read(addr[28:27],addr[26:13],{addr[12:6],3'd0},ddr2_array_line2);
470
         `DDR2_TOP.gen[3].u_mem0.memory_read(addr[28:27],addr[26:13],{addr[12:6],3'd0},ddr2_array_line3);
471
*/
472
         u_mem0.memory_read(addr[28:27],addr[26:13],{addr[12:6],3'd0},ddr2_array_line0);
473
         insn[31:0] = ddr2_array_line0[31:0];
474
         $display("SJK DEBUG");
475
 
476
/*
477
         case (addr[5:2])
478
           4'h0:
479
             begin
480
                insn[15:0] = ddr2_array_line0[15:0];
481
                insn[31:16] = ddr2_array_line1[15:0];
482
             end
483
           4'h1:
484
             begin
485
                insn[15:0] = ddr2_array_line2[15:0];
486
                insn[31:16] = ddr2_array_line3[15:0];
487
             end
488
           4'h2:
489
             begin
490
                insn[15:0] = ddr2_array_line0[31:16];
491
                insn[31:16] = ddr2_array_line1[31:16];
492
             end
493
           4'h3:
494
             begin
495
                insn[15:0] = ddr2_array_line2[31:16];
496
                insn[31:16] = ddr2_array_line3[31:16];
497
             end
498
           4'h4:
499
             begin
500
                insn[15:0] = ddr2_array_line0[47:32];
501
                insn[31:16] = ddr2_array_line1[47:32];
502
             end
503
           4'h5:
504
             begin
505
                insn[15:0] = ddr2_array_line2[47:32];
506
                insn[31:16] = ddr2_array_line3[47:32];
507
             end
508
           4'h6:
509
             begin
510
                insn[15:0] = ddr2_array_line0[63:48];
511
                insn[31:16] = ddr2_array_line1[63:48];
512
             end
513
           4'h7:
514
             begin
515
                insn[15:0] = ddr2_array_line2[63:48];
516
                insn[31:16] = ddr2_array_line3[63:48];
517
             end
518
           4'h8:
519
             begin
520
                insn[15:0] = ddr2_array_line0[79:64];
521
                insn[31:16] = ddr2_array_line1[79:64];
522
             end
523
           4'h9:
524
             begin
525
                insn[15:0] = ddr2_array_line2[79:64];
526
                insn[31:16] = ddr2_array_line3[79:64];
527
             end
528
           4'ha:
529
             begin
530
                insn[15:0] = ddr2_array_line0[95:80];
531
                insn[31:16] = ddr2_array_line1[95:80];
532
             end
533
           4'hb:
534
             begin
535
                insn[15:0] = ddr2_array_line2[95:80];
536
                insn[31:16] = ddr2_array_line3[95:80];
537
             end
538
           4'hc:
539
             begin
540
                insn[15:0] = ddr2_array_line0[111:96];
541
                insn[31:16] = ddr2_array_line1[111:96];
542
             end
543
           4'hd:
544
             begin
545
                insn[15:0] = ddr2_array_line2[111:96];
546
                insn[31:16] = ddr2_array_line3[111:96];
547
             end
548
           4'he:
549
             begin
550
                insn[15:0] = ddr2_array_line0[127:112];
551
                insn[31:16] = ddr2_array_line1[127:112];
552
             end
553
           4'hf:
554
             begin
555
                insn[15:0] = ddr2_array_line2[127:112];
556
                insn[31:16] = ddr2_array_line3[127:112];
557
             end
558
         endcase // case (addr[5:2])
559
SJK */
560
      end
561
   endtask // get_insn_from_xilinx_ddr2
562
`endif
563
 
564
 
565
   task get_insn_from_memory;
566
      input [31:0] id_pc;
567
      output [31:0] insn;
568
      begin
569
         // do a decode of which server we should look in
570
         case (id_pc[31:28])
571
`ifdef VERSATILE_SDRAM
572
           4'h0:
573
             get_insn_from_sdram(id_pc, insn);
574
`endif
575
`ifdef XILINX_DDR2
576
           4'h0:
577
             get_insn_from_xilinx_ddr2(id_pc, insn);
578
`endif
579
`ifdef RAM_WB
580
           4'h0:
581
             get_insn_from_wb_ram(id_pc, insn);
582
`endif
583
           4'hf:
584
             // Flash isn't stored in a memory, it's an FSM so just skip/ignore
585
             insn = `OR1200_TOP.`CPU_cpu.`CPU_ctrl.id_insn;
586
           default:
587
             begin
588
                $fdisplay(fgeneral, "%t: Unknown memory server for address 0x%h", $time,id_pc);
589
                insn = 32'hxxxxxxxx; // Unknown server
590
             end
591
         endcase // case (id_pc[31:28])
592
      end
593
   endtask // get_insn_from_memory
594
 
595
 
596
   //
597
   // Look in the iMMU TLB MR for this address' page, if MMUs are on and enabled
598
   //
599
   task check_for_immu_entry;
600
      input [31:0] pc;
601
      output [31:0] physical_pc;
602
      output        mmu_tlb_miss;
603
      integer       w,x;
604
 
605
      reg [31:`OR1200_IMMU_PS] pc_vpn;
606
 
607
      reg [`OR1200_ITLBTRW-1:0] itlb_tr;
608
      reg [`OR1200_ITLBMRW-1:0] itlb_mr;
609
 
610
      integer                   tlb_index;
611
      reg                       mmu_en;
612
 
613
 
614
      begin
615
         mmu_tlb_miss = 0;
616
 
617
`ifdef OR1200_NO_IMMU
618
         physical_pc = pc;
619
`else
620
         mmu_en = `OR1200_TOP.`CPU_immu_top.immu_en;
621
         // If MMU is enabled
622
         if (mmu_en)
623
           begin
624
 
625
              // Look in the iTLB for mapping - get virtual page number
626
              pc_vpn = pc[31:`OR1200_IMMU_PS];
627
 
628
              tlb_index = pc[`OR1200_ITLB_INDX];
629
 
630
              // Look at the ITLB match register
631
              itlb_mr = `OR1200_TOP.`CPU_immu_top.`CPU_immu_tlb.itlb_mr_ram.mem[tlb_index];
632
 
633
              // Get the translate register here too, in case there's an error, we print it
634
              itlb_tr = `OR1200_TOP.`CPU_immu_top.`CPU_immu_tlb.itlb_tr_ram.mem[tlb_index];
635
 
636
              if ((itlb_mr[`OR1200_ITLBMR_V_BITS] === 1'b1) & (itlb_mr[`OR1200_ITLBMRW-1:1] === pc[`OR1200_ITLB_TAG]))
637
                begin
638
                   // Page number in match register matches page number of virtual PC, so get the physical
639
                   // address from the translate memory            
640
                   // Now pull the physical page number out of the tranlsate register (it's after bottom 3 bits)
641
                   physical_pc = {itlb_tr[`OR1200_ITLBTRW-1:`OR1200_ITLBTRW-(32-`OR1200_IMMU_PS)],pc[`OR1200_IMMU_PS-1:0]};
642
                   //$display("check_for_immu_entry: found match for virtual PC 0x%h in entry %d of iMMU, mr = 0x%x tr = 0x%x, phys. PC = 0x%h", pc, pc[`OR1200_ITLB_INDX], itlb_mr, itlb_tr, physical_pc);
643
                end // if ((itlb_mr[`OR1200_ITLBMR_V_BITS]) & (itlb_mr[`OR1200_ITLBMRW-1:1] == pc[`OR1200_ITLB_TAG]))
644
              else
645
                begin
646
 
647
                   // Wait a couple of clocks, see if we're doing a miss
648
                   @(posedge `CPU_CORE_CLK);
649
                   @(posedge `CPU_CORE_CLK);
650
                   if (!(`OR1200_TOP.`CPU_immu_top.miss)) // MMU should indicate miss
651
                     begin
652
                        $display("%t: check_for_immu_entry - ERROR - no match found for virtual PC 0x%h in entry %d of iMMU, mr = 0x%x tr = 0x%x, and no miss generated",
653
                                 $time, pc, pc[`OR1200_ITLB_INDX], itlb_mr, itlb_tr);
654
                        #100;
655
                        $finish;
656
                     end
657
                   else
658
                     begin
659
                        mmu_tlb_miss = 1; // Started a miss, so ignore this instruction
660
                     end
661
                end // else: !if((itlb_mr[`OR1200_ITLBMR_V_BITS]) & (itlb_mr[`OR1200_ITLBMRW-1:1] == pc[`OR1200_ITLB_TAG]))
662
 
663
           end // if (`OR1200_TOP.`CPU_immu_top.immu_en === 1'b1)
664
         else
665
           physical_pc = pc;
666
`endif // !`ifdef OR1200_NO_IMMU
667
      end
668
   endtask // check_for_immu_entry
669
 
670
 
671
   /*
672
    Instruction memory coherence checking.
673
 
674
    For new instruction executed in the pipeline - ensure it matches
675
    what is in the main program memory. Perform MMU translations if
676
    it is enabled.
677
    */
678
 
679
   reg [31:0] mem_word;
680
   reg [31:0] last_addr = 0;
681
   reg [31:0] last_mem_word;
682
   reg [31:0] physical_pc;
683
   reg        tlb_miss;
684
 
685
 
686
`ifdef MEM_COHERENCE_CHECK
687
 `define MEM_COHERENCE_TRIGGER (`OR1200_TOP.`CPU_cpu.`CPU_ctrl.id_void === 1'b0)
688
 
689
 `define INSN_TO_CHECK `OR1200_TOP.`CPU_cpu.`CPU_ctrl.id_insn
690
 `define PC_TO_CHECK `OR1200_TOP.`CPU_cpu.`CPU_except.id_pc
691
 
692
   // Check instruction in decode stage is what is in the RAM
693
   always @(posedge `CPU_CORE_CLK)
694
     begin
695
        if (`MEM_COHERENCE_TRIGGER)
696
          begin
697
 
698
             check_for_immu_entry(`PC_TO_CHECK, physical_pc, tlb_miss);
699
 
700
             // Check if it's a new PC - will also get triggered if the
701
             // instruction has changed since we last checked it
702
             if (((physical_pc !== last_addr) ||
703
                  (last_mem_word != `INSN_TO_CHECK)) & !tlb_miss)
704
               begin
705
                  // Decode stage not void, check instruction
706
                  // get PC
707
                  get_insn_from_memory(physical_pc, mem_word);
708
 
709
                  if (mem_word !== `INSN_TO_CHECK)
710
                    begin
711
                       $fdisplay(fgeneral, "%t: Instruction mismatch for PC 0x%h (phys. 0x%h) - memory had 0x%h, CPU had 0x%h",
712
                                 $time, `PC_TO_CHECK, physical_pc, mem_word,
713
                                 `INSN_TO_CHECK);
714
                       $display("%t: Instruction mismatch for PC 0x%h (phys. 0x%h) - memory had 0x%h, CPU had 0x%h",
715
                                $time, `PC_TO_CHECK, physical_pc, mem_word,
716
                                `INSN_TO_CHECK);
717
                       #200;
718
                       $finish;
719
                    end
720
                  last_addr = physical_pc;
721
                  last_mem_word = mem_word;
722
 
723
               end // if (((physical_pc !== last_addr) || (last_mem_word != `INSN_TO_CHECK))...      
724
          end // if (`MEM_COHERENCE_TRIGGER)    
725
     end // always @ (posedge `CPU_CORE_CLK)
726
 
727
`endif //  `ifdef MEM_COHERENCE_CHECK
728
 
729
   // Trigger on each instruction that gets into writeback stage properly
730
   reg exception_coming1, exception_coming2, exception_here;
731
   reg will_jump, jumping, jump_dslot, jumped;
732
   reg rfe, except_during_rfe;
733
   reg dslot_expt;
734
 
735
 
736
   // Maintain a copy of GPRS for previous instruction
737
   reg [31:0] current_gprs [0:31];
738
   reg [31:0] current_epcr, current_eear, current_esr, current_sr;
739
   reg [31:0] previous_gprs [0:31];
740
   reg [31:0] previous_epcr;
741
   reg [31:0] previous_eear;
742
   reg [31:0] previous_esr;
743
   reg [31:0] previous_sr;
744
 
745
   task update_current_gprs;
746
      integer j;
747
      begin
748
         for(j=0;j<32;j=j+1)
749
           begin
750
              get_gpr(j,current_gprs[j]);
751
           end
752
         current_sr = `OR1200_TOP.`CPU_cpu.`CPU_sprs.sr ;
753
         current_esr = `OR1200_TOP.`CPU_cpu.`CPU_sprs.epcr ;
754
         current_epcr = `OR1200_TOP.`CPU_cpu.`CPU_sprs.epcr ;
755
         current_eear = `OR1200_TOP.`CPU_cpu.`CPU_sprs.eear ;
756
      end
757
   endtask
758
 
759
   task update_previous_gprs;
760
      integer j;
761
      begin
762
         for(j=0;j<32;j=j+1)
763
           begin
764
              previous_gprs[j] = current_gprs[j];
765
           end
766
         previous_sr = current_sr;
767
         previous_esr = current_esr;
768
         previous_epcr = current_epcr;
769
         previous_eear = current_eear;
770
      end
771
   endtask // update_previous_gprs
772
 
773
   // Maintain a list of addresses we expect the processor to execute
774
   // Whenever we hit a branch or jump or rfe we add to this list - when we
775
   // execute it then we remove it from the list.
776
   reg [31:0] expected_addresses [0:31];
777
   reg        expected_addresses_waiting [0:31]; // List indicating if address is waiting
778
   reg        duplicate_expected_addresses_waiting [0:31]; // List indicating if a waiting address will be cleared by the single return
779
   integer    expected_address_num;
780
   // Initialise things on reset
781
   always @(`OR1200_TOP.iwb_rst_i)
782
     begin
783
        for (expected_address_num=0;expected_address_num<32;expected_address_num=expected_address_num+1)
784
          begin
785
             expected_addresses_waiting[expected_address_num] = 0;
786
             duplicate_expected_addresses_waiting[expected_address_num] = 0;
787
          end
788
        expected_address_num = 0;
789
     end
790
 
791
   task add_expected_address;
792
      input [31:0] expected_pc;
793
      begin
794
         if (expected_address_num == 31)
795
           begin
796
              $display("%t: Too many branches not reached",$time);
797
              #100;
798
              $finish;
799
           end
800
         if (expected_addresses_waiting[expected_address_num])
801
           begin
802
              $display("%t: expected_addresses tracker bugged out. expected_address_num = %0d",$time,expected_address_num);
803
              #100;
804
              $finish;
805
           end
806
         else
807
           begin
808
`ifdef OR1200_MONITOR_JUMPTRACK_DEBUG_OUTPUT
809
              // Debugging output...
810
              $display("%t: Adding address 0x%h to expected list index %0d",$time, expected_pc,expected_address_num);
811
`endif
812
              // Put the expected PC in the list, increase the index
813
              expected_addresses[expected_address_num] = expected_pc;
814
              expected_addresses_waiting[expected_address_num] = 1;
815
              expected_address_num = expected_address_num + 1;
816
           end // else: !if(expected_addresses_waiting[expected_address_num])
817
      end
818
   endtask // add_address_to_expect
819
 
820
   // Use this in the case that there's an execption after a jump, in which 
821
   // case we'll have two entries when we finally jump back (the one the 
822
   // original jump put in, and the one put in by the l.rfe or l.jr/ when 
823
   // returning outside of exception handler), so mark this one as OK for 
824
   // removing the duplicate of
825
   task mark_duplicate_expected_address;
826
      begin
827
         // This will always be done on the first instruction of an exception 
828
         // that has occured after a delay slot instruction, so 
829
         // expected_address_num will be one past the entry for the one we will
830
         // get a duplicate return call for
831
         duplicate_expected_addresses_waiting[expected_address_num-1] = 1;
832
      end
833
   endtask // mark_duplicate_expected_address
834
 
835
 
836
   task check_expected_address;
837
      input [31:0] pc;
838
      input        expecting_hit;
839
      integer      i,j;
840
      reg          hit;
841
      reg          duplicates;
842
 
843
      begin
844
         hit = 0;
845
         //$display("%t: check_expected_addr 0x%h, index %0d",
846
         // $time,pc, expected_address_num);     
847
         if (expected_address_num > 0)
848
           begin
849
              // First check the last jump we did
850
              if (expected_addresses[expected_address_num-1] == pc)
851
                begin
852
                   // Jump address hit
853
                   // Debugging printout:
854
`ifdef OR1200_MONITOR_JUMPTRACK_DEBUG_OUTPUT
855
                   $display("%t: PC address 0x%h was in expected list, index %0d",$time, pc,expected_address_num-1);
856
`endif
857
                   expected_address_num = expected_address_num-1;
858
                   expected_addresses_waiting[expected_address_num] = 0;
859
                   hit = 1;
860
                end
861
              else
862
                begin
863
                   // Check through the list
864
                   for(i=0;i<expected_address_num;i=i+1)
865
                     begin
866
                        if (expected_addresses[i] == pc)
867
                          begin
868
                             // Jump address hit
869
                             // Debugging printout:
870
`ifdef OR1200_MONITOR_JUMPTRACK_DEBUG_OUTPUT
871
                             $display("%t: PC address 0x%h was in expected list, index %0d",$time, pc,i);
872
`endif
873
                             for(j=i;j<expected_address_num;j=j+1)
874
                               begin
875
                                  // Pull all of the ones above us down one
876
                                  expected_addresses_waiting[j]
877
                                    = expected_addresses_waiting[j+1];
878
                                  expected_addresses[j]
879
                                    = expected_addresses[j+1];
880
                                  duplicate_expected_addresses_waiting[j]
881
                                    = duplicate_expected_addresses_waiting[j+1];
882
                               end
883
                             expected_address_num = expected_address_num-1;
884
                             hit = 1;
885
                             // quit out. only allow 1 hit
886
                             i = expected_address_num;
887
                          end
888
                     end
889
                end // else: !if(expected_addresses[expected_ad...
890
           end // if (expected_address_num > 0)
891
 
892
         // Check for duplicates this way because of the way we've declared
893
         // the array...
894
         duplicates=0;
895
         for(i=0;i<32;i=i+1)
896
           duplicates = duplicates | duplicate_expected_addresses_waiting[i];
897
 
898
         if (hit & duplicates)
899
           begin
900
              // If we got a hit, check for duplicates we're also meant to clear
901
`ifdef OR1200_MONITOR_JUMPTRACK_DEBUG_OUTPUT
902
              $display;
903
`endif
904
              for(i=0;i<expected_address_num;i=i+1)
905
                begin
906
                   if(duplicate_expected_addresses_waiting[i] &
907
                      expected_addresses_waiting[i] &
908
                      expected_addresses[i] == pc)
909
                     begin
910
                        // Found a duplicate call address, clear it
911
                        duplicate_expected_addresses_waiting[i] = 0;
912
                        expected_addresses_waiting[i] = 0;
913
 
914
                        // Now reorder the list - pull all the ones above us
915
                        // down by one
916
                        for(j=i;j<expected_address_num;j=j+1)
917
                          begin
918
                             expected_addresses_waiting[j] = expected_addresses_waiting[j+1];
919
                             expected_addresses[j] = expected_addresses[j+1];
920
                             duplicate_expected_addresses_waiting[j] = duplicate_expected_addresses_waiting[j+1];
921
                          end
922
                        expected_address_num = expected_address_num - 1;
923
                     end
924
                end // for (i=0;i<expected_address_num;i=i+1)
925
           end // if (hit & duplicates)
926
 
927
         if (expecting_hit & !hit)
928
           begin
929
              // Expected this address to be one we're supposed to jump to, but it wasn't!
930
              $display("%t: Failed to find current PC, 0x%h, in expected PCs for branches/jumps",$time,pc);
931
              #100;
932
              $finish;
933
           end
934
 
935
      end
936
   endtask // check_expected_address
937
 
938
   // Task to assert value of GPR
939
   task assert_gpr_val;
940
      input [5:0] regnum;
941
      input [31:0] assert_value;
942
      input [31:0] pc;
943
      reg [31:0]   reg_val;
944
 
945
      begin
946
         get_gpr(regnum, reg_val);
947
         if (reg_val !== assert_value)
948
           begin
949
              $display("%t: Assert r%0d value (0x%h) = 0x%h failed. pc=0x%h",
950
                       $time, regnum, reg_val, assert_value,pc);
951
              #100;
952
              $finish;
953
           end
954
      end
955
   endtask // assert_gpr_val
956
 
957
   // Task to assert something is true
958
   task assert_this;
959
      input assert_result;
960
      input [31:0] pc;
961
      begin
962
         if (!assert_result)
963
           begin
964
              $display("%t: Assert failed for instruction at pc=0x%h",
965
                       $time , pc);
966
              #100;
967
              $finish;
968
           end
969
      end
970
   endtask // assert_gpr_val             
971
 
972
   // The jumping variable doesn't get updated until we do the proper check of
973
   // the current instruction reaching the writeback stage. We need to know
974
   // earlier, eg. in the exception checking part, if this instruction will
975
   // jump. We do that with this task.
976
   task check_for_jump;
977
      input [31:0] insn;
978
      reg [5:0]    opcode;
979
      reg          flag;
980
      begin
981
         opcode = insn[`OR1K_OPCODE_POS];
982
         // Use the flag from the previous instruction, as the decision 
983
         // is made in the execute stage not in te writeback stage, 
984
         // which is where we're getting our instructions.
985
         flag = previous_sr[`OR1200_SR_F];
986
 
987
         case (opcode)
988
           `OR1200_OR32_J,
989
             `OR1200_OR32_JR,
990
             `OR1200_OR32_JAL,
991
             `OR1200_OR32_JALR:
992
               will_jump = 1;
993
           `OR1200_OR32_BNF:
994
             will_jump = !flag;
995
           `OR1200_OR32_BF:
996
             will_jump = flag;
997
           default:
998
             will_jump = 0;
999
         endcase // case (opcode)
1000
      end
1001
   endtask // check_for_jump   
1002
 
1003
 
1004
 
1005
   // Detect exceptions from the processor here
1006
   reg [13:0] except_trig_r;
1007
   reg        exception_coming;
1008
 
1009
   always @(posedge `CPU_CORE_CLK)
1010
     if (`OR1200_TOP.iwb_rst_i)
1011
       begin
1012
          except_trig_r = 0;
1013
          exception_coming = 0;
1014
          except_during_rfe = 0;
1015
       end
1016
     else if ((|`OR1200_TOP.`CPU_cpu.`CPU_except.except_trig) && !exception_coming)
1017
       begin
1018
          exception_coming  = 1;
1019
          except_trig_r = `OR1200_TOP.`CPU_cpu.`CPU_except.except_trig;
1020
          except_during_rfe = rfe;
1021
       end
1022
 
1023
   task check_incoming_exceptions;
1024
      begin
1025
 
1026
         // Exception timing  - depends on the trigger.
1027
         // Appears to be: 
1028
         // tick timer - dslot - 1 instruction delay, else 2
1029
         // tlb lookasides - 1 instruction for both
1030
 
1031
         casex (except_trig_r)
1032
           13'b1_xxxx_xxxx_xxxx: begin
1033
              //except_type <= #1 `OR1200_EXCEPT_TICK;
1034
              exception_here = exception_coming2;
1035
              exception_coming2 = jump_dslot ? exception_coming: exception_coming1 ;
1036
              exception_coming1 = jump_dslot ? 0 : exception_coming;
1037
           end
1038
           13'b0_1xxx_xxxx_xxxx: begin
1039
              //except_type <= #1 `OR1200_EXCEPT_INT;
1040
              #1;
1041
           end
1042
           13'b0_01xx_xxxx_xxxx: begin
1043
              //except_type <= #1 `OR1200_EXCEPT_ITLBMISS;
1044
              exception_here = exception_coming2;
1045
              exception_coming2 = jump_dslot ? exception_coming : exception_coming1 ;
1046
              exception_coming1 = jump_dslot ? 0 : exception_coming;
1047
           end
1048
           13'b0_001x_xxxx_xxxx: begin
1049
              //except_type <= #1 `OR1200_EXCEPT_IPF;
1050
              exception_here = exception_coming2;
1051
              exception_coming2 = jump_dslot ? exception_coming : exception_coming1 ;
1052
              exception_coming1 = jump_dslot ? 0 : exception_coming;
1053
           end
1054
           13'b0_0001_xxxx_xxxx: begin
1055
              //except_type <= #1 `OR1200_EXCEPT_BUSERR;
1056
              exception_here = exception_coming;
1057
              exception_coming2 = 0;
1058
              exception_coming1 = 0;
1059
           end
1060
           13'b0_0000_1xxx_xxxx: begin
1061
              //except_type <= #1 `OR1200_EXCEPT_ILLEGAL;
1062
              if (will_jump)
1063
                begin
1064
                   // Writeback stage instruction will jump, and we have an
1065
                   // illegal instruction in the decode/execute stage, which is
1066
                   // the delay slot, so indicate the exception is coming...
1067
                   exception_here = exception_coming2;
1068
                   exception_coming2 = exception_coming;
1069
                   exception_coming1 = 0;
1070
                end
1071
              else
1072
                begin
1073
                   exception_here = jump_dslot ?
1074
                                    exception_coming2 : exception_coming;
1075
                   exception_coming2 = jump_dslot ? exception_coming : 0;
1076
                   exception_coming1 = 0;
1077
                end
1078
           end
1079
           13'b0_0000_01xx_xxxx: begin
1080
              //except_type <= #1 `OR1200_EXCEPT_ALIGN;
1081
              if(will_jump)
1082
                begin
1083
                   exception_here = exception_coming2;
1084
                   exception_coming2 = exception_coming;
1085
                   exception_coming1 = 0;
1086
                end
1087
              else
1088
                begin
1089
                   exception_here =  (rfe) ? exception_coming : exception_coming2;
1090
                   exception_coming2 = (rfe) ? 0 : exception_coming;
1091
                   exception_coming1 = 0;
1092
                end
1093
           end
1094
           13'b0_0000_001x_xxxx: begin
1095
              //except_type <= #1 `OR1200_EXCEPT_DTLBMISS;
1096
              // Looks like except_trig goes high here after we check the
1097
              // instruction before the itlb miss after a delay slot, so we
1098
              // miss the dslot variable (it gets propegated before we call
1099
              // this task) so we use the jumped variable here to see if we
1100
              // are an exception after a delay slot          
1101
              //exception_here = (jumped | rfe) ? exception_coming : exception_coming2 ;
1102
              //exception_coming2 = (jumped | rfe) ? 0 : exception_coming;
1103
 
1104
              exception_here = (jumped | rfe) ? exception_coming : exception_coming2 ;
1105
              exception_coming2 = (jumped | rfe) ? 0 : exception_coming;
1106
 
1107
              exception_coming1 = 0;
1108
           end
1109
           13'b0_0000_0001_xxxx: begin
1110
              //except_type <= #1 `OR1200_EXCEPT_DPF;
1111
              if (jumped) begin // Jumped onto illegal instruction
1112
                 exception_here = exception_coming ;
1113
                 exception_coming2 = 0;
1114
                 exception_coming1 = 0;
1115
              end
1116
              else begin
1117
                 exception_here =  exception_coming2;
1118
                 exception_coming2 = exception_coming;
1119
                 exception_coming1 = 0;
1120
              end
1121
           end
1122
           13'b0_0000_0000_1xxx: begin  // Data Bus Error
1123
              //except_type <= #1 `OR1200_EXCEPT_BUSERR;
1124
              exception_here = exception_coming2 ;
1125
              exception_coming2 = exception_coming;
1126
              exception_coming1 = 0;
1127
           end
1128
           13'b0_0000_0000_01xx: begin
1129
              //except_type <= #1 `OR1200_EXCEPT_RANGE;
1130
              #1;
1131
           end
1132
           13'b0_0000_0000_001x: begin
1133
              // trap         
1134
              #1;
1135
           end
1136
           13'b0_0000_0000_0001: begin
1137
              //except_type <= #1 `OR1200_EXCEPT_SYSCALL;
1138
              exception_here = exception_coming2;
1139
              exception_coming2 = jumped ? exception_coming: exception_coming1 ;
1140
              exception_coming1 = jumped ? 0 : exception_coming;
1141
           end
1142
         endcase // casex (except_trig_r)
1143
 
1144
         exception_coming = 0;
1145
         except_during_rfe = 0;
1146
 
1147
      end
1148
   endtask // check_incoming_exceptions
1149
 
1150
 
1151
 
1152
 
1153
   /////////////////////////////////////////////////////////////////////////
1154
   // Execution tracking task
1155
   /////////////////////////////////////////////////////////////////////////
1156
 
1157
 
1158
`ifdef OR1200_SYSTEM_CHECKER
1159
   always @(posedge `CPU_CORE_CLK)
1160
     begin
1161
        if (`OR1200_TOP.iwb_rst_i)
1162
          begin
1163
             exception_coming1 = 0;exception_coming2 = 0;exception_here= 0;
1164
             jumping = 0; jump_dslot = 0; jumped = 0;
1165
             rfe = 0;
1166
          end
1167
        if (!`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_freeze) begin
1168
           //#2 ;
1169
           // If instruction isn't a l.nop with bit 16 set (implementation's 
1170
           // filler instruction in pipeline), and do not have an exception 
1171
           // signaled with a dslot instruction in the execute stage
1172
           if (((`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn[`OR1K_OPCODE_POS] !=
1173
                 `OR1200_OR32_NOP) || !`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn[16])
1174
               && !(`OR1200_TOP.`CPU_cpu.`CPU_except.except_flushpipe &&
1175
                    `OR1200_TOP.`CPU_cpu.`CPU_except.ex_dslot)) // and not except start
1176
             begin
1177
 
1178
                // Propegate jump-tracking variables
1179
                // If was exception in delay slot, we didn't actually jump
1180
                // so don't set jumped in this case.
1181
                jumped = exception_here ? 0 : jump_dslot;
1182
                jump_dslot = jumping;
1183
                jumping = 0;
1184
                rfe = 0;
1185
 
1186
                // Now, check if current instruction will jump/branch, this is
1187
                // needed by the exception checking code, sets will_jump=1
1188
                check_for_jump(`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn);
1189
 
1190
                // Now check if it's an exception this instruction
1191
                check_incoming_exceptions;
1192
 
1193
                // Case where we just went to an exception after a jump, so we 
1194
                // mark the address we were meant to jump to as a place which will
1195
                // have duplicate return entries in the expected address list
1196
                if (exception_here & (jumped | jump_dslot))
1197
                  begin
1198
                     $display("%t: marked as jump address with exception (dup)"
1199
                              ,$time);
1200
                     mark_duplicate_expected_address;
1201
                  end
1202
 
1203
                or1200_check_execution(`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn,
1204
                                       `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc,
1205
                                       exception_here);
1206
                //$write("%t: pc:0x%h\t",$time,
1207
                //       `OR1200_TOP.`CPU_cpu.`CPU_except.wb_pc);
1208
                // Decode the instruction, print it out
1209
                //or1200_print_op(`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_insn); 
1210
                //$write("\t exc:%0h dsl:%0h\n",exception_here,jump_dslot);
1211
 
1212
 
1213
 
1214
             end
1215
        end // if (!`OR1200_TOP.`CPU_cpu.`CPU_ctrl.wb_freeze)
1216
     end // always @ (posedge `CPU_CORE_CLK)
1217
`endif
1218
 
1219
 
1220
   task or1200_check_execution;
1221
      input [31:0] insn;
1222
      input [31:0] pc;
1223
      input        exception;
1224
 
1225
      reg [5:0]    opcode;
1226
 
1227
      reg [25:0]   j_imm;
1228
      reg [25:0]   br_imm;
1229
 
1230
      reg [4:0]    rD_num, rA_num, rB_num;
1231
      reg [31:0]   rD_val, rA_val, rB_val;
1232
      reg [15:0]   imm_16bit;
1233
 
1234
      reg [15:0]   mtspr_imm;
1235
 
1236
      reg [3:0]    alu_op;
1237
      reg [1:0]    shrot_op;
1238
 
1239
      reg [5:0]    shroti_imm;
1240
 
1241
      reg [5:0]    sf_op;
1242
 
1243
      reg [5:0]    xsync_op;
1244
 
1245
      reg          flag;
1246
 
1247
      reg [31:0]   br_j_ea; // Branch/jump effective address
1248
 
1249
 
1250
      begin
1251
 
1252
         // Instruction opcode
1253
         opcode = insn[`OR1K_OPCODE_POS];
1254
         // Immediates for jump or branch instructions
1255
         j_imm = insn[`OR1K_J_BR_IMM_POS];
1256
         br_imm = insn[`OR1K_J_BR_IMM_POS];
1257
         // Register numbers (D, A and B)
1258
         rD_num = insn[`OR1K_RD_POS];
1259
         rA_num = insn[`OR1K_RA_POS];
1260
         rB_num = insn[`OR1K_RB_POS];
1261
         // Bottom 16 bits when used as immediates in various instructions
1262
         imm_16bit = insn[15:0];
1263
         // 16-bit immediate for mtspr instructions
1264
         mtspr_imm = {insn[25:21],insn[10:0]};
1265
         // ALU op for ALU instructions
1266
         alu_op = insn[`OR1K_ALU_OP_POS];
1267
         // Shift-rotate op for SHROT ALU instructions
1268
         shrot_op = insn[`OR1K_SHROT_OP_POS];
1269
         shroti_imm = insn[`OR1K_SHROTI_IMM_POS];
1270
 
1271
         // Set flag op
1272
         sf_op = insn[`OR1K_SF_OP];
1273
 
1274
         // Xsync/syscall/trap opcode
1275
         xsync_op = insn[`OR1K_XSYNC_OP_POS];
1276
 
1277
         // Use the flag from the previous instruction, as the decision 
1278
         // is made in the execute stage not in te writeback stage, 
1279
         // which is where we're getting our instructions.
1280
         flag = previous_sr[`OR1200_SR_F];
1281
 
1282
         update_current_gprs;
1283
 
1284
         // Check MSbit of the immediate, sign extend if set
1285
         br_j_ea = j_imm[25] ? pc + {4'hf,j_imm,2'b00} :
1286
                   pc + {4'h0,j_imm,2'b00};
1287
 
1288
         if (exception)
1289
           begin
1290
              $display("%t: exception - at 0x%x",$time, pc);
1291
              // get epcr, put it in the addresses we expect to jump
1292
              // back to
1293
              // Maybe DON'T do this. Because maybe in linux things we 
1294
              // interrupt out of, we don't want to execute them again?
1295
              //add_expected_address(current_epcr);
1296
           end
1297
 
1298
 
1299
         check_expected_address(pc, (jumped & !exception));
1300
 
1301
         rfe = 0;
1302
 
1303
         case (opcode)
1304
           `OR1200_OR32_J:
1305
             begin
1306
                //
1307
                // PC < - exts(Immediate < < 2) + JumpInsnAddr
1308
                //
1309
                //The immediate value is shifted left two bits, sign-extended 
1310
                // to program counter width, and then added to the address of 
1311
                // the jump instruction. The result is the effective address 
1312
                // of the jump. The program unconditionally jumps to EA with 
1313
                // a delay of one instruction.
1314
 
1315
                add_expected_address(br_j_ea);
1316
 
1317
                jumping = 1;
1318
             end
1319
           `OR1200_OR32_JAL:
1320
             begin
1321
                //
1322
                //PC < - exts(Immediate < < 2) + JumpInsnAddr
1323
                //LR < - DelayInsnAddr + 4
1324
                //
1325
                // Link reg is r9, check it is PC+8
1326
                //
1327
                add_expected_address(br_j_ea);
1328
                assert_gpr_val(9, pc+8, pc);
1329
                jumping = 1;    // 
1330
             end
1331
           `OR1200_OR32_BNF:
1332
             begin
1333
                //EA < - exts(Immediate < < 2) + BranchInsnAddr
1334
                //PC < - EA if SR[F] cleared
1335
                if (!flag)
1336
                  begin
1337
                     add_expected_address(br_j_ea);
1338
                     jumping = 1;
1339
                  end
1340
             end
1341
           `OR1200_OR32_BF:
1342
             begin
1343
                //EA < - exts(Immediate < < 2) + BranchInsnAddr
1344
                //PC < - EA if SR[F] set
1345
                if (flag)
1346
                  begin
1347
                     add_expected_address(br_j_ea);
1348
                     jumping = 1;
1349
                  end
1350
             end
1351
           `OR1200_OR32_RFE:
1352
             begin
1353
                add_expected_address(current_epcr);
1354
                // jumping variable keeps track of jumps/branches with delay 
1355
                // slot - there is none for l.rfe
1356
                rfe = 1;
1357
             end
1358
           `OR1200_OR32_JR:
1359
             begin
1360
                //PC < - rB
1361
                get_gpr(rB_num, rB_val);
1362
                add_expected_address(rB_val);
1363
                jumping = 1;
1364
             end
1365
           `OR1200_OR32_JALR:
1366
             begin
1367
                //PC < - rB
1368
                //LR < - DelayInsnAddr + 4
1369
                get_gpr(rB_num, rB_val);
1370
                add_expected_address(rB_val);
1371
                assert_gpr_val(9, pc+8, pc);
1372
                jumping = 1;
1373
             end
1374
           /*
1375
            `OR1200_OR32_LWZ,
1376
            `OR1200_OR32_LBZ,
1377
            `OR1200_OR32_LBS,
1378
            `OR1200_OR32_LHZ,
1379
            `OR1200_OR32_LHS,
1380
            `OR1200_OR32_SW,
1381
            `OR1200_OR32_SB,
1382
            `OR1200_OR32_SH:
1383
            begin
1384
            // Should result in databus access if data cache disabled
1385
            $display("%t: lsu instruction",$time);
1386
end
1387
 
1388
            `OR1200_OR32_MFSPR,
1389
            `OR1200_OR32_MTSPR:
1390
            begin
1391
            // Confirm RF values end up in the correct SPR
1392
            $display("%t: mxspr",$time);
1393
end
1394
 
1395
            `OR1200_OR32_MOVHI,
1396
            `OR1200_OR32_ADDI,
1397
            `OR1200_OR32_ADDIC,
1398
            `OR1200_OR32_ANDI,
1399
            `OR1200_OR32_ORI,
1400
            `OR1200_OR32_XORI,
1401
            `OR1200_OR32_MULI,
1402
            `OR1200_OR32_ALU:
1403
            begin
1404
            // Double check operations done on RF and immediate values
1405
            $display("%t: ALU op",$time);
1406
end
1407
 
1408
            `OR1200_OR32_SH_ROTI:
1409
            begin
1410
            // Rotate according to immediate - maybe should be in ALU ops
1411
            $display("%t: rotate op",$time);
1412
end
1413
 
1414
            `OR1200_OR32_SFXXI,
1415
            `OR1200_OR32_SFXX:
1416
            begin
1417
            // Set flag - do the check oursevles, check flag
1418
            $display("%t: set flag op",$time);
1419
end
1420
 
1421
            `OR1200_OR32_MACI,
1422
            `OR1200_OR32_MACMSB:
1423
            begin
1424
            // Either, multiply signed and accumulate, l.mac
1425
            // or multiply signed and subtract, l.msb
1426
            $display("%t: MAC op",$time);
1427
end
1428
            */
1429
 
1430
           /*default:
1431
            begin
1432
            $display("%t: Unknown opcode 0x%h at pc 0x%x\n",
1433
            $time,opcode, pc);
1434
end
1435
            */
1436
         endcase // case (opcode)
1437
 
1438
         update_previous_gprs;
1439
 
1440
      end
1441
   endtask // or1200_check_execution
1442
 
1443
 
1444
   /////////////////////////////////////////////////////////////////////////
1445
   // Instruction decode task
1446
   /////////////////////////////////////////////////////////////////////////
1447
 
1448
   task or1200_print_op;
1449
      input [31:0] insn;
1450
 
1451
      reg [5:0]    opcode;
1452
 
1453
      reg [25:0]   j_imm;
1454
      reg [25:0]   br_imm;
1455
 
1456
      reg [4:0]    rD_num, rA_num, rB_num;
1457
      reg [31:0]   rA_val, rB_val;
1458
      reg [15:0]   imm_16bit;
1459
      reg [10:0]   imm_split16bit;
1460
 
1461
      reg [3:0]    alu_op;
1462
      reg [1:0]    shrot_op;
1463
 
1464
      reg [5:0]    shroti_imm;
1465
 
1466
      reg [5:0]    sf_op;
1467
 
1468
      reg [5:0]    xsync_op;
1469
 
1470
      begin
1471
         // Instruction opcode
1472
         opcode = insn[`OR1K_OPCODE_POS];
1473
         // Immediates for jump or branch instructions
1474
         j_imm = insn[`OR1K_J_BR_IMM_POS];
1475
         br_imm = insn[`OR1K_J_BR_IMM_POS];
1476
         // Register numbers (D, A and B)
1477
         rD_num = insn[`OR1K_RD_POS];
1478
         rA_num = insn[`OR1K_RA_POS];
1479
         rB_num = insn[`OR1K_RB_POS];
1480
         // Bottom 16 bits when used as immediates in various instructions
1481
         imm_16bit = insn[15:0];
1482
         // Bottom 11 bits used as immediates for l.sX instructions
1483
 
1484
         // Split 16-bit immediate for l.mtspr/l.sX instructions
1485
         imm_split16bit = {insn[25:21],insn[10:0]};
1486
         // ALU op for ALU instructions
1487
         alu_op = insn[`OR1K_ALU_OP_POS];
1488
         // Shift-rotate op for SHROT ALU instructions
1489
         shrot_op = insn[`OR1K_SHROT_OP_POS];
1490
         shroti_imm = insn[`OR1K_SHROTI_IMM_POS];
1491
 
1492
         // Set flag op
1493
         sf_op = insn[`OR1K_SF_OP];
1494
 
1495
         // Xsync/syscall/trap opcode
1496
         xsync_op = insn[`OR1K_XSYNC_OP_POS];
1497
 
1498
         case (opcode)
1499
           `OR1200_OR32_J:
1500
             begin
1501
                $fwrite(finsn,"l.j 0x%h", {j_imm,2'b00});
1502
             end
1503
 
1504
           `OR1200_OR32_JAL:
1505
             begin
1506
                $fwrite(finsn,"l.jal 0x%h", {j_imm,2'b00});
1507
             end
1508
 
1509
           `OR1200_OR32_BNF:
1510
             begin
1511
                $fwrite(finsn,"l.bnf 0x%h", {br_imm,2'b00});
1512
             end
1513
 
1514
           `OR1200_OR32_BF:
1515
             begin
1516
                $fwrite(finsn,"l.bf 0x%h", {br_imm,2'b00});
1517
             end
1518
 
1519
           `OR1200_OR32_RFE:
1520
             begin
1521
                $fwrite(finsn,"l.rfe");
1522
             end
1523
 
1524
           `OR1200_OR32_JR:
1525
             begin
1526
                $fwrite(finsn,"l.jr r%0d",rB_num);
1527
             end
1528
 
1529
           `OR1200_OR32_JALR:
1530
             begin
1531
                $fwrite(finsn,"l.jalr r%0d",rB_num);
1532
             end
1533
 
1534
           `OR1200_OR32_LWZ:
1535
             begin
1536
                $fwrite(finsn,"l.lwz r%0d,0x%0h(r%0d)",rD_num,imm_16bit,rA_num);
1537
             end
1538
 
1539
           `OR1200_OR32_LBZ:
1540
             begin
1541
                $fwrite(finsn,"l.lbz r%0d,0x%0h(r%0d)",rD_num,imm_16bit,rA_num);
1542
             end
1543
 
1544
           `OR1200_OR32_LBS:
1545
             begin
1546
                $fwrite(finsn,"l.lbs r%0d,0x%0h(r%0d)",rD_num,imm_16bit,rA_num);
1547
             end
1548
 
1549
           `OR1200_OR32_LHZ:
1550
             begin
1551
                $fwrite(finsn,"l.lhz r%0d,0x%0h(r%0d)",rD_num,imm_16bit,rA_num);
1552
             end
1553
 
1554
           `OR1200_OR32_LHS:
1555
             begin
1556
                $fwrite(finsn,"l.lhs r%0d,0x%0h(r%0d)",rD_num,imm_16bit,rA_num);
1557
             end
1558
 
1559
           `OR1200_OR32_SW:
1560
             begin
1561
                $fwrite(finsn,"l.sw 0x%0h(r%0d),r%0d",imm_split16bit,rA_num,rB_num);
1562
             end
1563
 
1564
           `OR1200_OR32_SB:
1565
             begin
1566
                $fwrite(finsn,"l.sb 0x%0h(r%0d),r%0d",imm_split16bit,rA_num,rB_num);
1567
             end
1568
 
1569
           `OR1200_OR32_SH:
1570
             begin
1571
                $fwrite(finsn,"l.sh 0x%0h(r%0d),r%0d",imm_split16bit,rA_num,rB_num);
1572
             end
1573
 
1574
           `OR1200_OR32_MFSPR:
1575
             begin
1576
                $fwrite(finsn,"l.mfspr r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit,);
1577
             end
1578
 
1579
           `OR1200_OR32_MTSPR:
1580
             begin
1581
                $fwrite(finsn,"l.mtspr r%0d,r%0d,0x%h",rA_num,rB_num,imm_split16bit);
1582
             end
1583
 
1584
           `OR1200_OR32_MOVHI:
1585
             begin
1586
                if (!insn[16])
1587
                  $fwrite(finsn,"l.movhi r%0d,0x%h",rD_num,imm_16bit);
1588
                else
1589
                  $fwrite(finsn,"l.macrc r%0d",rD_num);
1590
             end
1591
 
1592
           `OR1200_OR32_ADDI:
1593
             begin
1594
                $fwrite(finsn,"l.addi r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1595
             end
1596
 
1597
           `OR1200_OR32_ADDIC:
1598
             begin
1599
                $fwrite(finsn,"l.addic r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1600
             end
1601
 
1602
           `OR1200_OR32_ANDI:
1603
             begin
1604
                $fwrite(finsn,"l.andi r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1605
             end
1606
 
1607
           `OR1200_OR32_ORI:
1608
             begin
1609
                $fwrite(finsn,"l.ori r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1610
             end
1611
 
1612
           `OR1200_OR32_XORI:
1613
             begin
1614
                $fwrite(finsn,"l.xori r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1615
             end
1616
 
1617
           `OR1200_OR32_MULI:
1618
             begin
1619
                $fwrite(finsn,"l.muli r%0d,r%0d,0x%h",rD_num,rA_num,imm_16bit);
1620
             end
1621
 
1622
           `OR1200_OR32_ALU:
1623
             begin
1624
                case(alu_op)
1625
                  `OR1200_ALUOP_ADD:
1626
                    $fwrite(finsn,"l.add ");
1627
                  `OR1200_ALUOP_ADDC:
1628
                    $fwrite(finsn,"l.addc ");
1629
                  `OR1200_ALUOP_SUB:
1630
                    $fwrite(finsn,"l.sub ");
1631
                  `OR1200_ALUOP_AND:
1632
                    $fwrite(finsn,"l.and ");
1633
                  `OR1200_ALUOP_OR:
1634
                    $fwrite(finsn,"l.or ");
1635
                  `OR1200_ALUOP_XOR:
1636
                    $fwrite(finsn,"l.xor ");
1637
                  `OR1200_ALUOP_MUL:
1638
                    $fwrite(finsn,"l.mul ");
1639
                  `OR1200_ALUOP_SHROT:
1640
                    begin
1641
                       case(shrot_op)
1642
                         `OR1200_SHROTOP_SLL:
1643
                           $fwrite(finsn,"l.sll ");
1644
                         `OR1200_SHROTOP_SRL:
1645
                           $fwrite(finsn,"l.srl ");
1646
                         `OR1200_SHROTOP_SRA:
1647
                           $fwrite(finsn,"l.sra ");
1648
                         `OR1200_SHROTOP_ROR:
1649
                           $fwrite(finsn,"l.ror ");
1650
                       endcase // case (shrot_op)
1651
                    end
1652
                  `OR1200_ALUOP_DIV:
1653
                    $fwrite(finsn,"l.div ");
1654
                  `OR1200_ALUOP_DIVU:
1655
                    $fwrite(finsn,"l.divu ");
1656
                  `OR1200_ALUOP_CMOV:
1657
                    $fwrite(finsn,"l.cmov ");
1658
                endcase // case (alu_op)
1659
                $fwrite(finsn,"r%0d,r%0d,r%0d",rD_num,rA_num,rB_num);
1660
             end
1661
 
1662
           `OR1200_OR32_SH_ROTI:
1663
             begin
1664
                case(shrot_op)
1665
                  `OR1200_SHROTOP_SLL:
1666
                    $fwrite(finsn,"l.slli ");
1667
                  `OR1200_SHROTOP_SRL:
1668
                    $fwrite(finsn,"l.srli ");
1669
                  `OR1200_SHROTOP_SRA:
1670
                    $fwrite(finsn,"l.srai ");
1671
                  `OR1200_SHROTOP_ROR:
1672
                    $fwrite(finsn,"l.rori ");
1673
                endcase // case (shrot_op)
1674
                $fwrite(finsn,"r%0d,r%0d,0x%h",rD_num,rA_num,shroti_imm);
1675
             end
1676
 
1677
           `OR1200_OR32_SFXXI:
1678
             begin
1679
                case(sf_op[2:0])
1680
                  `OR1200_COP_SFEQ:
1681
                    $fwrite(finsn,"l.sfeqi ");
1682
                  `OR1200_COP_SFNE:
1683
                    $fwrite(finsn,"l.sfnei ");
1684
                  `OR1200_COP_SFGT:
1685
                    begin
1686
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1687
                         $fwrite(finsn,"l.sfgtsi ");
1688
                       else
1689
                         $fwrite(finsn,"l.sfgtui ");
1690
                    end
1691
                  `OR1200_COP_SFGE:
1692
                    begin
1693
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1694
                         $fwrite(finsn,"l.sfgesi ");
1695
                       else
1696
                         $fwrite(finsn,"l.sfgeui ");
1697
                    end
1698
                  `OR1200_COP_SFLT:
1699
                    begin
1700
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1701
                         $fwrite(finsn,"l.sfltsi ");
1702
                       else
1703
                         $fwrite(finsn,"l.sfltui ");
1704
                    end
1705
                  `OR1200_COP_SFLE:
1706
                    begin
1707
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1708
                         $fwrite(finsn,"l.sflesi ");
1709
                       else
1710
                         $fwrite(finsn,"l.sfleui ");
1711
                    end
1712
                endcase // case (sf_op[2:0])
1713
 
1714
                $fwrite(finsn,"r%0d,0x%h",rA_num, imm_16bit);
1715
 
1716
             end // case: `OR1200_OR32_SFXXI
1717
 
1718
           `OR1200_OR32_SFXX:
1719
             begin
1720
                case(sf_op[2:0])
1721
                  `OR1200_COP_SFEQ:
1722
                    $fwrite(finsn,"l.sfeq ");
1723
                  `OR1200_COP_SFNE:
1724
                    $fwrite(finsn,"l.sfne ");
1725
                  `OR1200_COP_SFGT:
1726
                    begin
1727
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1728
                         $fwrite(finsn,"l.sfgts ");
1729
                       else
1730
                         $fwrite(finsn,"l.sfgtu ");
1731
                    end
1732
                  `OR1200_COP_SFGE:
1733
                    begin
1734
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1735
                         $fwrite(finsn,"l.sfges ");
1736
                       else
1737
                         $fwrite(finsn,"l.sfgeu ");
1738
                    end
1739
                  `OR1200_COP_SFLT:
1740
                    begin
1741
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1742
                         $fwrite(finsn,"l.sflts ");
1743
                       else
1744
                         $fwrite(finsn,"l.sfltu ");
1745
                    end
1746
                  `OR1200_COP_SFLE:
1747
                    begin
1748
                       if (sf_op[`OR1200_SIGNED_COMPARE])
1749
                         $fwrite(finsn,"l.sfles ");
1750
                       else
1751
                         $fwrite(finsn,"l.sfleu ");
1752
                    end
1753
 
1754
                endcase // case (sf_op[2:0])
1755
 
1756
                $fwrite(finsn,"r%0d,r%0d",rA_num, rB_num);
1757
 
1758
             end
1759
 
1760
           `OR1200_OR32_MACI:
1761
             begin
1762
                $fwrite(finsn,"l.maci r%0d,0x%h",rA_num,imm_16bit);
1763
             end
1764
 
1765
           `OR1200_OR32_MACMSB:
1766
             begin
1767
                if(insn[3:0] == 4'h1)
1768
                  $fwrite(finsn,"l.mac ");
1769
                else if(insn[3:0] == 4'h2)
1770
                  $fwrite(finsn,"l.msb ");
1771
 
1772
                $fwrite(finsn,"r%0d,r%0d",rA_num,rB_num);
1773
             end
1774
 
1775
           `OR1200_OR32_NOP:
1776
             begin
1777
                $fwrite(finsn,"l.nop 0x%0h",imm_16bit);
1778
             end
1779
 
1780
           `OR1200_OR32_XSYNC:
1781
             begin
1782
                case (xsync_op)
1783
                  5'd0:
1784
                    $fwrite(finsn,"l.sys 0x%h",imm_16bit);
1785
                  5'd8:
1786
                    $fwrite(finsn,"l.trap 0x%h",imm_16bit);
1787
                  5'd16:
1788
                    $fwrite(finsn,"l.msync");
1789
                  5'd20:
1790
                    $fwrite(finsn,"l.psync");
1791
                  5'd24:
1792
                    $fwrite(finsn,"l.csync");
1793
                  default:
1794
                    begin
1795
                       $display("%t: Instruction with opcode 0x%h has bad specific type information: 0x%h",$time,opcode,insn);
1796
                       $fwrite(finsn,"%t: Instruction with opcode 0x%h has has bad specific type information: 0x%h",$time,opcode,insn);
1797
                    end
1798
                endcase // case (xsync_op)
1799
             end
1800
 
1801
           default:
1802
             begin
1803
                $display("%t: Unknown opcode 0x%h",$time,opcode);
1804
                $fwrite(finsn,"%t: Unknown opcode 0x%h",$time,opcode);
1805
             end
1806
 
1807
         endcase // case (opcode)
1808
 
1809
      end
1810
   endtask // or1200_print_op
1811
 
1812
 
1813
 
1814
endmodule

powered by: WebSVN 2.1.0

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