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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [REGISTERS.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 9 ns32kum
//
3
// This file is part of the M32632 project
4
// http://opencores.org/project,m32632
5
//
6 23 ns32kum
//      Filename:       REGISTERS.v
7 48 ns32kum
//      Project:        M32632
8
//  Version:    3.1 bug fix of 25 February 2019
9 23 ns32kum
//      History:        1.0 first release of 30 Mai 2015
10 48 ns32kum
//      Author:         Udo Moeller
11
//      Date:           8 July 2017
12 9 ns32kum
//
13 48 ns32kum
// Copyright (C) 2019 Udo Moeller
14 9 ns32kum
// 
15
// This source file may be used and distributed without 
16
// restriction provided that this copyright statement is not 
17
// removed from the file and that any derivative work contains 
18
// the original copyright notice and the associated disclaimer.
19
// 
20
// This source file is free software; you can redistribute it 
21
// and/or modify it under the terms of the GNU Lesser General 
22
// Public License as published by the Free Software Foundation;
23
// either version 2.1 of the License, or (at your option) any 
24
// later version. 
25
// 
26
// This source is distributed in the hope that it will be 
27
// useful, but WITHOUT ANY WARRANTY; without even the implied 
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
29
// PURPOSE. See the GNU Lesser General Public License for more 
30
// details. 
31
// 
32
// You should have received a copy of the GNU Lesser General 
33
// Public License along with this source; if not, download it 
34
// from http://www.opencores.org/lgpl.shtml 
35
// 
36 29 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 9 ns32kum
//
38
//      Modules contained in this file:
39
//      1. CONFIG_REGS  Configuration and Debug Registers
40
//      2. FP_STAT_REG  Floating Point Status Register
41
//      3. REGISTER             General Purpose Registers
42
//
43 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
44 9 ns32kum
 
45 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46 9 ns32kum
//
47
//      1. CONFIG_REGS  Configuration and Debug Registers
48
//
49 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50
module CONFIG_REGS ( BCLK, BRESET, WREN, LD_OUT, OPCODE, SRC1, WRADR, PC_ARCHI, USER, PCMATCH, DBG_HIT, READ,
51 48 ns32kum
                                         CFG, MCR, PTB_WR, PTB_SEL, IVAR, IVAR_MUX, CINV, Y_INIT, DSR, DBG_TRAPS, DBG_IN );
52 9 ns32kum
 
53
        input                   BCLK,BRESET;
54
        input                   WREN,LD_OUT;
55
        input    [7:0]   OPCODE;
56
        input   [31:0]   SRC1;
57
        input    [5:0]   WRADR;
58
        input   [31:0]   PC_ARCHI;
59
        input                   USER;
60
        input                   PCMATCH;
61
        input                   DBG_HIT;
62
        input                   READ;
63
 
64
        output  [12:0]   CFG;
65
        output   [3:0]   MCR;
66
        output                  PTB_WR;
67
        output                  PTB_SEL;
68
        output   [1:0]   IVAR;
69 48 ns32kum
        output                  IVAR_MUX;
70 9 ns32kum
        output   [3:0]   CINV;
71
        output                  Y_INIT;
72
        output   [3:0]   DSR;
73
        output   [2:0]   DBG_TRAPS;
74
        output  [40:2]  DBG_IN;
75
 
76
        reg              [3:0]   MCR;
77
        reg             [12:0]   CFG;
78
        reg              [1:0]   old_cfg;
79
        reg                             PTB_WR,PTB_SEL;
80
        reg                             ivarreg;
81
        reg              [1:0]   ci_all,ci_line;
82
        reg                             check_y;
83
 
84
        wire                    ld_cfg,ld_mcr,do_cinv;
85
        wire                    init_ic,init_dc;
86
        wire                    op_ok;
87
 
88
        assign op_ok = (OPCODE == 8'h6A);       // Special Opcode - for security reason
89
 
90
        assign ld_cfg  = op_ok & (WRADR == 6'h1C)          & WREN;
91
        assign ld_mcr  = op_ok & (WRADR == 6'd9)           & WREN;
92
        assign do_cinv = op_ok & (WRADR[5:4] == 2'b11) & WREN;
93
 
94
        // PF is not implemented
95
        always @(posedge BCLK or negedge BRESET)
96
                if (!BRESET) CFG <= 13'h0;
97
                        else if (ld_cfg) CFG <= SRC1[12:0];
98
 
99
        always @(posedge BCLK or negedge BRESET)
100
                if (!BRESET) MCR <= 4'h0;
101
                        else if (ld_mcr) MCR <= SRC1[3:0];
102
 
103 48 ns32kum
        assign IVAR_MUX = op_ok & (WRADR[5:1] == 5'd7) & WREN;  // IVAR0/1 = Reg. Nr. 14/15
104
        always @(posedge BCLK) ivarreg <= IVAR_MUX;
105 9 ns32kum
        assign IVAR = {ivarreg,PTB_SEL};
106
 
107
        always @(posedge BCLK) PTB_WR  <= op_ok & (WRADR[5:1] == 5'd6) & WREN;  // PTB0/1 = Reg. Nr. 12/13
108
        always @(posedge BCLK) PTB_SEL <= WRADR[0];
109
 
110
        // The Cache content will be invalid if the Enable-Bit is set to 0
111
        always @(posedge BCLK) old_cfg <= {CFG[11],CFG[9]};
112
 
113 11 ns32kum
        // Cache Invalidate : the Flags are coming out of the Short-field which is otherwise used for Register selection
114 9 ns32kum
        always @(posedge BCLK) ci_all  <= do_cinv &  WRADR[2] ? WRADR[1:0] : 2'b0;       // clear all
115
        always @(posedge BCLK) ci_line <= do_cinv & ~WRADR[2] ? WRADR[1:0] : 2'b0;       // clear cache line
116
 
117
        assign init_ic = old_cfg[1] & (~CFG[11] | ci_all[1]);
118
        assign init_dc = old_cfg[0] & (~CFG[9]  | ci_all[0]);
119
 
120
        assign CINV = {init_ic,ci_line[1],init_dc,ci_line[0]};
121
 
122
        // Y_INIT is neccessary if nothing has changed and therefore no DC/IC_INIT is generated
123
        always @(posedge BCLK) check_y <= ld_cfg | do_cinv;
124
        assign Y_INIT = check_y & ~init_ic & ~init_dc;  // goes to register "old_init"
125
 
126
        // +++++++++++++  DEBUG Unit  +++++++++++++++
127
 
128
        reg              [3:0]   DSR;
129
        reg             [12:0]   dcr;
130
        reg             [31:0]   bpc;
131
        reg             [31:2]  car;
132
 
133
        wire                    op_dbg,ld_dcr,ld_bpc,ld_dsr,ld_car;
134
        wire                    enable;
135
 
136
        assign op_dbg = (OPCODE == 8'h76);
137
 
138
        assign ld_dcr = op_dbg & (WRADR == 6'h11) & WREN;
139
        assign ld_bpc = op_dbg & (WRADR == 6'h12) & WREN;
140
        assign ld_dsr = op_dbg & (WRADR == 6'h13) & WREN;
141
        assign ld_car = op_dbg & (WRADR == 6'h14) & WREN;
142
 
143
        assign enable = dcr[12] & (USER ? dcr[10] : dcr[11]);   // DEN & (USER ? UD : SD)
144
 
145
        always @(posedge BCLK or negedge BRESET)
146
                if (!BRESET) dcr <= 13'd0;
147
                        else if (ld_dcr) dcr <= {SRC1[23:19],SRC1[7:0]};
148
 
149
        always @(posedge BCLK) if (ld_bpc) bpc <= SRC1;
150
        always @(posedge BCLK) if (ld_car) car <= SRC1[31:2];
151
 
152
        //                                      DEN               SD        DEN       UD       CAE      CRD      CAE      CWR    VNP/CBE  CAR
153 11 ns32kum
        assign DBG_IN = {(dcr[12] & dcr[11]),(dcr[12] & dcr[10]),(dcr[7] & dcr[6]),(dcr[7] & dcr[5]),dcr[4:0],car};
154 9 ns32kum
 
155
        always @(posedge BCLK or negedge BRESET)
156
                if (!BRESET) DSR <= 4'd0;
157
                  else
158
                        if (ld_dsr) DSR <= SRC1[31:28];
159
                          else
160
                                begin
161
                                  DSR[3] <= DBG_HIT ? READ : DSR[3];
162
                                  DSR[2] <= DSR[2] | PCMATCH;
163
                                  DSR[1] <= DSR[1];
164
                                  DSR[0] <= DSR[0] | DBG_HIT;
165
                                end
166
 
167
        assign DBG_TRAPS[0] = enable & dcr[9] & (PC_ARCHI == bpc);       // dcr[9]=PCE
168
        assign DBG_TRAPS[1] = DBG_HIT;  // Compare Adress Hit
169
        assign DBG_TRAPS[2] = dcr[8];   // TR, Trap enable
170
 
171
endmodule
172
 
173 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174 9 ns32kum
//
175
//      2. FP_STAT_REG  Floating Point Status Register
176
//
177 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
178
module FP_STAT_REG ( BCLK, BRESET, LFSR, UP_SP, UP_DP, TT_SP, TT_DP, WREN, WRADR, DIN, FSR, TWREN, FPU_TRAP, SAVE_PC);
179 9 ns32kum
 
180
        input                   BCLK;
181
        input                   BRESET;
182
        input                   LFSR;   // Load by LFSR opcode
183
        input                   UP_SP,UP_DP;    // update if calculation operation
184
        input    [4:0]   TT_SP,TT_DP;
185
        input                   WREN;   // for RMB and LFSR
186
        input    [5:4]  WRADR;
187
        input   [16:0]   DIN;    // Data for LFSR opcode
188
 
189
        output  [31:0]   FSR;
190
        output                  TWREN;
191
        output  reg             FPU_TRAP;
192
        output                  SAVE_PC;
193
 
194
        reg              [4:3]  trap_d;
195
        reg                             update_d;
196
        reg                             set_rm_d;
197
        reg             [10:0]   set_bits;
198
        reg              [4:0]   flags;
199
        reg                             rm_bit;
200
 
201
        wire                    load_fsr;
202
        wire                    update,update_i;
203
        wire     [4:0]   trap;
204
        wire                    uflag,iflag,rmflag;
205
 
206
        assign load_fsr = LFSR & WREN;
207
 
208
        assign trap = UP_SP ? TT_SP : TT_DP;
209
 
210
        // This signal suppresses write into registers if FPU Trap, timing critical signal !
211
        assign TWREN = ~((UP_SP & (TT_SP[2:0] != 3'b0)) | (UP_DP & (TT_DP[2:0] != 3'b0)));
212
 
213
        always @(posedge BCLK or negedge BRESET)
214
                if (!BRESET) FPU_TRAP <= 1'b0;
215
                  else FPU_TRAP <= ~FPU_TRAP & ~TWREN;  // one pulse of one cycle informs the Opcode Decoder
216
 
217
        assign update_i = (UP_SP | UP_DP) & ~FPU_TRAP;  // unfortunately one FPU opcode may follow !
218
        always @(posedge BCLK) update_d <= update_i;
219
        always @(posedge BCLK) trap_d   <= trap[4:3];
220
        always @(posedge BCLK) set_rm_d <= WREN & (WRADR == 2'b10);
221
        assign update = update_d & ~FPU_TRAP;
222
 
223
        // The Flags are set and stay "1" 
224
        assign iflag  = (update & trap_d[4]) | flags[4];        // Inexact Result
225
        assign uflag  = (update & trap_d[3]) | flags[3];        // Underflow
226
        assign rmflag = (set_rm_d & ~FPU_TRAP) | rm_bit;        // Register Modify
227
 
228
        always @(posedge BCLK or negedge BRESET)
229
                if (!BRESET) flags[4:3] <= 2'b0;        // Inexact = Bit6, Underflow = Bit4
230
                  else
231
                  begin
232
                        if (load_fsr) flags[4:3] <= {DIN[6],DIN[4]};
233
                          else
234
                                if (update) flags[4:3] <= {iflag,uflag};
235
                  end
236
 
237
        always @(posedge BCLK or negedge BRESET)
238
                if (!BRESET) flags[2:0] <= 3'b0; // TT Field = Bit2-0
239
                  else
240
                  begin
241
                        if (load_fsr) flags[2:0] <= DIN[2:0];
242
                          else
243
                                if (update_i) flags[2:0] <= trap[2:0];
244
                  end
245
 
246
        always @(posedge BCLK or negedge BRESET)
247
                if (!BRESET) rm_bit <= 1'b0;    // Register Modify Bit
248
                  else
249
                  begin
250
                        if (load_fsr) rm_bit <= DIN[16];
251
                          else
252
                                if (set_rm_d & ~FPU_TRAP) rm_bit <= 1'b1;       // in case of TRAP there is no writing to Register
253
                  end
254
 
255
        always @(posedge BCLK or negedge BRESET)
256
                if (!BRESET) set_bits <= 11'b0; // all other Bits
257
                  else
258
                        if (load_fsr) set_bits <= {DIN[15:7],DIN[5],DIN[3]};
259
 
260
        assign FSR = {15'h0,rmflag,set_bits[10:2],iflag,set_bits[1],uflag,set_bits[0],flags[2:0]};
261
 
262
        assign SAVE_PC = (UP_SP | UP_DP) & ~FPU_TRAP;   // Store the correct PC for FPU Trap
263
 
264
endmodule
265
 
266 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267 9 ns32kum
//
268
//      3. REGISTER             General Purpose Registers
269
//
270 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
271 9 ns32kum
module REGISTER( BCLK, ENWR, DOWR, BYDIN, DIN, RADR, WADR, WMASKE, DOUT, SELI );
272
 
273
input                   BCLK;
274
input                   DOWR,ENWR;
275
input   [31:0]   BYDIN,DIN;
276
input    [7:0]   RADR;
277
input    [5:0]   WADR;
278
input    [1:0]   WMASKE;
279
 
280
output  [31:0]   DOUT;
281
output reg              SELI;
282
 
283 23 ns32kum
reg              [2:0]   mx;
284 9 ns32kum
 
285 23 ns32kum
wire     [2:0]   be;
286 9 ns32kum
wire                    eq_rw;
287
 
288
// +++++++++++++++++++ Memories ++++++++++++++++++++
289
 
290 23 ns32kum
reg             [15:0]   REGFILE_C [0:63];        // Byte 3 and 2 , Verilog allows no "Byte Write" in wider memories !!!
291
reg              [7:0]   REGFILE_B [0:63];        // Byte 1
292
reg              [7:0]   REGFILE_A [0:63];        // Byte 0
293 9 ns32kum
reg             [31:0]   RF;
294
 
295 23 ns32kum
assign  be = {WMASKE[1],(WMASKE[1] | WMASKE[0]),1'b1};
296 9 ns32kum
 
297
assign  eq_rw = ENWR & (RADR[5:0] == WADR);
298
 
299 23 ns32kum
always @(posedge BCLK) if (RADR[7]) mx[2:0] <= be[2:0] & {{3{eq_rw}}};
300 9 ns32kum
 
301
always @(posedge BCLK) if (RADR[7]) SELI <= RADR[6];
302
 
303 23 ns32kum
assign DOUT[31:16] = mx[2] ? BYDIN[31:16] : RF[31:16];
304
assign DOUT[15:8]  = mx[1] ? BYDIN[15:8]  : RF[15:8];
305
assign DOUT[7:0]   = mx[0] ? BYDIN[7:0]   : RF[7:0];
306 9 ns32kum
 
307
// ++++++++++++++++ Register File 64 * 32 Bits ++++++++++++
308
 
309
always @(posedge BCLK)
310
        if (RADR[7])
311
                begin
312 23 ns32kum
                        RF[31:16] <= REGFILE_C[RADR[5:0]];
313 9 ns32kum
                        RF[15:8]  <= REGFILE_B[RADR[5:0]];
314
                        RF[7:0]   <= REGFILE_A[RADR[5:0]];
315
                end
316
 
317
always @(posedge BCLK)
318
        if (DOWR)
319
                begin
320 23 ns32kum
                        if (be[2]) REGFILE_C[WADR] <= DIN[31:16];
321
                        if (be[1]) REGFILE_B[WADR] <= DIN[15:8];
322
                        if (be[0]) REGFILE_A[WADR] <= DIN[7:0];
323 9 ns32kum
                end
324
 
325
endmodule
326
 

powered by: WebSVN 2.1.0

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