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

Subversion Repositories openriscdevboard

[/] [openriscdevboard/] [trunk/] [cyc2-openrisc/] [rtl/] [or1200/] [or1200_ctrl.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
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: not supported by cvs2svn $
47
// Revision 1.1  2006/12/21 16:46:58  vak
48
// Initial revision imported from
49
// http://www.opencores.org/cvsget.cgi/or1k/orp/orp_soc/rtl/verilog.
50
//
51
// Revision 1.13  2005/01/13 11:03:43  phoenix
52
// revert to the old l.sfxxi behavior
53
//
54
// Revision 1.12  2005/01/07 09:31:07  andreje
55
// sign/zero extension for l.sfxxi instructions corrected
56
//
57
// Revision 1.11  2004/06/08 18:17:36  lampret
58
// Non-functional changes. Coding style fixes.
59
//
60
// Revision 1.10  2004/05/09 19:49:04  lampret
61
// Added some l.cust5 custom instructions as example
62
//
63
// Revision 1.9  2004/04/05 08:29:57  lampret
64
// Merged branch_qmem into main tree.
65
//
66
// Revision 1.8.4.1  2004/02/11 01:40:11  lampret
67
// preliminary HW breakpoints support in debug unit (by default disabled). To enable define OR1200_DU_HWBKPTS.
68
//
69
// Revision 1.8  2003/04/24 00:16:07  lampret
70
// No functional changes. Added defines to disable implementation of multiplier/MAC
71
//
72
// Revision 1.7  2002/09/07 05:42:02  lampret
73
// Added optional SR[CY]. Added define to enable additional (compare) flag modifiers. Defines are OR1200_IMPL_ADDC and OR1200_ADDITIONAL_FLAG_MODIFIERS.
74
//
75
// Revision 1.6  2002/03/29 15:16:54  lampret
76
// Some of the warnings fixed.
77
//
78
// Revision 1.5  2002/02/01 19:56:54  lampret
79
// Fixed combinational loops.
80
//
81
// Revision 1.4  2002/01/28 01:15:59  lampret
82
// 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.
83
//
84
// Revision 1.3  2002/01/18 14:21:43  lampret
85
// Fixed 'the NPC single-step fix'.
86
//
87
// Revision 1.2  2002/01/14 06:18:22  lampret
88
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
89
//
90
// Revision 1.1  2002/01/03 08:16:15  lampret
91
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
92
//
93
// Revision 1.14  2001/11/30 18:59:17  simons
94
// force_dslot_fetch does not work -  allways zero.
95
//
96
// Revision 1.13  2001/11/20 18:46:15  simons
97
// Break point bug fixed
98
//
99
// Revision 1.12  2001/11/18 08:36:28  lampret
100
// For GDB changed single stepping and disabled trap exception.
101
//
102
// Revision 1.11  2001/11/13 10:02:21  lampret
103
// Added 'setpc'. Renamed some signals (except_flushpipe into flushpipe etc)
104
//
105
// Revision 1.10  2001/11/12 01:45:40  lampret
106
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
107
//
108
// Revision 1.9  2001/11/10 03:43:57  lampret
109
// Fixed exceptions.
110
//
111
// Revision 1.8  2001/10/21 17:57:16  lampret
112
// 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.
113
//
114
// Revision 1.7  2001/10/14 13:12:09  lampret
115
// MP3 version.
116
//
117
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
118
// no message
119
//
120
// Revision 1.2  2001/08/13 03:36:20  lampret
121
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
122
//
123
// Revision 1.1  2001/08/09 13:39:33  lampret
124
// Major clean-up.
125
//
126
//
127
 
128
// synopsys translate_off
129
`include "timescale.v"
130
// synopsys translate_on
131
`include "or1200_defines.v"
132
 
133
module or1200_ctrl(
134
        // Clock and reset
135
        clk, rst,
136
 
137
        // Internal i/f
138
        id_freeze, ex_freeze, wb_freeze, flushpipe, if_insn, ex_insn, branch_op, branch_taken,
139
        rf_addra, rf_addrb, rf_rda, rf_rdb, alu_op, mac_op, shrot_op, comp_op, rf_addrw, rfwb_op,
140
        wb_insn, simm, branch_addrofs, lsu_addrofs, sel_a, sel_b, lsu_op,
141
        cust5_op, cust5_limm,
142
        multicycle, spr_addrimm, wbforw_valid, du_hwbkpt, sig_syscall, sig_trap,
143
        force_dslot_fetch, no_more_dslot, ex_void, id_macrc_op, ex_macrc_op, rfe, except_illegal
144
);
145
 
146
//
147
// I/O
148
//
149
input                                   clk;
150
input                                   rst;
151
input                                   id_freeze;
152
input                                   ex_freeze;
153
input                                   wb_freeze;
154
input                                   flushpipe;
155
input   [31:0]                           if_insn;
156
output  [31:0]                           ex_insn;
157
output  [`OR1200_BRANCHOP_WIDTH-1:0]             branch_op;
158
input                                           branch_taken;
159
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
160
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addra;
161
output  [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrb;
162
output                                  rf_rda;
163
output                                  rf_rdb;
164
output  [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
165
output  [`OR1200_MACOP_WIDTH-1:0]                mac_op;
166
output  [`OR1200_SHROTOP_WIDTH-1:0]              shrot_op;
167
output  [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
168
output  [31:0]                           wb_insn;
169
output  [31:0]                           simm;
170
output  [31:2]                          branch_addrofs;
171
output  [31:0]                           lsu_addrofs;
172
output  [`OR1200_SEL_WIDTH-1:0]          sel_a;
173
output  [`OR1200_SEL_WIDTH-1:0]          sel_b;
174
output  [`OR1200_LSUOP_WIDTH-1:0]                lsu_op;
175
output  [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
176
output  [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
177
output  [4:0]                            cust5_op;
178
output  [5:0]                            cust5_limm;
179
output  [15:0]                           spr_addrimm;
180
input                                   wbforw_valid;
181
input                                   du_hwbkpt;
182
output                                  sig_syscall;
183
output                                  sig_trap;
184
output                                  force_dslot_fetch;
185
output                                  no_more_dslot;
186
output                                  ex_void;
187
output                                  id_macrc_op;
188
output                                  ex_macrc_op;
189
output                                  rfe;
190
output                                  except_illegal;
191
 
192
//
193
// Internal wires and regs
194
//
195
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             pre_branch_op;
196
reg     [`OR1200_BRANCHOP_WIDTH-1:0]             branch_op;
197
reg     [`OR1200_ALUOP_WIDTH-1:0]                alu_op;
198
`ifdef OR1200_MAC_IMPLEMENTED
199
reg     [`OR1200_MACOP_WIDTH-1:0]                mac_op;
200
reg                                     ex_macrc_op;
201
`else
202
wire    [`OR1200_MACOP_WIDTH-1:0]                mac_op;
203
wire                                    ex_macrc_op;
204
`endif
205
reg     [`OR1200_SHROTOP_WIDTH-1:0]              shrot_op;
206
reg     [31:0]                           id_insn;
207
reg     [31:0]                           ex_insn;
208
reg     [31:0]                           wb_insn;
209
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] rf_addrw;
210
reg     [`OR1200_REGFILE_ADDR_WIDTH-1:0] wb_rfaddrw;
211
reg     [`OR1200_RFWBOP_WIDTH-1:0]               rfwb_op;
212
reg     [31:0]                           lsu_addrofs;
213
reg     [`OR1200_SEL_WIDTH-1:0]          sel_a;
214
reg     [`OR1200_SEL_WIDTH-1:0]          sel_b;
215
reg                                     sel_imm;
216
reg     [`OR1200_LSUOP_WIDTH-1:0]                lsu_op;
217
reg     [`OR1200_COMPOP_WIDTH-1:0]               comp_op;
218
reg     [`OR1200_MULTICYCLE_WIDTH-1:0]           multicycle;
219
reg                                     imm_signextend;
220
reg     [15:0]                           spr_addrimm;
221
reg                                     sig_syscall;
222
reg                                     sig_trap;
223
reg                                     except_illegal;
224
wire                                    id_void;
225
 
226
//
227
// Register file read addresses
228
//
229
assign rf_addra = if_insn[20:16];
230
assign rf_addrb = if_insn[15:11];
231
assign rf_rda = if_insn[31];
232
assign rf_rdb = if_insn[30];
233
 
234
//
235
// Force fetch of delay slot instruction when jump/branch is preceeded by load/store
236
// instructions
237
//
238
// SIMON
239
// assign force_dslot_fetch = ((|pre_branch_op) & (|lsu_op));
240
assign force_dslot_fetch = 1'b0;
241
assign no_more_dslot = |branch_op & !id_void & branch_taken | (branch_op == `OR1200_BRANCHOP_RFE);
242
assign id_void = (id_insn[31:26] == `OR1200_OR32_NOP) & id_insn[16];
243
assign ex_void = (ex_insn[31:26] == `OR1200_OR32_NOP) & ex_insn[16];
244
 
245
//
246
// Sign/Zero extension of immediates
247
//
248
assign simm = (imm_signextend == 1'b1) ? {{16{id_insn[15]}}, id_insn[15:0]} : {{16'b0}, id_insn[15:0]};
249
 
250
//
251
// Sign extension of branch offset
252
//
253
assign branch_addrofs = {{4{ex_insn[25]}}, ex_insn[25:0]};
254
 
255
//
256
// l.macrc in ID stage
257
//
258
`ifdef OR1200_MAC_IMPLEMENTED
259
assign id_macrc_op = (id_insn[31:26] == `OR1200_OR32_MOVHI) & id_insn[16];
260
`else
261
assign id_macrc_op = 1'b0;
262
`endif
263
 
264
//
265
// cust5_op, cust5_limm (L immediate)
266
//
267
assign cust5_op = ex_insn[4:0];
268
assign cust5_limm = ex_insn[10:5];
269
 
270
//
271
//
272
//
273
assign rfe = (pre_branch_op == `OR1200_BRANCHOP_RFE) | (branch_op == `OR1200_BRANCHOP_RFE);
274
 
275
//
276
// Generation of sel_a
277
//
278
always @(rf_addrw or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
279
        if ((id_insn[20:16] == rf_addrw) && rfwb_op[0])
280
                sel_a = `OR1200_SEL_EX_FORW;
281
        else if ((id_insn[20:16] == wb_rfaddrw) && wbforw_valid)
282
                sel_a = `OR1200_SEL_WB_FORW;
283
        else
284
                sel_a = `OR1200_SEL_RF;
285
 
286
//
287
// Generation of sel_b
288
//
289
always @(rf_addrw or sel_imm or id_insn or rfwb_op or wbforw_valid or wb_rfaddrw)
290
        if (sel_imm)
291
                sel_b = `OR1200_SEL_IMM;
292
        else if ((id_insn[15:11] == rf_addrw) && rfwb_op[0])
293
                sel_b = `OR1200_SEL_EX_FORW;
294
        else if ((id_insn[15:11] == wb_rfaddrw) && wbforw_valid)
295
                sel_b = `OR1200_SEL_WB_FORW;
296
        else
297
                sel_b = `OR1200_SEL_RF;
298
 
299
//
300
// l.macrc in EX stage
301
//
302
`ifdef OR1200_MAC_IMPLEMENTED
303
always @(posedge clk or posedge rst) begin
304
        if (rst)
305
                ex_macrc_op <= #1 1'b0;
306
        else if (!ex_freeze & id_freeze | flushpipe)
307
                ex_macrc_op <= #1 1'b0;
308
        else if (!ex_freeze)
309
                ex_macrc_op <= #1 id_macrc_op;
310
end
311
`else
312
assign ex_macrc_op = 1'b0;
313
`endif
314
 
315
//
316
// Decode of spr_addrimm
317
//
318
always @(posedge clk or posedge rst) begin
319
        if (rst)
320
                spr_addrimm <= #1 16'h0000;
321
        else if (!ex_freeze & id_freeze | flushpipe)
322
                spr_addrimm <= #1 16'h0000;
323
        else if (!ex_freeze) begin
324
                case (id_insn[31:26])   // synopsys parallel_case
325
                        // l.mfspr
326
                        `OR1200_OR32_MFSPR:
327
                                spr_addrimm <= #1 id_insn[15:0];
328
                        // l.mtspr
329
                        default:
330
                                spr_addrimm <= #1 {id_insn[25:21], id_insn[10:0]};
331
                endcase
332
        end
333
end
334
 
335
//
336
// Decode of multicycle
337
//
338
always @(id_insn) begin
339
  case (id_insn[31:26])         // synopsys parallel_case
340
`ifdef UNUSED
341
    // l.lwz
342
    `OR1200_OR32_LWZ:
343
      multicycle = `OR1200_TWO_CYCLES;
344
 
345
    // l.lbz
346
    `OR1200_OR32_LBZ:
347
      multicycle = `OR1200_TWO_CYCLES;
348
 
349
    // l.lbs
350
    `OR1200_OR32_LBS:
351
      multicycle = `OR1200_TWO_CYCLES;
352
 
353
    // l.lhz
354
    `OR1200_OR32_LHZ:
355
      multicycle = `OR1200_TWO_CYCLES;
356
 
357
    // l.lhs
358
    `OR1200_OR32_LHS:
359
      multicycle = `OR1200_TWO_CYCLES;
360
 
361
    // l.sw
362
    `OR1200_OR32_SW:
363
      multicycle = `OR1200_TWO_CYCLES;
364
 
365
    // l.sb
366
    `OR1200_OR32_SB:
367
      multicycle = `OR1200_TWO_CYCLES;
368
 
369
    // l.sh
370
    `OR1200_OR32_SH:
371
      multicycle = `OR1200_TWO_CYCLES;
372
`endif
373
    // ALU instructions except the one with immediate
374
    `OR1200_OR32_ALU:
375
      multicycle = id_insn[`OR1200_ALUMCYC_POS];
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-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.