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

Subversion Repositories openrisc

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

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 859 olof
   ex_spr_write, du_flush_pipe,
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 859 olof
input                                   du_flush_pipe;
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 859 olof
assign if_flushpipe = except_flushpipe | pc_we | extend_flush | du_flush_pipe;
248
assign id_flushpipe = except_flushpipe | pc_we | extend_flush | du_flush_pipe;
249
assign ex_flushpipe = except_flushpipe | pc_we | extend_flush | du_flush_pipe;
250
assign wb_flushpipe = except_flushpipe | pc_we | extend_flush | du_flush_pipe;
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 845 stekern
        `OR1200_OR32_LWZ, `OR1200_OR32_LWS,
279
   `OR1200_OR32_LBZ, `OR1200_OR32_LBS,
280 640 julius
        `OR1200_OR32_LHZ, `OR1200_OR32_LHS:
281 141 marcus.erl
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
282
 
283
        // l.muli
284
        `ifdef OR1200_MULT_IMPLEMENTED
285
        `OR1200_OR32_MULI:
286
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
287
        `endif
288
 
289
        // l.maci
290
        `ifdef OR1200_MAC_IMPLEMENTED
291
        `OR1200_OR32_MACI:
292 640 julius
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
293 141 marcus.erl
        `endif
294
 
295
        // l.mtspr
296
        `OR1200_OR32_MTSPR:
297
                id_simm = {16'b0, id_insn[25:21], id_insn[10:0]};
298
 
299
        // l.sxx (store instructions)
300
        `OR1200_OR32_SW, `OR1200_OR32_SH, `OR1200_OR32_SB:
301
                id_simm = {{16{id_insn[25]}}, id_insn[25:21], id_insn[10:0]};
302
 
303
        // l.xori
304
        `OR1200_OR32_XORI:
305
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
306
 
307
        // l.sfxxi (SFXX with immediate)
308
        `OR1200_OR32_SFXXI:
309
                id_simm = {{16{id_insn[15]}}, id_insn[15:0]};
310
 
311
        // Instructions with no or zero extended immediate
312
        default:
313
                id_simm = {{16'b0}, id_insn[15:0]};
314
 
315
        endcase
316
end
317
 
318
//
319
// ID Sign extension of branch offset
320
//
321
assign id_branch_addrtarget = {{4{id_insn[25]}}, id_insn[25:0]} + id_pc[31:2];
322
 
323
//
324
// EX Sign extension of branch offset
325
//
326
 
327
// pipeline ID and EX branch target address 
328 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
329
        if (rst == `OR1200_RST_VALUE)
330 364 julius
                ex_branch_addrtarget <=  0;
331 141 marcus.erl
        else if (!ex_freeze)
332 258 julius
                ex_branch_addrtarget <=  id_branch_addrtarget;
333 141 marcus.erl
end
334
// not pipelined
335
//assign ex_branch_addrtarget = {{4{ex_insn[25]}}, ex_insn[25:0]} + ex_pc[31:2];
336
 
337
//
338
// l.maci in IF stage
339
//
340
`ifdef OR1200_MAC_IMPLEMENTED
341
assign if_maci_op = (if_insn[31:26] == `OR1200_OR32_MACI);
342
`else
343
assign if_maci_op = 1'b0;
344
`endif
345
 
346
//
347 10 unneback
// l.macrc in ID stage
348
//
349
`ifdef OR1200_MAC_IMPLEMENTED
350 640 julius
assign id_macrc_op = (id_insn[31:26] == `OR1200_OR32_MACRC) & id_insn[16];
351 10 unneback
`else
352
assign id_macrc_op = 1'b0;
353
`endif
354
 
355
//
356 141 marcus.erl
// l.macrc in EX stage
357
//
358
`ifdef OR1200_MAC_IMPLEMENTED
359 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
360
        if (rst == `OR1200_RST_VALUE)
361 258 julius
                ex_macrc_op <=  1'b0;
362 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
363 258 julius
                ex_macrc_op <=  1'b0;
364 141 marcus.erl
        else if (!ex_freeze)
365 258 julius
                ex_macrc_op <=  id_macrc_op;
366 141 marcus.erl
end
367
`else
368
assign ex_macrc_op = 1'b0;
369
`endif
370
 
371
//
372 10 unneback
// cust5_op, cust5_limm (L immediate)
373
//
374
assign cust5_op = ex_insn[4:0];
375
assign cust5_limm = ex_insn[10:5];
376
 
377
//
378
//
379
//
380 640 julius
assign rfe = (id_branch_op == `OR1200_BRANCHOP_RFE) |
381
             (ex_branch_op == `OR1200_BRANCHOP_RFE);
382 10 unneback
 
383 353 julius
 
384
`ifdef verilator
385
   // Function to access wb_insn (for Verilator). Have to hide this from
386
   // simulator, since functions with no inputs are not allowed in IEEE
387
   // 1364-2001.
388
   function [31:0] get_wb_insn;
389
      // verilator public
390
      get_wb_insn = wb_insn;
391
   endfunction // get_wb_insn
392
 
393
   // Function to access id_insn (for Verilator). Have to hide this from
394
   // simulator, since functions with no inputs are not allowed in IEEE
395
   // 1364-2001.
396
   function [31:0] get_id_insn;
397
      // verilator public
398
      get_id_insn = id_insn;
399
   endfunction // get_id_insn
400
 
401
   // Function to access ex_insn (for Verilator). Have to hide this from
402
   // simulator, since functions with no inputs are not allowed in IEEE
403
   // 1364-2001.
404
   function [31:0] get_ex_insn;
405
      // verilator public
406
      get_ex_insn = ex_insn;
407
   endfunction // get_ex_insn
408
 
409
`endif
410
 
411
 
412 10 unneback
//
413
// Generation of sel_a
414
//
415
always @(rf_addrw or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
416
        if ((id_insn[20:16] == rf_addrw) && rfwb_op[0])
417
                sel_a = `OR1200_SEL_EX_FORW;
418
        else if ((id_insn[20:16] == wb_rfaddrw) && wbforw_valid)
419
                sel_a = `OR1200_SEL_WB_FORW;
420
        else
421
                sel_a = `OR1200_SEL_RF;
422
 
423
//
424
// Generation of sel_b
425
//
426 640 julius
always @(rf_addrw or sel_imm or id_insn or rfwb_op or wbforw_valid or
427
         wb_rfaddrw)
428 10 unneback
        if (sel_imm)
429
                sel_b = `OR1200_SEL_IMM;
430
        else if ((id_insn[15:11] == rf_addrw) && rfwb_op[0])
431
                sel_b = `OR1200_SEL_EX_FORW;
432
        else if ((id_insn[15:11] == wb_rfaddrw) && wbforw_valid)
433
                sel_b = `OR1200_SEL_WB_FORW;
434
        else
435
                sel_b = `OR1200_SEL_RF;
436
 
437
//
438
// Decode of multicycle
439
//
440
always @(id_insn) begin
441
  case (id_insn[31:26])         // synopsys parallel_case
442 644 julius
    // l.rfe
443
    `OR1200_OR32_RFE,
444 141 marcus.erl
    // l.mfspr
445
    `OR1200_OR32_MFSPR:
446
      multicycle = `OR1200_TWO_CYCLES;  // to read from ITLB/DTLB (sync RAMs)
447 10 unneback
    // Single cycle instructions
448
    default: begin
449
      multicycle = `OR1200_ONE_CYCLE;
450 258 julius
    end
451 10 unneback
  endcase
452 258 julius
end // always @ (id_insn)
453 10 unneback
 
454
//
455 258 julius
// Encode wait_on signal
456
//    
457
always @(id_insn) begin
458
   case (id_insn[31:26])                // synopsys parallel_case
459 640 julius
     `OR1200_OR32_ALU:
460
       wait_on =  ( 1'b0
461
`ifdef OR1200_DIV_IMPLEMENTED
462
                     | (id_insn[4:0] == `OR1200_ALUOP_DIV)
463
                     | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
464
`endif
465
`ifdef OR1200_MULT_IMPLEMENTED
466
                     | (id_insn[4:0] == `OR1200_ALUOP_MUL)
467
                     | (id_insn[4:0] == `OR1200_ALUOP_MULU)
468
`endif
469
                    ) ? `OR1200_WAIT_ON_MULTMAC : `OR1200_WAIT_ON_NOTHING;
470
`ifdef OR1200_MULT_IMPLEMENTED
471
`ifdef OR1200_MAC_IMPLEMENTED
472
     `OR1200_OR32_MACMSB,
473
     `OR1200_OR32_MACI,
474
`endif
475
     `OR1200_OR32_MULI:
476
         wait_on = `OR1200_WAIT_ON_MULTMAC;
477
`endif
478
`ifdef OR1200_MAC_IMPLEMENTED
479
     `OR1200_OR32_MACRC:
480
         wait_on = id_insn[16] ? `OR1200_WAIT_ON_MULTMAC :
481
                                 `OR1200_WAIT_ON_NOTHING;
482
`endif
483 258 julius
`ifdef OR1200_FPU_IMPLEMENTED
484
       `OR1200_OR32_FLOAT: begin
485
         wait_on = id_insn[`OR1200_FPUOP_DOUBLE_BIT] ? 0 : `OR1200_WAIT_ON_FPU;
486
       end
487
`endif
488 640 julius
`ifndef OR1200_DC_WRITEHROUGH
489 258 julius
     // l.mtspr
490
     `OR1200_OR32_MTSPR: begin
491
        wait_on = `OR1200_WAIT_ON_MTSPR;
492
     end
493
`endif
494
     default: begin
495 640 julius
        wait_on = `OR1200_WAIT_ON_NOTHING;
496 258 julius
     end
497
   endcase // case (id_insn[31:26])
498
end // always @ (id_insn)
499
 
500
 
501
 
502
 
503
//
504 10 unneback
// Register file write address
505
//
506 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
507
        if (rst == `OR1200_RST_VALUE)
508 258 julius
                rf_addrw <=  5'd0;
509 10 unneback
        else if (!ex_freeze & id_freeze)
510 258 julius
                rf_addrw <=  5'd00;
511 10 unneback
        else if (!ex_freeze)
512 141 marcus.erl
                case (id_insn[31:26])   // synopsys parallel_case
513
                        `OR1200_OR32_JAL, `OR1200_OR32_JALR:
514 258 julius
                                rf_addrw <=  5'd09;     // link register r9
515 10 unneback
                        default:
516 258 julius
                                rf_addrw <=  id_insn[25:21];
517 10 unneback
                endcase
518
end
519
 
520
//
521
// rf_addrw in wb stage (used in forwarding logic)
522
//
523 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
524
        if (rst == `OR1200_RST_VALUE)
525 258 julius
                wb_rfaddrw <=  5'd0;
526 10 unneback
        else if (!wb_freeze)
527 258 julius
                wb_rfaddrw <=  rf_addrw;
528 10 unneback
end
529
 
530
//
531
// Instruction latch in id_insn
532
//
533 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
534
        if (rst == `OR1200_RST_VALUE)
535 258 julius
                id_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
536 141 marcus.erl
        else if (id_flushpipe)
537 258 julius
                id_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};        // NOP -> id_insn[16] must be 1
538 10 unneback
        else if (!id_freeze) begin
539 258 julius
                id_insn <=  if_insn;
540 10 unneback
`ifdef OR1200_VERBOSE
541
// synopsys translate_off
542
                $display("%t: id_insn <= %h", $time, if_insn);
543
// synopsys translate_on
544
`endif
545
        end
546
end
547
 
548
//
549
// Instruction latch in ex_insn
550
//
551 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
552
        if (rst == `OR1200_RST_VALUE)
553 258 julius
                ex_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
554 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
555 258 julius
                ex_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};   // NOP -> ex_insn[16] must be 1
556 10 unneback
        else if (!ex_freeze) begin
557 258 julius
                ex_insn <=  id_insn;
558 10 unneback
`ifdef OR1200_VERBOSE
559
// synopsys translate_off
560
                $display("%t: ex_insn <= %h", $time, id_insn);
561
// synopsys translate_on
562
`endif
563
        end
564
end
565 258 julius
 
566 10 unneback
//
567
// Instruction latch in wb_insn
568
//
569 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
570
        if (rst == `OR1200_RST_VALUE)
571 258 julius
                wb_insn <=  {`OR1200_OR32_NOP, 26'h041_0000};
572 141 marcus.erl
        // wb_insn should not be changed by exceptions due to correct 
573
        // recording of display_arch_state in the or1200_monitor! 
574
        // wb_insn changed by exception is not used elsewhere! 
575 10 unneback
        else if (!wb_freeze) begin
576 258 julius
                wb_insn <=  ex_insn;
577 10 unneback
        end
578
end
579
 
580
//
581
// Decode of sel_imm
582
//
583 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
584
        if (rst == `OR1200_RST_VALUE)
585 258 julius
                sel_imm <=  1'b0;
586 10 unneback
        else if (!id_freeze) begin
587
          case (if_insn[31:26])         // synopsys parallel_case
588
 
589
            // j.jalr
590
            `OR1200_OR32_JALR:
591 258 julius
              sel_imm <=  1'b0;
592 10 unneback
 
593
            // l.jr
594
            `OR1200_OR32_JR:
595 258 julius
              sel_imm <=  1'b0;
596 10 unneback
 
597
            // l.rfe
598
            `OR1200_OR32_RFE:
599 258 julius
              sel_imm <=  1'b0;
600 10 unneback
 
601
            // l.mfspr
602
            `OR1200_OR32_MFSPR:
603 258 julius
              sel_imm <=  1'b0;
604 10 unneback
 
605
            // l.mtspr
606
            `OR1200_OR32_MTSPR:
607 258 julius
              sel_imm <=  1'b0;
608 10 unneback
 
609
            // l.sys, l.brk and all three sync insns
610
            `OR1200_OR32_XSYNC:
611 258 julius
              sel_imm <=  1'b0;
612 10 unneback
 
613
            // l.mac/l.msb
614
`ifdef OR1200_MAC_IMPLEMENTED
615
            `OR1200_OR32_MACMSB:
616 258 julius
              sel_imm <=  1'b0;
617 10 unneback
`endif
618
 
619
            // l.sw
620
            `OR1200_OR32_SW:
621 258 julius
              sel_imm <=  1'b0;
622 10 unneback
 
623
            // l.sb
624
            `OR1200_OR32_SB:
625 258 julius
              sel_imm <=  1'b0;
626 10 unneback
 
627
            // l.sh
628
            `OR1200_OR32_SH:
629 258 julius
              sel_imm <=  1'b0;
630 10 unneback
 
631
            // ALU instructions except the one with immediate
632
            `OR1200_OR32_ALU:
633 258 julius
              sel_imm <=  1'b0;
634 10 unneback
 
635
            // SFXX instructions
636
            `OR1200_OR32_SFXX:
637 258 julius
              sel_imm <=  1'b0;
638 10 unneback
 
639 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
640 10 unneback
            // l.cust5 instructions
641
            `OR1200_OR32_CUST5:
642 258 julius
              sel_imm <=  1'b0;
643 10 unneback
`endif
644 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
645
            // FPU instructions
646
            `OR1200_OR32_FLOAT:
647 258 julius
              sel_imm <=  1'b0;
648 185 julius
`endif
649 10 unneback
            // l.nop
650
            `OR1200_OR32_NOP:
651 258 julius
              sel_imm <=  1'b0;
652 10 unneback
 
653
            // All instructions with immediates
654
            default: begin
655 258 julius
              sel_imm <=  1'b1;
656 10 unneback
            end
657
 
658
          endcase
659
 
660
        end
661
end
662
 
663
//
664
// Decode of except_illegal
665
//
666 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
667
        if (rst == `OR1200_RST_VALUE)
668 258 julius
                except_illegal <=  1'b0;
669 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
670 258 julius
                except_illegal <=  1'b0;
671 10 unneback
        else if (!ex_freeze) begin
672 141 marcus.erl
                case (id_insn[31:26])           // synopsys parallel_case
673 10 unneback
 
674 141 marcus.erl
                `OR1200_OR32_J,
675
                `OR1200_OR32_JAL,
676
                `OR1200_OR32_JALR,
677
                `OR1200_OR32_JR,
678
                `OR1200_OR32_BNF,
679
                `OR1200_OR32_BF,
680
                `OR1200_OR32_RFE,
681
                `OR1200_OR32_MOVHI,
682
                `OR1200_OR32_MFSPR,
683
                `OR1200_OR32_XSYNC,
684 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
685 141 marcus.erl
                `OR1200_OR32_MACI,
686 10 unneback
`endif
687 141 marcus.erl
                `OR1200_OR32_LWZ,
688 845 stekern
                `OR1200_OR32_LWS,
689 141 marcus.erl
                `OR1200_OR32_LBZ,
690
                `OR1200_OR32_LBS,
691
                `OR1200_OR32_LHZ,
692
                `OR1200_OR32_LHS,
693
                `OR1200_OR32_ADDI,
694
                `OR1200_OR32_ADDIC,
695
                `OR1200_OR32_ANDI,
696
                `OR1200_OR32_ORI,
697
                `OR1200_OR32_XORI,
698 10 unneback
`ifdef OR1200_MULT_IMPLEMENTED
699 141 marcus.erl
                `OR1200_OR32_MULI,
700 10 unneback
`endif
701 141 marcus.erl
                `OR1200_OR32_SH_ROTI,
702
                `OR1200_OR32_SFXXI,
703
                `OR1200_OR32_MTSPR,
704 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
705 141 marcus.erl
                `OR1200_OR32_MACMSB,
706 10 unneback
`endif
707 141 marcus.erl
                `OR1200_OR32_SW,
708
                `OR1200_OR32_SB,
709
                `OR1200_OR32_SH,
710
                `OR1200_OR32_SFXX,
711 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
712 141 marcus.erl
                `OR1200_OR32_CUST5,
713 10 unneback
`endif
714 141 marcus.erl
        `OR1200_OR32_NOP:
715 364 julius
                except_illegal <=  1'b0;
716 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
717
            `OR1200_OR32_FLOAT:
718 364 julius
                // Check it's not a double precision instruction
719
                except_illegal <=  id_insn[`OR1200_FPUOP_DOUBLE_BIT];
720 185 julius
`endif
721 10 unneback
 
722 141 marcus.erl
        `OR1200_OR32_ALU:
723 364 julius
                except_illegal <=  1'b0
724 10 unneback
 
725 141 marcus.erl
`ifdef OR1200_MULT_IMPLEMENTED
726 258 julius
`ifdef OR1200_DIV_IMPLEMENTED
727 141 marcus.erl
`else
728 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
729
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
730 141 marcus.erl
`endif
731
`else
732 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
733
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
734
                | (id_insn[4:0] == `OR1200_ALUOP_MUL)
735 141 marcus.erl
`endif
736
 
737
`ifdef OR1200_IMPL_ADDC
738
`else
739 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_ADDC)
740 141 marcus.erl
`endif
741
 
742 401 julius
`ifdef OR1200_IMPL_ALU_FFL1
743
`else
744 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_FFL1)
745 401 julius
`endif
746
 
747 141 marcus.erl
`ifdef OR1200_IMPL_ALU_ROTATE
748
`else
749 640 julius
                | ((id_insn[4:0] == `OR1200_ALUOP_SHROT) &
750
                   (id_insn[9:6] == `OR1200_SHROTOP_ROR))
751 141 marcus.erl
`endif
752
 
753
`ifdef OR1200_IMPL_SUB
754
`else
755 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_SUB)
756 141 marcus.erl
`endif
757 640 julius
`ifdef OR1200_IMPL_ALU_EXT
758
`else
759
                | (id_insn[4:0] == `OR1200_ALUOP_EXTHB)
760
                | (id_insn[4:0] == `OR1200_ALUOP_EXTW)
761
`endif
762 364 julius
                ;
763 141 marcus.erl
 
764
                // Illegal and OR1200 unsupported instructions
765 364 julius
        default:
766
                except_illegal <=  1'b1;
767 141 marcus.erl
 
768 364 julius
        endcase
769
        end // if (!ex_freeze)
770 10 unneback
end
771 364 julius
 
772 10 unneback
 
773
//
774
// Decode of alu_op
775
//
776 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
777
        if (rst == `OR1200_RST_VALUE)
778 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
779 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
780 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
781 10 unneback
        else if (!ex_freeze) begin
782
          case (id_insn[31:26])         // synopsys parallel_case
783
 
784
            // l.movhi
785
            `OR1200_OR32_MOVHI:
786 258 julius
              alu_op <=  `OR1200_ALUOP_MOVHI;
787 10 unneback
 
788
            // l.addi
789
            `OR1200_OR32_ADDI:
790 258 julius
              alu_op <=  `OR1200_ALUOP_ADD;
791 10 unneback
 
792
            // l.addic
793
            `OR1200_OR32_ADDIC:
794 258 julius
              alu_op <=  `OR1200_ALUOP_ADDC;
795 10 unneback
 
796
            // l.andi
797
            `OR1200_OR32_ANDI:
798 258 julius
              alu_op <=  `OR1200_ALUOP_AND;
799 10 unneback
 
800
            // l.ori
801
            `OR1200_OR32_ORI:
802 258 julius
              alu_op <=  `OR1200_ALUOP_OR;
803 10 unneback
 
804
            // l.xori
805
            `OR1200_OR32_XORI:
806 258 julius
              alu_op <=  `OR1200_ALUOP_XOR;
807 10 unneback
 
808
            // l.muli
809
`ifdef OR1200_MULT_IMPLEMENTED
810
            `OR1200_OR32_MULI:
811 258 julius
              alu_op <=  `OR1200_ALUOP_MUL;
812 10 unneback
`endif
813
 
814
            // Shift and rotate insns with immediate
815
            `OR1200_OR32_SH_ROTI:
816 258 julius
              alu_op <=  `OR1200_ALUOP_SHROT;
817 10 unneback
 
818
            // SFXX insns with immediate
819
            `OR1200_OR32_SFXXI:
820 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
821 10 unneback
 
822
            // ALU instructions except the one with immediate
823
            `OR1200_OR32_ALU:
824 640 julius
              alu_op <=  {1'b0,id_insn[3:0]};
825 10 unneback
 
826
            // SFXX instructions
827
            `OR1200_OR32_SFXX:
828 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
829 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
830
            // l.cust5
831 10 unneback
            `OR1200_OR32_CUST5:
832 258 julius
              alu_op <=  `OR1200_ALUOP_CUST5;
833 640 julius
`endif
834 10 unneback
            // Default
835
            default: begin
836 258 julius
              alu_op <=  `OR1200_ALUOP_NOP;
837 10 unneback
            end
838
 
839
          endcase
840
 
841
        end
842
end
843
 
844 401 julius
 
845 10 unneback
//
846 640 julius
// Decode of second ALU operation field [9:6]
847 401 julius
//
848
always @(posedge clk or `OR1200_RST_EVENT rst) begin
849
        if (rst == `OR1200_RST_VALUE)
850
                alu_op2 <=  0;
851
        else if (!ex_freeze & id_freeze | ex_flushpipe)
852
                alu_op2 <= 0;
853
        else if (!ex_freeze) begin
854
                alu_op2 <=  id_insn[`OR1200_ALUOP2_POS];
855
        end
856
end
857
 
858
//
859 141 marcus.erl
// Decode of spr_read, spr_write
860
//
861 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
862
        if (rst == `OR1200_RST_VALUE) begin
863 258 julius
                spr_read <=  1'b0;
864
                spr_write <=  1'b0;
865 141 marcus.erl
        end
866
        else if (!ex_freeze & id_freeze | ex_flushpipe) begin
867 258 julius
                spr_read <=  1'b0;
868
                spr_write <=  1'b0;
869 141 marcus.erl
        end
870
        else if (!ex_freeze) begin
871
                case (id_insn[31:26])     // synopsys parallel_case
872
 
873
                // l.mfspr
874
                `OR1200_OR32_MFSPR: begin
875 258 julius
                        spr_read <=  1'b1;
876
                        spr_write <=  1'b0;
877 141 marcus.erl
                end
878
 
879
                // l.mtspr
880
                `OR1200_OR32_MTSPR: begin
881 258 julius
                        spr_read <=  1'b0;
882
                        spr_write <=  1'b1;
883 141 marcus.erl
                end
884
 
885
                // Default
886
                default: begin
887 258 julius
                        spr_read <=  1'b0;
888
                        spr_write <=  1'b0;
889 141 marcus.erl
                end
890
 
891
                endcase
892
        end
893
end
894
 
895
//
896 10 unneback
// Decode of mac_op
897
//
898
`ifdef OR1200_MAC_IMPLEMENTED
899 141 marcus.erl
always @(id_insn) begin
900
        case (id_insn[31:26])           // synopsys parallel_case
901 10 unneback
 
902 141 marcus.erl
        // l.maci
903
        `OR1200_OR32_MACI:
904 353 julius
                id_mac_op =  `OR1200_MACOP_MAC;
905 10 unneback
 
906 141 marcus.erl
        // l.mac, l.msb
907
        `OR1200_OR32_MACMSB:
908 353 julius
                id_mac_op =  id_insn[2:0];
909 10 unneback
 
910 141 marcus.erl
        // Illegal and OR1200 unsupported instructions
911
        default:
912 353 julius
                id_mac_op =  `OR1200_MACOP_NOP;
913 10 unneback
 
914 141 marcus.erl
        endcase
915 10 unneback
end
916 141 marcus.erl
 
917 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
918
        if (rst == `OR1200_RST_VALUE)
919 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
920 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
921 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
922 141 marcus.erl
        else if (!ex_freeze)
923 258 julius
                ex_mac_op <=  id_mac_op;
924 141 marcus.erl
end
925
 
926
assign mac_op = abort_mvspr ? `OR1200_MACOP_NOP : ex_mac_op;
927 10 unneback
`else
928 141 marcus.erl
assign id_mac_op = `OR1200_MACOP_NOP;
929 10 unneback
assign mac_op = `OR1200_MACOP_NOP;
930
`endif
931
 
932
 
933
//
934
// Decode of rfwb_op
935
//
936 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
937
        if (rst == `OR1200_RST_VALUE)
938 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
939 141 marcus.erl
        else  if (!ex_freeze & id_freeze | ex_flushpipe)
940 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
941 10 unneback
        else  if (!ex_freeze) begin
942
                case (id_insn[31:26])           // synopsys parallel_case
943
 
944 141 marcus.erl
                // j.jal
945
                `OR1200_OR32_JAL:
946 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
947 10 unneback
 
948 141 marcus.erl
                // j.jalr
949
                `OR1200_OR32_JALR:
950 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
951 10 unneback
 
952 141 marcus.erl
                // l.movhi
953
                `OR1200_OR32_MOVHI:
954 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
955 10 unneback
 
956 141 marcus.erl
                // l.mfspr
957
                `OR1200_OR32_MFSPR:
958 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_SPRS, 1'b1};
959 10 unneback
 
960 141 marcus.erl
                // l.lwz
961
                `OR1200_OR32_LWZ:
962 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
963 845 stekern
 
964
                // l.lws
965
                `OR1200_OR32_LWS:
966
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
967
 
968 141 marcus.erl
                // l.lbz
969
                `OR1200_OR32_LBZ:
970 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
971 10 unneback
 
972 141 marcus.erl
                // l.lbs
973
                `OR1200_OR32_LBS:
974 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
975 10 unneback
 
976 141 marcus.erl
                // l.lhz
977
                `OR1200_OR32_LHZ:
978 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
979 10 unneback
 
980 141 marcus.erl
                // l.lhs
981
                `OR1200_OR32_LHS:
982 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
983 10 unneback
 
984 141 marcus.erl
                // l.addi
985
                `OR1200_OR32_ADDI:
986 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
987 10 unneback
 
988 141 marcus.erl
                // l.addic
989
                `OR1200_OR32_ADDIC:
990 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
991 10 unneback
 
992 141 marcus.erl
                // l.andi
993
                `OR1200_OR32_ANDI:
994 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
995 10 unneback
 
996 141 marcus.erl
                // l.ori
997
                `OR1200_OR32_ORI:
998 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
999 10 unneback
 
1000 141 marcus.erl
                // l.xori
1001
                `OR1200_OR32_XORI:
1002 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1003 10 unneback
 
1004 141 marcus.erl
                // l.muli
1005 10 unneback
`ifdef OR1200_MULT_IMPLEMENTED
1006 141 marcus.erl
                `OR1200_OR32_MULI:
1007 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1008 10 unneback
`endif
1009
 
1010 141 marcus.erl
                // Shift and rotate insns with immediate
1011
                `OR1200_OR32_SH_ROTI:
1012 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1013 10 unneback
 
1014 141 marcus.erl
                // ALU instructions except the one with immediate
1015
                `OR1200_OR32_ALU:
1016 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1017 10 unneback
 
1018 640 julius
`ifdef OR1200_ALU_IMPL_CUST5
1019 141 marcus.erl
                // l.cust5 instructions
1020
                `OR1200_OR32_CUST5:
1021 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1022 10 unneback
`endif
1023 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1024
                  // FPU instructions, lf.XXX.s, except sfxx
1025
                  `OR1200_OR32_FLOAT:
1026 258 julius
                    rfwb_op <=  {`OR1200_RFWBOP_FPU,!id_insn[3]};
1027 185 julius
`endif
1028 141 marcus.erl
                // Instructions w/o register-file write-back
1029
                default:
1030 258 julius
                        rfwb_op <=  `OR1200_RFWBOP_NOP;
1031 10 unneback
 
1032 141 marcus.erl
 
1033 10 unneback
                endcase
1034
        end
1035
end
1036
 
1037
//
1038 141 marcus.erl
// Decode of id_branch_op
1039 10 unneback
//
1040 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1041
        if (rst == `OR1200_RST_VALUE)
1042 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1043 141 marcus.erl
        else if (id_flushpipe)
1044 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1045 10 unneback
        else if (!id_freeze) begin
1046
                case (if_insn[31:26])           // synopsys parallel_case
1047 141 marcus.erl
 
1048
                // l.j
1049
                `OR1200_OR32_J:
1050 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1051 10 unneback
 
1052 141 marcus.erl
                // j.jal
1053
                `OR1200_OR32_JAL:
1054 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1055 10 unneback
 
1056 141 marcus.erl
                // j.jalr
1057
                `OR1200_OR32_JALR:
1058 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1059 10 unneback
 
1060 141 marcus.erl
                // l.jr
1061
                `OR1200_OR32_JR:
1062 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1063 10 unneback
 
1064 141 marcus.erl
                // l.bnf
1065
                `OR1200_OR32_BNF:
1066 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BNF;
1067 10 unneback
 
1068 141 marcus.erl
                // l.bf
1069
                `OR1200_OR32_BF:
1070 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BF;
1071 10 unneback
 
1072 141 marcus.erl
                // l.rfe
1073
                `OR1200_OR32_RFE:
1074 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_RFE;
1075 10 unneback
 
1076 141 marcus.erl
                // Non branch instructions
1077
                default:
1078 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_NOP;
1079 141 marcus.erl
 
1080 10 unneback
                endcase
1081
        end
1082
end
1083
 
1084
//
1085 141 marcus.erl
// Generation of ex_branch_op
1086 10 unneback
//
1087 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
1088
        if (rst == `OR1200_RST_VALUE)
1089 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1090 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1091 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1092 10 unneback
        else if (!ex_freeze)
1093 258 julius
                ex_branch_op <=  id_branch_op;
1094 10 unneback
 
1095
//
1096 141 marcus.erl
// Decode of id_lsu_op
1097 10 unneback
//
1098 141 marcus.erl
always @(id_insn) begin
1099
        case (id_insn[31:26])           // synopsys parallel_case
1100
 
1101
        // l.lwz
1102
        `OR1200_OR32_LWZ:
1103 353 julius
                id_lsu_op =  `OR1200_LSUOP_LWZ;
1104 141 marcus.erl
 
1105 845 stekern
        // l.lws
1106
        `OR1200_OR32_LWS:
1107
                id_lsu_op =  `OR1200_LSUOP_LWS;
1108
 
1109 141 marcus.erl
        // l.lbz
1110
        `OR1200_OR32_LBZ:
1111 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBZ;
1112 141 marcus.erl
 
1113
        // l.lbs
1114
        `OR1200_OR32_LBS:
1115 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBS;
1116 141 marcus.erl
 
1117
        // l.lhz
1118
        `OR1200_OR32_LHZ:
1119 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHZ;
1120 141 marcus.erl
 
1121
        // l.lhs
1122
        `OR1200_OR32_LHS:
1123 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHS;
1124 141 marcus.erl
 
1125
        // l.sw
1126
        `OR1200_OR32_SW:
1127 353 julius
                id_lsu_op =  `OR1200_LSUOP_SW;
1128 141 marcus.erl
 
1129
        // l.sb
1130
        `OR1200_OR32_SB:
1131 353 julius
                id_lsu_op =  `OR1200_LSUOP_SB;
1132 141 marcus.erl
 
1133
        // l.sh
1134
        `OR1200_OR32_SH:
1135 353 julius
                id_lsu_op =  `OR1200_LSUOP_SH;
1136 141 marcus.erl
 
1137
        // Non load/store instructions
1138
        default:
1139 353 julius
                id_lsu_op =  `OR1200_LSUOP_NOP;
1140 141 marcus.erl
 
1141
        endcase
1142 10 unneback
end
1143
 
1144
//
1145
// Decode of comp_op
1146
//
1147 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1148
        if (rst == `OR1200_RST_VALUE) begin
1149 258 julius
                comp_op <=  4'd0;
1150 141 marcus.erl
        end else if (!ex_freeze & id_freeze | ex_flushpipe)
1151 258 julius
                comp_op <=  4'd0;
1152 10 unneback
        else if (!ex_freeze)
1153 258 julius
                comp_op <=  id_insn[24:21];
1154 10 unneback
end
1155
 
1156 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1157 10 unneback
//
1158 185 julius
// Decode of FPU ops
1159
//
1160 258 julius
   assign fpu_op = {(id_insn[31:26] == `OR1200_OR32_FLOAT),
1161
                    id_insn[`OR1200_FPUOP_WIDTH-2:0]};
1162 185 julius
`else
1163
   assign fpu_op = {`OR1200_FPUOP_WIDTH{1'b0}};
1164
`endif
1165
 
1166
 
1167
//
1168 10 unneback
// Decode of l.sys
1169
//
1170 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1171
        if (rst == `OR1200_RST_VALUE)
1172 258 julius
                sig_syscall <=  1'b0;
1173 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1174 258 julius
                sig_syscall <=  1'b0;
1175 10 unneback
        else if (!ex_freeze) begin
1176
`ifdef OR1200_VERBOSE
1177
// synopsys translate_off
1178
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000})
1179
                        $display("Generating sig_syscall");
1180
// synopsys translate_on
1181
`endif
1182 258 julius
                sig_syscall <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000});
1183 10 unneback
        end
1184
end
1185
 
1186
//
1187
// Decode of l.trap
1188
//
1189 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1190
        if (rst == `OR1200_RST_VALUE)
1191 258 julius
                sig_trap <=  1'b0;
1192 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1193 258 julius
                sig_trap <=  1'b0;
1194 10 unneback
        else if (!ex_freeze) begin
1195
`ifdef OR1200_VERBOSE
1196
// synopsys translate_off
1197
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1198
                        $display("Generating sig_trap");
1199
// synopsys translate_on
1200
`endif
1201 258 julius
                sig_trap <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1202 10 unneback
                        | du_hwbkpt;
1203
        end
1204
end
1205
 
1206 258 julius
// Decode destination register address for data cache to check if store ops
1207
// are being done from the stack register (r1) or frame pointer register (r2)
1208
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
1209 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1210
   if (rst == `OR1200_RST_VALUE)
1211 258 julius
     dc_no_writethrough <= 0;
1212
   else if (!ex_freeze)
1213
     dc_no_writethrough <= (id_insn[20:16] == 5'd1) | (id_insn[20:16] == 5'd2);
1214
end
1215
`else
1216
 
1217
   assign dc_no_writethrough = 0;
1218
 
1219
`endif
1220
 
1221 10 unneback
endmodule

powered by: WebSVN 2.1.0

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