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

Subversion Repositories or1k

[/] [or1k/] [branches/] [branch_qmem/] [or1200/] [rtl/] [verilog/] [or1200_ctrl.v] - Blame information for rev 1159

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

powered by: WebSVN 2.1.0

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