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 45

Go to most recent revision | 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
input                                   wb_freeze;
150
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
//
273
// Generation of sel_a
274
//
275
always @(rf_addrw or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
276
        if ((id_insn[20:16] == rf_addrw) && rfwb_op[0])
277
                sel_a = `OR1200_SEL_EX_FORW;
278
        else if ((id_insn[20:16] == wb_rfaddrw) && wbforw_valid)
279
                sel_a = `OR1200_SEL_WB_FORW;
280
        else
281
                sel_a = `OR1200_SEL_RF;
282
 
283
//
284
// Generation of sel_b
285
//
286
always @(rf_addrw or sel_imm or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
287
        if (sel_imm)
288
                sel_b = `OR1200_SEL_IMM;
289
        else if ((id_insn[15:11] == rf_addrw) && rfwb_op[0])
290
                sel_b = `OR1200_SEL_EX_FORW;
291
        else if ((id_insn[15:11] == wb_rfaddrw) && wbforw_valid)
292
                sel_b = `OR1200_SEL_WB_FORW;
293
        else
294
                sel_b = `OR1200_SEL_RF;
295
 
296
//
297
// l.macrc in EX stage
298
//
299
`ifdef OR1200_MAC_IMPLEMENTED
300
always @(posedge clk or posedge rst) begin
301
        if (rst)
302
                ex_macrc_op <= #1 1'b0;
303
        else if (!ex_freeze & id_freeze | flushpipe)
304
                ex_macrc_op <= #1 1'b0;
305
        else if (!ex_freeze)
306
                ex_macrc_op <= #1 id_macrc_op;
307
end
308
`else
309
assign ex_macrc_op = 1'b0;
310
`endif
311
 
312
//
313
// Decode of spr_addrimm
314
//
315
always @(posedge clk or posedge rst) begin
316
        if (rst)
317
                spr_addrimm <= #1 16'h0000;
318
        else if (!ex_freeze & id_freeze | flushpipe)
319
                spr_addrimm <= #1 16'h0000;
320
        else if (!ex_freeze) begin
321
                case (id_insn[31:26])   // synopsys parallel_case
322
                        // l.mfspr
323
                        `OR1200_OR32_MFSPR:
324
                                spr_addrimm <= #1 id_insn[15:0];
325
                        // l.mtspr
326
                        default:
327
                                spr_addrimm <= #1 {id_insn[25:21], id_insn[10:0]};
328
                endcase
329
        end
330
end
331
 
332
//
333
// Decode of multicycle
334
//
335
always @(id_insn) begin
336
  case (id_insn[31:26])         // synopsys parallel_case
337
`ifdef UNUSED
338
    // l.lwz
339
    `OR1200_OR32_LWZ:
340
      multicycle = `OR1200_TWO_CYCLES;
341
 
342
    // l.lbz
343
    `OR1200_OR32_LBZ:
344
      multicycle = `OR1200_TWO_CYCLES;
345
 
346
    // l.lbs
347
    `OR1200_OR32_LBS:
348
      multicycle = `OR1200_TWO_CYCLES;
349
 
350
    // l.lhz
351
    `OR1200_OR32_LHZ:
352
      multicycle = `OR1200_TWO_CYCLES;
353
 
354
    // l.lhs
355
    `OR1200_OR32_LHS:
356
      multicycle = `OR1200_TWO_CYCLES;
357
 
358
    // l.sw
359
    `OR1200_OR32_SW:
360
      multicycle = `OR1200_TWO_CYCLES;
361
 
362
    // l.sb
363
    `OR1200_OR32_SB:
364
      multicycle = `OR1200_TWO_CYCLES;
365
 
366
    // l.sh
367
    `OR1200_OR32_SH:
368
      multicycle = `OR1200_TWO_CYCLES;
369
`endif
370
    // ALU instructions except the one with immediate
371
    `OR1200_OR32_ALU:
372
      multicycle = id_insn[`OR1200_ALUMCYC_POS];
373
 
374
    `OR1200_OR32_MULI:
375
      multicycle = 2'h3;
376
 
377
    // Single cycle instructions
378
    default: begin
379
      multicycle = `OR1200_ONE_CYCLE;
380
    end
381
 
382
  endcase
383
 
384
end
385
 
386
//
387
// Decode of imm_signextend
388
//
389
always @(id_insn) begin
390
  case (id_insn[31:26])         // synopsys parallel_case
391
 
392
        // l.addi
393
        `OR1200_OR32_ADDI:
394
                imm_signextend = 1'b1;
395
 
396
        // l.addic
397
        `OR1200_OR32_ADDIC:
398
                imm_signextend = 1'b1;
399
 
400
        // l.xori
401
        `OR1200_OR32_XORI:
402
                imm_signextend = 1'b1;
403
 
404
        // l.muli
405
`ifdef OR1200_MULT_IMPLEMENTED
406
        `OR1200_OR32_MULI:
407
                imm_signextend = 1'b1;
408
`endif
409
 
410
        // l.maci
411
`ifdef OR1200_MAC_IMPLEMENTED
412
        `OR1200_OR32_MACI:
413
                imm_signextend = 1'b1;
414
`endif
415
 
416
        // SFXX insns with immediate
417
        `OR1200_OR32_SFXXI:
418
                imm_signextend = 1'b1;
419
 
420
        // Instructions with no or zero extended immediate
421
        default: begin
422
                imm_signextend = 1'b0;
423
        end
424
 
425
endcase
426
 
427
end
428
 
429
//
430
// LSU addr offset
431
//
432
always @(lsu_op or ex_insn) begin
433
        lsu_addrofs[10:0] = ex_insn[10:0];
434
        case(lsu_op)    // synopsys parallel_case
435
                `OR1200_LSUOP_SW, `OR1200_LSUOP_SH, `OR1200_LSUOP_SB :
436
                        lsu_addrofs[31:11] = {{16{ex_insn[25]}}, ex_insn[25:21]};
437
                default :
438
                        lsu_addrofs[31:11] = {{16{ex_insn[15]}}, ex_insn[15:11]};
439
        endcase
440
end
441
 
442
//
443
// Register file write address
444
//
445
always @(posedge clk or posedge rst) begin
446
        if (rst)
447
                rf_addrw <= #1 5'd0;
448
        else if (!ex_freeze & id_freeze)
449
                rf_addrw <= #1 5'd00;
450
        else if (!ex_freeze)
451
                case (pre_branch_op)    // synopsys parallel_case
452
                        `OR1200_BRANCHOP_JR, `OR1200_BRANCHOP_BAL:
453
                                rf_addrw <= #1 5'd09;   // link register r9
454
                        default:
455
                                rf_addrw <= #1 id_insn[25:21];
456
                endcase
457
end
458
 
459
//
460
// rf_addrw in wb stage (used in forwarding logic)
461
//
462
always @(posedge clk or posedge rst) begin
463
        if (rst)
464
                wb_rfaddrw <= #1 5'd0;
465
        else if (!wb_freeze)
466
                wb_rfaddrw <= #1 rf_addrw;
467
end
468
 
469
//
470
// Instruction latch in id_insn
471
//
472
always @(posedge clk or posedge rst) begin
473
        if (rst)
474
                id_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
475
        else if (flushpipe)
476
                id_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};        // id_insn[16] must be 1
477
        else if (!id_freeze) begin
478
                id_insn <= #1 if_insn;
479
`ifdef OR1200_VERBOSE
480
// synopsys translate_off
481
                $display("%t: id_insn <= %h", $time, if_insn);
482
// synopsys translate_on
483
`endif
484
        end
485
end
486
 
487
//
488
// Instruction latch in ex_insn
489
//
490
always @(posedge clk or posedge rst) begin
491
        if (rst)
492
                ex_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
493
        else if (!ex_freeze & id_freeze | flushpipe)
494
                ex_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000}; // ex_insn[16] must be 1
495
        else if (!ex_freeze) begin
496
                ex_insn <= #1 id_insn;
497
`ifdef OR1200_VERBOSE
498
// synopsys translate_off
499
                $display("%t: ex_insn <= %h", $time, id_insn);
500
// synopsys translate_on
501
`endif
502
        end
503
end
504
 
505
//
506
// Instruction latch in wb_insn
507
//
508
always @(posedge clk or posedge rst) begin
509
        if (rst)
510
                wb_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000};
511
        else if (flushpipe)
512
                wb_insn <= #1 {`OR1200_OR32_NOP, 26'h041_0000}; // wb_insn[16] must be 1
513
        else if (!wb_freeze) begin
514
                wb_insn <= #1 ex_insn;
515
        end
516
end
517
 
518
//
519
// Decode of sel_imm
520
//
521
always @(posedge clk or posedge rst) begin
522
        if (rst)
523
                sel_imm <= #1 1'b0;
524
        else if (!id_freeze) begin
525
          case (if_insn[31:26])         // synopsys parallel_case
526
 
527
            // j.jalr
528
            `OR1200_OR32_JALR:
529
              sel_imm <= #1 1'b0;
530
 
531
            // l.jr
532
            `OR1200_OR32_JR:
533
              sel_imm <= #1 1'b0;
534
 
535
            // l.rfe
536
            `OR1200_OR32_RFE:
537
              sel_imm <= #1 1'b0;
538
 
539
            // l.mfspr
540
            `OR1200_OR32_MFSPR:
541
              sel_imm <= #1 1'b0;
542
 
543
            // l.mtspr
544
            `OR1200_OR32_MTSPR:
545
              sel_imm <= #1 1'b0;
546
 
547
            // l.sys, l.brk and all three sync insns
548
            `OR1200_OR32_XSYNC:
549
              sel_imm <= #1 1'b0;
550
 
551
            // l.mac/l.msb
552
`ifdef OR1200_MAC_IMPLEMENTED
553
            `OR1200_OR32_MACMSB:
554
              sel_imm <= #1 1'b0;
555
`endif
556
 
557
            // l.sw
558
            `OR1200_OR32_SW:
559
              sel_imm <= #1 1'b0;
560
 
561
            // l.sb
562
            `OR1200_OR32_SB:
563
              sel_imm <= #1 1'b0;
564
 
565
            // l.sh
566
            `OR1200_OR32_SH:
567
              sel_imm <= #1 1'b0;
568
 
569
            // ALU instructions except the one with immediate
570
            `OR1200_OR32_ALU:
571
              sel_imm <= #1 1'b0;
572
 
573
            // SFXX instructions
574
            `OR1200_OR32_SFXX:
575
              sel_imm <= #1 1'b0;
576
 
577
`ifdef OR1200_OR32_CUST5
578
            // l.cust5 instructions
579
            `OR1200_OR32_CUST5:
580
              sel_imm <= #1 1'b0;
581
`endif
582
 
583
            // l.nop
584
            `OR1200_OR32_NOP:
585
              sel_imm <= #1 1'b0;
586
 
587
            // All instructions with immediates
588
            default: begin
589
              sel_imm <= #1 1'b1;
590
            end
591
 
592
          endcase
593
 
594
        end
595
end
596
 
597
//
598
// Decode of except_illegal
599
//
600
always @(posedge clk or posedge rst) begin
601
        if (rst)
602
                except_illegal <= #1 1'b0;
603
        else if (!ex_freeze & id_freeze | flushpipe)
604
                except_illegal <= #1 1'b0;
605
        else if (!ex_freeze) begin
606
          case (id_insn[31:26])         // synopsys parallel_case
607
 
608
            `OR1200_OR32_J,
609
            `OR1200_OR32_JAL,
610
            `OR1200_OR32_JALR,
611
            `OR1200_OR32_JR,
612
            `OR1200_OR32_BNF,
613
            `OR1200_OR32_BF,
614
            `OR1200_OR32_RFE,
615
            `OR1200_OR32_MOVHI,
616
            `OR1200_OR32_MFSPR,
617
            `OR1200_OR32_XSYNC,
618
`ifdef OR1200_MAC_IMPLEMENTED
619
            `OR1200_OR32_MACI,
620
`endif
621
            `OR1200_OR32_LWZ,
622
            `OR1200_OR32_LBZ,
623
            `OR1200_OR32_LBS,
624
            `OR1200_OR32_LHZ,
625
            `OR1200_OR32_LHS,
626
            `OR1200_OR32_ADDI,
627
            `OR1200_OR32_ADDIC,
628
            `OR1200_OR32_ANDI,
629
            `OR1200_OR32_ORI,
630
            `OR1200_OR32_XORI,
631
`ifdef OR1200_MULT_IMPLEMENTED
632
            `OR1200_OR32_MULI,
633
`endif
634
            `OR1200_OR32_SH_ROTI,
635
            `OR1200_OR32_SFXXI,
636
            `OR1200_OR32_MTSPR,
637
`ifdef OR1200_MAC_IMPLEMENTED
638
            `OR1200_OR32_MACMSB,
639
`endif
640
            `OR1200_OR32_SW,
641
            `OR1200_OR32_SB,
642
            `OR1200_OR32_SH,
643
            `OR1200_OR32_ALU,
644
            `OR1200_OR32_SFXX,
645
`ifdef OR1200_OR32_CUST5
646
            `OR1200_OR32_CUST5,
647
`endif
648
            `OR1200_OR32_NOP:
649
                except_illegal <= #1 1'b0;
650
 
651
            // Illegal and OR1200 unsupported instructions
652
            default:
653
              except_illegal <= #1 1'b1;
654
 
655
          endcase
656
 
657
        end
658
end
659
 
660
//
661
// Decode of alu_op
662
//
663
always @(posedge clk or posedge rst) begin
664
        if (rst)
665
                alu_op <= #1 `OR1200_ALUOP_NOP;
666
        else if (!ex_freeze & id_freeze | flushpipe)
667
                alu_op <= #1 `OR1200_ALUOP_NOP;
668
        else if (!ex_freeze) begin
669
          case (id_insn[31:26])         // synopsys parallel_case
670
 
671
            // l.j
672
            `OR1200_OR32_J:
673
              alu_op <= #1 `OR1200_ALUOP_IMM;
674
 
675
            // j.jal
676
            `OR1200_OR32_JAL:
677
              alu_op <= #1 `OR1200_ALUOP_IMM;
678
 
679
            // l.bnf
680
            `OR1200_OR32_BNF:
681
              alu_op <= #1 `OR1200_ALUOP_NOP;
682
 
683
            // l.bf
684
            `OR1200_OR32_BF:
685
              alu_op <= #1 `OR1200_ALUOP_NOP;
686
 
687
            // l.movhi
688
            `OR1200_OR32_MOVHI:
689
              alu_op <= #1 `OR1200_ALUOP_MOVHI;
690
 
691
            // l.mfspr
692
            `OR1200_OR32_MFSPR:
693
              alu_op <= #1 `OR1200_ALUOP_MFSR;
694
 
695
            // l.mtspr
696
            `OR1200_OR32_MTSPR:
697
              alu_op <= #1 `OR1200_ALUOP_MTSR;
698
 
699
            // l.addi
700
            `OR1200_OR32_ADDI:
701
              alu_op <= #1 `OR1200_ALUOP_ADD;
702
 
703
            // l.addic
704
            `OR1200_OR32_ADDIC:
705
              alu_op <= #1 `OR1200_ALUOP_ADDC;
706
 
707
            // l.andi
708
            `OR1200_OR32_ANDI:
709
              alu_op <= #1 `OR1200_ALUOP_AND;
710
 
711
            // l.ori
712
            `OR1200_OR32_ORI:
713
              alu_op <= #1 `OR1200_ALUOP_OR;
714
 
715
            // l.xori
716
            `OR1200_OR32_XORI:
717
              alu_op <= #1 `OR1200_ALUOP_XOR;
718
 
719
            // l.muli
720
`ifdef OR1200_MULT_IMPLEMENTED
721
            `OR1200_OR32_MULI:
722
              alu_op <= #1 `OR1200_ALUOP_MUL;
723
`endif
724
 
725
            // Shift and rotate insns with immediate
726
            `OR1200_OR32_SH_ROTI:
727
              alu_op <= #1 `OR1200_ALUOP_SHROT;
728
 
729
            // SFXX insns with immediate
730
            `OR1200_OR32_SFXXI:
731
              alu_op <= #1 `OR1200_ALUOP_COMP;
732
 
733
            // ALU instructions except the one with immediate
734
            `OR1200_OR32_ALU:
735
              alu_op <= #1 id_insn[3:0];
736
 
737
            // SFXX instructions
738
            `OR1200_OR32_SFXX:
739
              alu_op <= #1 `OR1200_ALUOP_COMP;
740
 
741
`ifdef OR1200_OR32_CUST5
742
            // l.cust5 instructions
743
            `OR1200_OR32_CUST5:
744
              alu_op <= #1 `OR1200_ALUOP_CUST5;
745
`endif
746
 
747
            // Default
748
            default: begin
749
              alu_op <= #1 `OR1200_ALUOP_NOP;
750
            end
751
 
752
          endcase
753
 
754
        end
755
end
756
 
757
//
758
// Decode of mac_op
759
//
760
`ifdef OR1200_MAC_IMPLEMENTED
761
always @(posedge clk or posedge rst) begin
762
        if (rst)
763
                mac_op <= #1 `OR1200_MACOP_NOP;
764
        else if (!ex_freeze & id_freeze | flushpipe)
765
                mac_op <= #1 `OR1200_MACOP_NOP;
766
        else if (!ex_freeze)
767
          case (id_insn[31:26])         // synopsys parallel_case
768
 
769
            // l.maci
770
            `OR1200_OR32_MACI:
771
              mac_op <= #1 `OR1200_MACOP_MAC;
772
 
773
            // l.nop
774
            `OR1200_OR32_MACMSB:
775
              mac_op <= #1 id_insn[1:0];
776
 
777
            // Illegal and OR1200 unsupported instructions
778
            default: begin
779
              mac_op <= #1 `OR1200_MACOP_NOP;
780
            end
781
 
782
          endcase
783
        else
784
                mac_op <= #1 `OR1200_MACOP_NOP;
785
end
786
`else
787
assign mac_op = `OR1200_MACOP_NOP;
788
`endif
789
 
790
//
791
// Decode of shrot_op
792
//
793
always @(posedge clk or posedge rst) begin
794
        if (rst)
795
                shrot_op <= #1 `OR1200_SHROTOP_NOP;
796
        else if (!ex_freeze & id_freeze | flushpipe)
797
                shrot_op <= #1 `OR1200_SHROTOP_NOP;
798
        else if (!ex_freeze) begin
799
                shrot_op <= #1 id_insn[`OR1200_SHROTOP_POS];
800
        end
801
end
802
 
803
//
804
// Decode of rfwb_op
805
//
806
always @(posedge clk or posedge rst) begin
807
        if (rst)
808
                rfwb_op <= #1 `OR1200_RFWBOP_NOP;
809
        else  if (!ex_freeze & id_freeze | flushpipe)
810
                rfwb_op <= #1 `OR1200_RFWBOP_NOP;
811
        else  if (!ex_freeze) begin
812
                case (id_insn[31:26])           // synopsys parallel_case
813
 
814
                  // j.jal
815
                  `OR1200_OR32_JAL:
816
                    rfwb_op <= #1 `OR1200_RFWBOP_LR;
817
 
818
                  // j.jalr
819
                  `OR1200_OR32_JALR:
820
                    rfwb_op <= #1 `OR1200_RFWBOP_LR;
821
 
822
                  // l.movhi
823
                  `OR1200_OR32_MOVHI:
824
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
825
 
826
                  // l.mfspr
827
                  `OR1200_OR32_MFSPR:
828
                    rfwb_op <= #1 `OR1200_RFWBOP_SPRS;
829
 
830
                  // l.lwz
831
                  `OR1200_OR32_LWZ:
832
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
833
 
834
                  // l.lbz
835
                  `OR1200_OR32_LBZ:
836
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
837
 
838
                  // l.lbs
839
                  `OR1200_OR32_LBS:
840
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
841
 
842
                  // l.lhz
843
                  `OR1200_OR32_LHZ:
844
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
845
 
846
                  // l.lhs
847
                  `OR1200_OR32_LHS:
848
                    rfwb_op <= #1 `OR1200_RFWBOP_LSU;
849
 
850
                  // l.addi
851
                  `OR1200_OR32_ADDI:
852
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
853
 
854
                  // l.addic
855
                  `OR1200_OR32_ADDIC:
856
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
857
 
858
                  // l.andi
859
                  `OR1200_OR32_ANDI:
860
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
861
 
862
                  // l.ori
863
                  `OR1200_OR32_ORI:
864
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
865
 
866
                  // l.xori
867
                  `OR1200_OR32_XORI:
868
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
869
 
870
                  // l.muli
871
`ifdef OR1200_MULT_IMPLEMENTED
872
                  `OR1200_OR32_MULI:
873
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
874
`endif
875
 
876
                  // Shift and rotate insns with immediate
877
                  `OR1200_OR32_SH_ROTI:
878
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
879
 
880
                  // ALU instructions except the one with immediate
881
                  `OR1200_OR32_ALU:
882
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
883
 
884
`ifdef OR1200_OR32_CUST5
885
                  // l.cust5 instructions
886
                  `OR1200_OR32_CUST5:
887
                    rfwb_op <= #1 `OR1200_RFWBOP_ALU;
888
`endif
889
 
890
                  // Instructions w/o register-file write-back
891
                  default: begin
892
                    rfwb_op <= #1 `OR1200_RFWBOP_NOP;
893
                  end
894
 
895
                endcase
896
        end
897
end
898
 
899
//
900
// Decode of pre_branch_op
901
//
902
always @(posedge clk or posedge rst) begin
903
        if (rst)
904
                pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
905
        else if (flushpipe)
906
                pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
907
        else if (!id_freeze) begin
908
                case (if_insn[31:26])           // synopsys parallel_case
909
 
910
                  // l.j
911
                  `OR1200_OR32_J:
912
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BAL;
913
 
914
                  // j.jal
915
                  `OR1200_OR32_JAL:
916
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BAL;
917
 
918
                  // j.jalr
919
                  `OR1200_OR32_JALR:
920
                    pre_branch_op <= #1 `OR1200_BRANCHOP_JR;
921
 
922
                  // l.jr
923
                  `OR1200_OR32_JR:
924
                    pre_branch_op <= #1 `OR1200_BRANCHOP_JR;
925
 
926
                  // l.bnf
927
                  `OR1200_OR32_BNF:
928
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BNF;
929
 
930
                  // l.bf
931
                  `OR1200_OR32_BF:
932
                    pre_branch_op <= #1 `OR1200_BRANCHOP_BF;
933
 
934
                  // l.rfe
935
                  `OR1200_OR32_RFE:
936
                    pre_branch_op <= #1 `OR1200_BRANCHOP_RFE;
937
 
938
                  // Non branch instructions
939
                  default: begin
940
                    pre_branch_op <= #1 `OR1200_BRANCHOP_NOP;
941
                  end
942
                endcase
943
        end
944
end
945
 
946
//
947
// Generation of branch_op
948
//
949
always @(posedge clk or posedge rst)
950
        if (rst)
951
                branch_op <= #1 `OR1200_BRANCHOP_NOP;
952
        else if (!ex_freeze & id_freeze | flushpipe)
953
                branch_op <= #1 `OR1200_BRANCHOP_NOP;
954
        else if (!ex_freeze)
955
                branch_op <= #1 pre_branch_op;
956
 
957
//
958
// Decode of lsu_op
959
//
960
always @(posedge clk or posedge rst) begin
961
        if (rst)
962
                lsu_op <= #1 `OR1200_LSUOP_NOP;
963
        else if (!ex_freeze & id_freeze | flushpipe)
964
                lsu_op <= #1 `OR1200_LSUOP_NOP;
965
        else if (!ex_freeze)  begin
966
          case (id_insn[31:26])         // synopsys parallel_case
967
 
968
            // l.lwz
969
            `OR1200_OR32_LWZ:
970
              lsu_op <= #1 `OR1200_LSUOP_LWZ;
971
 
972
            // l.lbz
973
            `OR1200_OR32_LBZ:
974
              lsu_op <= #1 `OR1200_LSUOP_LBZ;
975
 
976
            // l.lbs
977
            `OR1200_OR32_LBS:
978
              lsu_op <= #1 `OR1200_LSUOP_LBS;
979
 
980
            // l.lhz
981
            `OR1200_OR32_LHZ:
982
              lsu_op <= #1 `OR1200_LSUOP_LHZ;
983
 
984
            // l.lhs
985
            `OR1200_OR32_LHS:
986
              lsu_op <= #1 `OR1200_LSUOP_LHS;
987
 
988
            // l.sw
989
            `OR1200_OR32_SW:
990
              lsu_op <= #1 `OR1200_LSUOP_SW;
991
 
992
            // l.sb
993
            `OR1200_OR32_SB:
994
              lsu_op <= #1 `OR1200_LSUOP_SB;
995
 
996
            // l.sh
997
            `OR1200_OR32_SH:
998
              lsu_op <= #1 `OR1200_LSUOP_SH;
999
 
1000
            // Non load/store instructions
1001
            default: begin
1002
              lsu_op <= #1 `OR1200_LSUOP_NOP;
1003
            end
1004
          endcase
1005
        end
1006
end
1007
 
1008
//
1009
// Decode of comp_op
1010
//
1011
always @(posedge clk or posedge rst) begin
1012
        if (rst) begin
1013
                comp_op <= #1 4'd0;
1014
        end else if (!ex_freeze & id_freeze | flushpipe)
1015
                comp_op <= #1 4'd0;
1016
        else if (!ex_freeze)
1017
                comp_op <= #1 id_insn[24:21];
1018
end
1019
 
1020
//
1021
// Decode of l.sys
1022
//
1023
always @(posedge clk or posedge rst) begin
1024
        if (rst)
1025
                sig_syscall <= #1 1'b0;
1026
        else if (!ex_freeze & id_freeze | flushpipe)
1027
                sig_syscall <= #1 1'b0;
1028
        else if (!ex_freeze) begin
1029
`ifdef OR1200_VERBOSE
1030
// synopsys translate_off
1031
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000})
1032
                        $display("Generating sig_syscall");
1033
// synopsys translate_on
1034
`endif
1035
                sig_syscall <= #1 (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b000});
1036
        end
1037
end
1038
 
1039
//
1040
// Decode of l.trap
1041
//
1042
always @(posedge clk or posedge rst) begin
1043
        if (rst)
1044
                sig_trap <= #1 1'b0;
1045
        else if (!ex_freeze & id_freeze | flushpipe)
1046
                sig_trap <= #1 1'b0;
1047
        else if (!ex_freeze) begin
1048
`ifdef OR1200_VERBOSE
1049
// synopsys translate_off
1050
                if (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1051
                        $display("Generating sig_trap");
1052
// synopsys translate_on
1053
`endif
1054
                sig_trap <= #1 (id_insn[31:23] == {`OR1200_OR32_XSYNC, 3'b010})
1055
                        | du_hwbkpt;
1056
        end
1057
end
1058
 
1059
endmodule

powered by: WebSVN 2.1.0

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