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

Subversion Repositories or1k

[/] [or1k/] [tags/] [arelease/] [rc203soc/] [rtl/] [verilog/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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