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 617

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

powered by: WebSVN 2.1.0

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