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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber25/] [a25_register_bank.v] - Blame information for rev 20

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

Line No. Rev Author Line
1 16 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Register Bank for Amber 25 Core                             //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Contains 37 32-bit registers, 16 of which are visible       //
10
//  ina any one operating mode. Registers use real flipflops,   //
11
//  rather than SRAM. This makes sense for an FPGA              //
12
//  implementation, where flipflops are plentiful.              //
13
//                                                              //
14
//  Author(s):                                                  //
15
//      - Conor Santifort, csantifort.amber@gmail.com           //
16
//                                                              //
17
//////////////////////////////////////////////////////////////////
18
//                                                              //
19
// Copyright (C) 2011 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
module a25_register_bank (
45
 
46
input                       i_clk,
47
input                       i_access_stall,
48
input                       i_mem_stall,
49
 
50
input       [1:0]           i_mode_idec,            // user, supervisor, irq_idec, firq_idec etc.
51
                                                    // Used for register writes
52
input       [1:0]           i_mode_exec,            // 1 periods delayed from i_mode_idec
53
                                                    // Used for register reads
54
input       [3:0]           i_mode_rds_exec,        // Use one-hot version specifically for rds, 
55
                                                    // includes i_user_mode_regs_store
56
input                       i_firq_not_user_mode,
57
input       [3:0]           i_rm_sel,
58
input       [3:0]           i_rs_sel,
59
input       [3:0]           i_rn_sel,
60
 
61
input                       i_pc_wen,
62
input       [14:0]          i_reg_bank_wen,
63
 
64
input       [23:0]          i_pc,                   // program counter [25:2]
65
input       [31:0]          i_reg,
66
 
67
input       [31:0]          i_wb_read_data,
68
input                       i_wb_read_data_valid,
69
input       [3:0]           i_wb_read_data_rd,
70
input                       i_wb_user_mode,
71
 
72
input       [3:0]           i_status_bits_flags,
73
input                       i_status_bits_irq_mask,
74
input                       i_status_bits_firq_mask,
75
 
76
output      [31:0]          o_rm,
77
output reg  [31:0]          o_rs,
78
output reg  [31:0]          o_rd,
79
output      [31:0]          o_rn,
80
output      [31:0]          o_pc
81
 
82
);
83
 
84
`include "a25_localparams.v"
85
`include "a25_functions.v"
86
 
87
 
88
// User Mode Registers
89
reg  [31:0] r0  = 32'hdead_beef;
90
reg  [31:0] r1  = 32'hdead_beef;
91
reg  [31:0] r2  = 32'hdead_beef;
92
reg  [31:0] r3  = 32'hdead_beef;
93
reg  [31:0] r4  = 32'hdead_beef;
94
reg  [31:0] r5  = 32'hdead_beef;
95
reg  [31:0] r6  = 32'hdead_beef;
96
reg  [31:0] r7  = 32'hdead_beef;
97
reg  [31:0] r8  = 32'hdead_beef;
98
reg  [31:0] r9  = 32'hdead_beef;
99
reg  [31:0] r10 = 32'hdead_beef;
100
reg  [31:0] r11 = 32'hdead_beef;
101
reg  [31:0] r12 = 32'hdead_beef;
102
reg  [31:0] r13 = 32'hdead_beef;
103
reg  [31:0] r14 = 32'hdead_beef;
104
reg  [23:0] r15 = 24'hc0_ffee;
105
 
106
wire  [31:0] r0_out;
107
wire  [31:0] r1_out;
108
wire  [31:0] r2_out;
109
wire  [31:0] r3_out;
110
wire  [31:0] r4_out;
111
wire  [31:0] r5_out;
112
wire  [31:0] r6_out;
113
wire  [31:0] r7_out;
114
wire  [31:0] r8_out;
115
wire  [31:0] r9_out;
116
wire  [31:0] r10_out;
117
wire  [31:0] r11_out;
118
wire  [31:0] r12_out;
119
wire  [31:0] r13_out;
120
wire  [31:0] r14_out;
121
wire  [31:0] r15_out_rm;
122
wire  [31:0] r15_out_rm_nxt;
123
wire  [31:0] r15_out_rn;
124
 
125
wire  [31:0] r8_rds;
126
wire  [31:0] r9_rds;
127
wire  [31:0] r10_rds;
128
wire  [31:0] r11_rds;
129
wire  [31:0] r12_rds;
130
wire  [31:0] r13_rds;
131
wire  [31:0] r14_rds;
132
 
133
// Supervisor Mode Registers
134
reg  [31:0] r13_svc = 32'hdead_beef;
135
reg  [31:0] r14_svc = 32'hdead_beef;
136
 
137
// Interrupt Mode Registers
138
reg  [31:0] r13_irq = 32'hdead_beef;
139
reg  [31:0] r14_irq = 32'hdead_beef;
140
 
141
// Fast Interrupt Mode Registers
142
reg  [31:0] r8_firq  = 32'hdead_beef;
143
reg  [31:0] r9_firq  = 32'hdead_beef;
144
reg  [31:0] r10_firq = 32'hdead_beef;
145
reg  [31:0] r11_firq = 32'hdead_beef;
146
reg  [31:0] r12_firq = 32'hdead_beef;
147
reg  [31:0] r13_firq = 32'hdead_beef;
148
reg  [31:0] r14_firq = 32'hdead_beef;
149
 
150
wire        usr_exec;
151
wire        svc_exec;
152
wire        irq_exec;
153
wire        firq_exec;
154
 
155
wire        usr_idec;
156
wire        svc_idec;
157
wire        irq_idec;
158
wire        firq_idec;
159
wire [14:0] read_data_wen;
160
wire [14:0] reg_bank_wen_c;
161
wire        pc_wen_c;
162
wire        pc_dmem_wen;
163
 
164
 
165
    // Write Enables from execute stage
166
assign usr_idec  = i_mode_idec == USR;
167
assign svc_idec  = i_mode_idec == SVC;
168
assign irq_idec  = i_mode_idec == IRQ;
169
 
170
// pre-encoded in decode stage to speed up long path
171
assign firq_idec = i_firq_not_user_mode;
172
 
173
    // Read Enables from stage 1 (fetch)
174
assign usr_exec  = i_mode_exec == USR;
175
assign svc_exec  = i_mode_exec == SVC;
176
assign irq_exec  = i_mode_exec == IRQ;
177
assign firq_exec = i_mode_exec == FIRQ;
178
 
179
assign read_data_wen = {15{i_wb_read_data_valid & ~i_mem_stall}} & decode (i_wb_read_data_rd);
180
 
181
assign reg_bank_wen_c = {15{~i_access_stall}} & i_reg_bank_wen;
182
assign pc_wen_c       = ~i_access_stall & i_pc_wen;
183
assign pc_dmem_wen    = i_wb_read_data_valid & ~i_mem_stall & i_wb_read_data_rd == 4'd15;
184
 
185
 
186
// ========================================================
187
// Register Update
188
// ========================================================
189
always @ ( posedge i_clk )
190
    begin
191
    r0       <= reg_bank_wen_c[0 ]               ? i_reg : read_data_wen[0 ] ? i_wb_read_data : r0;
192
    r1       <= reg_bank_wen_c[1 ]               ? i_reg : read_data_wen[1 ] ? i_wb_read_data : r1;
193
    r2       <= reg_bank_wen_c[2 ]               ? i_reg : read_data_wen[2 ] ? i_wb_read_data : r2;
194
    r3       <= reg_bank_wen_c[3 ]               ? i_reg : read_data_wen[3 ] ? i_wb_read_data : r3;
195
    r4       <= reg_bank_wen_c[4 ]               ? i_reg : read_data_wen[4 ] ? i_wb_read_data : r4;
196
    r5       <= reg_bank_wen_c[5 ]               ? i_reg : read_data_wen[5 ] ? i_wb_read_data : r5;
197
    r6       <= reg_bank_wen_c[6 ]               ? i_reg : read_data_wen[6 ] ? i_wb_read_data : r6;
198
    r7       <= reg_bank_wen_c[7 ]               ? i_reg : read_data_wen[7 ] ? i_wb_read_data : r7;
199
 
200
    r8       <= reg_bank_wen_c[8 ] && !firq_idec ? i_reg : read_data_wen[8 ] && ( !firq_idec || i_wb_user_mode ) ? i_wb_read_data : r8;
201
    r9       <= reg_bank_wen_c[9 ] && !firq_idec ? i_reg : read_data_wen[9 ] && ( !firq_idec || i_wb_user_mode ) ? i_wb_read_data : r9;
202
    r10      <= reg_bank_wen_c[10] && !firq_idec ? i_reg : read_data_wen[10] && ( !firq_idec || i_wb_user_mode ) ? i_wb_read_data : r10;
203
    r11      <= reg_bank_wen_c[11] && !firq_idec ? i_reg : read_data_wen[11] && ( !firq_idec || i_wb_user_mode ) ? i_wb_read_data : r11;
204
    r12      <= reg_bank_wen_c[12] && !firq_idec ? i_reg : read_data_wen[12] && ( !firq_idec || i_wb_user_mode ) ? i_wb_read_data : r12;
205
 
206
    r8_firq  <= reg_bank_wen_c[8 ] &&  firq_idec ? i_reg : read_data_wen[8 ] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r8_firq;
207
    r9_firq  <= reg_bank_wen_c[9 ] &&  firq_idec ? i_reg : read_data_wen[9 ] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r9_firq;
208
    r10_firq <= reg_bank_wen_c[10] &&  firq_idec ? i_reg : read_data_wen[10] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r10_firq;
209
    r11_firq <= reg_bank_wen_c[11] &&  firq_idec ? i_reg : read_data_wen[11] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r11_firq;
210
    r12_firq <= reg_bank_wen_c[12] &&  firq_idec ? i_reg : read_data_wen[12] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r12_firq;
211
 
212
    r13      <= reg_bank_wen_c[13] &&  usr_idec  ? i_reg : read_data_wen[13] && ( usr_idec || i_wb_user_mode )   ? i_wb_read_data : r13;
213
    r14      <= reg_bank_wen_c[14] &&  usr_idec  ? i_reg : read_data_wen[14] && ( usr_idec || i_wb_user_mode )   ? i_wb_read_data : r14;
214
 
215
    r13_svc  <= reg_bank_wen_c[13] &&  svc_idec  ? i_reg : read_data_wen[13] && ( svc_idec && !i_wb_user_mode )  ? i_wb_read_data : r13_svc;
216
    r14_svc  <= reg_bank_wen_c[14] &&  svc_idec  ? i_reg : read_data_wen[14] && ( svc_idec && !i_wb_user_mode )  ? i_wb_read_data : r14_svc;
217
 
218
    r13_irq  <= reg_bank_wen_c[13] &&  irq_idec  ? i_reg : read_data_wen[13] && ( irq_idec && !i_wb_user_mode )  ? i_wb_read_data : r13_irq;
219
    r14_irq  <= reg_bank_wen_c[14] &&  irq_idec  ? i_reg : read_data_wen[14] && ( irq_idec && !i_wb_user_mode )  ? i_wb_read_data : r14_irq;
220
 
221
    r13_firq <= reg_bank_wen_c[13] &&  firq_idec ? i_reg : read_data_wen[13] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r13_firq;
222
    r14_firq <= reg_bank_wen_c[14] &&  firq_idec ? i_reg : read_data_wen[14] && ( firq_idec && !i_wb_user_mode ) ? i_wb_read_data : r14_firq;
223
 
224
    r15      <= pc_wen_c                         ?  i_pc : pc_dmem_wen ? i_wb_read_data[25:2] : r15;
225
    end
226
 
227
 
228
// ========================================================
229
// Register Read based on Mode
230
// ========================================================
231
assign r0_out = r0;
232
assign r1_out = r1;
233
assign r2_out = r2;
234
assign r3_out = r3;
235
assign r4_out = r4;
236
assign r5_out = r5;
237
assign r6_out = r6;
238
assign r7_out = r7;
239
 
240
assign r8_out  = firq_exec ? r8_firq  : r8;
241
assign r9_out  = firq_exec ? r9_firq  : r9;
242
assign r10_out = firq_exec ? r10_firq : r10;
243
assign r11_out = firq_exec ? r11_firq : r11;
244
assign r12_out = firq_exec ? r12_firq : r12;
245
 
246
assign r13_out = usr_exec ? r13      :
247
                 svc_exec ? r13_svc  :
248
                 irq_exec ? r13_irq  :
249
                          r13_firq ;
250
 
251
assign r14_out = usr_exec ? r14      :
252
                 svc_exec ? r14_svc  :
253
                 irq_exec ? r14_irq  :
254
                          r14_firq ;
255
 
256
 
257
assign r15_out_rm     = { i_status_bits_flags,
258
                          i_status_bits_irq_mask,
259
                          i_status_bits_firq_mask,
260
                          r15,
261
                          i_mode_exec};
262
 
263
assign r15_out_rm_nxt = { i_status_bits_flags,
264
                          i_status_bits_irq_mask,
265
                          i_status_bits_firq_mask,
266
                          i_pc,
267
                          i_mode_exec};
268
 
269
assign r15_out_rn     = {6'd0, r15, 2'd0};
270
 
271
 
272
// rds outputs
273
assign r8_rds  = i_mode_rds_exec[OH_FIRQ] ? r8_firq  : r8;
274
assign r9_rds  = i_mode_rds_exec[OH_FIRQ] ? r9_firq  : r9;
275
assign r10_rds = i_mode_rds_exec[OH_FIRQ] ? r10_firq : r10;
276
assign r11_rds = i_mode_rds_exec[OH_FIRQ] ? r11_firq : r11;
277
assign r12_rds = i_mode_rds_exec[OH_FIRQ] ? r12_firq : r12;
278
 
279
assign r13_rds = i_mode_rds_exec[OH_USR]  ? r13      :
280
                 i_mode_rds_exec[OH_SVC]  ? r13_svc  :
281
                 i_mode_rds_exec[OH_IRQ]  ? r13_irq  :
282
                                            r13_firq ;
283
 
284
assign r14_rds = i_mode_rds_exec[OH_USR]  ? r14      :
285
                 i_mode_rds_exec[OH_SVC]  ? r14_svc  :
286
                 i_mode_rds_exec[OH_IRQ]  ? r14_irq  :
287
                                            r14_firq ;
288
 
289
 
290
// ========================================================
291
// Program Counter out
292
// ========================================================
293
assign o_pc = r15_out_rn;
294
 
295
// ========================================================
296
// Rm Selector
297
// ========================================================
298
assign o_rm = i_rm_sel == 4'd0  ? r0_out  :
299
              i_rm_sel == 4'd1  ? r1_out  :
300
              i_rm_sel == 4'd2  ? r2_out  :
301
              i_rm_sel == 4'd3  ? r3_out  :
302
              i_rm_sel == 4'd4  ? r4_out  :
303
              i_rm_sel == 4'd5  ? r5_out  :
304
              i_rm_sel == 4'd6  ? r6_out  :
305
              i_rm_sel == 4'd7  ? r7_out  :
306
              i_rm_sel == 4'd8  ? r8_out  :
307
              i_rm_sel == 4'd9  ? r9_out  :
308
              i_rm_sel == 4'd10 ? r10_out :
309
              i_rm_sel == 4'd11 ? r11_out :
310
              i_rm_sel == 4'd12 ? r12_out :
311
              i_rm_sel == 4'd13 ? r13_out :
312
              i_rm_sel == 4'd14 ? r14_out :
313
                                  r15_out_rm ;
314
 
315
 
316
// ========================================================
317
// Rds Selector
318
// ========================================================
319
always @*
320
    case ( i_rs_sel )
321
       4'd0  :  o_rs = r0_out  ;
322
       4'd1  :  o_rs = r1_out  ;
323
       4'd2  :  o_rs = r2_out  ;
324
       4'd3  :  o_rs = r3_out  ;
325
       4'd4  :  o_rs = r4_out  ;
326
       4'd5  :  o_rs = r5_out  ;
327
       4'd6  :  o_rs = r6_out  ;
328
       4'd7  :  o_rs = r7_out  ;
329
       4'd8  :  o_rs = r8_rds  ;
330
       4'd9  :  o_rs = r9_rds  ;
331
       4'd10 :  o_rs = r10_rds ;
332
       4'd11 :  o_rs = r11_rds ;
333
       4'd12 :  o_rs = r12_rds ;
334
       4'd13 :  o_rs = r13_rds ;
335
       4'd14 :  o_rs = r14_rds ;
336
       4'd15 :  o_rs = r15_out_rn ;
337
       default: o_rs = r15_out_rn ;
338
    endcase
339
 
340
 
341
// ========================================================
342
// Rd Selector
343
// ========================================================
344
always @*
345
    case ( i_rs_sel )
346
       4'd0  :  o_rd = r0_out  ;
347
       4'd1  :  o_rd = r1_out  ;
348
       4'd2  :  o_rd = r2_out  ;
349
       4'd3  :  o_rd = r3_out  ;
350
       4'd4  :  o_rd = r4_out  ;
351
       4'd5  :  o_rd = r5_out  ;
352
       4'd6  :  o_rd = r6_out  ;
353
       4'd7  :  o_rd = r7_out  ;
354
       4'd8  :  o_rd = r8_rds  ;
355
       4'd9  :  o_rd = r9_rds  ;
356
       4'd10 :  o_rd = r10_rds ;
357
       4'd11 :  o_rd = r11_rds ;
358
       4'd12 :  o_rd = r12_rds ;
359
       4'd13 :  o_rd = r13_rds ;
360
       4'd14 :  o_rd = r14_rds ;
361
       4'd15 :  o_rd = r15_out_rm_nxt ;
362
       default: o_rd = r15_out_rm_nxt ;
363
    endcase
364
 
365
 
366
// ========================================================
367
// Rn Selector
368
// ========================================================
369
assign o_rn = i_rn_sel == 4'd0  ? r0_out  :
370
              i_rn_sel == 4'd1  ? r1_out  :
371
              i_rn_sel == 4'd2  ? r2_out  :
372
              i_rn_sel == 4'd3  ? r3_out  :
373
              i_rn_sel == 4'd4  ? r4_out  :
374
              i_rn_sel == 4'd5  ? r5_out  :
375
              i_rn_sel == 4'd6  ? r6_out  :
376
              i_rn_sel == 4'd7  ? r7_out  :
377
              i_rn_sel == 4'd8  ? r8_out  :
378
              i_rn_sel == 4'd9  ? r9_out  :
379
              i_rn_sel == 4'd10 ? r10_out :
380
              i_rn_sel == 4'd11 ? r11_out :
381
              i_rn_sel == 4'd12 ? r12_out :
382
              i_rn_sel == 4'd13 ? r13_out :
383
              i_rn_sel == 4'd14 ? r14_out :
384
                                  r15_out_rn ;
385
 
386
 
387
endmodule
388
 
389
 

powered by: WebSVN 2.1.0

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