Line 44... |
Line 44... |
|
|
module a25_mem
|
module a25_mem
|
(
|
(
|
input i_clk,
|
input i_clk,
|
input i_fetch_stall, // Fetch stage asserting stall
|
input i_fetch_stall, // Fetch stage asserting stall
|
|
input i_exec_stall, // Execute stage asserting stall
|
output o_mem_stall, // Mem stage asserting stall
|
output o_mem_stall, // Mem stage asserting stall
|
|
|
input [31:0] i_daddress,
|
input [31:0] i_daddress,
|
input i_daddress_valid,
|
input i_daddress_valid,
|
input [31:0] i_daddress_nxt, // un-registered version of address to the cache rams
|
input [31:0] i_daddress_nxt, // un-registered version of address to the cache rams
|
input [31:0] i_write_data,
|
input [31:0] i_write_data,
|
input i_write_enable,
|
input i_write_enable,
|
input i_exclusive, // high for read part of swap access
|
input i_exclusive, // high for read part of swap access
|
input [3:0] i_byte_enable,
|
input [3:0] i_byte_enable,
|
input [7:0] i_exec_load_rd, // The destination register for a load instruction
|
input [8:0] i_exec_load_rd, // The destination register for a load instruction
|
input i_cache_enable, // cache enable
|
input i_cache_enable, // cache enable
|
input i_cache_flush, // cache flush
|
input i_cache_flush, // cache flush
|
input [31:0] i_cacheable_area, // each bit corresponds to 2MB address space
|
input [31:0] i_cacheable_area, // each bit corresponds to 2MB address space
|
|
|
output [31:0] o_mem_read_data,
|
output [31:0] o_mem_read_data,
|
output o_mem_read_data_valid,
|
output o_mem_read_data_valid,
|
output [9:0] o_mem_load_rd, // The destination register for a load instruction
|
output [10:0] o_mem_load_rd, // The destination register for a load instruction
|
|
|
// Wishbone accesses
|
// Wishbone accesses
|
output o_wb_cached_req, // Cached Request
|
output o_wb_cached_req, // Cached Request
|
output o_wb_uncached_req, // Unached Request
|
output o_wb_uncached_req, // Unached Request
|
output o_wb_qword, // High for a quad-word read request
|
output o_wb_qword, // High for a quad-word read request
|
output o_wb_write, // Read=0, Write=1
|
output o_wb_write, // Read=0, Write=1
|
output [3:0] o_wb_byte_enable, // byte eable
|
output [15:0] o_wb_byte_enable, // byte eable
|
output [31:0] o_wb_write_data,
|
output [127:0] o_wb_write_data,
|
output [31:0] o_wb_address, // wb bus
|
output [31:0] o_wb_address, // wb bus
|
input [31:0] i_wb_read_data, // wb bus
|
input [127:0] i_wb_uncached_rdata, // wb bus
|
|
input [127:0] i_wb_cached_rdata, // wb bus
|
input i_wb_cached_ready, // wishbone access complete and read data valid
|
input i_wb_cached_ready, // wishbone access complete and read data valid
|
input i_wb_uncached_ready // wishbone access complete and read data valid
|
input i_wb_uncached_ready // wishbone access complete and read data valid
|
);
|
);
|
|
|
`include "memory_configuration.v"
|
`include "memory_configuration.v"
|
Line 92... |
Line 94... |
reg uncached_wb_stop_r = 'd0;
|
reg uncached_wb_stop_r = 'd0;
|
reg cached_wb_stop_r = 'd0;
|
reg cached_wb_stop_r = 'd0;
|
wire daddress_valid_p; // pulse
|
wire daddress_valid_p; // pulse
|
reg [31:0] mem_read_data_r = 'd0;
|
reg [31:0] mem_read_data_r = 'd0;
|
reg mem_read_data_valid_r = 'd0;
|
reg mem_read_data_valid_r = 'd0;
|
reg [9:0] mem_load_rd_r = 'd0;
|
reg [10:0] mem_load_rd_r = 'd0;
|
wire [9:0] mem_load_rd_c;
|
wire [10:0] mem_load_rd_c;
|
wire [31:0] mem_read_data_c;
|
wire [31:0] mem_read_data_c;
|
wire mem_read_data_valid_c;
|
wire mem_read_data_valid_c;
|
reg mem_stall_r = 'd0;
|
reg mem_stall_r = 'd0;
|
wire use_mem_reg;
|
wire use_mem_reg;
|
reg fetch_only_stall_r = 'd0;
|
reg fetch_only_stall_r = 'd0;
|
wire fetch_only_stall;
|
wire fetch_only_stall;
|
wire void_output;
|
wire void_output;
|
wire wb_stop;
|
wire wb_stop;
|
reg daddress_valid_stop_r = 'd0;
|
reg daddress_valid_stop_r = 'd0;
|
|
wire [31:0] wb_rdata32;
|
|
|
// ======================================
|
// ======================================
|
// Memory Decode
|
// Memory Decode
|
// ======================================
|
// ======================================
|
assign address_cachable = in_cachable_mem( i_daddress ) && i_cacheable_area[i_daddress[25:21]];
|
assign address_cachable = in_cachable_mem( i_daddress ) && i_cacheable_area[i_daddress[25:21]];
|
Line 121... |
Line 123... |
assign o_mem_load_rd = use_mem_reg ? mem_load_rd_r : mem_load_rd_c;
|
assign o_mem_load_rd = use_mem_reg ? mem_load_rd_r : mem_load_rd_c;
|
assign o_mem_read_data_valid = !void_output && (use_mem_reg ? mem_read_data_valid_r : mem_read_data_valid_c);
|
assign o_mem_read_data_valid = !void_output && (use_mem_reg ? mem_read_data_valid_r : mem_read_data_valid_c);
|
|
|
|
|
// Return read data either from the wishbone bus or the cache
|
// Return read data either from the wishbone bus or the cache
|
|
assign wb_rdata32 = i_daddress[3:2] == 2'd0 ? i_wb_uncached_rdata[ 31: 0] :
|
|
i_daddress[3:2] == 2'd1 ? i_wb_uncached_rdata[ 63:32] :
|
|
i_daddress[3:2] == 2'd2 ? i_wb_uncached_rdata[ 95:64] :
|
|
i_wb_uncached_rdata[127:96] ;
|
|
|
assign mem_read_data_c = sel_cache ? cache_read_data :
|
assign mem_read_data_c = sel_cache ? cache_read_data :
|
uncached_data_access ? i_wb_read_data :
|
uncached_data_access ? wb_rdata32 :
|
32'h76543210 ;
|
32'h76543210 ;
|
|
|
assign mem_load_rd_c = {i_daddress[1:0], i_exec_load_rd};
|
assign mem_load_rd_c = {i_daddress[1:0], i_exec_load_rd};
|
assign mem_read_data_valid_c = i_daddress_valid && !i_write_enable && !o_mem_stall;
|
assign mem_read_data_valid_c = i_daddress_valid && !i_write_enable && !o_mem_stall;
|
|
|
assign o_mem_stall = uncached_wb_wait || cache_stall;
|
assign o_mem_stall = uncached_wb_wait || cache_stall;
|
|
|
// Request wishbone access
|
// Request wishbone access
|
assign o_wb_byte_enable = i_byte_enable;
|
assign o_wb_byte_enable = i_daddress[3:2] == 2'd0 ? {12'd0, i_byte_enable } :
|
|
i_daddress[3:2] == 2'd1 ? { 8'd0, i_byte_enable, 4'd0} :
|
|
i_daddress[3:2] == 2'd2 ? { 4'd0, i_byte_enable, 8'd0} :
|
|
{ i_byte_enable, 12'd0} ;
|
|
|
assign o_wb_write = i_write_enable;
|
assign o_wb_write = i_write_enable;
|
assign o_wb_address = {i_daddress[31:2], 2'd0};
|
assign o_wb_address = {i_daddress[31:2], 2'd0};
|
assign o_wb_write_data = i_write_data;
|
assign o_wb_write_data = {4{i_write_data}};
|
assign o_wb_cached_req = !cached_wb_stop_r && cached_wb_req;
|
assign o_wb_cached_req = !cached_wb_stop_r && cached_wb_req;
|
assign o_wb_uncached_req = !uncached_wb_stop_r && uncached_data_access_p;
|
assign o_wb_uncached_req = !uncached_wb_stop_r && uncached_data_access_p;
|
assign o_wb_qword = !cached_wb_stop_r && cached_wb_req && !i_write_enable;
|
assign o_wb_qword = !cached_wb_stop_r && cached_wb_req && !i_write_enable;
|
|
|
assign uncached_wb_wait = (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
|
assign uncached_wb_wait = (o_wb_uncached_req || uncached_wb_req_r) && !i_wb_uncached_ready;
|
Line 183... |
Line 195... |
// L1 Data Cache
|
// L1 Data Cache
|
// ======================================
|
// ======================================
|
a25_dcache u_dcache (
|
a25_dcache u_dcache (
|
.i_clk ( i_clk ),
|
.i_clk ( i_clk ),
|
.i_fetch_stall ( i_fetch_stall ),
|
.i_fetch_stall ( i_fetch_stall ),
|
|
.i_exec_stall ( i_exec_stall ),
|
.o_stall ( cache_stall ),
|
.o_stall ( cache_stall ),
|
|
|
.i_request ( sel_cache_p ),
|
.i_request ( sel_cache_p ),
|
.i_exclusive ( i_exclusive ),
|
.i_exclusive ( i_exclusive ),
|
.i_write_data ( i_write_data ),
|
.i_write_data ( i_write_data ),
|
Line 197... |
Line 210... |
|
|
.i_cache_enable ( i_cache_enable ),
|
.i_cache_enable ( i_cache_enable ),
|
.i_cache_flush ( i_cache_flush ),
|
.i_cache_flush ( i_cache_flush ),
|
.o_read_data ( cache_read_data ),
|
.o_read_data ( cache_read_data ),
|
|
|
.o_wb_req ( cached_wb_req ),
|
.o_wb_cached_req ( cached_wb_req ),
|
.i_wb_read_data ( i_wb_read_data ),
|
.i_wb_cached_rdata ( i_wb_cached_rdata ),
|
.i_wb_ready ( i_wb_cached_ready )
|
.i_wb_cached_ready ( i_wb_cached_ready )
|
);
|
);
|
|
|
|
|
|
|
endmodule
|
endmodule
|