Revision 6,
3.8 KB
checked in by pntsvt00, 14 years ago
(diff) |
versione iniziale opensparc
|
Rev | Line | |
---|
[6] | 1 | module l1idir( |
---|
| 2 | input clk, |
---|
| 3 | input reset, |
---|
| 4 | |
---|
| 5 | input [ 6:0] index, |
---|
| 6 | input [ 1:0] way, |
---|
| 7 | input [27:0] tag, |
---|
| 8 | input strobe, |
---|
| 9 | input query, |
---|
| 10 | input allocate, //tag->{way,index} |
---|
| 11 | input deallocate, //if({way,index}==tag) {way,index}<-FFFFFF |
---|
| 12 | input invalidate, //all ways |
---|
| 13 | |
---|
| 14 | output reg [2:0] hit, |
---|
| 15 | |
---|
| 16 | output reg ready // directory init completed |
---|
| 17 | ); |
---|
| 18 | |
---|
| 19 | `define INVAL_TAG 28'h8000000 |
---|
| 20 | |
---|
| 21 | reg [27:0] tag_d; |
---|
| 22 | reg [ 6:0] addr; |
---|
| 23 | reg [ 3:0] we; |
---|
| 24 | reg [ 3:0] re; |
---|
| 25 | reg [28:0] di; |
---|
| 26 | |
---|
| 27 | wire [28:0] do0; |
---|
| 28 | wire [28:0] do1; |
---|
| 29 | wire [28:0] do2; |
---|
| 30 | wire [28:0] do3; |
---|
| 31 | reg query_d; |
---|
| 32 | reg deallocate_d; |
---|
| 33 | reg query_d1; |
---|
| 34 | reg deallocate_d1; |
---|
| 35 | |
---|
| 36 | always @(posedge clk) |
---|
| 37 | if(strobe) |
---|
| 38 | if(query || deallocate) |
---|
| 39 | begin |
---|
| 40 | tag_d<=tag; |
---|
| 41 | end |
---|
| 42 | |
---|
| 43 | always @(posedge clk) |
---|
| 44 | begin |
---|
| 45 | query_d<=query && strobe; |
---|
| 46 | deallocate_d<=deallocate && strobe; |
---|
| 47 | query_d1<=query_d; |
---|
| 48 | deallocate_d1<=deallocate_d; |
---|
| 49 | end |
---|
| 50 | |
---|
| 51 | cachedir icache01 ( |
---|
| 52 | .clock(clk), |
---|
| 53 | .enable(we[0] || re[0] || we[1] || re[1]), |
---|
| 54 | .wren_a(we[0]), |
---|
| 55 | .address_a({1'b0,addr}), |
---|
| 56 | .data_a(di), |
---|
| 57 | .q_a(do0), |
---|
| 58 | |
---|
| 59 | .wren_b(we[1]), |
---|
| 60 | .address_b({1'b1,addr}), |
---|
| 61 | .data_b(di), |
---|
| 62 | .q_b(do1) |
---|
| 63 | ); |
---|
| 64 | |
---|
| 65 | cachedir icache23 ( |
---|
| 66 | .clock(clk), |
---|
| 67 | .enable(we[2] || re[2] || we[3] || re[3]), |
---|
| 68 | .wren_a(we[2]), |
---|
| 69 | .address_a({1'b0,addr}), |
---|
| 70 | .data_a(di), |
---|
| 71 | .q_a(do2), |
---|
| 72 | |
---|
| 73 | .wren_b(we[3]), |
---|
| 74 | .address_b({1'b1,addr}), |
---|
| 75 | .data_b(di), |
---|
| 76 | .q_b(do3) |
---|
| 77 | ); |
---|
| 78 | |
---|
| 79 | wire [3:0] hitvect={(do3[28:1]==tag_d),(do2[28:1]==tag_d),(do1[28:1]==tag_d),(do0[28:1]==tag_d)}; |
---|
| 80 | |
---|
| 81 | `define L1IDIR_RESET 3'b000 |
---|
| 82 | `define L1IDIR_INIT 3'b001 |
---|
| 83 | `define L1IDIR_IDLE 3'b010 |
---|
| 84 | `define L1IDIR_READ 3'b011 |
---|
| 85 | `define L1IDIR_DEALLOC 3'b100 |
---|
| 86 | |
---|
| 87 | reg [2:0] state; |
---|
| 88 | |
---|
| 89 | always @(posedge clk or posedge reset) |
---|
| 90 | if(reset) |
---|
| 91 | begin |
---|
| 92 | state<=`L1IDIR_RESET; |
---|
| 93 | ready<=0; |
---|
| 94 | end |
---|
| 95 | else |
---|
| 96 | case(state) |
---|
| 97 | `L1IDIR_RESET: |
---|
| 98 | begin |
---|
| 99 | addr<=7'b0; |
---|
| 100 | di<={`INVAL_TAG,1'b0}; |
---|
| 101 | we<=4'b1111; |
---|
| 102 | state<=`L1IDIR_INIT; |
---|
| 103 | end |
---|
| 104 | `L1IDIR_INIT: |
---|
| 105 | begin |
---|
| 106 | addr<=addr+1; |
---|
| 107 | if(addr==7'b1111111) |
---|
| 108 | begin |
---|
| 109 | we<=4'b0; |
---|
| 110 | ready<=1; |
---|
| 111 | state<=`L1IDIR_IDLE; |
---|
| 112 | end |
---|
| 113 | end |
---|
| 114 | `L1IDIR_IDLE: |
---|
| 115 | if(strobe) |
---|
| 116 | if(invalidate) |
---|
| 117 | begin |
---|
| 118 | we<=4'b1111; |
---|
| 119 | addr<=index; |
---|
| 120 | di<={`INVAL_TAG,1'b0}; |
---|
| 121 | end |
---|
| 122 | else |
---|
| 123 | if(allocate) |
---|
| 124 | begin |
---|
| 125 | case(way) |
---|
| 126 | 2'b00:we<=4'b0001; |
---|
| 127 | 2'b01:we<=4'b0010; |
---|
| 128 | 2'b10:we<=4'b0100; |
---|
| 129 | 2'b11:we<=4'b1000; |
---|
| 130 | endcase |
---|
| 131 | addr<=index; |
---|
| 132 | di<={tag,1'b0}; |
---|
| 133 | end |
---|
| 134 | else |
---|
| 135 | if(deallocate) |
---|
| 136 | begin |
---|
| 137 | re<=4'b1111; |
---|
| 138 | we<=0; |
---|
| 139 | addr<=index; |
---|
| 140 | state<=`L1IDIR_READ; |
---|
| 141 | end |
---|
| 142 | else |
---|
| 143 | if(query) |
---|
| 144 | begin |
---|
| 145 | addr<=index; |
---|
| 146 | re<=4'b1111; |
---|
| 147 | we<=0; |
---|
| 148 | end |
---|
| 149 | else |
---|
| 150 | begin |
---|
| 151 | we<=0; |
---|
| 152 | re<=0; |
---|
| 153 | end |
---|
| 154 | `L1IDIR_READ: |
---|
| 155 | state<=`L1IDIR_DEALLOC; |
---|
| 156 | `L1IDIR_DEALLOC: |
---|
| 157 | begin |
---|
| 158 | re<=0; |
---|
| 159 | di<={`INVAL_TAG,1'b0}; |
---|
| 160 | we<=hitvect; |
---|
| 161 | state<=`L1IDIR_IDLE; |
---|
| 162 | end |
---|
| 163 | endcase |
---|
| 164 | |
---|
| 165 | always @(posedge clk) |
---|
| 166 | if(query_d1 || deallocate_d1) |
---|
| 167 | case(hitvect) |
---|
| 168 | 4'b0001:hit<=3'b100; |
---|
| 169 | 4'b0010:hit<=3'b101; |
---|
| 170 | 4'b0100:hit<=3'b110; |
---|
| 171 | 4'b1000:hit<=3'b111; |
---|
| 172 | default:hit<=3'b000; // Hits will be ORed then |
---|
| 173 | endcase |
---|
| 174 | else |
---|
| 175 | if(strobe) |
---|
| 176 | hit<=3'b000; |
---|
| 177 | |
---|
| 178 | endmodule |
---|
Note: See
TracBrowser
for help on using the repository browser.