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 504

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

powered by: WebSVN 2.1.0

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