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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orp/] [orp_soc/] [rtl/] [verilog/] [or1200.old/] [or1200_ctrl.v] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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