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

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [or1200/] [rtl/] [verilog/] [sprs.v] - Blame information for rev 210

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

Line No. Rev Author Line
1 161 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 203 lampret
// Revision 1.3  2001/08/13 03:36:20  lampret
48
// Added cfg regs. Moved all defines into one defines.v file. More cleanup.
49
//
50 170 lampret
// Revision 1.2  2001/08/09 13:39:33  lampret
51
// Major clean-up.
52
//
53 168 lampret
// Revision 1.1  2001/07/20 00:46:21  lampret
54
// Development version of RTL. Libraries are missing.
55 161 lampret
//
56 168 lampret
//
57 161 lampret
 
58 168 lampret
`include "timescale.v"
59
`include "defines.v"
60 161 lampret
 
61
module sprs(
62
                // Clk & Rst
63
                clk, rst,
64
 
65 168 lampret
                // Internal CPU interface
66
                flag, addrbase, addrofs, dat_i, alu_op, branch_op,
67
                epcr, eear, esr, except_start, except_started,
68
                to_wbmux, epcr_we, eear_we, esr_we, sr,
69 209 lampret
                spr_dat_cfgr, spr_dat_rf,
70 161 lampret
 
71
                // From/to other RISC units
72
                spr_dat_pic, spr_dat_tt, spr_dat_pm,
73 209 lampret
                spr_dat_dmmu, spr_dat_immu, spr_dat_du,
74
                spr_addr, spr_dataout, spr_cs, spr_we,
75
 
76
                du_addr, du_dat_du, du_read,
77
                du_write
78
 
79 161 lampret
);
80
 
81
parameter width = `OPERAND_WIDTH;
82
 
83
//
84
// I/O Ports
85
//
86
 
87
//
88 168 lampret
// Internal CPU interface
89 161 lampret
//
90 168 lampret
input                           clk;            // Clock
91
input                           rst;            // Reset
92
input                           flag;           // From ALU
93
input   [width-1:0]              addrbase;       // SPR base address
94
input   [15:0]                   addrofs;        // SPR offset
95
input   [width-1:0]              dat_i;          // SPR write data
96
input   [`ALUOP_WIDTH-1:0]       alu_op;         // ALU operation
97
input   [`BRANCHOP_WIDTH-1:0]    branch_op;      // Branch operation
98
input   [width-1:0]              epcr;           // EPCR0
99
input   [width-1:0]              eear;           // EEAR0
100
input   [`SR_WIDTH-1:0]  esr;            // ESR0
101
input                           except_start;   // Start of exception
102
input                           except_started; // Exception was started
103
output  [width-1:0]              to_wbmux;       // For l.mfspr
104
output                          epcr_we;        // EPCR0 write enable
105
output                          eear_we;        // EEAR0 write enable
106
output                          esr_we;         // ESR0 write enable
107
output  [`SR_WIDTH-1:0]          sr;             // SR
108 170 lampret
input   [31:0]                   spr_dat_cfgr;   // Data from CFGR
109 209 lampret
input   [31:0]                   spr_dat_rf;     // Data from RF
110 161 lampret
 
111 168 lampret
//
112 161 lampret
// To/from other RISC units
113 168 lampret
//
114
input   [31:0]                   spr_dat_pic;    // Data from PIC
115
input   [31:0]                   spr_dat_tt;     // Data from TT
116
input   [31:0]                   spr_dat_pm;     // Data from PM
117 203 lampret
input   [31:0]                   spr_dat_dmmu;   // Data from DMMU
118 209 lampret
input   [31:0]                   spr_dat_immu;   // Data from IMMU
119
input   [31:0]                   spr_dat_du;     // Data from DU
120 168 lampret
output  [31:0]                   spr_addr;       // SPR Address
121
output  [31:0]                   spr_dataout;    // Data to unit
122
output  [31:0]                   spr_cs;         // Unit select
123
output                          spr_we;         // SPR write enable
124 161 lampret
 
125 168 lampret
//
126 209 lampret
// To/from Debug Unit
127
//
128
input   [width-1:0]              du_addr;        // Address
129
input   [width-1:0]              du_dat_du;      // Data from DU to SPRS
130
input                           du_read;        // Read qualifier
131
input                           du_write;       // Write qualifier
132
 
133
//
134 168 lampret
// Internal regs & wires
135
//
136
reg     [`SR_WIDTH-1:0]          sr;             // SR
137
reg                             write_spr;      // Write SPR
138
reg                             read_spr;       // Read SPR
139
reg     [width-1:0]              to_wbmux;       // For l.mfspr
140
wire                            sr_we;          // Write enable SR
141 170 lampret
wire                            cfgr_sel;       // Select for cfg regs
142 209 lampret
wire                            rf_sel;         // Select for RF
143 168 lampret
wire                            sr_sel;         // Select for SR        
144
wire                            epcr_sel;       // Select for EPCR0
145
wire                            eear_sel;       // Select for EEAR0
146
wire                            esr_sel;        // Select for ESR0
147
wire    [31:0]                   sys_data;       // Read data from system SPRs
148
wire    [`SR_WIDTH-1:0]          to_sr;          // Data to SR
149 209 lampret
wire                            du_access;      // Debug unit access
150
wire    [`ALUOP_WIDTH-1:0]       sprs_op;        // ALU operation
151
reg     [31:0]                   unqualified_cs; // Unqualified chip selects
152 161 lampret
 
153 168 lampret
//
154 209 lampret
// Decide if it is debug unit access
155
//
156
assign du_access = du_read | du_write;
157
 
158
//
159
// Generate sprs opcode
160
//
161
assign sprs_op = du_write ? `ALUOP_MTSR : du_read ? `ALUOP_MFSR : alu_op;
162
 
163
//
164 168 lampret
// Generate SPR address from base address and offset
165 209 lampret
// OR from debug unit address
166 168 lampret
//
167 209 lampret
assign spr_addr = du_access ? du_addr : addrbase + {16'h0000, addrofs};
168 161 lampret
 
169
//
170 209 lampret
// SPR is written with dat_i from l.mtspr
171
// OR by debug unit
172 161 lampret
//
173 209 lampret
assign spr_dataout = du_access ? du_dat_du : dat_i;
174 161 lampret
 
175 168 lampret
//
176
// Write into SPRs when l.mtspr
177
//
178 209 lampret
assign spr_we = du_write | write_spr;
179 161 lampret
 
180 168 lampret
//
181 209 lampret
// Qualify chip selects
182
//
183
assign spr_cs = unqualified_cs & {32{read_spr | write_spr}};
184
 
185
//
186 168 lampret
// Decoding of groups
187
//
188
always @(spr_addr)
189
        case (spr_addr[`SPR_GROUP_BITS])        // synopsys parallel_case
190 209 lampret
                `SPR_GROUP_WIDTH'd00: unqualified_cs = 32'b00000000_00000000_00000000_00000001;
191
                `SPR_GROUP_WIDTH'd01: unqualified_cs = 32'b00000000_00000000_00000000_00000010;
192
                `SPR_GROUP_WIDTH'd02: unqualified_cs = 32'b00000000_00000000_00000000_00000100;
193
                `SPR_GROUP_WIDTH'd03: unqualified_cs = 32'b00000000_00000000_00000000_00001000;
194
                `SPR_GROUP_WIDTH'd04: unqualified_cs = 32'b00000000_00000000_00000000_00010000;
195
                `SPR_GROUP_WIDTH'd05: unqualified_cs = 32'b00000000_00000000_00000000_00100000;
196
                `SPR_GROUP_WIDTH'd06: unqualified_cs = 32'b00000000_00000000_00000000_01000000;
197
                `SPR_GROUP_WIDTH'd07: unqualified_cs = 32'b00000000_00000000_00000000_10000000;
198
                `SPR_GROUP_WIDTH'd08: unqualified_cs = 32'b00000000_00000000_00000001_00000000;
199
                `SPR_GROUP_WIDTH'd09: unqualified_cs = 32'b00000000_00000000_00000010_00000000;
200
                `SPR_GROUP_WIDTH'd10: unqualified_cs = 32'b00000000_00000000_00000100_00000000;
201
                `SPR_GROUP_WIDTH'd11: unqualified_cs = 32'b00000000_00000000_00001000_00000000;
202
                `SPR_GROUP_WIDTH'd12: unqualified_cs = 32'b00000000_00000000_00010000_00000000;
203
                `SPR_GROUP_WIDTH'd13: unqualified_cs = 32'b00000000_00000000_00100000_00000000;
204
                `SPR_GROUP_WIDTH'd14: unqualified_cs = 32'b00000000_00000000_01000000_00000000;
205
                `SPR_GROUP_WIDTH'd15: unqualified_cs = 32'b00000000_00000000_10000000_00000000;
206
                `SPR_GROUP_WIDTH'd16: unqualified_cs = 32'b00000000_00000001_00000000_00000000;
207
                `SPR_GROUP_WIDTH'd17: unqualified_cs = 32'b00000000_00000010_00000000_00000000;
208
                `SPR_GROUP_WIDTH'd18: unqualified_cs = 32'b00000000_00000100_00000000_00000000;
209
                `SPR_GROUP_WIDTH'd19: unqualified_cs = 32'b00000000_00001000_00000000_00000000;
210
                `SPR_GROUP_WIDTH'd20: unqualified_cs = 32'b00000000_00010000_00000000_00000000;
211
                `SPR_GROUP_WIDTH'd21: unqualified_cs = 32'b00000000_00100000_00000000_00000000;
212
                `SPR_GROUP_WIDTH'd22: unqualified_cs = 32'b00000000_01000000_00000000_00000000;
213
                `SPR_GROUP_WIDTH'd23: unqualified_cs = 32'b00000000_10000000_00000000_00000000;
214
                `SPR_GROUP_WIDTH'd24: unqualified_cs = 32'b00000001_00000000_00000000_00000000;
215
                `SPR_GROUP_WIDTH'd25: unqualified_cs = 32'b00000010_00000000_00000000_00000000;
216
                `SPR_GROUP_WIDTH'd26: unqualified_cs = 32'b00000100_00000000_00000000_00000000;
217
                `SPR_GROUP_WIDTH'd27: unqualified_cs = 32'b00001000_00000000_00000000_00000000;
218
                `SPR_GROUP_WIDTH'd28: unqualified_cs = 32'b00010000_00000000_00000000_00000000;
219
                `SPR_GROUP_WIDTH'd29: unqualified_cs = 32'b00100000_00000000_00000000_00000000;
220
                `SPR_GROUP_WIDTH'd30: unqualified_cs = 32'b01000000_00000000_00000000_00000000;
221
                `SPR_GROUP_WIDTH'd31: unqualified_cs = 32'b10000000_00000000_00000000_00000000;
222 168 lampret
        endcase
223 161 lampret
 
224 168 lampret
//
225
// SPRs System Group
226
//
227 161 lampret
 
228 168 lampret
//
229
// What to write into SR
230
//
231 209 lampret
assign to_sr = (branch_op == `BRANCHOP_RFE) ? esr : spr_dataout[`SR_WIDTH-1:0];
232 161 lampret
 
233 168 lampret
//
234
// Selects for system SPRs
235
//
236 209 lampret
assign cfgr_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:4] == `SPR_CFGR));
237
assign rf_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:5] == `SPR_RF));
238
assign sr_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:0] == `SPR_SR));
239
assign epcr_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:0] == `SPR_EPCR));
240
assign eear_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:0] == `SPR_EEAR));
241
assign esr_sel = (spr_cs[`SPR_GROUP_SYS] && (spr_addr[10:0] == `SPR_ESR));
242 168 lampret
 
243
//
244
// Write enables for system SPRs
245
//
246 161 lampret
assign sr_we = (write_spr && sr_sel) | (branch_op == `BRANCHOP_RFE);
247
assign epcr_we = (write_spr && epcr_sel);
248
assign eear_we = (write_spr && eear_sel);
249
assign esr_we = (write_spr && esr_sel);
250
 
251 168 lampret
//
252
// Output from system SPRs
253
//
254 170 lampret
assign sys_data = (spr_dat_cfgr & {32{read_spr & cfgr_sel}}) |
255 209 lampret
                  (spr_dat_rf & {32{read_spr & rf_sel}}) |
256
                  ({{32-`SR_WIDTH{1'b0}},sr} & {32{read_spr & sr_sel}}) |
257 161 lampret
                  (epcr & {32{read_spr & epcr_sel}}) |
258
                  (eear & {32{read_spr & eear_sel}}) |
259 209 lampret
                  ({{32-`SR_WIDTH{1'b0}},esr} & {32{read_spr & esr_sel}});
260 161 lampret
 
261 168 lampret
//
262 161 lampret
// Supervision register
263 168 lampret
//
264 161 lampret
always @(posedge clk or posedge rst)
265
        if (rst)
266
                sr <= #1 `SR_WIDTH'b011;
267
        else if (except_started) begin
268 203 lampret
`ifdef OR1200_VERBOSE
269
// synopsys translate_off
270 161 lampret
                $display(" INFO: exception started. SR[SUPV] set and SR[EXR] cleared.");
271 203 lampret
// synopsys translate_on
272
`endif
273 161 lampret
                sr[`SR_SUPV] <= #1 1'b1;
274
                sr[`SR_EXR] <= #1 1'b0;
275 210 lampret
                sr[`SR_WIDTH-1:2] <= #1 {`SR_WIDTH-2{1'b0}};
276 161 lampret
        end
277
        else if (sr_we) begin
278 203 lampret
`ifdef OR1200_VERBOSE
279
// synopsys translate_off
280 209 lampret
                $display(" INFO: writing into SR register: %h", spr_dataout);
281 203 lampret
// synopsys translate_on
282
`endif
283 161 lampret
                sr <= #1 to_sr;
284
        end
285
 
286 168 lampret
//
287
// MTSPR/MFSPR interface
288
//
289 209 lampret
always @(sprs_op or spr_addr or spr_dataout or sys_data or spr_dat_pic or spr_dat_pm or
290
        spr_dat_dmmu or spr_dat_immu or spr_dat_du or spr_dat_tt) begin
291
        case (sprs_op)  // synopsys full_case parallel_case
292 161 lampret
                `ALUOP_MTSR : begin
293 203 lampret
`ifdef OR1200_VERBOSE
294
// synopsys translate_off
295 209 lampret
                        $display("%t: SPRS: mtspr (%h) <- %h", $time, spr_addr, spr_dataout);
296 203 lampret
// synopsys translate_on
297
`endif
298
                        write_spr = 1'b1;
299
                        read_spr = 1'b0;
300
                        to_wbmux = 32'b0;
301 161 lampret
                end
302
                `ALUOP_MFSR : begin
303 168 lampret
                        casex (spr_addr[`SPR_GROUP_BITS])
304 161 lampret
                                `SPR_GROUP_TT:
305 203 lampret
                                        to_wbmux = spr_dat_tt;
306 161 lampret
                                `SPR_GROUP_PIC:
307 203 lampret
                                        to_wbmux = spr_dat_pic;
308 161 lampret
                                `SPR_GROUP_PM:
309 203 lampret
                                        to_wbmux = spr_dat_pm;
310
                                `SPR_GROUP_DMMU:
311
                                        to_wbmux = spr_dat_dmmu;
312 209 lampret
                                `SPR_GROUP_IMMU:
313
                                        to_wbmux = spr_dat_immu;
314
                                `SPR_GROUP_DU:
315
                                        to_wbmux = spr_dat_du;
316 161 lampret
                                `SPR_GROUP_SYS:
317 203 lampret
                                        to_wbmux = sys_data;
318 161 lampret
                                default:
319 203 lampret
                                        to_wbmux = 32'b0;
320 161 lampret
                        endcase
321 203 lampret
                        write_spr = 1'b0;
322
                        read_spr = 1'b1;
323 161 lampret
                end
324
                default : begin
325 203 lampret
                        write_spr = 1'b0;
326
                        read_spr = 1'b0;
327
                        to_wbmux = 32'b0;
328 161 lampret
                end
329
        endcase
330
end
331
 
332
endmodule

powered by: WebSVN 2.1.0

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