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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [rtl/] [verilog/] [components/] [or1200r2/] [or1200_ctrl.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's Instruction decode                                 ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
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
// CVS Revision History
45
//
46
// $Log: or1200_ctrl.v,v $
47
// Revision 1.13  2005/01/13 11:03:43  phoenix
48
// revert to the old l.sfxxi behavior
49
//
50
// Revision 1.12  2005/01/07 09:31:07  andreje
51
// sign/zero extension for l.sfxxi instructions corrected
52
//
53
// Revision 1.11  2004/06/08 18:17:36  lampret
54
// Non-functional changes. Coding style fixes.
55
//
56
// Revision 1.10  2004/05/09 19:49:04  lampret
57
// Added some l.cust5 custom instructions as example
58
//
59
// Revision 1.9  2004/04/05 08:29:57  lampret
60
// Merged branch_qmem into main tree.
61
//
62
// Revision 1.8.4.1  2004/02/11 01:40:11  lampret
63
// preliminary HW breakpoints support in debug unit (by default disabled). To enable define OR1200_DU_HWBKPTS.
64
//
65
// Revision 1.8  2003/04/24 00:16:07  lampret
66
// No functional changes. Added defines to disable implementation of multiplier/MAC
67
//
68
// Revision 1.7  2002/09/07 05:42:02  lampret
69
// Added optional SR[CY]. Added define to enable additional (compare) flag modifiers. Defines are OR1200_IMPL_ADDC and OR1200_ADDITIONAL_FLAG_MODIFIERS.
70
//
71
// Revision 1.6  2002/03/29 15:16:54  lampret
72
// Some of the warnings fixed.
73
//
74
// Revision 1.5  2002/02/01 19:56:54  lampret
75
// Fixed combinational loops.
76
//
77
// Revision 1.4  2002/01/28 01:15:59  lampret
78
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
79
//
80
// Revision 1.3  2002/01/18 14:21:43  lampret
81
// Fixed 'the NPC single-step fix'.
82
//
83
// Revision 1.2  2002/01/14 06:18:22  lampret
84
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
85
//
86
// Revision 1.1  2002/01/03 08:16:15  lampret
87
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
88
//
89
// Revision 1.14  2001/11/30 18:59:17  simons
90
// force_dslot_fetch does not work -  allways zero.
91
//
92
// Revision 1.13  2001/11/20 18:46:15  simons
93
// Break point bug fixed
94
//
95
// Revision 1.12  2001/11/18 08:36:28  lampret
96
// For GDB changed single stepping and disabled trap exception.
97
//
98
// Revision 1.11  2001/11/13 10:02:21  lampret
99
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
100
//
101
// Revision 1.10  2001/11/12 01:45:40  lampret
102
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
103
//
104
// Revision 1.9  2001/11/10 03:43:57  lampret
105
// Fixed exceptions.
106
//
107
// Revision 1.8  2001/10/21 17:57:16  lampret
108
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
109
//
110
// Revision 1.7  2001/10/14 13:12:09  lampret
111
// MP3 version.
112
//
113
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
114
// no message
115
//
116
// Revision 1.2  2001/08/13 03:36:20  lampret
117
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
118
//
119
// Revision 1.1  2001/08/09 13:39:33  lampret
120
// Major clean-up.
121
//
122
//
123
 
124
// synopsys translate_off
125
`include "timescale.v"
126
// synopsys translate_on
127
`include "or1200_defines.v"
128
 
129
module or1200_ctrl(
130
        // Clock and reset
131
        clk, rst,
132
 
133
        // Internal i/f
134
        id_freeze, ex_freeze, wb_freeze, flushpipe, if_insn, ex_insn, pre_branch_op, branch_op, branch_taken,
135
        rf_addra, rf_addrb, rf_rda, rf_rdb, alu_op, mac_op, shrot_op, comp_op, rf_addrw, rfwb_op,
136
        wb_insn, simm, branch_addrofs, lsu_addrofs, sel_a, sel_b, lsu_op,
137
        cust5_op, cust5_limm,
138
        multicycle, spr_addrimm, wbforw_valid, du_hwbkpt, sig_syscall, sig_trap,
139
        force_dslot_fetch, no_more_dslot, ex_void, id_macrc_op, ex_macrc_op, rfe, except_illegal
140
);
141
 
142
//
143
// I/O
144
//
145
input                                   clk;
146
input                                   rst;
147
input                                   id_freeze;
148
input                                   ex_freeze;
149 48 julius
input                                   wb_freeze /* verilator public */;
150 18 unneback
input                                   flushpipe;
151
input   [31:0]                           if_insn;
152
output  [31:0]                           ex_insn;
153
output  [`OR1200_BRANCHOP_WIDTH-1:0]             pre_branch_op;
154
output  [`OR1200_BRANCHOP_WIDTH-1:0]             branch_op;
155
input                                           branch_taken;
156
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
157
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addra;
158
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrb;
159
output                                  rf_rda;
160
output                                  rf_rdb;
161
output  [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
162
output  [`OR1200_MACOP_WIDTH-1:0]                mac_op;
163
output  [`OR1200_SHROTOP_WIDTH-1:0]              shrot_op;
164
output  [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
165
output  [31:0]                           wb_insn;
166
output  [31:0]                           simm;
167
output  [31:2]                          branch_addrofs;
168
output  [31:0]                           lsu_addrofs;
169
output  [`OR1200_SEL_WIDTH-1:0]          sel_a;
170
output  [`OR1200_SEL_WIDTH-1:0]          sel_b;
171
output  [`OR1200_LSUOP_WIDTH-1:0]                lsu_op;
172
output  [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
173
output  [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
174
output  [4:0]                            cust5_op;
175
output  [5:0]                            cust5_limm;
176
output  [15:0]                           spr_addrimm;
177
input                                   wbforw_valid;
178
input                                   du_hwbkpt;
179
output                                  sig_syscall;
180
output                                  sig_trap;
181
output                                  force_dslot_fetch;
182
output                                  no_more_dslot;
183
output                                  ex_void;
184
output                                  id_macrc_op;
185
output                                  ex_macrc_op;
186
output                                  rfe;
187
output                                  except_illegal;
188
 
189
//
190
// Internal wires and regs
191
//
192
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             pre_branch_op;
193
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             branch_op;
194
reg     [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
195
`ifdef OR1200_MAC_IMPLEMENTED
196
reg     [`OR1200_MACOP_WIDTH-1:0]                mac_op;
197
reg                                     ex_macrc_op;
198
`else
199
wire    [`OR1200_MACOP_WIDTH-1:0]                mac_op;
200
wire                                    ex_macrc_op;
201
`endif
202
reg     [`OR1200_SHROTOP_WIDTH-1:0]              shrot_op;
203
reg     [31:0]                           id_insn;
204
reg     [31:0]                           ex_insn;
205
reg     [31:0]                           wb_insn;
206
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
207
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] wb_rfaddrw;
208
reg     [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
209
reg     [31:0]                           lsu_addrofs;
210
reg     [`OR1200_SEL_WIDTH-1:0]          sel_a;
211
reg     [`OR1200_SEL_WIDTH-1:0]          sel_b;
212
reg                                     sel_imm;
213
reg     [`OR1200_LSUOP_WIDTH-1:0]                lsu_op;
214
reg     [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
215
reg     [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
216
reg                                     imm_signextend;
217
reg     [15:0]                           spr_addrimm;
218
reg                                     sig_syscall;
219
reg                                     sig_trap;
220
reg                                     except_illegal;
221
wire                                    id_void;
222
 
223
//
224
// Register file read addresses
225
//
226
assign rf_addra = if_insn[20:16];
227
assign rf_addrb = if_insn[15:11];
228
assign rf_rda = if_insn[31];
229
assign rf_rdb = if_insn[30];
230
 
231
//
232
// Force fetch of delay slot instruction when jump/branch is preceeded by load/store
233
// instructions
234
//
235
// SIMON
236
// assign force_dslot_fetch = ((|pre_branch_op) & (|lsu_op));
237
assign force_dslot_fetch = 1'b0;
238
assign no_more_dslot = |branch_op & !id_void & branch_taken | (branch_op == `OR1200_BRANCHOP_RFE);
239
assign id_void = (id_insn[31:26] == `OR1200_OR32_NOP) & id_insn[16];
240
assign ex_void = (ex_insn[31:26] == `OR1200_OR32_NOP) & ex_insn[16];
241
 
242
//
243
// Sign/Zero extension of immediates
244
//
245
assign simm = (imm_signextend == 1'b1) ? {{16{id_insn[15]}}, id_insn[15:0]} : {{16'b0}, id_insn[15:0]};
246
 
247
//
248
// Sign extension of branch offset
249
//
250
assign branch_addrofs = {{4{ex_insn[25]}}, ex_insn[25:0]};
251
 
252
//
253
// l.macrc in ID stage
254
//
255
`ifdef OR1200_MAC_IMPLEMENTED
256
assign id_macrc_op = (id_insn[31:26] == `OR1200_OR32_MOVHI) & id_insn[16];
257
`else
258
assign id_macrc_op = 1'b0;
259
`endif
260
 
261
//
262
// cust5_op, cust5_limm (L immediate)
263
//
264
assign cust5_op = ex_insn[4:0];
265
assign cust5_limm = ex_insn[10:5];
266
 
267
//
268
//
269
//
270
assign rfe = (pre_branch_op == `OR1200_BRANCHOP_RFE) | (branch_op == `OR1200_BRANCHOP_RFE);
271
 
272 48 julius
`ifdef verilator
273
   // Function to access wb_insn (for Verilator). Have to hide this from
274
   // simulator, since functions with no inputs are not allowed in IEEE
275
   // 1364-2001.
276
   function [31:0] get_wb_insn;
277
      // verilator public
278
      get_wb_insn = wb_insn;
279
   endfunction // get_wb_insn
280
`endif
281
 
282
 
283 18 unneback
//
284
// Generation of sel_a
285
//
286
always @(rf_addrw or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
287
        if ((id_insn[20:16] == rf_addrw) && rfwb_op[0])
288
                sel_a = `OR1200_SEL_EX_FORW;
289
        else if ((id_insn[20:16] == wb_rfaddrw) && wbforw_valid)
290
                sel_a = `OR1200_SEL_WB_FORW;
291
        else
292
                sel_a = `OR1200_SEL_RF;
293
 
294
//
295
// Generation of sel_b
296
//
297
always @(rf_addrw or sel_imm or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
298
        if (sel_imm)
299
                sel_b = `OR1200_SEL_IMM;
300
        else if ((id_insn[15:11] == rf_addrw) && rfwb_op[0])
301
                sel_b = `OR1200_SEL_EX_FORW;
302
        else if ((id_insn[15:11] == wb_rfaddrw) && wbforw_valid)
303
                sel_b = `OR1200_SEL_WB_FORW;
304
        else
305
                sel_b = `OR1200_SEL_RF;
306
 
307
//
308
// l.macrc in EX stage
309
//
310
`ifdef OR1200_MAC_IMPLEMENTED
311
always @(posedge clk or posedge rst) begin
312
        if (rst)
313
                ex_macrc_op <= #1 1'b0;
314
        else if (!ex_freeze & id_freeze | flushpipe)
315
                ex_macrc_op <= #1 1'b0;
316
        else if (!ex_freeze)
317
                ex_macrc_op <= #1 id_macrc_op;
318
end
319
`else
320
assign ex_macrc_op = 1'b0;
321
`endif
322
 
323
//
324
// Decode of spr_addrimm
325
//
326
always @(posedge clk or posedge rst) begin
327
        if (rst)
328
                spr_addrimm <= #1 16'h0000;
329
        else if (!ex_freeze & id_freeze | flushpipe)
330
                spr_addrimm <= #1 16'h0000;
331
        else if (!ex_freeze) begin
332
                case (id_insn[31:26])   // synopsys parallel_case
333
                        // l.mfspr
334
                        `OR1200_OR32_MFSPR:
335
                                spr_addrimm <= #1 id_insn[15:0];
336
                        // l.mtspr
337
                        default:
338
                                spr_addrimm <= #1 {id_insn[25:21], id_insn[10:0]};
339
                endcase
340
        end
341
end
342
 
343
//
344
// Decode of multicycle
345
//
346
always @(id_insn) begin
347
  case (id_insn[31:26])         // synopsys parallel_case
348
`ifdef UNUSED
349
    // l.lwz
350
    `OR1200_OR32_LWZ:
351
      multicycle = `OR1200_TWO_CYCLES;
352
 
353
    // l.lbz
354
    `OR1200_OR32_LBZ:
355
      multicycle = `OR1200_TWO_CYCLES;
356
 
357
    // l.lbs
358
    `OR1200_OR32_LBS:
359
      multicycle = `OR1200_TWO_CYCLES;
360
 
361
    // l.lhz
362
    `OR1200_OR32_LHZ:
363
      multicycle = `OR1200_TWO_CYCLES;
364
 
365
    // l.lhs
366
    `OR1200_OR32_LHS:
367
      multicycle = `OR1200_TWO_CYCLES;
368
 
369
    // l.sw
370
    `OR1200_OR32_SW:
371
      multicycle = `OR1200_TWO_CYCLES;
372
 
373
    // l.sb
374
    `OR1200_OR32_SB:
375
      multicycle = `OR1200_TWO_CYCLES;
376
 
377
    // l.sh
378
    `OR1200_OR32_SH:
379
      multicycle = `OR1200_TWO_CYCLES;
380
`endif
381
    // ALU instructions except the one with immediate
382
    `OR1200_OR32_ALU:
383
      multicycle = id_insn[`OR1200_ALUMCYC_POS];
384
 
385
    `OR1200_OR32_MULI:
386
      multicycle = 2'h3;
387
 
388
    // Single cycle instructions
389
    default: begin
390
      multicycle = `OR1200_ONE_CYCLE;
391
    end
392
 
393
  endcase
394
 
395
end
396
 
397
//
398
// Decode of imm_signextend
399
//
400
always @(id_insn) begin
401
  case (id_insn[31:26])         // synopsys parallel_case
402
 
403
        // l.addi
404
        `OR1200_OR32_ADDI:
405
                imm_signextend = 1'b1;
406
 
407
        // l.addic
408
        `OR1200_OR32_ADDIC:
409
                imm_signextend = 1'b1;
410
 
411
        // l.xori
412
        `OR1200_OR32_XORI:
413
                imm_signextend = 1'b1;
414
 
415
        // l.muli
416
`ifdef OR1200_MULT_IMPLEMENTED
417
        `OR1200_OR32_MULI:
418
                imm_signextend = 1'b1;
419
`endif
420
 
421
        // l.maci
422
`ifdef OR1200_MAC_IMPLEMENTED
423
        `OR1200_OR32_MACI:
424
                imm_signextend = 1'b1;
425
`endif
426
 
427
        // SFXX insns with immediate
428
        `OR1200_OR32_SFXXI:
429
                imm_signextend = 1'b1;
430
 
431
        // Instructions with no or zero extended immediate
432
        default: begin
433
                imm_signextend = 1'b0;
434
        end
435
 
436
endcase
437
 
438
end
439
 
440
//
441
// LSU addr offset
442
//
443
always @(lsu_op or ex_insn) begin
444
        lsu_addrofs[10:0] = ex_insn[10:0];
445
        case(lsu_op)    // synopsys parallel_case
446
                `OR1200_LSUOP_SW, `OR1200_LSUOP_SH, `OR1200_LSUOP_SB :
447
                        lsu_addrofs[31:11] = {{16{ex_insn[25]}}, ex_insn[25:21]};
448
                default :
449
                        lsu_addrofs[31:11] = {{16{ex_insn[15]}}, ex_insn[15:11]};
450
        endcase
451
end
452
 
453
//
454
// Register file write address
455
//
456
always @(posedge clk or posedge rst) begin
457
        if (rst)
458
                rf_addrw <= #1 5'd0;
459
        else if (!ex_freeze & id_freeze)
460
                rf_addrw <= #1 5'd00;
461
        else if (!ex_freeze)
462
                case (pre_branch_op)    // synopsys parallel_case
463
                        `OR1200_BRANCHOP_JR, `OR1200_BRANCHOP_BAL:
464
                                rf_addrw <= #1 5'd09;   // link register r9
465
                        default:
466
                                rf_addrw <= #1 id_insn[25:21];
467
                endcase
468
end
469
 
470
//
471
// rf_addrw in wb stage (used in forwarding logic)
472
//
473
always @(posedge clk or posedge rst) begin
474
        if (rst)
475
                wb_rfaddrw <= #1 5'd0;
476
        else if (!wb_freeze)
477
                wb_rfaddrw <= #1 rf_addrw;
478
end
479
 
480
//
481
// Instruction latch in id_insn
482
//
483
always @(posedge clk or posedge rst) begin
484
        if (rst)
485
                id_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
486
        else if (flushpipe)
487
                id_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};        // id_insn[16] must be 1
488
        else if (!id_freeze) begin
489
                id_insn <= #1 if_insn;
490
`ifdef OR1200_VERBOSE
491
// synopsys translate_off
492
                $display("%t: id_insn <= %h", $time, if_insn);
493
// synopsys translate_on
494
`endif
495
        end
496
end
497
 
498
//
499
// Instruction latch in ex_insn
500
//
501
always @(posedge clk or posedge rst) begin
502
        if (rst)
503
                ex_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
504
        else if (!ex_freeze & id_freeze | flushpipe)
505
                ex_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000}; // ex_insn[16] must be 1
506
        else if (!ex_freeze) begin
507
                ex_insn <= #1 id_insn;
508
`ifdef OR1200_VERBOSE
509
// synopsys translate_off
510
                $display("%t: ex_insn <= %h", $time, id_insn);
511
// synopsys translate_on
512
`endif
513
        end
514
end
515
 
516
//
517
// Instruction latch in wb_insn
518
//
519
always @(posedge clk or posedge rst) begin
520
        if (rst)
521
                wb_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
522
        else if (flushpipe)
523
                wb_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000}; // wb_insn[16] must be 1
524
        else if (!wb_freeze) begin
525
                wb_insn <= #1 ex_insn;
526
        end
527
end
528
 
529
//
530
// Decode of sel_imm
531
//
532
always @(posedge clk or posedge rst) begin
533
        if (rst)
534
                sel_imm <= #1 1'b0;
535
        else if (!id_freeze) begin
536
          case (if_insn[31:26])         // synopsys parallel_case
537
 
538
            // j.jalr
539
            `OR1200_OR32_JALR:
540
              sel_imm <= #1 1'b0;
541
 
542
            // l.jr
543
            `OR1200_OR32_JR:
544
              sel_imm <= #1 1'b0;
545
 
546
            // l.rfe
547
            `OR1200_OR32_RFE:
548
              sel_imm <= #1 1'b0;
549
 
550
            // l.mfspr
551
            `OR1200_OR32_MFSPR:
552
              sel_imm <= #1 1'b0;
553
 
554
            // l.mtspr
555
            `OR1200_OR32_MTSPR:
556
              sel_imm <= #1 1'b0;
557
 
558
            // l.sys, l.brk and all three sync insns
559
            `OR1200_OR32_XSYNC:
560
              sel_imm <= #1 1'b0;
561
 
562
            // l.mac/l.msb
563
`ifdef OR1200_MAC_IMPLEMENTED
564
            `OR1200_OR32_MACMSB:
565
              sel_imm <= #1 1'b0;
566
`endif
567
 
568
            // l.sw
569
            `OR1200_OR32_SW:
570
              sel_imm <= #1 1'b0;
571
 
572
            // l.sb
573
            `OR1200_OR32_SB:
574
              sel_imm <= #1 1'b0;
575
 
576
            // l.sh
577
            `OR1200_OR32_SH:
578
              sel_imm <= #1 1'b0;
579
 
580
            // ALU instructions except the one with immediate
581
            `OR1200_OR32_ALU:
582
              sel_imm <= #1 1'b0;
583
 
584
            // SFXX instructions
585
            `OR1200_OR32_SFXX:
586
              sel_imm <= #1 1'b0;
587
 
588
`ifdef OR1200_OR32_CUST5
589
            // l.cust5 instructions
590
            `OR1200_OR32_CUST5:
591
              sel_imm <= #1 1'b0;
592
`endif
593
 
594
            // l.nop
595
            `OR1200_OR32_NOP:
596
              sel_imm <= #1 1'b0;
597
 
598
            // All instructions with immediates
599
            default: begin
600
              sel_imm <= #1 1'b1;
601
            end
602
 
603
          endcase
604
 
605
        end
606
end
607
 
608
//
609
// Decode of except_illegal
610
//
611
always @(posedge clk or posedge rst) begin
612
        if (rst)
613
                except_illegal <= #1 1'b0;
614
        else if (!ex_freeze & id_freeze | flushpipe)
615
                except_illegal <= #1 1'b0;
616
        else if (!ex_freeze) begin
617
          case (id_insn[31:26])         // synopsys parallel_case
618
 
619
            `OR1200_OR32_J,
620
            `OR1200_OR32_JAL,
621
            `OR1200_OR32_JALR,
622
            `OR1200_OR32_JR,
623
            `OR1200_OR32_BNF,
624
            `OR1200_OR32_BF,
625
            `OR1200_OR32_RFE,
626
            `OR1200_OR32_MOVHI,
627
            `OR1200_OR32_MFSPR,
628
            `OR1200_OR32_XSYNC,
629
`ifdef OR1200_MAC_IMPLEMENTED
630
            `OR1200_OR32_MACI,
631
`endif
632
            `OR1200_OR32_LWZ,
633
            `OR1200_OR32_LBZ,
634
            `OR1200_OR32_LBS,
635
            `OR1200_OR32_LHZ,
636
            `OR1200_OR32_LHS,
637
            `OR1200_OR32_ADDI,
638
            `OR1200_OR32_ADDIC,
639
            `OR1200_OR32_ANDI,
640
            `OR1200_OR32_ORI,
641
            `OR1200_OR32_XORI,
642
`ifdef OR1200_MULT_IMPLEMENTED
643
            `OR1200_OR32_MULI,
644
`endif
645
            `OR1200_OR32_SH_ROTI,
646
            `OR1200_OR32_SFXXI,
647
            `OR1200_OR32_MTSPR,
648
`ifdef OR1200_MAC_IMPLEMENTED
649
            `OR1200_OR32_MACMSB,
650
`endif
651
            `OR1200_OR32_SW,
652
            `OR1200_OR32_SB,
653
            `OR1200_OR32_SH,
654
            `OR1200_OR32_ALU,
655
            `OR1200_OR32_SFXX,
656
`ifdef OR1200_OR32_CUST5
657
            `OR1200_OR32_CUST5,
658
`endif
659
            `OR1200_OR32_NOP:
660
                except_illegal <= #1 1'b0;
661
 
662
            // Illegal and OR1200 unsupported instructions
663
            default:
664
              except_illegal <= #1 1'b1;
665
 
666
          endcase
667
 
668
        end
669
end
670
 
671
//
672
// Decode of alu_op
673
//
674
always @(posedge clk or posedge rst) begin
675
        if (rst)
676
                alu_op <= #1 `OR1200_ALUOP_NOP;
677
        else if (!ex_freeze & id_freeze | flushpipe)
678
                alu_op <= #1 `OR1200_ALUOP_NOP;
679
        else if (!ex_freeze) begin
680
          case (id_insn[31:26])         // synopsys parallel_case
681
 
682
            // l.j
683
            `OR1200_OR32_J:
684
              alu_op <= #1 `OR1200_ALUOP_IMM;
685
 
686
            // j.jal
687
            `OR1200_OR32_JAL:
688
              alu_op <= #1 `OR1200_ALUOP_IMM;
689
 
690
            // l.bnf
691
            `OR1200_OR32_BNF:
692
              alu_op <= #1 `OR1200_ALUOP_NOP;
693
 
694
            // l.bf
695
            `OR1200_OR32_BF:
696
              alu_op <= #1 `OR1200_ALUOP_NOP;
697
 
698
            // l.movhi
699
            `OR1200_OR32_MOVHI:
700
              alu_op <= #1 `OR1200_ALUOP_MOVHI;
701
 
702
            // l.mfspr
703
            `OR1200_OR32_MFSPR:
704
              alu_op <= #1 `OR1200_ALUOP_MFSR;
705
 
706
            // l.mtspr
707
            `OR1200_OR32_MTSPR:
708
              alu_op <= #1 `OR1200_ALUOP_MTSR;
709
 
710
            // l.addi
711
            `OR1200_OR32_ADDI:
712
              alu_op <= #1 `OR1200_ALUOP_ADD;
713
 
714
            // l.addic
715
            `OR1200_OR32_ADDIC:
716
              alu_op <= #1 `OR1200_ALUOP_ADDC;
717
 
718
            // l.andi
719
            `OR1200_OR32_ANDI:
720
              alu_op <= #1 `OR1200_ALUOP_AND;
721
 
722
            // l.ori
723
            `OR1200_OR32_ORI:
724
              alu_op <= #1 `OR1200_ALUOP_OR;
725
 
726
            // l.xori
727
            `OR1200_OR32_XORI:
728
              alu_op <= #1 `OR1200_ALUOP_XOR;
729
 
730
            // l.muli
731
`ifdef OR1200_MULT_IMPLEMENTED
732
            `OR1200_OR32_MULI:
733
              alu_op <= #1 `OR1200_ALUOP_MUL;
734
`endif
735
 
736
            // Shift and rotate insns with immediate
737
            `OR1200_OR32_SH_ROTI:
738
              alu_op <= #1 `OR1200_ALUOP_SHROT;
739
 
740
            // SFXX insns with immediate
741
            `OR1200_OR32_SFXXI:
742
              alu_op <= #1 `OR1200_ALUOP_COMP;
743
 
744
            // ALU instructions except the one with immediate
745
            `OR1200_OR32_ALU:
746
              alu_op <= #1 id_insn[3:0];
747
 
748
            // SFXX instructions
749
            `OR1200_OR32_SFXX:
750
              alu_op <= #1 `OR1200_ALUOP_COMP;
751
 
752
`ifdef OR1200_OR32_CUST5
753
            // l.cust5 instructions
754
            `OR1200_OR32_CUST5:
755
              alu_op <= #1 `OR1200_ALUOP_CUST5;
756
`endif
757
 
758
            // Default
759
            default: begin
760
              alu_op <= #1 `OR1200_ALUOP_NOP;
761
            end
762
 
763
          endcase
764
 
765
        end
766
end
767
 
768
//
769
// Decode of mac_op
770
//
771
`ifdef OR1200_MAC_IMPLEMENTED
772
always @(posedge clk or posedge rst) begin
773
        if (rst)
774
                mac_op <= #1 `OR1200_MACOP_NOP;
775
        else if (!ex_freeze & id_freeze | flushpipe)
776
                mac_op <= #1 `OR1200_MACOP_NOP;
777
        else if (!ex_freeze)
778
          case (id_insn[31:26])         // synopsys parallel_case
779
 
780
            // l.maci
781
            `OR1200_OR32_MACI:
782
              mac_op <= #1 `OR1200_MACOP_MAC;
783
 
784
            // l.nop
785
            `OR1200_OR32_MACMSB:
786
              mac_op <= #1 id_insn[1:0];
787
 
788
            // Illegal and OR1200 unsupported instructions
789
            default: begin
790
              mac_op <= #1 `OR1200_MACOP_NOP;
791
            end
792
 
793
          endcase
794
        else
795
                mac_op <= #1 `OR1200_MACOP_NOP;
796
end
797
`else
798
assign mac_op = `OR1200_MACOP_NOP;
799
`endif
800
 
801
//
802
// Decode of shrot_op
803
//
804
always @(posedge clk or posedge rst) begin
805
        if (rst)
806
                shrot_op <= #1 `OR1200_SHROTOP_NOP;
807
        else if (!ex_freeze & id_freeze | flushpipe)
808
                shrot_op <= #1 `OR1200_SHROTOP_NOP;
809
        else if (!ex_freeze) begin
810
                shrot_op <= #1 id_insn[`OR1200_SHROTOP_POS];
811
        end
812
end
813
 
814
//
815
// Decode of rfwb_op
816
//
817
always @(posedge clk or posedge rst) begin
818
        if (rst)
819
                rfwb_op <= #1 `OR1200_RFWBOP_NOP;
820
        else  if (!ex_freeze & id_freeze | flushpipe)
821
                rfwb_op <= #1 `OR1200_RFWBOP_NOP;
822
        else  if (!ex_freeze) begin
823
                case (id_insn[31:26])           // synopsys parallel_case
824
 
825
                  // j.jal
826
                  `OR1200_OR32_JAL:
827
                    rfwb_op <= #1 `OR1200_RFWBOP_LR;
828
 
829
                  // j.jalr
830
                  `OR1200_OR32_JALR:
831
                    rfwb_op <= #1 `OR1200_RFWBOP_LR;
832
 
833
                  // l.movhi
834
                  `OR1200_OR32_MOVHI:
835
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
836
 
837
                  // l.mfspr
838
                  `OR1200_OR32_MFSPR:
839
                    rfwb_op <= #1 `OR1200_RFWBOP_SPRS;
840
 
841
                  // l.lwz
842
                  `OR1200_OR32_LWZ:
843
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
844
 
845
                  // l.lbz
846
                  `OR1200_OR32_LBZ:
847
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
848
 
849
                  // l.lbs
850
                  `OR1200_OR32_LBS:
851
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
852
 
853
                  // l.lhz
854
                  `OR1200_OR32_LHZ:
855
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
856
 
857
                  // l.lhs
858
                  `OR1200_OR32_LHS:
859
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
860
 
861
                  // l.addi
862
                  `OR1200_OR32_ADDI:
863
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
864
 
865
                  // l.addic
866
                  `OR1200_OR32_ADDIC:
867
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
868
 
869
                  // l.andi
870
                  `OR1200_OR32_ANDI:
871
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
872
 
873
                  // l.ori
874
                  `OR1200_OR32_ORI:
875
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
876
 
877
                  // l.xori
878
                  `OR1200_OR32_XORI:
879
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
880
 
881
                  // l.muli
882
`ifdef OR1200_MULT_IMPLEMENTED
883
                  `OR1200_OR32_MULI:
884
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
885
`endif
886
 
887
                  // Shift and rotate insns with immediate
888
                  `OR1200_OR32_SH_ROTI:
889
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
890
 
891
                  // ALU instructions except the one with immediate
892
                  `OR1200_OR32_ALU:
893
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
894
 
895
`ifdef OR1200_OR32_CUST5
896
                  // l.cust5 instructions
897
                  `OR1200_OR32_CUST5:
898
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
899
`endif
900
 
901
                  // Instructions w/o register-file write-back
902
                  default: begin
903
                    rfwb_op <= #1 `OR1200_RFWBOP_NOP;
904
                  end
905
 
906
                endcase
907
        end
908
end
909
 
910
//
911
// Decode of pre_branch_op
912
//
913
always @(posedge clk or posedge rst) begin
914
        if (rst)
915
                pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
916
        else if (flushpipe)
917
                pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
918
        else if (!id_freeze) begin
919
                case (if_insn[31:26])           // synopsys parallel_case
920
 
921
                  // l.j
922
                  `OR1200_OR32_J:
923
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BAL;
924
 
925
                  // j.jal
926
                  `OR1200_OR32_JAL:
927
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BAL;
928
 
929
                  // j.jalr
930
                  `OR1200_OR32_JALR:
931
                    pre_branch_op <= #1 `OR1200_BRANCHOP_JR;
932
 
933
                  // l.jr
934
                  `OR1200_OR32_JR:
935
                    pre_branch_op <= #1 `OR1200_BRANCHOP_JR;
936
 
937
                  // l.bnf
938
                  `OR1200_OR32_BNF:
939
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BNF;
940
 
941
                  // l.bf
942
                  `OR1200_OR32_BF:
943
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BF;
944
 
945
                  // l.rfe
946
                  `OR1200_OR32_RFE:
947
                    pre_branch_op <= #1 `OR1200_BRANCHOP_RFE;
948
 
949
                  // Non branch instructions
950
                  default: begin
951
                    pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
952
                  end
953
                endcase
954
        end
955
end
956
 
957
//
958
// Generation of branch_op
959
//
960
always @(posedge clk or posedge rst)
961
        if (rst)
962
                branch_op <= #1 `OR1200_BRANCHOP_NOP;
963
        else if (!ex_freeze & id_freeze | flushpipe)
964
                branch_op <= #1 `OR1200_BRANCHOP_NOP;
965
        else if (!ex_freeze)
966
                branch_op <= #1 pre_branch_op;
967
 
968
//
969
// Decode of lsu_op
970
//
971
always @(posedge clk or posedge rst) begin
972
        if (rst)
973
                lsu_op <= #1 `OR1200_LSUOP_NOP;
974
        else if (!ex_freeze & id_freeze | flushpipe)
975
                lsu_op <= #1 `OR1200_LSUOP_NOP;
976
        else if (!ex_freeze)  begin
977
          case (id_insn[31:26])         // synopsys parallel_case
978
 
979
            // l.lwz
980
            `OR1200_OR32_LWZ:
981
              lsu_op <= #1 `OR1200_LSUOP_LWZ;
982
 
983
            // l.lbz
984
            `OR1200_OR32_LBZ:
985
              lsu_op <= #1 `OR1200_LSUOP_LBZ;
986
 
987
            // l.lbs
988
            `OR1200_OR32_LBS:
989
              lsu_op <= #1 `OR1200_LSUOP_LBS;
990
 
991
            // l.lhz
992
            `OR1200_OR32_LHZ:
993
              lsu_op <= #1 `OR1200_LSUOP_LHZ;
994
 
995
            // l.lhs
996
            `OR1200_OR32_LHS:
997
              lsu_op <= #1 `OR1200_LSUOP_LHS;
998
 
999
            // l.sw
1000
            `OR1200_OR32_SW:
1001
              lsu_op <= #1 `OR1200_LSUOP_SW;
1002
 
1003
            // l.sb
1004
            `OR1200_OR32_SB:
1005
              lsu_op <= #1 `OR1200_LSUOP_SB;
1006
 
1007
            // l.sh
1008
            `OR1200_OR32_SH:
1009
              lsu_op <= #1 `OR1200_LSUOP_SH;
1010
 
1011
            // Non load/store instructions
1012
            default: begin
1013
              lsu_op <= #1 `OR1200_LSUOP_NOP;
1014
            end
1015
          endcase
1016
        end
1017
end
1018
 
1019
//
1020
// Decode of comp_op
1021
//
1022
always @(posedge clk or posedge rst) begin
1023
        if (rst) begin
1024
                comp_op <= #1 4'd0;
1025
        end else if (!ex_freeze & id_freeze | flushpipe)
1026
                comp_op <= #1 4'd0;
1027
        else if (!ex_freeze)
1028
                comp_op <= #1 id_insn[24:21];
1029
end
1030
 
1031
//
1032
// Decode of l.sys
1033
//
1034
always @(posedge clk or posedge rst) begin
1035
        if (rst)
1036
                sig_syscall <= #1 1'b0;
1037
        else if (!ex_freeze & id_freeze | flushpipe)
1038
                sig_syscall <= #1 1'b0;
1039
        else if (!ex_freeze) begin
1040
`ifdef OR1200_VERBOSE
1041
// synopsys translate_off
1042
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000})
1043
                        $display("Generating sig_syscall");
1044
// synopsys translate_on
1045
`endif
1046
                sig_syscall <= #1 (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000});
1047
        end
1048
end
1049
 
1050
//
1051
// Decode of l.trap
1052
//
1053
always @(posedge clk or posedge rst) begin
1054
        if (rst)
1055
                sig_trap <= #1 1'b0;
1056
        else if (!ex_freeze & id_freeze | flushpipe)
1057
                sig_trap <= #1 1'b0;
1058
        else if (!ex_freeze) begin
1059
`ifdef OR1200_VERBOSE
1060
// synopsys translate_off
1061
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1062
                        $display("Generating sig_trap");
1063
// synopsys translate_on
1064
`endif
1065
                sig_trap <= #1 (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1066
                        | du_hwbkpt;
1067
        end
1068
end
1069
 
1070
endmodule

powered by: WebSVN 2.1.0

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