OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [cpu/] [prefetch.v] - Blame information for rev 46

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    prefetch.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     This is a very simple instruction fetch approach.  It gets
8
//              one instruction at a time.  Future versions should pipeline
9
//              fetches and perhaps even cache results--this doesn't do that.
10
//              It should, however, be simple enough to get things running.
11
//
12
//              The interface is fascinating.  The 'i_pc' input wire is just
13
//              a suggestion of what to load.  Other wires may be loaded
14
//              instead. i_pc is what must be output, not necessarily input.
15
//
16
//      20150919 -- Added support for the WB error signal.  When reading an
17
//              instruction results in this signal being raised, the pipefetch
18
//              module will set an illegal instruction flag to be returned to
19
//              the CPU together with the instruction.  Hence, the ZipCPU
20
//              can trap on it if necessary.
21
//
22
// Creator:     Dan Gisselquist, Ph.D.
23
//              Gisselquist Technology, LLC
24
//
25
////////////////////////////////////////////////////////////////////////////////
26
//
27 46 dgisselq
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
28 2 dgisselq
//
29
// This program is free software (firmware): you can redistribute it and/or
30
// modify it under the terms of  the GNU General Public License as published
31
// by the Free Software Foundation, either version 3 of the License, or (at
32
// your option) any later version.
33
//
34
// This program is distributed in the hope that it will be useful, but WITHOUT
35
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
36
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37
// for more details.
38
//
39 46 dgisselq
// You should have received a copy of the GNU General Public License along
40
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
41
// target there if the PDF file isn't present.)  If not, see
42
// <http://www.gnu.org/licenses/> for a copy.
43
//
44 2 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
45
//              http://www.gnu.org/licenses/gpl.html
46
//
47
//
48
////////////////////////////////////////////////////////////////////////////////
49
//
50 46 dgisselq
//
51 2 dgisselq
// Flash requires a minimum of 4 clocks per byte to read, so that would be
52
// 4*(4bytes/32bit word) = 16 clocks per word read---and that's in pipeline
53
// mode which this prefetch does not support.  In non--pipelined mode, the
54
// flash will require (16+6+6)*2 = 56 clocks plus 16 clocks per word read,
55
// or 72 clocks to fetch one instruction.
56
module  prefetch(i_clk, i_rst, i_ce, i_stalled_n, i_pc, i_aux,
57
                        o_i, o_pc, o_aux, o_valid, o_illegal,
58
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
59
                        i_wb_ack, i_wb_stall, i_wb_err, i_wb_data);
60
        parameter               ADDRESS_WIDTH=32, AUX_WIDTH = 1, AW=ADDRESS_WIDTH;
61
        input                           i_clk, i_rst, i_ce, i_stalled_n;
62
        input           [(AW-1):0]       i_pc;
63
        input   [(AUX_WIDTH-1):0]        i_aux;
64
        output  reg     [31:0]           o_i;
65
        output  reg     [(AW-1):0]       o_pc;
66
        output  reg [(AUX_WIDTH-1):0]    o_aux;
67
        output  reg                     o_valid, o_illegal;
68
        // Wishbone outputs
69
        output  reg                     o_wb_cyc, o_wb_stb;
70
        output  wire                    o_wb_we;
71
        output  reg     [(AW-1):0]       o_wb_addr;
72
        output  wire    [31:0]           o_wb_data;
73
        // And return inputs
74
        input                   i_wb_ack, i_wb_stall, i_wb_err;
75
        input           [31:0]   i_wb_data;
76
 
77
        assign  o_wb_we = 1'b0;
78
        assign  o_wb_data = 32'h0000;
79
 
80
        // Let's build it simple and upgrade later: For each instruction
81
        // we do one bus cycle to get the instruction.  Later we should
82
        // pipeline this, but for now let's just do one at a time.
83
        initial o_wb_cyc = 1'b0;
84
        initial o_wb_stb = 1'b0;
85
        initial o_wb_addr= 0;
86
        always @(posedge i_clk)
87
                if ((i_rst)||(i_wb_ack))
88
                begin
89
                        o_wb_cyc <= 1'b0;
90
                        o_wb_stb <= 1'b0;
91
                end else if ((i_ce)&&(~o_wb_cyc)) // Initiate a bus cycle
92
                begin
93
                        o_wb_cyc <= 1'b1;
94
                        o_wb_stb <= 1'b1;
95
                end else if (o_wb_cyc) // Independent of ce
96
                begin
97
                        if ((o_wb_cyc)&&(o_wb_stb)&&(~i_wb_stall))
98
                                o_wb_stb <= 1'b0;
99
                        if (i_wb_ack)
100
                                o_wb_cyc <= 1'b0;
101
                end
102
 
103
        always @(posedge i_clk)
104
                if (i_rst) // Set the address to guarantee the result is invalid
105
                        o_wb_addr <= {(AW){1'b1}};
106
                else if ((i_ce)&&(~o_wb_cyc))
107
                        o_wb_addr <= i_pc;
108
        always @(posedge i_clk)
109
                if ((o_wb_cyc)&&(i_wb_ack))
110
                        o_aux <= i_aux;
111
        always @(posedge i_clk)
112
                if ((o_wb_cyc)&&(i_wb_ack))
113
                        o_i <= i_wb_data;
114
        always @(posedge i_clk)
115
                if ((o_wb_cyc)&&(i_wb_ack))
116
                        o_pc <= o_wb_addr;
117
        initial o_valid   = 1'b0;
118
        initial o_illegal = 1'b0;
119
        always @(posedge i_clk)
120
                if ((o_wb_cyc)&&(i_wb_ack))
121
                begin
122
                        o_valid <= (i_pc == o_wb_addr)&&(~i_wb_err);
123 46 dgisselq
                        o_illegal <= (i_wb_err)&&(i_pc == o_wb_addr);
124 2 dgisselq
                end else if (i_stalled_n)
125
                begin
126
                        o_valid <= 1'b0;
127
                        o_illegal <= 1'b0;
128
                end
129
 
130
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.