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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 12

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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