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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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