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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_21/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 562

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

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

powered by: WebSVN 2.1.0

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