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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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