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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [core/] [prefetch.v] - Blame information for rev 201

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 36 dgisselq
//      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 2 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
23 69 dgisselq
//              Gisselquist Technology, LLC
24 2 dgisselq
//
25
////////////////////////////////////////////////////////////////////////////////
26
//
27 201 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 201 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 201 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 69 dgisselq
module  prefetch(i_clk, i_rst, i_ce, i_stalled_n, i_pc, i_aux,
57 36 dgisselq
                        o_i, o_pc, o_aux, o_valid, o_illegal,
58 2 dgisselq
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
59 36 dgisselq
                        i_wb_ack, i_wb_stall, i_wb_err, i_wb_data);
60 48 dgisselq
        parameter               ADDRESS_WIDTH=32, AUX_WIDTH = 1, AW=ADDRESS_WIDTH;
61 69 dgisselq
        input                           i_clk, i_rst, i_ce, i_stalled_n;
62 48 dgisselq
        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 69 dgisselq
        output  reg                     o_valid, o_illegal;
68 2 dgisselq
        // Wishbone outputs
69 48 dgisselq
        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 2 dgisselq
        // And return inputs
74 36 dgisselq
        input                   i_wb_ack, i_wb_stall, i_wb_err;
75 2 dgisselq
        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 63 dgisselq
                if ((i_rst)||(i_wb_ack))
88 2 dgisselq
                begin
89
                        o_wb_cyc <= 1'b0;
90 63 dgisselq
                        o_wb_stb <= 1'b0;
91 2 dgisselq
                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 63 dgisselq
                if (i_rst) // Set the address to guarantee the result is invalid
105 69 dgisselq
                        o_wb_addr <= {(AW){1'b1}};
106 63 dgisselq
                else if ((i_ce)&&(~o_wb_cyc))
107
                        o_wb_addr <= i_pc;
108
        always @(posedge i_clk)
109 2 dgisselq
                if ((o_wb_cyc)&&(i_wb_ack))
110 63 dgisselq
                        o_aux <= i_aux;
111
        always @(posedge i_clk)
112
                if ((o_wb_cyc)&&(i_wb_ack))
113 2 dgisselq
                        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 69 dgisselq
        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 201 dgisselq
                        o_illegal <= (i_wb_err)&&(i_pc == o_wb_addr);
124 69 dgisselq
                end else if (i_stalled_n)
125
                begin
126
                        o_valid <= 1'b0;
127
                        o_illegal <= 1'b0;
128
                end
129 2 dgisselq
 
130
endmodule

powered by: WebSVN 2.1.0

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