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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber25/] [a25_mem.v] - Blame information for rev 35

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

Line No. Rev Author Line
1 16 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Memory Access - Instantiates the memory access stage        //
4
//  sub-modules of the Amber 25 Core                            //
5
//                                                              //
6
//  This file is part of the Amber project                      //
7
//  http://www.opencores.org/project,amber                      //
8
//                                                              //
9
//  Description                                                 //
10
//  Instantiates the Data Cache                                 //
11
//  Also contains a little bit of logic to decode memory        //
12
//  accesses to decide if they are cached or not                //
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
 
45
module a25_mem
46
(
47
input                       i_clk,
48
input                       i_fetch_stall,          // Fetch stage asserting stall
49 35 csantifort
input                       i_exec_stall,           // Execute stage asserting stall
50 16 csantifort
output                      o_mem_stall,            // Mem stage asserting stall
51
 
52
input       [31:0]          i_daddress,
53
input                       i_daddress_valid,
54
input       [31:0]          i_daddress_nxt,         // un-registered version of address to the cache rams
55
input       [31:0]          i_write_data,
56
input                       i_write_enable,
57
input                       i_exclusive,            // high for read part of swap access
58
input       [3:0]           i_byte_enable,
59 35 csantifort
input       [8:0]           i_exec_load_rd,         // The destination register for a load instruction
60 16 csantifort
input                       i_cache_enable,         // cache enable
61
input                       i_cache_flush,          // cache flush
62
input       [31:0]          i_cacheable_area,       // each bit corresponds to 2MB address space
63
 
64
output      [31:0]          o_mem_read_data,
65
output                      o_mem_read_data_valid,
66 35 csantifort
output      [10:0]          o_mem_load_rd,          // The destination register for a load instruction
67 16 csantifort
 
68
// Wishbone accesses                                                         
69
output                      o_wb_cached_req,        // Cached Request
70
output                      o_wb_uncached_req,      // Unached Request
71
output                      o_wb_qword,             // High for a quad-word read request
72
output                      o_wb_write,             // Read=0, Write=1
73 35 csantifort
output     [15:0]           o_wb_byte_enable,       // byte eable
74
output     [127:0]          o_wb_write_data,
75 16 csantifort
output     [31:0]           o_wb_address,           // wb bus                                 
76 35 csantifort
input      [127:0]          i_wb_uncached_rdata,    // wb bus                              
77
input      [127:0]          i_wb_cached_rdata,      // wb bus                              
78 16 csantifort
input                       i_wb_cached_ready,      // wishbone access complete and read data valid
79
input                       i_wb_uncached_ready     // wishbone access complete and read data valid
80
);
81
 
82
`include "memory_configuration.v"
83
 
84
wire    [31:0]              cache_read_data;
85
wire                        address_cachable;
86
wire                        sel_cache_p;
87
wire                        sel_cache;
88
wire                        cached_wb_req;
89
wire                        uncached_data_access;
90
wire                        uncached_data_access_p;
91
wire                        cache_stall;
92
wire                        uncached_wb_wait;
93
reg                         uncached_wb_req_r = 'd0;
94
reg                         uncached_wb_stop_r = 'd0;
95
reg                         cached_wb_stop_r = 'd0;
96
wire                        daddress_valid_p;  // pulse
97
reg      [31:0]             mem_read_data_r = 'd0;
98
reg                         mem_read_data_valid_r = 'd0;
99 35 csantifort
reg      [10:0]             mem_load_rd_r = 'd0;
100
wire     [10:0]             mem_load_rd_c;
101
wire     [31:0]             mem_read_data_c;
102 16 csantifort
wire                        mem_read_data_valid_c;
103
reg                         mem_stall_r = 'd0;
104
wire                        use_mem_reg;
105
reg                         fetch_only_stall_r = 'd0;
106
wire                        fetch_only_stall;
107
wire                        void_output;
108
wire                        wb_stop;
109
reg                         daddress_valid_stop_r = 'd0;
110 35 csantifort
wire     [31:0]             wb_rdata32;
111 16 csantifort
 
112
// ======================================
113
// Memory Decode
114
// ======================================
115
assign address_cachable         = in_cachable_mem( i_daddress ) && i_cacheable_area[i_daddress[25:21]];
116
assign sel_cache_p              = daddress_valid_p && address_cachable && i_cache_enable && !i_exclusive;
117
assign sel_cache                = i_daddress_valid && address_cachable && i_cache_enable && !i_exclusive;
118
assign uncached_data_access     = i_daddress_valid && !sel_cache   && !(cache_stall);
119
assign uncached_data_access_p   = daddress_valid_p && !sel_cache   && !(cache_stall);
120
 
121
assign use_mem_reg              = wb_stop && !mem_stall_r;
122
assign o_mem_read_data          = use_mem_reg ? mem_read_data_r       : mem_read_data_c;
123
assign o_mem_load_rd            = use_mem_reg ? mem_load_rd_r         : mem_load_rd_c;
124
assign o_mem_read_data_valid    = !void_output && (use_mem_reg ? mem_read_data_valid_r : mem_read_data_valid_c);
125
 
126
 
127
// Return read data either from the wishbone bus or the cache
128 35 csantifort
assign wb_rdata32               = i_daddress[3:2] == 2'd0 ? i_wb_uncached_rdata[ 31: 0] :
129
                                  i_daddress[3:2] == 2'd1 ? i_wb_uncached_rdata[ 63:32] :
130
                                  i_daddress[3:2] == 2'd2 ? i_wb_uncached_rdata[ 95:64] :
131
                                                            i_wb_uncached_rdata[127:96] ;
132
 
133 16 csantifort
assign mem_read_data_c          = sel_cache             ? cache_read_data :
134 35 csantifort
                                  uncached_data_access  ? wb_rdata32      :
135 16 csantifort
                                                          32'h76543210    ;
136 35 csantifort
 
137 16 csantifort
assign mem_load_rd_c            = {i_daddress[1:0], i_exec_load_rd};
138
assign mem_read_data_valid_c    = i_daddress_valid && !i_write_enable && !o_mem_stall;
139
 
140
assign o_mem_stall              = uncached_wb_wait || cache_stall;
141
 
142
// Request wishbone access
143 35 csantifort
assign o_wb_byte_enable         = i_daddress[3:2] == 2'd0 ? {12'd0, i_byte_enable       } :
144
                                  i_daddress[3:2] == 2'd1 ? { 8'd0, i_byte_enable,  4'd0} :
145
                                  i_daddress[3:2] == 2'd2 ? { 4'd0, i_byte_enable,  8'd0} :
146
                                                            {       i_byte_enable, 12'd0} ;
147
 
148 16 csantifort
assign o_wb_write               = i_write_enable;
149
assign o_wb_address             = {i_daddress[31:2], 2'd0};
150 35 csantifort
assign o_wb_write_data          = {4{i_write_data}};
151 16 csantifort
assign o_wb_cached_req          = !cached_wb_stop_r && cached_wb_req;
152
assign o_wb_uncached_req        = !uncached_wb_stop_r && uncached_data_access_p;
153
assign o_wb_qword               = !cached_wb_stop_r && cached_wb_req && !i_write_enable;
154
 
155
assign uncached_wb_wait         = (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
156
 
157
always @( posedge i_clk )
158
    begin
159
    uncached_wb_req_r <=  (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
160
    end
161
 
162
assign fetch_only_stall     = i_fetch_stall && !o_mem_stall;
163
 
164
always @( posedge i_clk )
165
    fetch_only_stall_r <= fetch_only_stall;
166
 
167
assign void_output = (fetch_only_stall_r && fetch_only_stall) || (fetch_only_stall_r && mem_read_data_valid_r);
168
 
169
 
170
// pulse this signal
171
assign daddress_valid_p = i_daddress_valid && !daddress_valid_stop_r;
172
 
173
always @( posedge i_clk )
174
    begin
175
    uncached_wb_stop_r      <= (uncached_wb_stop_r || uncached_data_access_p) && (i_fetch_stall || o_mem_stall);
176
    cached_wb_stop_r        <= (cached_wb_stop_r   || cached_wb_req)          && (i_fetch_stall || o_mem_stall);
177
    daddress_valid_stop_r   <= (daddress_valid_stop_r || daddress_valid_p)    && (i_fetch_stall || o_mem_stall);
178
    // hold this until the mem access completes
179
    mem_stall_r <= o_mem_stall;
180
    end
181
 
182
 
183
assign wb_stop = uncached_wb_stop_r || cached_wb_stop_r;
184
 
185
always @( posedge i_clk )
186
    if ( !wb_stop || o_mem_stall )
187
        begin
188
        mem_read_data_r         <= mem_read_data_c;
189
        mem_load_rd_r           <= mem_load_rd_c;
190
        mem_read_data_valid_r   <= mem_read_data_valid_c;
191
        end
192
 
193
 
194
// ======================================
195
// L1 Data Cache
196
// ======================================
197
a25_dcache u_dcache (
198
    .i_clk                      ( i_clk                 ),
199
    .i_fetch_stall              ( i_fetch_stall         ),
200 35 csantifort
    .i_exec_stall               ( i_exec_stall          ),
201 16 csantifort
    .o_stall                    ( cache_stall           ),
202
 
203
    .i_request                  ( sel_cache_p           ),
204
    .i_exclusive                ( i_exclusive           ),
205
    .i_write_data               ( i_write_data          ),
206
    .i_write_enable             ( i_write_enable        ),
207
    .i_address                  ( i_daddress            ),
208
    .i_address_nxt              ( i_daddress_nxt        ),
209
    .i_byte_enable              ( i_byte_enable         ),
210
 
211
    .i_cache_enable             ( i_cache_enable        ),
212
    .i_cache_flush              ( i_cache_flush         ),
213
    .o_read_data                ( cache_read_data       ),
214
 
215 35 csantifort
    .o_wb_cached_req            ( cached_wb_req         ),
216
    .i_wb_cached_rdata          ( i_wb_cached_rdata     ),
217
    .i_wb_cached_ready          ( i_wb_cached_ready     )
218 16 csantifort
);
219
 
220
 
221
 
222
endmodule
223
 

powered by: WebSVN 2.1.0

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