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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [ADDR_UNIT.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 9 ns32kum
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
//
3
// This file is part of the M32632 project
4
// http://opencores.org/project,m32632
5
//
6
// Filename: ADDR_UNIT.v
7 12 ns32kum
// Version:  1.1 bug fix
8
// History:  1.0 first release of 30 Mai 2015
9
// Date:     7 October 2015
10 9 ns32kum
//
11
// Copyright (C) 2015 Udo Moeller
12
// 
13
// This source file may be used and distributed without 
14
// restriction provided that this copyright statement is not 
15
// removed from the file and that any derivative work contains 
16
// the original copyright notice and the associated disclaimer.
17
// 
18
// This source file is free software; you can redistribute it 
19
// and/or modify it under the terms of the GNU Lesser General 
20
// Public License as published by the Free Software Foundation;
21
// either version 2.1 of the License, or (at your option) any 
22
// later version. 
23
// 
24
// This source is distributed in the hope that it will be 
25
// useful, but WITHOUT ANY WARRANTY; without even the implied 
26
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
27
// PURPOSE. See the GNU Lesser General Public License for more 
28
// details. 
29
// 
30
// You should have received a copy of the GNU Lesser General 
31
// Public License along with this source; if not, download it 
32
// from http://www.opencores.org/lgpl.shtml 
33
// 
34
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35
//
36
//      Modules contained in this file:
37
//      ADDR_UNIT       generates data access addresses and controls data cache operation
38
//
39 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 9 ns32kum
 
41 11 ns32kum
module ADDR_UNIT ( BCLK, BRESET, READ, WRITE, LDEA, NEWACC, CLRMSW, POST, DISP_OK, FULLACC, SRC2SEL, INDEX, ASIZE, SRC1, SRC2, BWD,
42
                                   DISP, PC_ARCHI, PC_ICACHE, IO_READY, ACC_STAT, MMU_UPDATE, IC_TEX, ABO_STAT, ADIVAR, RWVAL_1, OP_RMW, PHASE_17,
43 12 ns32kum
                                   NO_TRAP, FPU_TRAP, READ_OUT, WRITE_OUT, ZTEST, RMW, VADR, ADDR, SIZE, PACKET, ACC_DONE, ABORT, REG_OUT, BITSEL,
44
                                   QWATWO );
45 9 ns32kum
 
46
        input                   BCLK,BRESET;
47
        input                   READ,WRITE,LDEA;
48
        input                   NEWACC;
49
        input                   CLRMSW,POST,FULLACC;
50
        input    [1:0]   SRC2SEL;
51
        input    [3:0]   INDEX;
52
        input    [1:0]   ASIZE;
53
        input   [31:0]   SRC1,SRC2;
54
        input    [1:0]   BWD;
55
        input   [31:0]   DISP;
56
        input   [31:0]   PC_ARCHI,PC_ICACHE;
57
        input                   DISP_OK;
58
        input                   IO_READY;
59
        input    [5:0]   ACC_STAT;       // Feedback from data cache about the running access
60
        input    [1:0]   MMU_UPDATE;
61
        input    [2:0]   IC_TEX;
62
        input    [1:0]   ABO_STAT;
63
        input                   ADIVAR;
64
        input                   RWVAL_1;        // special access for RDVAL + WRVAL
65
        input                   OP_RMW;
66
        input                   PHASE_17;
67
        input                   NO_TRAP;
68
        input                   FPU_TRAP;
69
 
70
        output                  READ_OUT,WRITE_OUT,ZTEST,RMW;
71
        output  [31:0]   VADR;
72
        output  [31:0]   ADDR;
73
        output   [1:0]   SIZE;
74
        output   [3:0]   PACKET;
75
        output                  ACC_DONE;
76
        output                  ABORT;
77
        output                  REG_OUT;
78
        output   [2:0]   BITSEL;
79 12 ns32kum
        output  reg             QWATWO;
80 9 ns32kum
 
81
        reg             [31:0]   VADR;
82
        reg                             READ_OUT,write_reg,ZTEST,RMW;
83
        reg              [1:0]   SIZE;
84
        reg              [3:0]   PACKET;
85
        reg              [2:0]   BITSEL;
86
        reg             [31:0]   source2;
87
        reg             [31:0]   index_val;
88
        reg             [31:0]   vadr_reg;
89
        reg             [31:0]   ea_reg;
90
        reg             [31:0]   tos_offset;
91
        reg             [31:0]   icache_adr;
92
        reg             [31:0]   sign_ext_src1;
93
        reg        [31:12]      pg_areg;
94
        reg                             reg_out_i,next_reg;
95
        reg                             ld_ea_reg;
96
        reg                             acc_run,acc_ende,acc_step;
97
        reg                             qwa_flag;
98
        reg                             no_done;
99
        reg                             frueh_ok;
100
        reg                             io_rdy;
101
        reg                             ABORT;
102
        reg              [1:0]   tex_feld;
103
        reg              [2:0]   u_ddt;
104
        reg                             pg_op;
105
        reg                             do_wr;
106
 
107
        wire                    acc_ok,acc_err,io_acc;
108
        wire                    acc_pass;
109
        wire                    ca_hit;
110
        wire    [31:0]   reg_adder;
111
        wire    [31:0]   next_vadr;
112
        wire    [31:0]   final_addr;
113
        wire    [31:0]   pg_addr;
114
        wire     [1:0]   inc_pack;
115
        wire     [3:0]   index_sel;
116
        wire                    ld_ea_i;
117
        wire                    ea_ok;
118
        wire                    qw_align;
119
        wire                    init_acc;
120
        wire                    in_page;
121
        wire                    all_ok;
122
        wire                    fa_out;
123
        wire                    pg_test;
124
 
125
        // ++++++++++++++++++++  Decoding ACC_STAT from data cache  ++++++++++++++++++++++++++++
126
 
127
        // ACC_STAT[5:0] : CA_HIT, IO_ACC, PROT_ERROR , ABO_LEVEL1 , ABORT , ACC_OK
128
 
129
        assign ca_hit   = ACC_STAT[5];
130
        assign io_acc   = ACC_STAT[4];
131
        assign acc_err  = ACC_STAT[3] | ACC_STAT[1];    // Abort or Protection Error
132
        assign acc_ok   = ACC_STAT[0] & ~pg_op;
133
        assign acc_pass = ACC_STAT[0] & ZTEST;
134
 
135
        always @(posedge BCLK) ABORT <= acc_err;        // Signal to Steuerung - only a pulse
136
 
137 11 ns32kum
        always @(posedge BCLK) if (acc_err) tex_feld <= ACC_STAT[3] ? 2'b11 : {~ACC_STAT[2],ACC_STAT[2]};       // for MSR
138 9 ns32kum
        always @(posedge BCLK) if (acc_err) u_ddt        <= {RMW,ABO_STAT[1],(WRITE_OUT | ZTEST)};
139
 
140
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141
 
142
        always @(SRC2SEL or CLRMSW or SRC2 or PC_ARCHI or ea_reg)
143
                case (SRC2SEL)
144 11 ns32kum
                  2'b00 : source2 = {(CLRMSW ? 16'h0000 : SRC2[31:16]),SRC2[15:0]};      // base reg, External Addressing with MOD 
145 9 ns32kum
                  2'b01 : source2 = PC_ARCHI;           // PC relative
146
                  2'b10 : source2 = 32'h0;                      // Absolute Addressing
147
                  2'b11 : source2 = ea_reg;                     // REUSE : 2. TOS
148
                endcase
149
 
150 11 ns32kum
        assign index_sel = POST ? 4'h0 : INDEX; // Alternative application of Index for POST Adder : POP from Stack
151 9 ns32kum
 
152
        always @(BWD or SRC1)
153
                casex (BWD)
154
                        2'b00 : sign_ext_src1 = {{24{SRC1[7]}}, SRC1[7:0]};              // Byte
155
                        2'b01 : sign_ext_src1 = {{16{SRC1[15]}},SRC1[15:0]};     // Word
156
                  default : sign_ext_src1 = SRC1;
157
                endcase
158
 
159
        always @(index_sel or sign_ext_src1 or SRC1)
160
                casex (index_sel)
161
                  4'b1_0xx : index_val = sign_ext_src1; // für CASE
162
                  4'b1_1xx : index_val = {{ 3{sign_ext_src1[31]}},sign_ext_src1[31:3]}; // for Bit Opcodes
163
                  4'b0_100 : index_val = SRC1;
164
                  4'b0_101 : index_val = {SRC1[30:0],1'b0};
165
                  4'b0_110 : index_val = {SRC1[29:0],2'b00};
166
                  4'b0_111 : index_val = {SRC1[28:0],3'b000};
167
                  default  : index_val = 32'h0;
168
                endcase
169
 
170
        assign reg_adder = source2 + index_val; // SRC2 allows simple MOV with SRC1
171
 
172
        assign final_addr = reg_adder + DISP;   // That's the final access address
173
 
174 11 ns32kum
        always @(posedge BCLK) if (LDEA && (index_sel[3:2] == 2'b11)) BITSEL <= SRC1[2:0];       // for Bit Opcodes in I_PFAD
175 9 ns32kum
 
176
        always @(INDEX) // SP POP Operation & String Backward
177
                case (INDEX[2:0])
178
                  3'b000 : tos_offset = 32'h0000_0001;
179
                  3'b001 : tos_offset = 32'h0000_0002;
180
                  3'b010 : tos_offset = 32'h0000_0004;
181
                  3'b011 : tos_offset = 32'h0000_0008;
182
                  3'b100 : tos_offset = 32'hFFFF_FFFF;
183
                  3'b101 : tos_offset = 32'hFFFF_FFFE;
184
                  3'b110 : tos_offset = 32'hFFFF_FFFC;
185
                  3'b111 : tos_offset = 32'hFFFF_FFF8;
186
                endcase
187
 
188
        always @(posedge BCLK or negedge BRESET)
189
                if (!BRESET) ld_ea_reg <= 1'b0;
190
                  else ld_ea_reg <= (LDEA | ld_ea_reg) & ~DISP_OK;
191
 
192
        assign ld_ea_i = (LDEA | ld_ea_reg) & DISP_OK;
193
 
194
        assign ea_ok = (READ | WRITE | LDEA | ld_ea_reg) & ~FULLACC & DISP_OK;
195
 
196
        always @(posedge BCLK) icache_adr <= PC_ICACHE;
197
 
198
        // Memory for the calculated address for reuse and Register for POST modified addresses : 
199
        always @(posedge BCLK)
200
                if (ld_ea_i)
201
                  begin
202
                        casex ({MMU_UPDATE[1],INDEX[0],POST})
203
                          3'b10x : ea_reg <= MMU_UPDATE[0] ? vadr_reg : icache_adr;              // TEAR
204
                          3'b11x : ea_reg <= MMU_UPDATE[0] ?
205
                                                                  {24'h0000_00,3'b101,          u_ddt,                   tex_feld}              // MSR
206
                                                                : {24'h0000_00,3'b100,IC_TEX[2],ABO_STAT[0],1'b0,IC_TEX[1:0]};    // only READ from ICACHE
207
                          3'b0x1 : ea_reg <= source2 + tos_offset ;
208
                          3'b0x0 : ea_reg <= final_addr;
209
                        endcase
210
                  end
211
 
212
        assign ADDR = ea_reg;   // used for ADDR opcode and TOS Addressing
213
 
214
        // This pulse stores all parameters of access
215 11 ns32kum
        assign init_acc = ((FULLACC ? (NEWACC & acc_ende) : acc_ende) | ~acc_run) & DISP_OK & (READ | WRITE) & ~ABORT & NO_TRAP;
216 9 ns32kum
 
217
        assign fa_out = init_acc | ADIVAR;      // special case for LMR IVAR,...
218
 
219
        always @(fa_out or acc_ok or final_addr or qw_align or pg_op or pg_areg or vadr_reg or next_vadr)
220
                casex ({fa_out,acc_ok})
221
                  2'b1x : VADR = {final_addr[31:3],(final_addr[2] | qw_align),final_addr[1:0]};
222
                  2'b00 : VADR = pg_op ? {pg_areg,12'h0} : vadr_reg;
223
                  2'b01 : VADR = next_vadr;
224
                endcase
225
 
226
        always @(posedge BCLK)
227
                if (init_acc) vadr_reg <= {final_addr[31:3],(final_addr[2] | qw_align),final_addr[1:0]};
228
                  else
229
                        if (pg_op && ZTEST && acc_err) vadr_reg <= {pg_areg,12'h0};     // for TEAR !
230
                          else
231
                                if (acc_ok) vadr_reg <= next_vadr;
232
 
233
        assign next_vadr = qwa_flag ? {vadr_reg[31:3],3'b000} : ({vadr_reg[31:2],2'b00} + 32'h0000_0004);
234
 
235
        // Logic for Page border WRITE Test
236
        assign pg_addr = final_addr + {29'h0,(ASIZE[1] & ASIZE[0]),ASIZE[1],(ASIZE[1] | ASIZE[0])};
237
        always @(posedge BCLK) if (init_acc) pg_areg <= pg_addr[31:12];
238
        assign pg_test = (final_addr[12] != pg_addr[12]) & ~OP_RMW;     // At RMW no Test necessary
239
 
240
        always @(posedge BCLK or negedge BRESET)
241
                if (!BRESET) pg_op <= 1'b0;
242
                  else
243
                        pg_op <= init_acc ? (WRITE & ~RWVAL_1 & pg_test) : (pg_op & ~acc_pass & ~acc_err);
244
 
245
        always @(posedge BCLK) do_wr <= pg_op & ZTEST & acc_pass;       // All ok, Page exists => continue
246
 
247
        always @(posedge BCLK or negedge BRESET)
248
                if (!BRESET) READ_OUT <= 1'b0;
249
                  else
250
                        READ_OUT  <= init_acc ? (READ & ~RWVAL_1) : (READ_OUT  & ~acc_ende & ~acc_err);
251
 
252
        always @(posedge BCLK or negedge BRESET)
253
                if (!BRESET) write_reg <= 1'b0;
254
                  else
255 11 ns32kum
                        write_reg <= (init_acc ? (WRITE & ~RWVAL_1 & ~pg_test) : (write_reg & ~acc_ende & ~acc_err & ~FPU_TRAP)) | do_wr;
256 9 ns32kum
 
257
        assign WRITE_OUT = write_reg & ~FPU_TRAP;
258
 
259
        // Special case for RDVAL and WRVAL
260
        always @(posedge BCLK or negedge BRESET)
261
                if (!BRESET) ZTEST <= 1'b0;
262
                  else
263 11 ns32kum
                        ZTEST <= pg_op ? (~ZTEST | (~acc_pass & ~acc_err)) : (init_acc ? RWVAL_1  : (ZTEST  & ~acc_ende & ~acc_err));
264 9 ns32kum
 
265
        always @(posedge BCLK or negedge BRESET)
266
                if (!BRESET) RMW <= 1'b0;
267
                  else
268
                        RMW <= init_acc ? (OP_RMW & PHASE_17) : (RMW  & ~acc_ende & ~acc_err);
269
 
270
        // Special case : first MSD access by aligned QWORD READ
271
        assign qw_align = (final_addr[2:0] == 3'b000) & READ & (ASIZE == 2'b11);
272
 
273
        always @(posedge BCLK) if (init_acc) qwa_flag <= qw_align;
274
 
275
        always @(posedge BCLK or negedge BRESET)        // central flag that shows the ADDR_UNIT is busy
276
                if (!BRESET) acc_run <= 1'b0;
277
                  else
278
                        acc_run <= init_acc | (acc_run & ~acc_ende & ~acc_err & ~FPU_TRAP);
279
 
280
        always @(posedge BCLK) if (init_acc) SIZE <= ASIZE;
281
 
282
        assign inc_pack = (PACKET[1:0] == 2'b00) ? 2'b10 : {(SIZE[1] ^ SIZE[0]),(SIZE[1] & SIZE[0])};
283
 
284 11 ns32kum
        // Counter for data packets 1 to 3 : special case aligned QWORD : only 2 packets. Additionally start address in bits 1 und 0.
285 9 ns32kum
        // special coding (00) -> [01] -> (10) , [01] optional by QWORD and (10) shows always the end
286
        always @(posedge BCLK)
287
                if (init_acc) PACKET <= {2'b00,final_addr[1:0]};
288
                  else
289
                        if (acc_ok) PACKET <= PACKET + {inc_pack,2'b00};
290
 
291
        // This signal is the End signal for the ADDR_UNIT internally.
292
        always @(SIZE or PACKET or acc_ok)
293
                casex ({SIZE,PACKET[3],PACKET[1:0]})
294
                  5'b00_x_xx : acc_ende = acc_ok;       // Byte
295
                  5'b01_0_0x : acc_ende = acc_ok;       // Word         1 packet
296
                  5'b01_0_10 : acc_ende = acc_ok;       //                      1 packet
297
                  5'b01_1_xx : acc_ende = acc_ok;       //                      2 packets
298
                  5'b10_0_00 : acc_ende = acc_ok;       // DWord        1 packet
299
                  5'b10_1_xx : acc_ende = acc_ok;       //                      2 packets
300
                  5'b11_1_xx : acc_ende = acc_ok;       // QWord        at least 2 packets
301
                  default    : acc_ende = 1'b0;
302
                endcase
303
 
304 11 ns32kum
        assign in_page = (vadr_reg[11:3] != 9'h1FF);    // Access inside a page ? During WRITE address is increasing : 1. LSD 2. MSD
305 9 ns32kum
 
306
        always @(SIZE or vadr_reg or in_page or PACKET)
307
                casex (SIZE)
308
                  2'b01 : frueh_ok = (vadr_reg[3:2] != 2'b11);  //Word
309
                  2'b10 : frueh_ok = (vadr_reg[3:2] != 2'b11);  //DWord
310 11 ns32kum
                  2'b11 : frueh_ok = (PACKET[1:0] == 2'b00) ? (~vadr_reg[3] | ~vadr_reg[2]) : ((PACKET[3:2] == 2'b01) & (vadr_reg[3:2] != 2'b11));
311 9 ns32kum
                default : frueh_ok = 1'b1;                                              // Byte don't case
312
                endcase
313
 
314
        assign all_ok = SIZE[1] ? (PACKET[1:0] == 2'b00) : (PACKET[1:0] != 2'b11);        // for DWord : Word
315
 
316 11 ns32kum
        always @(SIZE or READ_OUT or frueh_ok or PACKET or all_ok or io_acc or acc_ok or qwa_flag or io_rdy or ca_hit)
317 9 ns32kum
                casex ({SIZE,READ_OUT,frueh_ok,PACKET[3],io_acc,all_ok})
318
                  7'b00_xxxx_x : acc_step = acc_ok;     // Byte, all ok
319
                //
320
                  7'b01_xxxx_1 : acc_step = acc_ok;     // Word :       aligned access , only 1 packet
321
                  7'b01_1x1x_0 : acc_step = acc_ok;     //                      READ must wait for all data
322
                  7'b01_001x_0 : acc_step = acc_ok;     //                      WRITE Adr. ist not perfect and waits for last packet
323
                  7'b01_01xx_0 : acc_step = acc_ok;     //                      WRITE Adr. perfect - acc_step after 1. packet
324
                //
325
                  7'b10_xxxx_1 : acc_step = acc_ok;     // DWord :      aligned access , only 1 packet
326
                  7'b10_1x1x_0 : acc_step = acc_ok;     //                      READ must wait for all data
327
                  7'b10_001x_0 : acc_step = acc_ok;     //                      WRITE Adr. ist not perfect and waits for last packet
328
                  7'b10_01xx_0 : acc_step = acc_ok;     //                      WRITE Adr. perfect - acc_step after 1. packet
329
                // fast QWord READ : there would be a 2. acc_step if not ~PACK... 
330
                  7'b11_1xxx_x : acc_step = acc_ok & ( (qwa_flag & ~io_rdy & ca_hit) ? ~PACKET[3] : PACKET[3] );
331
                  7'b11_0x1x_x : acc_step = acc_ok;
332 11 ns32kum
                  7'b11_0100_x : acc_step = acc_ok;     //                      WRITE Adr. perfect - acc_step after 1. packet if not io_acc
333 9 ns32kum
                  default      : acc_step = 1'b0;
334
                endcase
335
 
336
        // There is a 2. acc_step if packet (10) - this must be suppressed
337
        always @(posedge BCLK or negedge BRESET)
338
                if (!BRESET) no_done <= 1'b0;
339
                  else no_done <= (~acc_ende & acc_step) | (no_done & ~(acc_run & acc_ende));
340
 
341
        // The final DONE Multiplexer
342
        assign ACC_DONE = acc_run ? (acc_step & ~no_done) : ea_ok;
343
 
344 12 ns32kum
        // Bugfix of 7.October 2015
345
        always @(posedge BCLK) QWATWO <= acc_run & acc_ok & qwa_flag & ~io_rdy & ca_hit & ~PACKET[3] & (SIZE == 2'b11) & READ_OUT & ~no_done;
346
 
347 11 ns32kum
        always @(posedge BCLK) reg_out_i <= ~acc_step & BRESET & ((qwa_flag & (io_rdy | ~ca_hit) & acc_ok) | reg_out_i);
348 9 ns32kum
 
349
        always @(posedge BCLK) io_rdy  <= IO_READY & (WRITE_OUT | READ_OUT);
350
 
351
        always @(posedge BCLK) next_reg <= (acc_step & ~qwa_flag) & (SIZE == 2'b11);
352
        assign REG_OUT = reg_out_i | next_reg;
353
 
354
endmodule

powered by: WebSVN 2.1.0

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