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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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