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

Subversion Repositories claw

[/] [claw/] [trunk/] [or1200_cpu/] [or1200_ctrl.v] - Blame information for rev 4

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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