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

Subversion Repositories openrisc

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

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 865 olof
`ifdef OR1200_IMPL_ALU_ROTATE
702 141 marcus.erl
                `OR1200_OR32_SH_ROTI,
703 865 olof
`endif
704 141 marcus.erl
                `OR1200_OR32_SFXXI,
705
                `OR1200_OR32_MTSPR,
706 10 unneback
`ifdef OR1200_MAC_IMPLEMENTED
707 141 marcus.erl
                `OR1200_OR32_MACMSB,
708 10 unneback
`endif
709 141 marcus.erl
                `OR1200_OR32_SW,
710
                `OR1200_OR32_SB,
711
                `OR1200_OR32_SH,
712
                `OR1200_OR32_SFXX,
713 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
714 141 marcus.erl
                `OR1200_OR32_CUST5,
715 10 unneback
`endif
716 141 marcus.erl
        `OR1200_OR32_NOP:
717 364 julius
                except_illegal <=  1'b0;
718 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
719
            `OR1200_OR32_FLOAT:
720 364 julius
                // Check it's not a double precision instruction
721
                except_illegal <=  id_insn[`OR1200_FPUOP_DOUBLE_BIT];
722 185 julius
`endif
723 10 unneback
 
724 141 marcus.erl
        `OR1200_OR32_ALU:
725 364 julius
                except_illegal <=  1'b0
726 10 unneback
 
727 141 marcus.erl
`ifdef OR1200_MULT_IMPLEMENTED
728 258 julius
`ifdef OR1200_DIV_IMPLEMENTED
729 141 marcus.erl
`else
730 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
731
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
732 141 marcus.erl
`endif
733
`else
734 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_DIV)
735
                | (id_insn[4:0] == `OR1200_ALUOP_DIVU)
736
                | (id_insn[4:0] == `OR1200_ALUOP_MUL)
737 141 marcus.erl
`endif
738
 
739
`ifdef OR1200_IMPL_ADDC
740
`else
741 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_ADDC)
742 141 marcus.erl
`endif
743
 
744 401 julius
`ifdef OR1200_IMPL_ALU_FFL1
745
`else
746 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_FFL1)
747 401 julius
`endif
748
 
749 141 marcus.erl
`ifdef OR1200_IMPL_ALU_ROTATE
750
`else
751 640 julius
                | ((id_insn[4:0] == `OR1200_ALUOP_SHROT) &
752
                   (id_insn[9:6] == `OR1200_SHROTOP_ROR))
753 141 marcus.erl
`endif
754
 
755
`ifdef OR1200_IMPL_SUB
756
`else
757 640 julius
                | (id_insn[4:0] == `OR1200_ALUOP_SUB)
758 141 marcus.erl
`endif
759 640 julius
`ifdef OR1200_IMPL_ALU_EXT
760
`else
761
                | (id_insn[4:0] == `OR1200_ALUOP_EXTHB)
762
                | (id_insn[4:0] == `OR1200_ALUOP_EXTW)
763
`endif
764 364 julius
                ;
765 141 marcus.erl
 
766
                // Illegal and OR1200 unsupported instructions
767 364 julius
        default:
768
                except_illegal <=  1'b1;
769 141 marcus.erl
 
770 364 julius
        endcase
771
        end // if (!ex_freeze)
772 10 unneback
end
773 364 julius
 
774 10 unneback
 
775
//
776
// Decode of alu_op
777
//
778 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
779
        if (rst == `OR1200_RST_VALUE)
780 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
781 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
782 258 julius
                alu_op <=  `OR1200_ALUOP_NOP;
783 10 unneback
        else if (!ex_freeze) begin
784
          case (id_insn[31:26])         // synopsys parallel_case
785
 
786
            // l.movhi
787
            `OR1200_OR32_MOVHI:
788 258 julius
              alu_op <=  `OR1200_ALUOP_MOVHI;
789 10 unneback
 
790
            // l.addi
791
            `OR1200_OR32_ADDI:
792 258 julius
              alu_op <=  `OR1200_ALUOP_ADD;
793 10 unneback
 
794
            // l.addic
795
            `OR1200_OR32_ADDIC:
796 258 julius
              alu_op <=  `OR1200_ALUOP_ADDC;
797 10 unneback
 
798
            // l.andi
799
            `OR1200_OR32_ANDI:
800 258 julius
              alu_op <=  `OR1200_ALUOP_AND;
801 10 unneback
 
802
            // l.ori
803
            `OR1200_OR32_ORI:
804 258 julius
              alu_op <=  `OR1200_ALUOP_OR;
805 10 unneback
 
806
            // l.xori
807
            `OR1200_OR32_XORI:
808 258 julius
              alu_op <=  `OR1200_ALUOP_XOR;
809 10 unneback
 
810
            // l.muli
811
`ifdef OR1200_MULT_IMPLEMENTED
812
            `OR1200_OR32_MULI:
813 258 julius
              alu_op <=  `OR1200_ALUOP_MUL;
814 10 unneback
`endif
815 865 olof
`ifdef OR1200_IMPL_ALU_ROTATE
816 10 unneback
            // Shift and rotate insns with immediate
817
            `OR1200_OR32_SH_ROTI:
818 258 julius
              alu_op <=  `OR1200_ALUOP_SHROT;
819 865 olof
`endif
820 10 unneback
            // SFXX insns with immediate
821
            `OR1200_OR32_SFXXI:
822 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
823 10 unneback
 
824
            // ALU instructions except the one with immediate
825
            `OR1200_OR32_ALU:
826 640 julius
              alu_op <=  {1'b0,id_insn[3:0]};
827 10 unneback
 
828
            // SFXX instructions
829
            `OR1200_OR32_SFXX:
830 258 julius
              alu_op <=  `OR1200_ALUOP_COMP;
831 640 julius
`ifdef OR1200_IMPL_ALU_CUST5
832
            // l.cust5
833 10 unneback
            `OR1200_OR32_CUST5:
834 258 julius
              alu_op <=  `OR1200_ALUOP_CUST5;
835 640 julius
`endif
836 10 unneback
            // Default
837
            default: begin
838 258 julius
              alu_op <=  `OR1200_ALUOP_NOP;
839 10 unneback
            end
840
 
841
          endcase
842
 
843
        end
844
end
845
 
846 401 julius
 
847 10 unneback
//
848 640 julius
// Decode of second ALU operation field [9:6]
849 401 julius
//
850
always @(posedge clk or `OR1200_RST_EVENT rst) begin
851
        if (rst == `OR1200_RST_VALUE)
852
                alu_op2 <=  0;
853
        else if (!ex_freeze & id_freeze | ex_flushpipe)
854
                alu_op2 <= 0;
855
        else if (!ex_freeze) begin
856
                alu_op2 <=  id_insn[`OR1200_ALUOP2_POS];
857
        end
858
end
859
 
860
//
861 141 marcus.erl
// Decode of spr_read, spr_write
862
//
863 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
864
        if (rst == `OR1200_RST_VALUE) begin
865 258 julius
                spr_read <=  1'b0;
866
                spr_write <=  1'b0;
867 141 marcus.erl
        end
868
        else if (!ex_freeze & id_freeze | ex_flushpipe) begin
869 258 julius
                spr_read <=  1'b0;
870
                spr_write <=  1'b0;
871 141 marcus.erl
        end
872
        else if (!ex_freeze) begin
873
                case (id_insn[31:26])     // synopsys parallel_case
874
 
875
                // l.mfspr
876
                `OR1200_OR32_MFSPR: begin
877 258 julius
                        spr_read <=  1'b1;
878
                        spr_write <=  1'b0;
879 141 marcus.erl
                end
880
 
881
                // l.mtspr
882
                `OR1200_OR32_MTSPR: begin
883 258 julius
                        spr_read <=  1'b0;
884
                        spr_write <=  1'b1;
885 141 marcus.erl
                end
886
 
887
                // Default
888
                default: begin
889 258 julius
                        spr_read <=  1'b0;
890
                        spr_write <=  1'b0;
891 141 marcus.erl
                end
892
 
893
                endcase
894
        end
895
end
896
 
897
//
898 10 unneback
// Decode of mac_op
899
//
900
`ifdef OR1200_MAC_IMPLEMENTED
901 141 marcus.erl
always @(id_insn) begin
902
        case (id_insn[31:26])           // synopsys parallel_case
903 10 unneback
 
904 141 marcus.erl
        // l.maci
905
        `OR1200_OR32_MACI:
906 353 julius
                id_mac_op =  `OR1200_MACOP_MAC;
907 10 unneback
 
908 141 marcus.erl
        // l.mac, l.msb
909
        `OR1200_OR32_MACMSB:
910 353 julius
                id_mac_op =  id_insn[2:0];
911 10 unneback
 
912 141 marcus.erl
        // Illegal and OR1200 unsupported instructions
913
        default:
914 353 julius
                id_mac_op =  `OR1200_MACOP_NOP;
915 10 unneback
 
916 141 marcus.erl
        endcase
917 10 unneback
end
918 141 marcus.erl
 
919 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
920
        if (rst == `OR1200_RST_VALUE)
921 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
922 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
923 258 julius
                ex_mac_op <=  `OR1200_MACOP_NOP;
924 141 marcus.erl
        else if (!ex_freeze)
925 258 julius
                ex_mac_op <=  id_mac_op;
926 141 marcus.erl
end
927
 
928
assign mac_op = abort_mvspr ? `OR1200_MACOP_NOP : ex_mac_op;
929 10 unneback
`else
930 141 marcus.erl
assign id_mac_op = `OR1200_MACOP_NOP;
931 10 unneback
assign mac_op = `OR1200_MACOP_NOP;
932
`endif
933
 
934
 
935
//
936
// Decode of rfwb_op
937
//
938 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
939
        if (rst == `OR1200_RST_VALUE)
940 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
941 141 marcus.erl
        else  if (!ex_freeze & id_freeze | ex_flushpipe)
942 258 julius
                rfwb_op <=  `OR1200_RFWBOP_NOP;
943 10 unneback
        else  if (!ex_freeze) begin
944
                case (id_insn[31:26])           // synopsys parallel_case
945
 
946 141 marcus.erl
                // j.jal
947
                `OR1200_OR32_JAL:
948 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
949 10 unneback
 
950 141 marcus.erl
                // j.jalr
951
                `OR1200_OR32_JALR:
952 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LR, 1'b1};
953 10 unneback
 
954 141 marcus.erl
                // l.movhi
955
                `OR1200_OR32_MOVHI:
956 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
957 10 unneback
 
958 141 marcus.erl
                // l.mfspr
959
                `OR1200_OR32_MFSPR:
960 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_SPRS, 1'b1};
961 10 unneback
 
962 141 marcus.erl
                // l.lwz
963
                `OR1200_OR32_LWZ:
964 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
965 845 stekern
 
966
                // l.lws
967
                `OR1200_OR32_LWS:
968
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
969
 
970 141 marcus.erl
                // l.lbz
971
                `OR1200_OR32_LBZ:
972 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
973 10 unneback
 
974 141 marcus.erl
                // l.lbs
975
                `OR1200_OR32_LBS:
976 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
977 10 unneback
 
978 141 marcus.erl
                // l.lhz
979
                `OR1200_OR32_LHZ:
980 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
981 10 unneback
 
982 141 marcus.erl
                // l.lhs
983
                `OR1200_OR32_LHS:
984 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_LSU, 1'b1};
985 10 unneback
 
986 141 marcus.erl
                // l.addi
987
                `OR1200_OR32_ADDI:
988 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
989 10 unneback
 
990 141 marcus.erl
                // l.addic
991
                `OR1200_OR32_ADDIC:
992 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
993 10 unneback
 
994 141 marcus.erl
                // l.andi
995
                `OR1200_OR32_ANDI:
996 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
997 10 unneback
 
998 141 marcus.erl
                // l.ori
999
                `OR1200_OR32_ORI:
1000 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1001 10 unneback
 
1002 141 marcus.erl
                // l.xori
1003
                `OR1200_OR32_XORI:
1004 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1005 10 unneback
 
1006 141 marcus.erl
                // l.muli
1007 10 unneback
`ifdef OR1200_MULT_IMPLEMENTED
1008 141 marcus.erl
                `OR1200_OR32_MULI:
1009 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1010 10 unneback
`endif
1011
 
1012 141 marcus.erl
                // Shift and rotate insns with immediate
1013 865 olof
`ifdef OR1200_IMPL_ALU_ROTATE
1014 141 marcus.erl
                `OR1200_OR32_SH_ROTI:
1015 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1016 865 olof
`endif
1017 141 marcus.erl
                // ALU instructions except the one with immediate
1018
                `OR1200_OR32_ALU:
1019 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1020 10 unneback
 
1021 640 julius
`ifdef OR1200_ALU_IMPL_CUST5
1022 141 marcus.erl
                // l.cust5 instructions
1023
                `OR1200_OR32_CUST5:
1024 258 julius
                        rfwb_op <=  {`OR1200_RFWBOP_ALU, 1'b1};
1025 10 unneback
`endif
1026 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1027
                  // FPU instructions, lf.XXX.s, except sfxx
1028
                  `OR1200_OR32_FLOAT:
1029 258 julius
                    rfwb_op <=  {`OR1200_RFWBOP_FPU,!id_insn[3]};
1030 185 julius
`endif
1031 141 marcus.erl
                // Instructions w/o register-file write-back
1032
                default:
1033 258 julius
                        rfwb_op <=  `OR1200_RFWBOP_NOP;
1034 10 unneback
 
1035 141 marcus.erl
 
1036 10 unneback
                endcase
1037
        end
1038
end
1039
 
1040
//
1041 141 marcus.erl
// Decode of id_branch_op
1042 10 unneback
//
1043 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1044
        if (rst == `OR1200_RST_VALUE)
1045 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1046 141 marcus.erl
        else if (id_flushpipe)
1047 258 julius
                id_branch_op <=  `OR1200_BRANCHOP_NOP;
1048 10 unneback
        else if (!id_freeze) begin
1049
                case (if_insn[31:26])           // synopsys parallel_case
1050 141 marcus.erl
 
1051
                // l.j
1052
                `OR1200_OR32_J:
1053 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1054 10 unneback
 
1055 141 marcus.erl
                // j.jal
1056
                `OR1200_OR32_JAL:
1057 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_J;
1058 10 unneback
 
1059 141 marcus.erl
                // j.jalr
1060
                `OR1200_OR32_JALR:
1061 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1062 10 unneback
 
1063 141 marcus.erl
                // l.jr
1064
                `OR1200_OR32_JR:
1065 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_JR;
1066 10 unneback
 
1067 141 marcus.erl
                // l.bnf
1068
                `OR1200_OR32_BNF:
1069 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BNF;
1070 10 unneback
 
1071 141 marcus.erl
                // l.bf
1072
                `OR1200_OR32_BF:
1073 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_BF;
1074 10 unneback
 
1075 141 marcus.erl
                // l.rfe
1076
                `OR1200_OR32_RFE:
1077 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_RFE;
1078 10 unneback
 
1079 141 marcus.erl
                // Non branch instructions
1080
                default:
1081 258 julius
                        id_branch_op <=  `OR1200_BRANCHOP_NOP;
1082 141 marcus.erl
 
1083 10 unneback
                endcase
1084
        end
1085
end
1086
 
1087
//
1088 141 marcus.erl
// Generation of ex_branch_op
1089 10 unneback
//
1090 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst)
1091
        if (rst == `OR1200_RST_VALUE)
1092 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1093 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1094 258 julius
                ex_branch_op <=  `OR1200_BRANCHOP_NOP;
1095 10 unneback
        else if (!ex_freeze)
1096 258 julius
                ex_branch_op <=  id_branch_op;
1097 10 unneback
 
1098
//
1099 141 marcus.erl
// Decode of id_lsu_op
1100 10 unneback
//
1101 141 marcus.erl
always @(id_insn) begin
1102
        case (id_insn[31:26])           // synopsys parallel_case
1103
 
1104
        // l.lwz
1105
        `OR1200_OR32_LWZ:
1106 353 julius
                id_lsu_op =  `OR1200_LSUOP_LWZ;
1107 141 marcus.erl
 
1108 845 stekern
        // l.lws
1109
        `OR1200_OR32_LWS:
1110
                id_lsu_op =  `OR1200_LSUOP_LWS;
1111
 
1112 141 marcus.erl
        // l.lbz
1113
        `OR1200_OR32_LBZ:
1114 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBZ;
1115 141 marcus.erl
 
1116
        // l.lbs
1117
        `OR1200_OR32_LBS:
1118 353 julius
                id_lsu_op =  `OR1200_LSUOP_LBS;
1119 141 marcus.erl
 
1120
        // l.lhz
1121
        `OR1200_OR32_LHZ:
1122 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHZ;
1123 141 marcus.erl
 
1124
        // l.lhs
1125
        `OR1200_OR32_LHS:
1126 353 julius
                id_lsu_op =  `OR1200_LSUOP_LHS;
1127 141 marcus.erl
 
1128
        // l.sw
1129
        `OR1200_OR32_SW:
1130 353 julius
                id_lsu_op =  `OR1200_LSUOP_SW;
1131 141 marcus.erl
 
1132
        // l.sb
1133
        `OR1200_OR32_SB:
1134 353 julius
                id_lsu_op =  `OR1200_LSUOP_SB;
1135 141 marcus.erl
 
1136
        // l.sh
1137
        `OR1200_OR32_SH:
1138 353 julius
                id_lsu_op =  `OR1200_LSUOP_SH;
1139 141 marcus.erl
 
1140
        // Non load/store instructions
1141
        default:
1142 353 julius
                id_lsu_op =  `OR1200_LSUOP_NOP;
1143 141 marcus.erl
 
1144
        endcase
1145 10 unneback
end
1146
 
1147
//
1148
// Decode of comp_op
1149
//
1150 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1151
        if (rst == `OR1200_RST_VALUE) begin
1152 258 julius
                comp_op <=  4'd0;
1153 141 marcus.erl
        end else if (!ex_freeze & id_freeze | ex_flushpipe)
1154 258 julius
                comp_op <=  4'd0;
1155 10 unneback
        else if (!ex_freeze)
1156 258 julius
                comp_op <=  id_insn[24:21];
1157 10 unneback
end
1158
 
1159 185 julius
`ifdef OR1200_FPU_IMPLEMENTED
1160 10 unneback
//
1161 185 julius
// Decode of FPU ops
1162
//
1163 258 julius
   assign fpu_op = {(id_insn[31:26] == `OR1200_OR32_FLOAT),
1164
                    id_insn[`OR1200_FPUOP_WIDTH-2:0]};
1165 185 julius
`else
1166
   assign fpu_op = {`OR1200_FPUOP_WIDTH{1'b0}};
1167
`endif
1168
 
1169
 
1170
//
1171 10 unneback
// Decode of l.sys
1172
//
1173 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1174
        if (rst == `OR1200_RST_VALUE)
1175 258 julius
                sig_syscall <=  1'b0;
1176 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1177 258 julius
                sig_syscall <=  1'b0;
1178 10 unneback
        else if (!ex_freeze) begin
1179
`ifdef OR1200_VERBOSE
1180
// synopsys translate_off
1181
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000})
1182
                        $display("Generating sig_syscall");
1183
// synopsys translate_on
1184
`endif
1185 258 julius
                sig_syscall <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000});
1186 10 unneback
        end
1187
end
1188
 
1189
//
1190
// Decode of l.trap
1191
//
1192 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1193
        if (rst == `OR1200_RST_VALUE)
1194 258 julius
                sig_trap <=  1'b0;
1195 141 marcus.erl
        else if (!ex_freeze & id_freeze | ex_flushpipe)
1196 258 julius
                sig_trap <=  1'b0;
1197 10 unneback
        else if (!ex_freeze) begin
1198
`ifdef OR1200_VERBOSE
1199
// synopsys translate_off
1200
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1201
                        $display("Generating sig_trap");
1202
// synopsys translate_on
1203
`endif
1204 258 julius
                sig_trap <=  (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1205 10 unneback
                        | du_hwbkpt;
1206
        end
1207
end
1208
 
1209 258 julius
// Decode destination register address for data cache to check if store ops
1210
// are being done from the stack register (r1) or frame pointer register (r2)
1211
`ifdef OR1200_DC_NOSTACKWRITETHROUGH
1212 358 julius
always @(posedge clk or `OR1200_RST_EVENT rst) begin
1213
   if (rst == `OR1200_RST_VALUE)
1214 258 julius
     dc_no_writethrough <= 0;
1215
   else if (!ex_freeze)
1216
     dc_no_writethrough <= (id_insn[20:16] == 5'd1) | (id_insn[20:16] == 5'd2);
1217
end
1218
`else
1219
 
1220
   assign dc_no_writethrough = 0;
1221
 
1222
`endif
1223
 
1224 10 unneback
endmodule

powered by: WebSVN 2.1.0

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