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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_sprs.v] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's interface to SPRs                                  ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Decoding of SPR addresses and access to SPRs                ////
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.9.4.1  2003/12/17 13:43:38  simons
48
// Exception prefix configuration changed.
49
//
50
// Revision 1.9  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
// Revision 1.8  2002/08/28 01:44:25  lampret
54
// Removed some commented RTL. Fixed SR/ESR flag bug.
55
//
56
// Revision 1.7  2002/03/29 15:16:56  lampret
57
// Some of the warnings fixed.
58
//
59
// Revision 1.6  2002/03/11 01:26:57  lampret
60
// Changed generation of SPR address. Now it is ORed from base and offset instead of a sum.
61
//
62
// Revision 1.5  2002/02/01 19:56:54  lampret
63
// Fixed combinational loops.
64
//
65
// Revision 1.4  2002/01/23 07:52:36  lampret
66
// Changed default reset values for SR and ESR to match or1ksim's. Fixed flop model in or1200_dpram_32x32 when OR1200_XILINX_RAM32X1D is defined.
67
//
68
// Revision 1.3  2002/01/19 09:27:49  lampret
69
// SR[TEE] should be zero after reset.
70
//
71
// Revision 1.2  2002/01/18 07:56:00  lampret
72
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
73
//
74
// Revision 1.1  2002/01/03 08:16:15  lampret
75
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
76
//
77
// Revision 1.12  2001/11/23 21:42:31  simons
78
// Program counter divided to PPC and NPC.
79
//
80
// Revision 1.11  2001/11/23 08:38:51  lampret
81
// Changed DSR/DRR behavior and exception detection.
82
//
83
// Revision 1.10  2001/11/12 01:45:41  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/10/21 17:57:16  lampret
87
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
88
//
89
// Revision 1.8  2001/10/14 13:12:10  lampret
90
// MP3 version.
91
//
92
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
93
// no message
94
//
95
// Revision 1.3  2001/08/13 03:36:20  lampret
96
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
97
//
98
// Revision 1.2  2001/08/09 13:39:33  lampret
99
// Major clean-up.
100
//
101
// Revision 1.1  2001/07/20 00:46:21  lampret
102
// Development version of RTL. Libraries are missing.
103
//
104
//
105
 
106
// synopsys translate_off
107
`include "timescale.v"
108
// synopsys translate_on
109
`include "or1200_defines.v"
110
 
111
module or1200_sprs(
112
                // Clk & Rst
113
                clk, rst,
114
 
115
                // Internal CPU interface
116
                flagforw, flag_we, flag, cyforw, cy_we, carry,
117
                addrbase, addrofs, dat_i, alu_op, branch_op,
118
                epcr, eear, esr, except_started,
119
                to_wbmux, epcr_we, eear_we, esr_we, pc_we, sr_we, to_sr, sr,
120
                spr_dat_cfgr, spr_dat_rf, spr_dat_npc, spr_dat_ppc, spr_dat_mac,
121
 
122
                // From/to other RISC units
123
                spr_dat_pic, spr_dat_tt, spr_dat_pm,
124
                spr_dat_dmmu, spr_dat_immu, spr_dat_du,
125
                spr_addr, spr_dat_o, spr_cs, spr_we,
126
 
127
                du_addr, du_dat_du, du_read,
128
                du_write, du_dat_cpu
129
 
130
);
131
 
132
parameter width = `OR1200_OPERAND_WIDTH;
133
 
134
//
135
// I/O Ports
136
//
137
 
138
//
139
// Internal CPU interface
140
//
141
input                           clk;            // Clock
142
input                           rst;            // Reset
143
input                           flagforw;       // From ALU
144
input                           flag_we;        // From ALU
145
output                          flag;           // SR[F]
146
input                           cyforw;         // From ALU
147
input                           cy_we;          // From ALU
148
output                          carry;          // SR[CY]
149
input   [width-1:0]              addrbase;       // SPR base address
150
input   [15:0]                   addrofs;        // SPR offset
151
input   [width-1:0]              dat_i;          // SPR write data
152
input   [`OR1200_ALUOP_WIDTH-1:0]        alu_op;         // ALU operation
153
input   [`OR1200_BRANCHOP_WIDTH-1:0]     branch_op;      // Branch operation
154
input   [width-1:0]              epcr;           // EPCR0
155
input   [width-1:0]              eear;           // EEAR0
156
input   [`OR1200_SR_WIDTH-1:0]   esr;            // ESR0
157
input                           except_started; // Exception was started
158
output  [width-1:0]              to_wbmux;       // For l.mfspr
159
output                          epcr_we;        // EPCR0 write enable
160
output                          eear_we;        // EEAR0 write enable
161
output                          esr_we;         // ESR0 write enable
162
output                          pc_we;          // PC write enable
163
output                          sr_we;          // Write enable SR
164
output  [`OR1200_SR_WIDTH-1:0]   to_sr;          // Data to SR
165
output  [`OR1200_SR_WIDTH-1:0]   sr;             // SR
166
input   [31:0]                   spr_dat_cfgr;   // Data from CFGR
167
input   [31:0]                   spr_dat_rf;     // Data from RF
168
input   [31:0]                   spr_dat_npc;    // Data from NPC
169
input   [31:0]                   spr_dat_ppc;    // Data from PPC   
170
input   [31:0]                   spr_dat_mac;    // Data from MAC
171
 
172
//
173
// To/from other RISC units
174
//
175
input   [31:0]                   spr_dat_pic;    // Data from PIC
176
input   [31:0]                   spr_dat_tt;     // Data from TT
177
input   [31:0]                   spr_dat_pm;     // Data from PM
178
input   [31:0]                   spr_dat_dmmu;   // Data from DMMU
179
input   [31:0]                   spr_dat_immu;   // Data from IMMU
180
input   [31:0]                   spr_dat_du;     // Data from DU
181
output  [31:0]                   spr_addr;       // SPR Address
182
output  [31:0]                   spr_dat_o;      // Data to unit
183
output  [31:0]                   spr_cs;         // Unit select
184
output                          spr_we;         // SPR write enable
185
 
186
//
187
// To/from Debug Unit
188
//
189
input   [width-1:0]              du_addr;        // Address
190
input   [width-1:0]              du_dat_du;      // Data from DU to SPRS
191
input                           du_read;        // Read qualifier
192
input                           du_write;       // Write qualifier
193
output  [width-1:0]              du_dat_cpu;     // Data from SPRS to DU
194
 
195
//
196
// Internal regs & wires
197
//
198
reg     [`OR1200_SR_WIDTH-1:0]           sr;             // SR
199
reg                             write_spr;      // Write SPR
200
reg                             read_spr;       // Read SPR
201
reg     [width-1:0]              to_wbmux;       // For l.mfspr
202
wire                            cfgr_sel;       // Select for cfg regs
203
wire                            rf_sel;         // Select for RF
204
wire                            npc_sel;        // Select for NPC
205
wire                            ppc_sel;        // Select for PPC
206
wire                            sr_sel;         // Select for SR        
207
wire                            epcr_sel;       // Select for EPCR0
208
wire                            eear_sel;       // Select for EEAR0
209
wire                            esr_sel;        // Select for ESR0
210
wire    [31:0]                   sys_data;       // Read data from system SPRs
211
wire                            du_access;      // Debug unit access
212
wire    [`OR1200_ALUOP_WIDTH-1:0]        sprs_op;        // ALU operation
213
reg     [31:0]                   unqualified_cs; // Unqualified chip selects
214
 
215
//
216
// Decide if it is debug unit access
217
//
218
assign du_access = du_read | du_write;
219
 
220
//
221
// Generate sprs opcode
222
//
223
assign sprs_op = du_write ? `OR1200_ALUOP_MTSR : du_read ? `OR1200_ALUOP_MFSR : alu_op;
224
 
225
//
226
// Generate SPR address from base address and offset
227
// OR from debug unit address
228
//
229
assign spr_addr = du_access ? du_addr : addrbase | {16'h0000, addrofs};
230
 
231
//
232
// SPR is written by debug unit or by l.mtspr
233
//
234
assign spr_dat_o = du_write ? du_dat_du : dat_i;
235
 
236
//
237
// debug unit data input:
238
//  - write into debug unit SPRs by debug unit itself
239
//  - read of SPRS by debug unit
240
//  - write into debug unit SPRs by l.mtspr
241
//
242
assign du_dat_cpu = du_write ? du_dat_du : du_read ? to_wbmux : dat_i;
243
 
244
//
245
// Write into SPRs when l.mtspr
246
//
247
assign spr_we = du_write | write_spr;
248
 
249
//
250
// Qualify chip selects
251
//
252
assign spr_cs = unqualified_cs & {32{read_spr | write_spr}};
253
 
254
//
255
// Decoding of groups
256
//
257
always @(spr_addr)
258
        case (spr_addr[`OR1200_SPR_GROUP_BITS]) // synopsys parallel_case
259
                `OR1200_SPR_GROUP_WIDTH'd00: unqualified_cs = 32'b00000000_00000000_00000000_00000001;
260
                `OR1200_SPR_GROUP_WIDTH'd01: unqualified_cs = 32'b00000000_00000000_00000000_00000010;
261
                `OR1200_SPR_GROUP_WIDTH'd02: unqualified_cs = 32'b00000000_00000000_00000000_00000100;
262
                `OR1200_SPR_GROUP_WIDTH'd03: unqualified_cs = 32'b00000000_00000000_00000000_00001000;
263
                `OR1200_SPR_GROUP_WIDTH'd04: unqualified_cs = 32'b00000000_00000000_00000000_00010000;
264
                `OR1200_SPR_GROUP_WIDTH'd05: unqualified_cs = 32'b00000000_00000000_00000000_00100000;
265
                `OR1200_SPR_GROUP_WIDTH'd06: unqualified_cs = 32'b00000000_00000000_00000000_01000000;
266
                `OR1200_SPR_GROUP_WIDTH'd07: unqualified_cs = 32'b00000000_00000000_00000000_10000000;
267
                `OR1200_SPR_GROUP_WIDTH'd08: unqualified_cs = 32'b00000000_00000000_00000001_00000000;
268
                `OR1200_SPR_GROUP_WIDTH'd09: unqualified_cs = 32'b00000000_00000000_00000010_00000000;
269
                `OR1200_SPR_GROUP_WIDTH'd10: unqualified_cs = 32'b00000000_00000000_00000100_00000000;
270
                `OR1200_SPR_GROUP_WIDTH'd11: unqualified_cs = 32'b00000000_00000000_00001000_00000000;
271
                `OR1200_SPR_GROUP_WIDTH'd12: unqualified_cs = 32'b00000000_00000000_00010000_00000000;
272
                `OR1200_SPR_GROUP_WIDTH'd13: unqualified_cs = 32'b00000000_00000000_00100000_00000000;
273
                `OR1200_SPR_GROUP_WIDTH'd14: unqualified_cs = 32'b00000000_00000000_01000000_00000000;
274
                `OR1200_SPR_GROUP_WIDTH'd15: unqualified_cs = 32'b00000000_00000000_10000000_00000000;
275
                `OR1200_SPR_GROUP_WIDTH'd16: unqualified_cs = 32'b00000000_00000001_00000000_00000000;
276
                `OR1200_SPR_GROUP_WIDTH'd17: unqualified_cs = 32'b00000000_00000010_00000000_00000000;
277
                `OR1200_SPR_GROUP_WIDTH'd18: unqualified_cs = 32'b00000000_00000100_00000000_00000000;
278
                `OR1200_SPR_GROUP_WIDTH'd19: unqualified_cs = 32'b00000000_00001000_00000000_00000000;
279
                `OR1200_SPR_GROUP_WIDTH'd20: unqualified_cs = 32'b00000000_00010000_00000000_00000000;
280
                `OR1200_SPR_GROUP_WIDTH'd21: unqualified_cs = 32'b00000000_00100000_00000000_00000000;
281
                `OR1200_SPR_GROUP_WIDTH'd22: unqualified_cs = 32'b00000000_01000000_00000000_00000000;
282
                `OR1200_SPR_GROUP_WIDTH'd23: unqualified_cs = 32'b00000000_10000000_00000000_00000000;
283
                `OR1200_SPR_GROUP_WIDTH'd24: unqualified_cs = 32'b00000001_00000000_00000000_00000000;
284
                `OR1200_SPR_GROUP_WIDTH'd25: unqualified_cs = 32'b00000010_00000000_00000000_00000000;
285
                `OR1200_SPR_GROUP_WIDTH'd26: unqualified_cs = 32'b00000100_00000000_00000000_00000000;
286
                `OR1200_SPR_GROUP_WIDTH'd27: unqualified_cs = 32'b00001000_00000000_00000000_00000000;
287
                `OR1200_SPR_GROUP_WIDTH'd28: unqualified_cs = 32'b00010000_00000000_00000000_00000000;
288
                `OR1200_SPR_GROUP_WIDTH'd29: unqualified_cs = 32'b00100000_00000000_00000000_00000000;
289
                `OR1200_SPR_GROUP_WIDTH'd30: unqualified_cs = 32'b01000000_00000000_00000000_00000000;
290
                `OR1200_SPR_GROUP_WIDTH'd31: unqualified_cs = 32'b10000000_00000000_00000000_00000000;
291
        endcase
292
 
293
//
294
// SPRs System Group
295
//
296
 
297
//
298
// What to write into SR
299
//
300
assign to_sr[`OR1200_SR_FO:`OR1200_SR_OV] =
301
                (branch_op == `OR1200_BRANCHOP_RFE) ? esr[`OR1200_SR_FO:`OR1200_SR_OV] :
302
                (write_spr && sr_sel) ? {1'b1, spr_dat_o[`OR1200_SR_FO-1:`OR1200_SR_OV]}:
303
                sr[`OR1200_SR_FO:`OR1200_SR_OV];
304
assign to_sr[`OR1200_SR_CY] =
305
                (branch_op == `OR1200_BRANCHOP_RFE) ? esr[`OR1200_SR_CY] :
306
                cy_we ? cyforw :
307
                (write_spr && sr_sel) ? spr_dat_o[`OR1200_SR_CY] :
308
                sr[`OR1200_SR_CY];
309
assign to_sr[`OR1200_SR_F] =
310
                (branch_op == `OR1200_BRANCHOP_RFE) ? esr[`OR1200_SR_F] :
311
                flag_we ? flagforw :
312
                (write_spr && sr_sel) ? spr_dat_o[`OR1200_SR_F] :
313
                sr[`OR1200_SR_F];
314
assign to_sr[`OR1200_SR_CE:`OR1200_SR_SM] =
315
                (branch_op == `OR1200_BRANCHOP_RFE) ? esr[`OR1200_SR_CE:`OR1200_SR_SM] :
316
                (write_spr && sr_sel) ? spr_dat_o[`OR1200_SR_CE:`OR1200_SR_SM]:
317
                sr[`OR1200_SR_CE:`OR1200_SR_SM];
318
 
319
//
320
// Selects for system SPRs
321
//
322
assign cfgr_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:4] == `OR1200_SPR_CFGR));
323
assign rf_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:5] == `OR1200_SPR_RF));
324
assign npc_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_NPC));
325
assign ppc_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_PPC));
326
assign sr_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_SR));
327
assign epcr_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_EPCR));
328
assign eear_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_EEAR));
329
assign esr_sel = (spr_cs[`OR1200_SPR_GROUP_SYS] && (spr_addr[10:0] == `OR1200_SPR_ESR));
330
 
331
//
332
// Write enables for system SPRs
333
//
334
assign sr_we = (write_spr && sr_sel) | (branch_op == `OR1200_BRANCHOP_RFE) | flag_we | cy_we;
335
assign pc_we = (write_spr && (npc_sel | ppc_sel));
336
assign epcr_we = (write_spr && epcr_sel);
337
assign eear_we = (write_spr && eear_sel);
338
assign esr_we = (write_spr && esr_sel);
339
 
340
//
341
// Output from system SPRs
342
//
343
assign sys_data = (spr_dat_cfgr & {32{read_spr & cfgr_sel}}) |
344
                  (spr_dat_rf & {32{read_spr & rf_sel}}) |
345
                  (spr_dat_npc & {32{read_spr & npc_sel}}) |
346
                  (spr_dat_ppc & {32{read_spr & ppc_sel}}) |
347
                  ({{32-`OR1200_SR_WIDTH{1'b0}},sr} & {32{read_spr & sr_sel}}) |
348
                  (epcr & {32{read_spr & epcr_sel}}) |
349
                  (eear & {32{read_spr & eear_sel}}) |
350
                  ({{32-`OR1200_SR_WIDTH{1'b0}},esr} & {32{read_spr & esr_sel}});
351
 
352
//
353
// Flag alias
354
//
355
assign flag = sr[`OR1200_SR_F];
356
 
357
//
358
// Carry alias
359
//
360
assign carry = sr[`OR1200_SR_CY];
361
 
362
//
363
// Supervision register
364
//
365
always @(posedge clk or posedge rst)
366
        if (rst)
367
                sr <= #1 {1'b1, `OR1200_SR_EPH_DEF, {`OR1200_SR_WIDTH-3{1'b0}}, 1'b1};
368
        else if (except_started) begin
369
                sr[`OR1200_SR_SM]  <= #1 1'b1;
370
                sr[`OR1200_SR_TEE] <= #1 1'b0;
371
                sr[`OR1200_SR_IEE] <= #1 1'b0;
372
                sr[`OR1200_SR_DME] <= #1 1'b0;
373
                sr[`OR1200_SR_IME] <= #1 1'b0;
374
        end
375
        else if (sr_we)
376
                sr <= #1 to_sr[`OR1200_SR_WIDTH-1:0];
377
 
378
//
379
// MTSPR/MFSPR interface
380
//
381
always @(sprs_op or spr_addr or sys_data or spr_dat_mac or spr_dat_pic or spr_dat_pm or
382
        spr_dat_dmmu or spr_dat_immu or spr_dat_du or spr_dat_tt) begin
383
        case (sprs_op)  // synopsys parallel_case
384
                `OR1200_ALUOP_MTSR : begin
385
                        write_spr = 1'b1;
386
                        read_spr = 1'b0;
387
                        to_wbmux = 32'b0;
388
                end
389
                `OR1200_ALUOP_MFSR : begin
390
                        casex (spr_addr[`OR1200_SPR_GROUP_BITS]) // synopsys parallel_case
391
                                `OR1200_SPR_GROUP_TT:
392
                                        to_wbmux = spr_dat_tt;
393
                                `OR1200_SPR_GROUP_PIC:
394
                                        to_wbmux = spr_dat_pic;
395
                                `OR1200_SPR_GROUP_PM:
396
                                        to_wbmux = spr_dat_pm;
397
                                `OR1200_SPR_GROUP_DMMU:
398
                                        to_wbmux = spr_dat_dmmu;
399
                                `OR1200_SPR_GROUP_IMMU:
400
                                        to_wbmux = spr_dat_immu;
401
                                `OR1200_SPR_GROUP_MAC:
402
                                        to_wbmux = spr_dat_mac;
403
                                `OR1200_SPR_GROUP_DU:
404
                                        to_wbmux = spr_dat_du;
405
                                `OR1200_SPR_GROUP_SYS:
406
                                        to_wbmux = sys_data;
407
                                default:
408
                                        to_wbmux = 32'b0;
409
                        endcase
410
                        write_spr = 1'b0;
411
                        read_spr = 1'b1;
412
                end
413
                default : begin
414
                        write_spr = 1'b0;
415
                        read_spr = 1'b0;
416
                        to_wbmux = 32'b0;
417
                end
418
        endcase
419
end
420
 
421
endmodule

powered by: WebSVN 2.1.0

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