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 1765

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

powered by: WebSVN 2.1.0

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