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

Subversion Repositories amber

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

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_write,             // Read=0, Write=1
72 35 csantifort
output     [15:0]           o_wb_byte_enable,       // byte eable
73
output     [127:0]          o_wb_write_data,
74 16 csantifort
output     [31:0]           o_wb_address,           // wb bus                                 
75 35 csantifort
input      [127:0]          i_wb_uncached_rdata,    // wb bus                              
76
input      [127:0]          i_wb_cached_rdata,      // wb bus                              
77 16 csantifort
input                       i_wb_cached_ready,      // wishbone access complete and read data valid
78
input                       i_wb_uncached_ready     // wishbone access complete and read data valid
79
);
80
 
81
`include "memory_configuration.v"
82
 
83
wire    [31:0]              cache_read_data;
84
wire                        address_cachable;
85
wire                        sel_cache_p;
86
wire                        sel_cache;
87
wire                        cached_wb_req;
88
wire                        uncached_data_access;
89
wire                        uncached_data_access_p;
90
wire                        cache_stall;
91
wire                        uncached_wb_wait;
92
reg                         uncached_wb_req_r = 'd0;
93
reg                         uncached_wb_stop_r = 'd0;
94
reg                         cached_wb_stop_r = 'd0;
95
wire                        daddress_valid_p;  // pulse
96
reg      [31:0]             mem_read_data_r = 'd0;
97
reg                         mem_read_data_valid_r = 'd0;
98 35 csantifort
reg      [10:0]             mem_load_rd_r = 'd0;
99
wire     [10:0]             mem_load_rd_c;
100
wire     [31:0]             mem_read_data_c;
101 16 csantifort
wire                        mem_read_data_valid_c;
102
reg                         mem_stall_r = 'd0;
103
wire                        use_mem_reg;
104
reg                         fetch_only_stall_r = 'd0;
105
wire                        fetch_only_stall;
106
wire                        void_output;
107
wire                        wb_stop;
108
reg                         daddress_valid_stop_r = 'd0;
109 35 csantifort
wire     [31:0]             wb_rdata32;
110 16 csantifort
 
111
// ======================================
112
// Memory Decode
113
// ======================================
114
assign address_cachable         = in_cachable_mem( i_daddress ) && i_cacheable_area[i_daddress[25:21]];
115
assign sel_cache_p              = daddress_valid_p && address_cachable && i_cache_enable && !i_exclusive;
116
assign sel_cache                = i_daddress_valid && address_cachable && i_cache_enable && !i_exclusive;
117
assign uncached_data_access     = i_daddress_valid && !sel_cache   && !(cache_stall);
118
assign uncached_data_access_p   = daddress_valid_p && !sel_cache   && !(cache_stall);
119
 
120
assign use_mem_reg              = wb_stop && !mem_stall_r;
121
assign o_mem_read_data          = use_mem_reg ? mem_read_data_r       : mem_read_data_c;
122
assign o_mem_load_rd            = use_mem_reg ? mem_load_rd_r         : mem_load_rd_c;
123
assign o_mem_read_data_valid    = !void_output && (use_mem_reg ? mem_read_data_valid_r : mem_read_data_valid_c);
124
 
125
 
126
// Return read data either from the wishbone bus or the cache
127 35 csantifort
assign wb_rdata32               = i_daddress[3:2] == 2'd0 ? i_wb_uncached_rdata[ 31: 0] :
128
                                  i_daddress[3:2] == 2'd1 ? i_wb_uncached_rdata[ 63:32] :
129
                                  i_daddress[3:2] == 2'd2 ? i_wb_uncached_rdata[ 95:64] :
130
                                                            i_wb_uncached_rdata[127:96] ;
131
 
132 16 csantifort
assign mem_read_data_c          = sel_cache             ? cache_read_data :
133 35 csantifort
                                  uncached_data_access  ? wb_rdata32      :
134 16 csantifort
                                                          32'h76543210    ;
135 35 csantifort
 
136 16 csantifort
assign mem_load_rd_c            = {i_daddress[1:0], i_exec_load_rd};
137
assign mem_read_data_valid_c    = i_daddress_valid && !i_write_enable && !o_mem_stall;
138
 
139
assign o_mem_stall              = uncached_wb_wait || cache_stall;
140
 
141
// Request wishbone access
142 35 csantifort
assign o_wb_byte_enable         = i_daddress[3:2] == 2'd0 ? {12'd0, i_byte_enable       } :
143
                                  i_daddress[3:2] == 2'd1 ? { 8'd0, i_byte_enable,  4'd0} :
144
                                  i_daddress[3:2] == 2'd2 ? { 4'd0, i_byte_enable,  8'd0} :
145
                                                            {       i_byte_enable, 12'd0} ;
146
 
147 16 csantifort
assign o_wb_write               = i_write_enable;
148
assign o_wb_address             = {i_daddress[31:2], 2'd0};
149 35 csantifort
assign o_wb_write_data          = {4{i_write_data}};
150 16 csantifort
assign o_wb_cached_req          = !cached_wb_stop_r && cached_wb_req;
151
assign o_wb_uncached_req        = !uncached_wb_stop_r && uncached_data_access_p;
152
 
153
assign uncached_wb_wait         = (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
154
 
155
always @( posedge i_clk )
156
    begin
157
    uncached_wb_req_r <=  (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
158
    end
159
 
160
assign fetch_only_stall     = i_fetch_stall && !o_mem_stall;
161
 
162
always @( posedge i_clk )
163
    fetch_only_stall_r <= fetch_only_stall;
164
 
165
assign void_output = (fetch_only_stall_r && fetch_only_stall) || (fetch_only_stall_r && mem_read_data_valid_r);
166
 
167
 
168
// pulse this signal
169
assign daddress_valid_p = i_daddress_valid && !daddress_valid_stop_r;
170
 
171
always @( posedge i_clk )
172
    begin
173
    uncached_wb_stop_r      <= (uncached_wb_stop_r || uncached_data_access_p) && (i_fetch_stall || o_mem_stall);
174
    cached_wb_stop_r        <= (cached_wb_stop_r   || cached_wb_req)          && (i_fetch_stall || o_mem_stall);
175
    daddress_valid_stop_r   <= (daddress_valid_stop_r || daddress_valid_p)    && (i_fetch_stall || o_mem_stall);
176
    // hold this until the mem access completes
177
    mem_stall_r <= o_mem_stall;
178
    end
179
 
180
 
181
assign wb_stop = uncached_wb_stop_r || cached_wb_stop_r;
182
 
183
always @( posedge i_clk )
184
    if ( !wb_stop || o_mem_stall )
185
        begin
186
        mem_read_data_r         <= mem_read_data_c;
187
        mem_load_rd_r           <= mem_load_rd_c;
188
        mem_read_data_valid_r   <= mem_read_data_valid_c;
189
        end
190
 
191
 
192
// ======================================
193
// L1 Data Cache
194
// ======================================
195
a25_dcache u_dcache (
196
    .i_clk                      ( i_clk                 ),
197
    .i_fetch_stall              ( i_fetch_stall         ),
198 35 csantifort
    .i_exec_stall               ( i_exec_stall          ),
199 16 csantifort
    .o_stall                    ( cache_stall           ),
200
 
201
    .i_request                  ( sel_cache_p           ),
202
    .i_exclusive                ( i_exclusive           ),
203
    .i_write_data               ( i_write_data          ),
204
    .i_write_enable             ( i_write_enable        ),
205
    .i_address                  ( i_daddress            ),
206
    .i_address_nxt              ( i_daddress_nxt        ),
207
    .i_byte_enable              ( i_byte_enable         ),
208
 
209
    .i_cache_enable             ( i_cache_enable        ),
210
    .i_cache_flush              ( i_cache_flush         ),
211
    .o_read_data                ( cache_read_data       ),
212
 
213 35 csantifort
    .o_wb_cached_req            ( cached_wb_req         ),
214
    .i_wb_cached_rdata          ( i_wb_cached_rdata     ),
215
    .i_wb_cached_ready          ( i_wb_cached_ready     )
216 16 csantifort
);
217
 
218
 
219
 
220
endmodule
221
 

powered by: WebSVN 2.1.0

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