]> Joshua Wise's Git repositories - firearm.git/blame - ICache.v
Add chip enable correctness for CellularRAM.
[firearm.git] / ICache.v
CommitLineData
7e757d70
JW
1/* 16 cache entries, 64-byte long cache lines */
2
3module ICache(
4 input clk,
c808669d
JW
5
6 /* ARM core interface */
2bf779cf
JW
7 input [31:0] ic__rd_addr_0a,
8 input ic__rd_req_0a,
9 output wire ic__rd_wait_0a,
3c947a99 10 output wire [31:0] ic__rd_data_1a,
c808669d
JW
11
12 /* bus interface */
3c947a99
JW
13 output wire bus_req,
14 input bus_ack,
15 output reg [31:0] bus_addr,
16 input [31:0] bus_rdata,
cb1e103e 17 output wire [31:0] bus_wdata,
3c947a99
JW
18 output reg bus_rd,
19 output wire bus_wr,
20 input bus_ready);
c808669d
JW
21
22 assign bus_wr = 0;
cb1e103e 23 assign bus_wdata = 0;
7e757d70 24
2bf779cf
JW
25 wire [31:0] rd_addr_0a;
26 wire rd_req_0a;
27 reg rd_wait_0a;
3c947a99 28 reg [31:0] rd_data_1a;
2bf779cf 29 assign ic__rd_wait_0a = rd_wait_0a;
3c947a99 30 assign ic__rd_data_1a = rd_data_1a;
2bf779cf
JW
31 assign rd_addr_0a = ic__rd_addr_0a;
32 assign rd_req_0a = ic__rd_req_0a;
33
f83818d5 34 /* [31 tag 10] [9 cache index 6] [5 data index 0]
7e757d70
JW
35 * so the data index is 6 bits long
36 * so the cache index is 4 bits long
f83818d5 37 * so the tag is 22 bits long. c.c
7e757d70
JW
38 */
39
40 reg cache_valid [15:0];
f83818d5 41 reg [21:0] cache_tags [15:0];
ba1c1a27 42 reg [31:0] cache_data [255:0 /* {line, word} */]; //synthesis attribute ram_style of cache_data is block
7e757d70 43
4dc31744 44 integer i;
7e757d70 45 initial
cb1e103e 46 for (i = 0; i < 16; i = i + 1)
90ff449a 47 begin
cb1e103e 48 cache_valid[i[3:0]] = 0;
90ff449a
JW
49 cache_tags[i[3:0]] = 0;
50 end
7e757d70 51
3c947a99
JW
52 wire [5:0] rd_didx_0a = rd_addr_0a[5:0];
53 wire [3:0] rd_didx_word_0a = rd_didx_0a[5:2];
54 wire [3:0] rd_idx_0a = rd_addr_0a[9:6];
55 wire [21:0] rd_tag_0a = rd_addr_0a[31:10];
7e757d70 56
3c947a99 57 reg [31:0] rd_addr_1a = 32'hFFFFFFFF;
8b417b45 58
3c947a99 59 wire cache_hit_0a = cache_valid[rd_idx_0a] && (cache_tags[rd_idx_0a] == rd_tag_0a);
c808669d 60
3c947a99
JW
61 reg [3:0] cache_fill_pos_0a = 0;
62 assign bus_req = rd_req_0a && !cache_hit_0a; /* xxx, needed for Verilator */
28c904cc 63 always @(*)
3c947a99
JW
64 if (rd_req_0a && !cache_hit_0a && bus_ack) begin
65 bus_addr = {rd_addr_0a[31:6], cache_fill_pos_0a[3:0], 2'b00 /* reads are 32-bits */};
45fa96c0 66 bus_rd = 1;
327f45ff 67 end else begin
327f45ff
JW
68 bus_addr = 0;
69 bus_rd = 0;
70 end
2b5c79c0 71
2b5c79c0 72 always @(*) begin
3c947a99 73 rd_wait_0a = rd_req_0a && !cache_hit_0a;
2b5c79c0 74 end
327f45ff 75
8b417b45 76 always @(posedge clk) begin
3c947a99
JW
77 // Do the actual read.
78 rd_data_1a <= cache_data[{rd_idx_0a,rd_didx_word_0a}];
79
80 rd_addr_1a <= {rd_addr_0a[31:6], 6'b0};
81 if (cache_fill_pos_0a != 0 && ((rd_addr_1a != {rd_addr_0a[31:6], 6'b0}) || cache_hit_0a)) /* If this wasn't from the same line, or we've moved on somehow, reset the fill circuitry. */
82 cache_fill_pos_0a <= 0;
83 else if (rd_req_0a && !cache_hit_0a && bus_ack && bus_ready) begin
2bf779cf 84 $display("ICACHE: FILL: rd addr %08x; bus addr %08x; bus data %08x", rd_addr_0a, bus_addr, bus_rdata);
3c947a99
JW
85 cache_data[{rd_idx_0a,cache_fill_pos_0a}] <= bus_rdata;
86 cache_fill_pos_0a <= cache_fill_pos_0a + 1;
87 if (cache_fill_pos_0a == 15) begin /* Done? */
88 cache_tags[rd_idx_0a] <= rd_tag_0a;
89 cache_valid[rd_idx_0a] <= 1;
90 $display("ICACHE: Fill complete for line %x, tag %x", rd_idx_0a, rd_tag_0a);
2b5c79c0 91 end else
3c947a99 92 cache_valid[rd_idx_0a] <= 0;
c808669d 93 end
8b417b45 94 end
7e757d70 95endmodule
This page took 0.045798 seconds and 4 git commands to generate.