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 317

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

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

powered by: WebSVN 2.1.0

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