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 636

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

powered by: WebSVN 2.1.0

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