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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 108

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

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

powered by: WebSVN 2.1.0

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