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 |
|
|
module fetch(
|
30 |
|
|
input clk,
|
31 |
|
|
input rst_n,
|
32 |
|
|
|
33 |
|
|
input pr_reset,
|
34 |
|
|
|
35 |
|
|
// get prefetch_eip
|
36 |
|
|
input [31:0] wr_eip,
|
37 |
|
|
|
38 |
|
|
output [31:0] prefetch_eip,
|
39 |
|
|
|
40 |
|
|
// prefetch_fifo
|
41 |
|
|
output prefetchfifo_accept_do,
|
42 |
|
|
input [67:0] prefetchfifo_accept_data,
|
43 |
|
|
input prefetchfifo_accept_empty,
|
44 |
|
|
|
45 |
|
|
// fetch interface to decode
|
46 |
|
|
output [3:0] fetch_valid,
|
47 |
|
|
output [63:0] fetch,
|
48 |
|
|
output fetch_limit,
|
49 |
|
|
output fetch_page_fault,
|
50 |
|
|
|
51 |
|
|
// feedback from decode
|
52 |
|
|
input [3:0] dec_acceptable
|
53 |
|
|
);
|
54 |
|
|
|
55 |
|
|
//------------------------------------------------------------------------------
|
56 |
|
|
|
57 |
|
|
wire partial;
|
58 |
|
|
|
59 |
|
|
//------------------------------------------------------------------------------
|
60 |
|
|
|
61 |
|
|
assign prefetch_eip = wr_eip;
|
62 |
|
|
|
63 |
|
|
//------------------------------------------------------------------------------
|
64 |
|
|
|
65 |
|
|
assign fetch_valid = (prefetchfifo_accept_empty || prefetchfifo_accept_data[67:64] >= `PREFETCH_MIN_FAULT)? 4'd0 : prefetchfifo_accept_data[67:64] - fetch_count;
|
66 |
|
|
|
67 |
|
|
assign fetch_limit = prefetchfifo_accept_empty == `FALSE && prefetchfifo_accept_data[67:64] == `PREFETCH_GP_FAULT;
|
68 |
|
|
assign fetch_page_fault = prefetchfifo_accept_empty == `FALSE && prefetchfifo_accept_data[67:64] == `PREFETCH_PF_FAULT;
|
69 |
|
|
|
70 |
|
|
assign fetch =
|
71 |
|
|
(prefetchfifo_accept_empty)? 64'd0 :
|
72 |
|
|
(fetch_count == 4'd0)? prefetchfifo_accept_data[63:0] :
|
73 |
|
|
(fetch_count == 4'd1)? { 8'd0, prefetchfifo_accept_data[63:8] } :
|
74 |
|
|
(fetch_count == 4'd2)? { 16'd0, prefetchfifo_accept_data[63:16] } :
|
75 |
|
|
(fetch_count == 4'd3)? { 24'd0, prefetchfifo_accept_data[63:24] } :
|
76 |
|
|
(fetch_count == 4'd4)? { 32'd0, prefetchfifo_accept_data[63:32] } :
|
77 |
|
|
(fetch_count == 4'd5)? { 40'd0, prefetchfifo_accept_data[63:40] } :
|
78 |
|
|
(fetch_count == 4'd6)? { 48'd0, prefetchfifo_accept_data[63:48] } :
|
79 |
|
|
{ 56'd0, prefetchfifo_accept_data[63:56] };
|
80 |
|
|
|
81 |
|
|
//------------------------------------------------------------------------------
|
82 |
|
|
|
83 |
|
|
assign prefetchfifo_accept_do = dec_acceptable >= fetch_valid && prefetchfifo_accept_empty == `FALSE && prefetchfifo_accept_data[67:64] < `PREFETCH_MIN_FAULT;
|
84 |
|
|
|
85 |
|
|
assign partial = dec_acceptable < fetch_valid && prefetchfifo_accept_empty == `FALSE && prefetchfifo_accept_data[67:64] < `PREFETCH_MIN_FAULT;
|
86 |
|
|
|
87 |
|
|
//------------------------------------------------------------------------------
|
88 |
|
|
|
89 |
|
|
reg [3:0] fetch_count;
|
90 |
|
|
always @(posedge clk or negedge rst_n) begin
|
91 |
|
|
if(rst_n == 1'b0) fetch_count <= 4'd0;
|
92 |
|
|
else if(pr_reset) fetch_count <= 4'd0;
|
93 |
|
|
else if(prefetchfifo_accept_do) fetch_count <= 4'd0;
|
94 |
|
|
else if(partial) fetch_count <= fetch_count + dec_acceptable;
|
95 |
|
|
end
|
96 |
|
|
|
97 |
|
|
//------------------------------------------------------------------------------
|
98 |
|
|
|
99 |
|
|
//------------------------------------------------------------------------------
|
100 |
|
|
|
101 |
|
|
//------------------------------------------------------------------------------
|
102 |
|
|
|
103 |
|
|
endmodule
|