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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_10/] [or1200/] [rtl/] [verilog/] [or1200_sprs.v] - Blame information for rev 636

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

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

powered by: WebSVN 2.1.0

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