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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 797

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

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Instruction decode                                 ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6 185 julius
////  http://www.opencores.org/project,or1k                       ////
7 10 unneback
////                                                              ////
8
////  Description                                                 ////
9
////  Majority of instruction decoding is performed here.         ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
//
45 141 marcus.erl
// $Log: or1200_ctrl.v,v $
46
// Revision 2.0  2010/06/30 11:00:00  ORSoC
47
// Major update: 
48
// Structure reordered and bugs fixed. 
49 10 unneback
 
50
// synopsys translate_off
51
`include "timescale.v"
52
// synopsys translate_on
53
`include "or1200_defines.v"
54
 
55 185 julius
module or1200_ctrl
56
  (
57
   // Clock and reset
58
   clk, rst,
59
 
60
   // Internal i/f
61
   except_flushpipe, extend_flush, if_flushpipe, id_flushpipe, ex_flushpipe,
62
   wb_flushpipe,
63
   id_freeze, ex_freeze, wb_freeze, if_insn, id_insn, ex_insn, abort_mvspr,
64
   id_branch_op, ex_branch_op, ex_branch_taken, pc_we,
65 640 julius
   rf_addra, rf_addrb, rf_rda, rf_rdb, alu_op, alu_op2, mac_op,
66 401 julius
   comp_op, rf_addrw, rfwb_op, fpu_op,
67 185 julius
   wb_insn, id_simm, ex_simm, id_branch_addrtarget, ex_branch_addrtarget, sel_a,
68
   sel_b, id_lsu_op,
69
   cust5_op, cust5_limm, id_pc, ex_pc, du_hwbkpt,
70 258 julius
   multicycle, wait_on, wbforw_valid, sig_syscall, sig_trap,
71 185 julius
   force_dslot_fetch, no_more_dslot, id_void, ex_void, ex_spr_read,
72
   ex_spr_write,
73 258 julius
   id_mac_op, id_macrc_op, ex_macrc_op, rfe, except_illegal, dc_no_writethrough
74 185 julius
   );
75 10 unneback
 
76
//
77
// I/O
78
//
79
input                                   clk;
80
input                                   rst;
81
input                                   id_freeze;
82 353 julius
input                                   ex_freeze /* verilator public */;
83
input                                   wb_freeze /* verilator public */;
84 141 marcus.erl
output                                  if_flushpipe;
85
output                                  id_flushpipe;
86
output                                  ex_flushpipe;
87
output                                  wb_flushpipe;
88
input                                   extend_flush;
89
input                                   except_flushpipe;
90
input                           abort_mvspr ;
91
input   [31:0]                   if_insn;
92
output  [31:0]                   id_insn;
93 353 julius
output  [31:0]                   ex_insn /* verilator public */;
94 141 marcus.erl
output  [`OR1200_BRANCHOP_WIDTH-1:0]             ex_branch_op;
95
output  [`OR1200_BRANCHOP_WIDTH-1:0]             id_branch_op;
96
input                                           ex_branch_taken;
97 10 unneback
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
98
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addra;
99
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrb;
100
output                                  rf_rda;
101
output                                  rf_rdb;
102
output  [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
103 401 julius
output [`OR1200_ALUOP2_WIDTH-1:0]                alu_op2;
104 10 unneback
output  [`OR1200_MACOP_WIDTH-1:0]                mac_op;
105
output  [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
106 258 julius
output  [`OR1200_FPUOP_WIDTH-1:0]                fpu_op;
107 141 marcus.erl
input                                   pc_we;
108 10 unneback
output  [31:0]                           wb_insn;
109 141 marcus.erl
output  [31:2]                          id_branch_addrtarget;
110
output  [31:2]                          ex_branch_addrtarget;
111 10 unneback
output  [`OR1200_SEL_WIDTH-1:0]          sel_a;
112
output  [`OR1200_SEL_WIDTH-1:0]          sel_b;
113 141 marcus.erl
output  [`OR1200_LSUOP_WIDTH-1:0]                id_lsu_op;
114 10 unneback
output  [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
115
output  [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
116 258 julius
output  [`OR1200_WAIT_ON_WIDTH-1:0]              wait_on;
117 10 unneback
output  [4:0]                            cust5_op;
118
output  [5:0]                            cust5_limm;
119 141 marcus.erl
input   [31:0]                          id_pc;
120
input   [31:0]                          ex_pc;
121
output  [31:0]                           id_simm;
122
output  [31:0]                           ex_simm;
123 10 unneback
input                                   wbforw_valid;
124
input                                   du_hwbkpt;
125
output                                  sig_syscall;
126
output                                  sig_trap;
127
output                                  force_dslot_fetch;
128
output                                  no_more_dslot;
129 141 marcus.erl
output                                  id_void;
130 10 unneback
output                                  ex_void;
131 141 marcus.erl
output                                  ex_spr_read;
132
output                                  ex_spr_write;
133
output  [`OR1200_MACOP_WIDTH-1:0]        id_mac_op;
134 10 unneback
output                                  id_macrc_op;
135
output                                  ex_macrc_op;
136
output                                  rfe;
137
output                                  except_illegal;
138 258 julius
output                                  dc_no_writethrough;
139
 
140
 
141 10 unneback
//
142
// Internal wires and regs
143
//
144 141 marcus.erl
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             id_branch_op;
145
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             ex_branch_op;
146 10 unneback
reg     [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
147 401 julius
reg [`OR1200_ALUOP2_WIDTH-1:0]                   alu_op2;
148 141 marcus.erl
wire                                    if_maci_op;
149 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
150 141 marcus.erl
reg     [`OR1200_MACOP_WIDTH-1:0]                ex_mac_op;
151
reg     [`OR1200_MACOP_WIDTH-1:0]                id_mac_op;
152
wire    [`OR1200_MACOP_WIDTH-1:0]                mac_op;
153 10 unneback
reg                                     ex_macrc_op;
154
`else
155
wire    [`OR1200_MACOP_WIDTH-1:0]                mac_op;
156
wire                                    ex_macrc_op;
157
`endif
158 353 julius
reg     [31:0]                           id_insn /* verilator public */;
159
reg     [31:0]                           ex_insn /* verilator public */;
160
reg     [31:0]                           wb_insn /* verilator public */;
161 10 unneback
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
162
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] wb_rfaddrw;
163
reg     [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
164
reg     [`OR1200_SEL_WIDTH-1:0]          sel_a;
165
reg     [`OR1200_SEL_WIDTH-1:0]          sel_b;
166
reg                                     sel_imm;
167 141 marcus.erl
reg     [`OR1200_LSUOP_WIDTH-1:0]                id_lsu_op;
168 10 unneback
reg     [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
169
reg     [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
170 258 julius
reg     [`OR1200_WAIT_ON_WIDTH-1:0]              wait_on;
171 141 marcus.erl
reg     [31:0]                           id_simm;
172
reg     [31:0]                           ex_simm;
173 10 unneback
reg                                     sig_syscall;
174
reg                                     sig_trap;
175
reg                                     except_illegal;
176
wire                                    id_void;
177 141 marcus.erl
wire                                    ex_void;
178
wire                                    wb_void;
179
reg                                     ex_delayslot_dsi;
180
reg                                     ex_delayslot_nop;
181
reg                                     spr_read;
182
reg                                     spr_write;
183
reg     [31:2]                          ex_branch_addrtarget;
184 258 julius
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
185
reg                                     dc_no_writethrough;
186
`endif
187
 
188 10 unneback
//
189
// Register file read addresses
190
//
191
assign rf_addra = if_insn[20:16];
192
assign rf_addrb = if_insn[15:11];
193 141 marcus.erl
assign rf_rda = if_insn[31] || if_maci_op;
194 10 unneback
assign rf_rdb = if_insn[30];
195
 
196
//
197 640 julius
// Force fetch of delay slot instruction when jump/branch is preceeded by 
198
// load/store instructions
199 10 unneback
//
200
assign force_dslot_fetch = 1'b0;
201 640 julius
assign no_more_dslot = (|ex_branch_op & !id_void & ex_branch_taken) |
202
                       (ex_branch_op == `OR1200_BRANCHOP_RFE);
203 141 marcus.erl
 
204 10 unneback
assign id_void = (id_insn[31:26] == `OR1200_OR32_NOP) & id_insn[16];
205
assign ex_void = (ex_insn[31:26] == `OR1200_OR32_NOP) & ex_insn[16];
206 141 marcus.erl
assign wb_void = (wb_insn[31:26] == `OR1200_OR32_NOP) & wb_insn[16];
207 10 unneback
 
208 141 marcus.erl
assign ex_spr_write = spr_write && !abort_mvspr;
209
assign ex_spr_read = spr_read && !abort_mvspr;
210
 
211 10 unneback
//
212 141 marcus.erl
// ex_delayslot_dsi: delay slot insn is in EX stage
213 640 julius
// ex_delayslot_nop: (filler) nop insn is in EX stage (before nops 
214
//                   jump/branch was executed)
215 10 unneback
//
216 141 marcus.erl
//  ex_delayslot_dsi & !ex_delayslot_nop - DS insn in EX stage
217
//  !ex_delayslot_dsi & ex_delayslot_nop - NOP insn in EX stage, 
218
//       next different is DS insn, previous different was Jump/Branch
219
//  !ex_delayslot_dsi & !ex_delayslot_nop - normal insn in EX stage
220
//
221 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
222
        if (rst == `OR1200_RST_VALUE) begin
223 258 julius
                ex_delayslot_nop <=  1'b0;
224
                ex_delayslot_dsi <=  1'b0;
225 141 marcus.erl
        end
226
        else if (!ex_freeze & !ex_delayslot_dsi & ex_delayslot_nop) begin
227 258 julius
                ex_delayslot_nop <=  id_void;
228
                ex_delayslot_dsi <=  !id_void;
229 141 marcus.erl
        end
230
        else if (!ex_freeze & ex_delayslot_dsi & !ex_delayslot_nop) begin
231 258 julius
                ex_delayslot_nop <=  1'b0;
232
                ex_delayslot_dsi <=  1'b0;
233 141 marcus.erl
        end
234
        else if (!ex_freeze) begin
235 640 julius
                ex_delayslot_nop <=  id_void && ex_branch_taken &&
236
                                     (ex_branch_op != `OR1200_BRANCHOP_NOP) &&
237
                                     (ex_branch_op != `OR1200_BRANCHOP_RFE);
238
                ex_delayslot_dsi <=  !id_void && ex_branch_taken &&
239
                                     (ex_branch_op != `OR1200_BRANCHOP_NOP) &&
240
                                     (ex_branch_op != `OR1200_BRANCHOP_RFE);
241 141 marcus.erl
        end
242
end
243 10 unneback
 
244
//
245 141 marcus.erl
// Flush pipeline
246 10 unneback
//
247 141 marcus.erl
assign if_flushpipe = except_flushpipe | pc_we | extend_flush;
248
assign id_flushpipe = except_flushpipe | pc_we | extend_flush;
249
assign ex_flushpipe = except_flushpipe | pc_we | extend_flush;
250
assign wb_flushpipe = except_flushpipe | pc_we | extend_flush;
251 10 unneback
 
252
//
253 141 marcus.erl
// EX Sign/Zero extension of immediates
254
//
255 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
256
        if (rst == `OR1200_RST_VALUE)
257 258 julius
                ex_simm <=  32'h0000_0000;
258 141 marcus.erl
        else if (!ex_freeze) begin
259 258 julius
                ex_simm <=  id_simm;
260 141 marcus.erl
        end
261
end
262
 
263
//
264
// ID Sign/Zero extension of immediate
265
//
266
always @(id_insn) begin
267
        case (id_insn[31:26])     // synopsys parallel_case
268
 
269
        // l.addi
270
        `OR1200_OR32_ADDI:
271
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
272
 
273
        // l.addic
274
        `OR1200_OR32_ADDIC:
275
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
276
 
277
        // l.lxx (load instructions)
278 640 julius
        `OR1200_OR32_LWZ, `OR1200_OR32_LBZ, `OR1200_OR32_LBS,
279
        `OR1200_OR32_LHZ, `OR1200_OR32_LHS:
280 141 marcus.erl
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
281
 
282
        // l.muli
283
        `ifdef OR1200_MULT_IMPLEMENTED
284
        `OR1200_OR32_MULI:
285
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
286
        `endif
287
 
288
        // l.maci
289
        `ifdef OR1200_MAC_IMPLEMENTED
290
        `OR1200_OR32_MACI:
291 640 julius
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
292 141 marcus.erl
        `endif
293
 
294
        // l.mtspr
295
        `OR1200_OR32_MTSPR:
296
                id_simm = {16'b0, id_insn[25:21], id_insn[10:0]};
297
 
298
        // l.sxx (store instructions)
299
        `OR1200_OR32_SW, `OR1200_OR32_SH, `OR1200_OR32_SB:
300
                id_simm = {{16{id_insn[25]}}, id_insn[25:21], id_insn[10:0]};
301
 
302
        // l.xori
303
        `OR1200_OR32_XORI:
304
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
305
 
306
        // l.sfxxi (SFXX with immediate)
307
        `OR1200_OR32_SFXXI:
308
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
309
 
310
        // Instructions with no or zero extended immediate
311
        default:
312
                id_simm = {{16'b0}, id_insn[15:0]};
313
 
314
        endcase
315
end
316
 
317
//
318
// ID Sign extension of branch offset
319
//
320
assign id_branch_addrtarget = {{4{id_insn[25]}}, id_insn[25:0]} + id_pc[31:2];
321
 
322
//
323
// EX Sign extension of branch offset
324
//
325
 
326
// pipeline ID and EX branch target address 
327 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
328
        if (rst == `OR1200_RST_VALUE)
329 364 julius
                ex_branch_addrtarget <=  0;
330 141 marcus.erl
        else if (!ex_freeze)
331 258 julius
                ex_branch_addrtarget <=  id_branch_addrtarget;
332 141 marcus.erl
end
333
// not pipelined
334
//assign ex_branch_addrtarget = {{4{ex_insn[25]}}, ex_insn[25:0]} + ex_pc[31:2];
335
 
336
//
337
// l.maci in IF stage
338
//
339
`ifdef OR1200_MAC_IMPLEMENTED
340
assign if_maci_op = (if_insn[31:26] == `OR1200_OR32_MACI);
341
`else
342
assign if_maci_op = 1'b0;
343
`endif
344
 
345
//
346 10 unneback
// l.macrc in ID stage
347
//
348
`ifdef OR1200_MAC_IMPLEMENTED
349 640 julius
assign id_macrc_op = (id_insn[31:26] == `OR1200_OR32_MACRC) & id_insn[16];
350 10 unneback
`else
351
assign id_macrc_op = 1'b0;
352
`endif
353
 
354
//
355 141 marcus.erl
// l.macrc in EX stage
356
//
357
`ifdef OR1200_MAC_IMPLEMENTED
358 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
359
        if (rst == `OR1200_RST_VALUE)
360 258 julius
                ex_macrc_op <=  1'b0;
361 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
362 258 julius
                ex_macrc_op <=  1'b0;
363 141 marcus.erl
        else if (!ex_freeze)
364 258 julius
                ex_macrc_op <=  id_macrc_op;
365 141 marcus.erl
end
366
`else
367
assign ex_macrc_op = 1'b0;
368
`endif
369
 
370
//
371 10 unneback
// cust5_op, cust5_limm (L immediate)
372
//
373
assign cust5_op = ex_insn[4:0];
374
assign cust5_limm = ex_insn[10:5];
375
 
376
//
377
//
378
//
379 640 julius
assign rfe = (id_branch_op == `OR1200_BRANCHOP_RFE) |
380
             (ex_branch_op == `OR1200_BRANCHOP_RFE);
381 10 unneback
 
382 353 julius
 
383
`ifdef verilator
384
   // Function to access wb_insn (for Verilator). Have to hide this from
385
   // simulator, since functions with no inputs are not allowed in IEEE
386
   // 1364-2001.
387
   function [31:0] get_wb_insn;
388
      // verilator public
389
      get_wb_insn = wb_insn;
390
   endfunction // get_wb_insn
391
 
392
   // Function to access id_insn (for Verilator). Have to hide this from
393
   // simulator, since functions with no inputs are not allowed in IEEE
394
   // 1364-2001.
395
   function [31:0] get_id_insn;
396
      // verilator public
397
      get_id_insn = id_insn;
398
   endfunction // get_id_insn
399
 
400
   // Function to access ex_insn (for Verilator). Have to hide this from
401
   // simulator, since functions with no inputs are not allowed in IEEE
402
   // 1364-2001.
403
   function [31:0] get_ex_insn;
404
      // verilator public
405
      get_ex_insn = ex_insn;
406
   endfunction // get_ex_insn
407
 
408
`endif
409
 
410
 
411 10 unneback
//
412
// Generation of sel_a
413
//
414
always @(rf_addrw or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
415
        if ((id_insn[20:16] == rf_addrw) && rfwb_op[0])
416
                sel_a = `OR1200_SEL_EX_FORW;
417
        else if ((id_insn[20:16] == wb_rfaddrw) && wbforw_valid)
418
                sel_a = `OR1200_SEL_WB_FORW;
419
        else
420
                sel_a = `OR1200_SEL_RF;
421
 
422
//
423
// Generation of sel_b
424
//
425 640 julius
always @(rf_addrw or sel_imm or id_insn or rfwb_op or wbforw_valid or
426
         wb_rfaddrw)
427 10 unneback
        if (sel_imm)
428
                sel_b = `OR1200_SEL_IMM;
429
        else if ((id_insn[15:11] == rf_addrw) && rfwb_op[0])
430
                sel_b = `OR1200_SEL_EX_FORW;
431
        else if ((id_insn[15:11] == wb_rfaddrw) && wbforw_valid)
432
                sel_b = `OR1200_SEL_WB_FORW;
433
        else
434
                sel_b = `OR1200_SEL_RF;
435
 
436
//
437
// Decode of multicycle
438
//
439
always @(id_insn) begin
440
  case (id_insn[31:26])         // synopsys parallel_case
441 644 julius
    // l.rfe
442
    `OR1200_OR32_RFE,
443 141 marcus.erl
    // l.mfspr
444
    `OR1200_OR32_MFSPR:
445
      multicycle = `OR1200_TWO_CYCLES;  // to read from ITLB/DTLB (sync RAMs)
446 10 unneback
    // Single cycle instructions
447
    default: begin
448
      multicycle = `OR1200_ONE_CYCLE;
449 258 julius
    end
450 10 unneback
  endcase
451 258 julius
end // always @ (id_insn)
452 10 unneback
 
453
//
454 258 julius
// Encode wait_on signal
455
//    
456
always @(id_insn) begin
457
   case (id_insn[31:26])                // synopsys parallel_case
458 640 julius
     `OR1200_OR32_ALU:
459
       wait_on =  ( 1'b0
460
`ifdef OR1200_DIV_IMPLEMENTED
461
                     | (id_insn[4:0] == `OR1200_ALUOP_DIV)
462
                     | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
463
`endif
464
`ifdef OR1200_MULT_IMPLEMENTED
465
                     | (id_insn[4:0] == `OR1200_ALUOP_MUL)
466
                     | (id_insn[4:0] == `OR1200_ALUOP_MULU)
467
`endif
468
                    ) ? `OR1200_WAIT_ON_MULTMAC : `OR1200_WAIT_ON_NOTHING;
469
`ifdef OR1200_MULT_IMPLEMENTED
470
`ifdef OR1200_MAC_IMPLEMENTED
471
     `OR1200_OR32_MACMSB,
472
     `OR1200_OR32_MACI,
473
`endif
474
     `OR1200_OR32_MULI:
475
         wait_on = `OR1200_WAIT_ON_MULTMAC;
476
`endif
477
`ifdef OR1200_MAC_IMPLEMENTED
478
     `OR1200_OR32_MACRC:
479
         wait_on = id_insn[16] ? `OR1200_WAIT_ON_MULTMAC :
480
                                 `OR1200_WAIT_ON_NOTHING;
481
`endif
482 258 julius
`ifdef OR1200_FPU_IMPLEMENTED
483
       `OR1200_OR32_FLOAT: begin
484
         wait_on = id_insn[`OR1200_FPUOP_DOUBLE_BIT] ? 0 : `OR1200_WAIT_ON_FPU;
485
       end
486
`endif
487 640 julius
`ifndef OR1200_DC_WRITEHROUGH
488 258 julius
     // l.mtspr
489
     `OR1200_OR32_MTSPR: begin
490
        wait_on = `OR1200_WAIT_ON_MTSPR;
491
     end
492
`endif
493
     default: begin
494 640 julius
        wait_on = `OR1200_WAIT_ON_NOTHING;
495 258 julius
     end
496
   endcase // case (id_insn[31:26])
497
end // always @ (id_insn)
498
 
499
 
500
 
501
 
502
//
503 10 unneback
// Register file write address
504
//
505 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
506
        if (rst == `OR1200_RST_VALUE)
507 258 julius
                rf_addrw <=  5'd0;
508 10 unneback
        else if (!ex_freeze & id_freeze)
509 258 julius
                rf_addrw <=  5'd00;
510 10 unneback
        else if (!ex_freeze)
511 141 marcus.erl
                case (id_insn[31:26])   // synopsys parallel_case
512
                        `OR1200_OR32_JAL, `OR1200_OR32_JALR:
513 258 julius
                                rf_addrw <=  5'd09;     // link register r9
514 10 unneback
                        default:
515 258 julius
                                rf_addrw <=  id_insn[25:21];
516 10 unneback
                endcase
517
end
518
 
519
//
520
// rf_addrw in wb stage (used in forwarding logic)
521
//
522 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
523
        if (rst == `OR1200_RST_VALUE)
524 258 julius
                wb_rfaddrw <=  5'd0;
525 10 unneback
        else if (!wb_freeze)
526 258 julius
                wb_rfaddrw <=  rf_addrw;
527 10 unneback
end
528
 
529
//
530
// Instruction latch in id_insn
531
//
532 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
533
        if (rst == `OR1200_RST_VALUE)
534 258 julius
                id_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
535 141 marcus.erl
        else if (id_flushpipe)
536 258 julius
                id_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};        // NOP -> id_insn[16] must be 1
537 10 unneback
        else if (!id_freeze) begin
538 258 julius
                id_insn <=  if_insn;
539 10 unneback
`ifdef OR1200_VERBOSE
540
// synopsys translate_off
541
                $display("%t: id_insn <= %h", $time, if_insn);
542
// synopsys translate_on
543
`endif
544
        end
545
end
546
 
547
//
548
// Instruction latch in ex_insn
549
//
550 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
551
        if (rst == `OR1200_RST_VALUE)
552 258 julius
                ex_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
553 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
554 258 julius
                ex_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};   // NOP -> ex_insn[16] must be 1
555 10 unneback
        else if (!ex_freeze) begin
556 258 julius
                ex_insn <=  id_insn;
557 10 unneback
`ifdef OR1200_VERBOSE
558
// synopsys translate_off
559
                $display("%t: ex_insn <= %h", $time, id_insn);
560
// synopsys translate_on
561
`endif
562
        end
563
end
564 258 julius
 
565 10 unneback
//
566
// Instruction latch in wb_insn
567
//
568 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
569
        if (rst == `OR1200_RST_VALUE)
570 258 julius
                wb_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
571 141 marcus.erl
        // wb_insn should not be changed by exceptions due to correct 
572
        // recording of display_arch_state in the or1200_monitor! 
573
        // wb_insn changed by exception is not used elsewhere! 
574 10 unneback
        else if (!wb_freeze) begin
575 258 julius
                wb_insn <=  ex_insn;
576 10 unneback
        end
577
end
578
 
579
//
580
// Decode of sel_imm
581
//
582 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
583
        if (rst == `OR1200_RST_VALUE)
584 258 julius
                sel_imm <=  1'b0;
585 10 unneback
        else if (!id_freeze) begin
586
          case (if_insn[31:26])         // synopsys parallel_case
587
 
588
            // j.jalr
589
            `OR1200_OR32_JALR:
590 258 julius
              sel_imm <=  1'b0;
591 10 unneback
 
592
            // l.jr
593
            `OR1200_OR32_JR:
594 258 julius
              sel_imm <=  1'b0;
595 10 unneback
 
596
            // l.rfe
597
            `OR1200_OR32_RFE:
598 258 julius
              sel_imm <=  1'b0;
599 10 unneback
 
600
            // l.mfspr
601
            `OR1200_OR32_MFSPR:
602 258 julius
              sel_imm <=  1'b0;
603 10 unneback
 
604
            // l.mtspr
605
            `OR1200_OR32_MTSPR:
606 258 julius
              sel_imm <=  1'b0;
607 10 unneback
 
608
            // l.sys, l.brk and all three sync insns
609
            `OR1200_OR32_XSYNC:
610 258 julius
              sel_imm <=  1'b0;
611 10 unneback
 
612
            // l.mac/l.msb
613
`ifdef OR1200_MAC_IMPLEMENTED
614
            `OR1200_OR32_MACMSB:
615 258 julius
              sel_imm <=  1'b0;
616 10 unneback
`endif
617
 
618
            // l.sw
619
            `OR1200_OR32_SW:
620 258 julius
              sel_imm <=  1'b0;
621 10 unneback
 
622
            // l.sb
623
            `OR1200_OR32_SB:
624 258 julius
              sel_imm <=  1'b0;
625 10 unneback
 
626
            // l.sh
627
            `OR1200_OR32_SH:
628 258 julius
              sel_imm <=  1'b0;
629 10 unneback
 
630
            // ALU instructions except the one with immediate
631
            `OR1200_OR32_ALU:
632 258 julius
              sel_imm <=  1'b0;
633 10 unneback
 
634
            // SFXX instructions
635
            `OR1200_OR32_SFXX:
636 258 julius
              sel_imm <=  1'b0;
637 10 unneback
 
638 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
639 10 unneback
            // l.cust5 instructions
640
            `OR1200_OR32_CUST5:
641 258 julius
              sel_imm <=  1'b0;
642 10 unneback
`endif
643 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
644
            // FPU instructions
645
            `OR1200_OR32_FLOAT:
646 258 julius
              sel_imm <=  1'b0;
647 185 julius
`endif
648 10 unneback
            // l.nop
649
            `OR1200_OR32_NOP:
650 258 julius
              sel_imm <=  1'b0;
651 10 unneback
 
652
            // All instructions with immediates
653
            default: begin
654 258 julius
              sel_imm <=  1'b1;
655 10 unneback
            end
656
 
657
          endcase
658
 
659
        end
660
end
661
 
662
//
663
// Decode of except_illegal
664
//
665 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
666
        if (rst == `OR1200_RST_VALUE)
667 258 julius
                except_illegal <=  1'b0;
668 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
669 258 julius
                except_illegal <=  1'b0;
670 10 unneback
        else if (!ex_freeze) begin
671 141 marcus.erl
                case (id_insn[31:26])           // synopsys parallel_case
672 10 unneback
 
673 141 marcus.erl
                `OR1200_OR32_J,
674
                `OR1200_OR32_JAL,
675
                `OR1200_OR32_JALR,
676
                `OR1200_OR32_JR,
677
                `OR1200_OR32_BNF,
678
                `OR1200_OR32_BF,
679
                `OR1200_OR32_RFE,
680
                `OR1200_OR32_MOVHI,
681
                `OR1200_OR32_MFSPR,
682
                `OR1200_OR32_XSYNC,
683 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
684 141 marcus.erl
                `OR1200_OR32_MACI,
685 10 unneback
`endif
686 141 marcus.erl
                `OR1200_OR32_LWZ,
687
                `OR1200_OR32_LBZ,
688
                `OR1200_OR32_LBS,
689
                `OR1200_OR32_LHZ,
690
                `OR1200_OR32_LHS,
691
                `OR1200_OR32_ADDI,
692
                `OR1200_OR32_ADDIC,
693
                `OR1200_OR32_ANDI,
694
                `OR1200_OR32_ORI,
695
                `OR1200_OR32_XORI,
696 10 unneback
`ifdef OR1200_MULT_IMPLEMENTED
697 141 marcus.erl
                `OR1200_OR32_MULI,
698 10 unneback
`endif
699 141 marcus.erl
                `OR1200_OR32_SH_ROTI,
700
                `OR1200_OR32_SFXXI,
701
                `OR1200_OR32_MTSPR,
702 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
703 141 marcus.erl
                `OR1200_OR32_MACMSB,
704 10 unneback
`endif
705 141 marcus.erl
                `OR1200_OR32_SW,
706
                `OR1200_OR32_SB,
707
                `OR1200_OR32_SH,
708
                `OR1200_OR32_SFXX,
709 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
710 141 marcus.erl
                `OR1200_OR32_CUST5,
711 10 unneback
`endif
712 141 marcus.erl
        `OR1200_OR32_NOP:
713 364 julius
                except_illegal <=  1'b0;
714 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
715
            `OR1200_OR32_FLOAT:
716 364 julius
                // Check it's not a double precision instruction
717
                except_illegal <=  id_insn[`OR1200_FPUOP_DOUBLE_BIT];
718 185 julius
`endif
719 10 unneback
 
720 141 marcus.erl
        `OR1200_OR32_ALU:
721 364 julius
                except_illegal <=  1'b0
722 10 unneback
 
723 141 marcus.erl
`ifdef OR1200_MULT_IMPLEMENTED
724 258 julius
`ifdef OR1200_DIV_IMPLEMENTED
725 141 marcus.erl
`else
726 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
727
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
728 141 marcus.erl
`endif
729
`else
730 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
731
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
732
                | (id_insn[4:0] == `OR1200_ALUOP_MUL)
733 141 marcus.erl
`endif
734
 
735
`ifdef OR1200_IMPL_ADDC
736
`else
737 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_ADDC)
738 141 marcus.erl
`endif
739
 
740 401 julius
`ifdef OR1200_IMPL_ALU_FFL1
741
`else
742 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_FFL1)
743 401 julius
`endif
744
 
745 141 marcus.erl
`ifdef OR1200_IMPL_ALU_ROTATE
746
`else
747 640 julius
                | ((id_insn[4:0] == `OR1200_ALUOP_SHROT) &
748
                   (id_insn[9:6] == `OR1200_SHROTOP_ROR))
749 141 marcus.erl
`endif
750
 
751
`ifdef OR1200_IMPL_SUB
752
`else
753 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_SUB)
754 141 marcus.erl
`endif
755 640 julius
`ifdef OR1200_IMPL_ALU_EXT
756
`else
757
                | (id_insn[4:0] == `OR1200_ALUOP_EXTHB)
758
                | (id_insn[4:0] == `OR1200_ALUOP_EXTW)
759
`endif
760 364 julius
                ;
761 141 marcus.erl
 
762
                // Illegal and OR1200 unsupported instructions
763 364 julius
        default:
764
                except_illegal <=  1'b1;
765 141 marcus.erl
 
766 364 julius
        endcase
767
        end // if (!ex_freeze)
768 10 unneback
end
769 364 julius
 
770 10 unneback
 
771
//
772
// Decode of alu_op
773
//
774 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
775
        if (rst == `OR1200_RST_VALUE)
776 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
777 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
778 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
779 10 unneback
        else if (!ex_freeze) begin
780
          case (id_insn[31:26])         // synopsys parallel_case
781
 
782
            // l.movhi
783
            `OR1200_OR32_MOVHI:
784 258 julius
              alu_op <=  `OR1200_ALUOP_MOVHI;
785 10 unneback
 
786
            // l.addi
787
            `OR1200_OR32_ADDI:
788 258 julius
              alu_op <=  `OR1200_ALUOP_ADD;
789 10 unneback
 
790
            // l.addic
791
            `OR1200_OR32_ADDIC:
792 258 julius
              alu_op <=  `OR1200_ALUOP_ADDC;
793 10 unneback
 
794
            // l.andi
795
            `OR1200_OR32_ANDI:
796 258 julius
              alu_op <=  `OR1200_ALUOP_AND;
797 10 unneback
 
798
            // l.ori
799
            `OR1200_OR32_ORI:
800 258 julius
              alu_op <=  `OR1200_ALUOP_OR;
801 10 unneback
 
802
            // l.xori
803
            `OR1200_OR32_XORI:
804 258 julius
              alu_op <=  `OR1200_ALUOP_XOR;
805 10 unneback
 
806
            // l.muli
807
`ifdef OR1200_MULT_IMPLEMENTED
808
            `OR1200_OR32_MULI:
809 258 julius
              alu_op <=  `OR1200_ALUOP_MUL;
810 10 unneback
`endif
811
 
812
            // Shift and rotate insns with immediate
813
            `OR1200_OR32_SH_ROTI:
814 258 julius
              alu_op <=  `OR1200_ALUOP_SHROT;
815 10 unneback
 
816
            // SFXX insns with immediate
817
            `OR1200_OR32_SFXXI:
818 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
819 10 unneback
 
820
            // ALU instructions except the one with immediate
821
            `OR1200_OR32_ALU:
822 640 julius
              alu_op <=  {1'b0,id_insn[3:0]};
823 10 unneback
 
824
            // SFXX instructions
825
            `OR1200_OR32_SFXX:
826 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
827 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
828
            // l.cust5
829 10 unneback
            `OR1200_OR32_CUST5:
830 258 julius
              alu_op <=  `OR1200_ALUOP_CUST5;
831 640 julius
`endif
832 10 unneback
            // Default
833
            default: begin
834 258 julius
              alu_op <=  `OR1200_ALUOP_NOP;
835 10 unneback
            end
836
 
837
          endcase
838
 
839
        end
840
end
841
 
842 401 julius
 
843 10 unneback
//
844 640 julius
// Decode of second ALU operation field [9:6]
845 401 julius
//
846
always @(posedge clk or `OR1200_RST_EVENT rst) begin
847
        if (rst == `OR1200_RST_VALUE)
848
                alu_op2 <=  0;
849
        else if (!ex_freeze & id_freeze | ex_flushpipe)
850
                alu_op2 <= 0;
851
        else if (!ex_freeze) begin
852
                alu_op2 <=  id_insn[`OR1200_ALUOP2_POS];
853
        end
854
end
855
 
856
//
857 141 marcus.erl
// Decode of spr_read, spr_write
858
//
859 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
860
        if (rst == `OR1200_RST_VALUE) begin
861 258 julius
                spr_read <=  1'b0;
862
                spr_write <=  1'b0;
863 141 marcus.erl
        end
864
        else if (!ex_freeze & id_freeze | ex_flushpipe) begin
865 258 julius
                spr_read <=  1'b0;
866
                spr_write <=  1'b0;
867 141 marcus.erl
        end
868
        else if (!ex_freeze) begin
869
                case (id_insn[31:26])     // synopsys parallel_case
870
 
871
                // l.mfspr
872
                `OR1200_OR32_MFSPR: begin
873 258 julius
                        spr_read <=  1'b1;
874
                        spr_write <=  1'b0;
875 141 marcus.erl
                end
876
 
877
                // l.mtspr
878
                `OR1200_OR32_MTSPR: begin
879 258 julius
                        spr_read <=  1'b0;
880
                        spr_write <=  1'b1;
881 141 marcus.erl
                end
882
 
883
                // Default
884
                default: begin
885 258 julius
                        spr_read <=  1'b0;
886
                        spr_write <=  1'b0;
887 141 marcus.erl
                end
888
 
889
                endcase
890
        end
891
end
892
 
893
//
894 10 unneback
// Decode of mac_op
895
//
896
`ifdef OR1200_MAC_IMPLEMENTED
897 141 marcus.erl
always @(id_insn) begin
898
        case (id_insn[31:26])           // synopsys parallel_case
899 10 unneback
 
900 141 marcus.erl
        // l.maci
901
        `OR1200_OR32_MACI:
902 353 julius
                id_mac_op =  `OR1200_MACOP_MAC;
903 10 unneback
 
904 141 marcus.erl
        // l.mac, l.msb
905
        `OR1200_OR32_MACMSB:
906 353 julius
                id_mac_op =  id_insn[2:0];
907 10 unneback
 
908 141 marcus.erl
        // Illegal and OR1200 unsupported instructions
909
        default:
910 353 julius
                id_mac_op =  `OR1200_MACOP_NOP;
911 10 unneback
 
912 141 marcus.erl
        endcase
913 10 unneback
end
914 141 marcus.erl
 
915 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
916
        if (rst == `OR1200_RST_VALUE)
917 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
918 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
919 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
920 141 marcus.erl
        else if (!ex_freeze)
921 258 julius
                ex_mac_op <=  id_mac_op;
922 141 marcus.erl
end
923
 
924
assign mac_op = abort_mvspr ? `OR1200_MACOP_NOP : ex_mac_op;
925 10 unneback
`else
926 141 marcus.erl
assign id_mac_op = `OR1200_MACOP_NOP;
927 10 unneback
assign mac_op = `OR1200_MACOP_NOP;
928
`endif
929
 
930
 
931
//
932
// Decode of rfwb_op
933
//
934 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
935
        if (rst == `OR1200_RST_VALUE)
936 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
937 141 marcus.erl
        else  if (!ex_freeze & id_freeze | ex_flushpipe)
938 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
939 10 unneback
        else  if (!ex_freeze) begin
940
                case (id_insn[31:26])           // synopsys parallel_case
941
 
942 141 marcus.erl
                // j.jal
943
                `OR1200_OR32_JAL:
944 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
945 10 unneback
 
946 141 marcus.erl
                // j.jalr
947
                `OR1200_OR32_JALR:
948 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
949 10 unneback
 
950 141 marcus.erl
                // l.movhi
951
                `OR1200_OR32_MOVHI:
952 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
953 10 unneback
 
954 141 marcus.erl
                // l.mfspr
955
                `OR1200_OR32_MFSPR:
956 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_SPRS, 1'b1};
957 10 unneback
 
958 141 marcus.erl
                // l.lwz
959
                `OR1200_OR32_LWZ:
960 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
961 10 unneback
 
962 141 marcus.erl
                // l.lbz
963
                `OR1200_OR32_LBZ:
964 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
965 10 unneback
 
966 141 marcus.erl
                // l.lbs
967
                `OR1200_OR32_LBS:
968 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
969 10 unneback
 
970 141 marcus.erl
                // l.lhz
971
                `OR1200_OR32_LHZ:
972 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
973 10 unneback
 
974 141 marcus.erl
                // l.lhs
975
                `OR1200_OR32_LHS:
976 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
977 10 unneback
 
978 141 marcus.erl
                // l.addi
979
                `OR1200_OR32_ADDI:
980 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
981 10 unneback
 
982 141 marcus.erl
                // l.addic
983
                `OR1200_OR32_ADDIC:
984 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
985 10 unneback
 
986 141 marcus.erl
                // l.andi
987
                `OR1200_OR32_ANDI:
988 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
989 10 unneback
 
990 141 marcus.erl
                // l.ori
991
                `OR1200_OR32_ORI:
992 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
993 10 unneback
 
994 141 marcus.erl
                // l.xori
995
                `OR1200_OR32_XORI:
996 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
997 10 unneback
 
998 141 marcus.erl
                // l.muli
999 10 unneback
`ifdef OR1200_MULT_IMPLEMENTED
1000 141 marcus.erl
                `OR1200_OR32_MULI:
1001 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1002 10 unneback
`endif
1003
 
1004 141 marcus.erl
                // Shift and rotate insns with immediate
1005
                `OR1200_OR32_SH_ROTI:
1006 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1007 10 unneback
 
1008 141 marcus.erl
                // ALU instructions except the one with immediate
1009
                `OR1200_OR32_ALU:
1010 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1011 10 unneback
 
1012 640 julius
`ifdef OR1200_ALU_IMPL_CUST5
1013 141 marcus.erl
                // l.cust5 instructions
1014
                `OR1200_OR32_CUST5:
1015 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1016 10 unneback
`endif
1017 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1018
                  // FPU instructions, lf.XXX.s, except sfxx
1019
                  `OR1200_OR32_FLOAT:
1020 258 julius
                    rfwb_op <=  {`OR1200_RFWBOP_FPU,!id_insn[3]};
1021 185 julius
`endif
1022 141 marcus.erl
                // Instructions w/o register-file write-back
1023
                default:
1024 258 julius
                        rfwb_op <=  `OR1200_RFWBOP_NOP;
1025 10 unneback
 
1026 141 marcus.erl
 
1027 10 unneback
                endcase
1028
        end
1029
end
1030
 
1031
//
1032 141 marcus.erl
// Decode of id_branch_op
1033 10 unneback
//
1034 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1035
        if (rst == `OR1200_RST_VALUE)
1036 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1037 141 marcus.erl
        else if (id_flushpipe)
1038 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1039 10 unneback
        else if (!id_freeze) begin
1040
                case (if_insn[31:26])           // synopsys parallel_case
1041 141 marcus.erl
 
1042
                // l.j
1043
                `OR1200_OR32_J:
1044 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1045 10 unneback
 
1046 141 marcus.erl
                // j.jal
1047
                `OR1200_OR32_JAL:
1048 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1049 10 unneback
 
1050 141 marcus.erl
                // j.jalr
1051
                `OR1200_OR32_JALR:
1052 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1053 10 unneback
 
1054 141 marcus.erl
                // l.jr
1055
                `OR1200_OR32_JR:
1056 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1057 10 unneback
 
1058 141 marcus.erl
                // l.bnf
1059
                `OR1200_OR32_BNF:
1060 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BNF;
1061 10 unneback
 
1062 141 marcus.erl
                // l.bf
1063
                `OR1200_OR32_BF:
1064 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BF;
1065 10 unneback
 
1066 141 marcus.erl
                // l.rfe
1067
                `OR1200_OR32_RFE:
1068 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_RFE;
1069 10 unneback
 
1070 141 marcus.erl
                // Non branch instructions
1071
                default:
1072 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_NOP;
1073 141 marcus.erl
 
1074 10 unneback
                endcase
1075
        end
1076
end
1077
 
1078
//
1079 141 marcus.erl
// Generation of ex_branch_op
1080 10 unneback
//
1081 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
1082
        if (rst == `OR1200_RST_VALUE)
1083 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1084 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1085 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1086 10 unneback
        else if (!ex_freeze)
1087 258 julius
                ex_branch_op <=  id_branch_op;
1088 10 unneback
 
1089
//
1090 141 marcus.erl
// Decode of id_lsu_op
1091 10 unneback
//
1092 141 marcus.erl
always @(id_insn) begin
1093
        case (id_insn[31:26])           // synopsys parallel_case
1094
 
1095
        // l.lwz
1096
        `OR1200_OR32_LWZ:
1097 353 julius
                id_lsu_op =  `OR1200_LSUOP_LWZ;
1098 141 marcus.erl
 
1099
        // l.lbz
1100
        `OR1200_OR32_LBZ:
1101 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBZ;
1102 141 marcus.erl
 
1103
        // l.lbs
1104
        `OR1200_OR32_LBS:
1105 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBS;
1106 141 marcus.erl
 
1107
        // l.lhz
1108
        `OR1200_OR32_LHZ:
1109 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHZ;
1110 141 marcus.erl
 
1111
        // l.lhs
1112
        `OR1200_OR32_LHS:
1113 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHS;
1114 141 marcus.erl
 
1115
        // l.sw
1116
        `OR1200_OR32_SW:
1117 353 julius
                id_lsu_op =  `OR1200_LSUOP_SW;
1118 141 marcus.erl
 
1119
        // l.sb
1120
        `OR1200_OR32_SB:
1121 353 julius
                id_lsu_op =  `OR1200_LSUOP_SB;
1122 141 marcus.erl
 
1123
        // l.sh
1124
        `OR1200_OR32_SH:
1125 353 julius
                id_lsu_op =  `OR1200_LSUOP_SH;
1126 141 marcus.erl
 
1127
        // Non load/store instructions
1128
        default:
1129 353 julius
                id_lsu_op =  `OR1200_LSUOP_NOP;
1130 141 marcus.erl
 
1131
        endcase
1132 10 unneback
end
1133
 
1134
//
1135
// Decode of comp_op
1136
//
1137 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1138
        if (rst == `OR1200_RST_VALUE) begin
1139 258 julius
                comp_op <=  4'd0;
1140 141 marcus.erl
        end else if (!ex_freeze & id_freeze | ex_flushpipe)
1141 258 julius
                comp_op <=  4'd0;
1142 10 unneback
        else if (!ex_freeze)
1143 258 julius
                comp_op <=  id_insn[24:21];
1144 10 unneback
end
1145
 
1146 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1147 10 unneback
//
1148 185 julius
// Decode of FPU ops
1149
//
1150 258 julius
   assign fpu_op = {(id_insn[31:26] == `OR1200_OR32_FLOAT),
1151
                    id_insn[`OR1200_FPUOP_WIDTH-2:0]};
1152 185 julius
`else
1153
   assign fpu_op = {`OR1200_FPUOP_WIDTH{1'b0}};
1154
`endif
1155
 
1156
 
1157
//
1158 10 unneback
// Decode of l.sys
1159
//
1160 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1161
        if (rst == `OR1200_RST_VALUE)
1162 258 julius
                sig_syscall <=  1'b0;
1163 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1164 258 julius
                sig_syscall <=  1'b0;
1165 10 unneback
        else if (!ex_freeze) begin
1166
`ifdef OR1200_VERBOSE
1167
// synopsys translate_off
1168
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000})
1169
                        $display("Generating sig_syscall");
1170
// synopsys translate_on
1171
`endif
1172 258 julius
                sig_syscall <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000});
1173 10 unneback
        end
1174
end
1175
 
1176
//
1177
// Decode of l.trap
1178
//
1179 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1180
        if (rst == `OR1200_RST_VALUE)
1181 258 julius
                sig_trap <=  1'b0;
1182 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1183 258 julius
                sig_trap <=  1'b0;
1184 10 unneback
        else if (!ex_freeze) begin
1185
`ifdef OR1200_VERBOSE
1186
// synopsys translate_off
1187
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1188
                        $display("Generating sig_trap");
1189
// synopsys translate_on
1190
`endif
1191 258 julius
                sig_trap <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1192 10 unneback
                        | du_hwbkpt;
1193
        end
1194
end
1195
 
1196 258 julius
// Decode destination register address for data cache to check if store ops
1197
// are being done from the stack register (r1) or frame pointer register (r2)
1198
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
1199 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1200
   if (rst == `OR1200_RST_VALUE)
1201 258 julius
     dc_no_writethrough <= 0;
1202
   else if (!ex_freeze)
1203
     dc_no_writethrough <= (id_insn[20:16] == 5'd1) | (id_insn[20:16] == 5'd2);
1204
end
1205
`else
1206
 
1207
   assign dc_no_writethrough = 0;
1208
 
1209
`endif
1210
 
1211 10 unneback
endmodule

powered by: WebSVN 2.1.0

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