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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [rtl/] [lxp32_fetch.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 ring0_mipt
---------------------------------------------------------------------
2
-- Instruction fetch
3
--
4
-- Part of the LXP32 CPU
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- The first stage of the LXP32 pipeline.
9
---------------------------------------------------------------------
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.numeric_std.all;
14
 
15
entity lxp32_fetch is
16
        generic(
17
                START_ADDR: std_logic_vector(29 downto 0)
18
        );
19
        port(
20
                clk_i: in std_logic;
21
                rst_i: in std_logic;
22
 
23
                lli_re_o: out std_logic;
24
                lli_adr_o: out std_logic_vector(29 downto 0);
25
                lli_dat_i: in std_logic_vector(31 downto 0);
26
                lli_busy_i: in std_logic;
27
 
28
                word_o: out std_logic_vector(31 downto 0);
29
                next_ip_o: out std_logic_vector(29 downto 0);
30
                valid_o: out std_logic;
31
                ready_i: in std_logic;
32
 
33
                jump_valid_i: in std_logic;
34
                jump_dst_i: in std_logic_vector(29 downto 0);
35
                jump_ready_o: out std_logic
36
        );
37
end entity;
38
 
39
architecture rtl of lxp32_fetch is
40
 
41
signal init: std_logic:='1';
42
signal init_cnt: unsigned(7 downto 0):=(others=>'0');
43
 
44
signal fetch_addr: std_logic_vector(29 downto 0):=START_ADDR;
45
 
46
signal next_word: std_logic;
47
signal suppress_re: std_logic:='0';
48
signal re: std_logic;
49
signal requested: std_logic:='0';
50
 
51
signal fifo_rst: std_logic;
52
signal fifo_we: std_logic;
53
signal fifo_din: std_logic_vector(61 downto 0);
54
signal fifo_re: std_logic;
55
signal fifo_dout: std_logic_vector(61 downto 0);
56
signal fifo_empty: std_logic;
57
signal fifo_full: std_logic;
58
 
59
signal jr: std_logic:='0';
60
 
61
begin
62
 
63
-- INIT state machine (to initialize all registers)
64
 
65
-- All CPU registers are expected to be zero-initialized after reset.
66
-- Since these registers are implemented as a RAM block, we perform
67
-- the initialization sequentially by generating "mov rN, 0" instructions
68
-- for each N from 0 to 255.
69
--
70
-- With SRAM-based FPGAs, flip-flops and RAM blocks have deterministic
71
-- state after configuration. On these technologies the CPU can operate
72
-- without reset and the initialization procedure described above is not
73
-- needed. However, the initialization is still performed as usual when
74
-- external reset signal is asserted.
75
 
76
process (clk_i) is
77
begin
78
        if rising_edge(clk_i) then
79
                if rst_i='1' then
80
                        init<='0';
81
                        init_cnt<=(others=>'0');
82
                else
83
                        if init='0' and ready_i='1' then
84
                                init_cnt<=init_cnt+1;
85
                                if init_cnt=X"FF" then
86
                                        init<='1';
87
                                end if;
88
                        end if;
89
                end if;
90
        end if;
91
end process;
92
 
93
-- FETCH state machine
94
 
95
process (clk_i) is
96
begin
97
        if rising_edge(clk_i) then
98
                if rst_i='1' then
99
                        fetch_addr<=START_ADDR;
100
                        requested<='0';
101
                        jr<='0';
102
                        suppress_re<='0';
103
                else
104
                        jr<='0';
105
-- Suppress LLI request if jump signal is active but will not be processed
106
-- in this cycle. Helps to reduce jump latency with high-latency LLI slaves.
107
-- Note: gating "re" with "jump_valid_i and not jr" asynchronously would
108
-- reduce jump latency even more, but we really want to avoid too large
109
-- clock-to-out on LLI outputs.
110
                        suppress_re<=jump_valid_i and not jr and not next_word;
111
                        if lli_busy_i='0' then
112
                                requested<=re and not (jump_valid_i and not jr);
113
                        end if;
114
                        if next_word='1' then
115
                                if jump_valid_i='1' and jr='0' then
116
                                        fetch_addr<=jump_dst_i;
117
                                        jr<='1';
118
                                else
119
                                        fetch_addr<=std_logic_vector(unsigned(fetch_addr)+1);
120
                                end if;
121
                        end if;
122
                end if;
123
        end if;
124
end process;
125
 
126
next_word<=(fifo_empty or ready_i) and not lli_busy_i and init;
127
re<=(fifo_empty or ready_i) and init and not suppress_re;
128
lli_re_o<=re;
129
lli_adr_o<=fetch_addr;
130
 
131
jump_ready_o<=jr;
132
 
133
-- Small instruction buffer
134
 
135
fifo_rst<=rst_i or (jump_valid_i and not jr);
136
fifo_we<=requested and not lli_busy_i;
137
fifo_din<=fetch_addr&lli_dat_i;
138
fifo_re<=ready_i and not fifo_empty;
139
 
140
ubuf_inst: entity work.lxp32_ubuf(rtl)
141
        generic map(
142
                DATA_WIDTH=>62
143
        )
144
        port map(
145
                clk_i=>clk_i,
146
                rst_i=>fifo_rst,
147
 
148
                we_i=>fifo_we,
149
                d_i=>fifo_din,
150
                re_i=>fifo_re,
151
                d_o=>fifo_dout,
152
 
153
                empty_o=>fifo_empty,
154
                full_o=>fifo_full
155
        );
156
 
157
next_ip_o<=fifo_dout(61 downto 32);
158
 
159
word_o<=fifo_dout(31 downto 0) when init='1' else X"40"&std_logic_vector(init_cnt)&X"0000";
160
valid_o<=not fifo_empty or not init;
161
 
162
end architecture;

powered by: WebSVN 2.1.0

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