1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright (c) 2014, Aleksander Osman
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
9 |
|
|
* list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
`include "defines.v"
|
28 |
|
|
|
29 |
|
|
//PARSED_COMMENTS: this file contains parsed script comments
|
30 |
|
|
|
31 |
|
|
module icache_control_ram(
|
32 |
|
|
input clk,
|
33 |
|
|
input rst_n,
|
34 |
|
|
|
35 |
|
|
input [31:0] address,
|
36 |
|
|
|
37 |
|
|
//RESP:
|
38 |
|
|
input read_do,
|
39 |
|
|
output [6:0] q,
|
40 |
|
|
//END
|
41 |
|
|
|
42 |
|
|
//RESP:
|
43 |
|
|
input write_do,
|
44 |
|
|
input [6:0] data,
|
45 |
|
|
//END
|
46 |
|
|
|
47 |
|
|
//RESP:
|
48 |
|
|
input invdcode_do,
|
49 |
|
|
output invdcode_done
|
50 |
|
|
//END
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
//------------------------------------------------------------------------------
|
54 |
|
|
|
55 |
|
|
reg [7:0] last_address;
|
56 |
|
|
reg after_invalidate;
|
57 |
|
|
reg state;
|
58 |
|
|
reg init_done;
|
59 |
|
|
reg [7:0] invd_counter;
|
60 |
|
|
|
61 |
|
|
//------------------------------------------------------------------------------
|
62 |
|
|
|
63 |
|
|
wire [6:0] ram_q_a;
|
64 |
|
|
|
65 |
|
|
//------------------------------------------------------------------------------
|
66 |
|
|
|
67 |
|
|
localparam STATE_IDLE = 1'd0;
|
68 |
|
|
localparam STATE_INVD = 1'd1;
|
69 |
|
|
|
70 |
|
|
//------------------------------------------------------------------------------
|
71 |
|
|
|
72 |
|
|
assign q = (~(init_done) || state == STATE_INVD || after_invalidate)? 7'd0 : ram_q_a;
|
73 |
|
|
|
74 |
|
|
//------------------------------------------------------------------------------
|
75 |
|
|
|
76 |
|
|
always @(posedge clk or negedge rst_n) begin
|
77 |
|
|
if(rst_n == 1'b0) last_address <= 8'd0;
|
78 |
|
|
else if(read_do) last_address <= address[11:4];
|
79 |
|
|
end
|
80 |
|
|
|
81 |
|
|
//------------------------------------------------------------------------------
|
82 |
|
|
|
83 |
|
|
// port a: q - 7 bits; {3 pLRU, 4 msi}; msi: 0 - invalid; 1 - valid
|
84 |
|
|
|
85 |
|
|
simple_ram #(
|
86 |
|
|
.width (7),
|
87 |
|
|
.widthad (8)
|
88 |
|
|
)
|
89 |
|
|
icache_control_ram_inst(
|
90 |
|
|
.clk (clk), //input
|
91 |
|
|
|
92 |
|
|
.wraddress ((~(init_done) || state == STATE_INVD)? invd_counter : address[11:4]), //input [7:0]
|
93 |
|
|
.wren ((~(init_done) || state == STATE_INVD) || (init_done && state == STATE_IDLE && write_do)), //input
|
94 |
|
|
.data ((~(init_done) || state == STATE_INVD)? 7'd0 : data), //input [6:0]
|
95 |
|
|
|
96 |
|
|
.rdaddress ((read_do)? address[11:4] : last_address), //input [7:0]
|
97 |
|
|
.q (ram_q_a) //output [6:0]
|
98 |
|
|
);
|
99 |
|
|
|
100 |
|
|
//------------------------------------------------------------------------------
|
101 |
|
|
|
102 |
|
|
//------------------------------------------------------------------------------
|
103 |
|
|
|
104 |
|
|
// synthesis translate_off
|
105 |
|
|
wire _unused_ok = &{ 1'b0, address[31:12], address[3:0], 1'b0 };
|
106 |
|
|
// synthesis translate_on
|
107 |
|
|
|
108 |
|
|
//------------------------------------------------------------------------------
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
/*******************************************************************************SCRIPT
|
112 |
|
|
|
113 |
|
|
IF(init_done == `FALSE);
|
114 |
|
|
|
115 |
|
|
SAVE(invd_counter, invd_counter + 8'd1);
|
116 |
|
|
|
117 |
|
|
IF(invd_counter == 8'd255);
|
118 |
|
|
SAVE(after_invalidate, `TRUE);
|
119 |
|
|
SAVE(init_done, `TRUE);
|
120 |
|
|
ENDIF();
|
121 |
|
|
ENDIF();
|
122 |
|
|
*/
|
123 |
|
|
|
124 |
|
|
/*******************************************************************************SCRIPT
|
125 |
|
|
|
126 |
|
|
IF(state == STATE_IDLE);
|
127 |
|
|
SAVE(after_invalidate, `FALSE);
|
128 |
|
|
|
129 |
|
|
IF(init_done && invdcode_do);
|
130 |
|
|
SAVE(state, STATE_INVD);
|
131 |
|
|
ENDIF();
|
132 |
|
|
|
133 |
|
|
ENDIF();
|
134 |
|
|
*/
|
135 |
|
|
|
136 |
|
|
/*******************************************************************************SCRIPT
|
137 |
|
|
|
138 |
|
|
IF(state == STATE_INVD);
|
139 |
|
|
SAVE(invd_counter, invd_counter + 8'd1);
|
140 |
|
|
|
141 |
|
|
IF(invd_counter == 8'd255);
|
142 |
|
|
SET(invdcode_done);
|
143 |
|
|
|
144 |
|
|
SAVE(after_invalidate, `TRUE);
|
145 |
|
|
SAVE(state, STATE_IDLE);
|
146 |
|
|
ENDIF();
|
147 |
|
|
ENDIF();
|
148 |
|
|
*/
|
149 |
|
|
|
150 |
|
|
//------------------------------------------------------------------------------
|
151 |
|
|
|
152 |
|
|
`include "autogen/icache_control_ram.v"
|
153 |
|
|
|
154 |
|
|
endmodule
|