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

Subversion Repositories rv01_riscv_core

[/] [rv01_riscv_core/] [trunk/] [VHDL/] [RV01_ftchlog_1w.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2017 Stefano Tonello                          --
6
--                                                             --
7
-- This source file may be used and distributed without        --
8
-- restriction provided that this copyright statement is not   --
9
-- removed from the file and that any derivative work contains --
10
-- the original copyright notice and the associated disclaimer.--
11
--                                                             --
12
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY         --
13
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   --
15
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      --
16
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         --
17
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    --
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   --
19
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        --
20
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  --
21
-- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  --
22
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  --
23
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         --
24
-- POSSIBILITY OF SUCH DAMAGE.                                 --
25
--                                                             --
26
-----------------------------------------------------------------
27
 
28
---------------------------------------------------------------
29
-- RV01 Instruction Fecthing Logic (scalar version)
30
---------------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
 
36
library work;
37
use work.RV01_CONSTS_PKG.all;
38
use work.RV01_TYPES_PKG.all;
39
use work.RV01_CSR_PKG.all;
40
 
41
entity RV01_FTCHLOG_1W is
42
  port(
43
    CLK_i : in std_logic;
44
    RST_i : in std_logic;
45
    STRT_i : in std_logic;
46
    STRTPC_i : in ADR_T;
47
    HALT_i : in std_logic;
48
    BJX_i : in std_logic;
49
    BJTA_i : in ADR_T;
50
    PBX_i : in std_logic;
51
    PBTA_i : in ADR_T;
52
    KLL1_i : in std_logic;
53
    PJRX_i : std_logic;
54
    PJRTA_i : in ADR_T;
55
    EXCP_i : in std_logic;
56
    ERET_i : in std_logic;
57
    RFTCH_i : in std_logic;
58
    ETVA_i : in ADR_T;
59
    PSTALL_i : in std_logic;
60
    -- Debug interface
61
    DHALT_i : in std_logic;
62
 
63
    IFV_o : out std_logic;
64
    IADR0_o : out ADR_T;
65
    IADR_MIS_o : out std_logic
66
  );
67
end RV01_FTCHLOG_1W;
68
 
69
architecture ARC of RV01_FTCHLOG_1W is
70
 
71
  signal PC,PC_q : unsigned(ALEN-3 downto 0);
72
  signal PC_NS : unsigned(ALEN-3 downto 0);
73
  signal PCP4,PCP4_q : unsigned(ALEN-3 downto 0);
74
  signal HALT_q : std_logic;
75
  signal FC : std_logic;
76
  signal PC_NS_FC : unsigned(ALEN-3 downto 0);
77
 
78
begin
79
 
80
  -- Halt flag register
81
  process(CLK_i)
82
  begin
83
    if(CLK_i = '1' and CLK_i'event) then
84
      if(RST_i = '1' or HALT_i = '1') then
85
        HALT_q <= '1';
86
      elsif(STRT_i = '1') then
87
        HALT_q <= '0';
88
      end if;
89
    end if;
90
  end process;
91
 
92
  -- Instructions are always fetched from a word address, so
93
  -- that PC LS 2 bits are guaranteed to be zero and are 
94
  -- therefore not physically implemented.
95
 
96
  -- Fetched instruction #0 is always valid, unless processor is
97
  -- halted or fetch address is odd.
98
 
99
  IFV_o <= not(HALT_q) or STRT_i;
100
 
101
  -- PC register reset value is set to reset exception vector
102
  -- "low" address.
103
 
104
  -- PC register is incremented only if pipeline is not
105
  -- stalled (i.e. when PSTALL_i = '0').
106
 
107
  -- PC+4 value is pre-calculated in current cycle and stored
108
  -- into PCP4 to remove addition from address critical path.
109
 
110
  -- Program Counter register
111
  process(CLK_i)
112
  begin
113
    if(CLK_i = '1' and CLK_i'event) then
114
      if(RST_i = '1') then
115
        PC_q <= to_unsigned(0,SDLEN-2);
116
        PCP4_q <= to_unsigned(1,SDLEN-2);
117
      elsif((HALT_q = '0') or (STRT_i = '1')) then
118
        PC_q <= PC;
119
        PCP4_q <= PCP4;
120
      end if;
121
    end if;
122
  end process;
123
 
124
  -- PC plus 4
125
  PCP4 <= PC_NS + 1 when (
126
    PSTALL_i = '0' or
127
    EXCP_i = '1' or
128
    ERET_i = '1' or
129
    RFTCH_i = '1'
130
  ) else PCP4_q;
131
 
132
  -- Flow change flag (non sequential fetch)
133
  FC <= EXCP_i or ERET_i or RFTCH_i or BJX_i;
134
 
135
  -- PC no-stall value
136
  process(PBX_i,PJRX_i,FC,PC_NS_FC,PBTA_i,PJRTA_i,PSTALL_i,PC_q,KLL1_i)
137
  begin
138
    if(PBX_i = '1' and FC = '0' and PSTALL_i = '0' and KLL1_i = '0') then
139
      PC_NS <= PBTA_i(ALEN-1 downto 2);
140
    elsif(PJRX_i = '1' and FC = '0' and PSTALL_i = '0') then
141
      PC_NS <= PJRTA_i(ALEN-1 downto 2);
142
    elsif(FC = '1' or PSTALL_i = '0') then
143
      PC_NS <= PC_NS_FC;
144
    else
145
      PC_NS <= PC_q;
146
    end if;
147
  end process;
148
 
149
  -- Current cycle PC value mux
150
 
151
  -- ETVA_i can be true exception vector, an address from CSR MEPC,
152
  -- a re-fetch address, debug memory address or a resume address.
153
  -- STRTPC_i can be the reset vector or an address from CSR MRV01HA.
154
 
155
  process(STRT_i,EXCP_i,ERET_i,RFTCH_i,ETVA_i,BJX_i,BJTA_i,
156
    PCP4_q,DHALT_i,STRTPC_i)
157
  begin
158
    if(
159
      BJX_i = '1' and
160
      (EXCP_i = '0' and ERET_i = '0' and RFTCH_i = '0' and DHALT_i = '0')
161
    ) then
162
      -- Note: the complicated if-condition allows to remove one
163
      -- muxing level on BJTA_i path.
164
      PC_NS_FC <= BJTA_i(ALEN-1 downto 2);
165
    elsif(
166
      EXCP_i = '1' or ERET_i = '1' or RFTCH_i = '1' or DHALT_i = '1'
167
    ) then
168
      PC_NS_FC <= ETVA_i(ALEN-1 downto 2);
169
    elsif(STRT_i = '1') then
170
      PC_NS_FC <= STRTPC_i(ALEN-1 downto 2);
171
    else
172
      PC_NS_FC <= PCP4_q;
173
    end if;
174
  end process;
175
 
176
  -- Current cycle PC
177
  PC <= PC_NS;
178
 
179
  -- Fetch address
180
  IADR0_o <= PC & "00";
181
 
182
  -- A misaligned instruction address can be generated only
183
  -- by a B/J instruction.
184
 
185
  process(BJX_i,PBX_i,PJRX_i,BJTA_i,PJRTA_i,PBTA_i)
186
  begin
187
    IADR_MIS_o <= '0';
188
    if(BJX_i = '1' and BJTA_i(1 downto 0) /= "00") then
189
      IADR_MIS_o <= '1';
190
    elsif(PBX_i = '1' and PBTA_i(1 downto 0) /= "00" and KLL1_i = '0') then
191
      IADR_MIS_o <= '1';
192
    elsif(PJRX_i = '1' and PJRTA_i(1 downto 0) /= "00") then
193
      IADR_MIS_o <= '1';
194
    end if;
195
  end process;
196
 
197
end ARC;

powered by: WebSVN 2.1.0

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