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

Subversion Repositories amber

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

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

powered by: WebSVN 2.1.0

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