1 |
2 |
madsilicon |
-----------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-----------------------------------------------------------------
|
4 |
|
|
-- --
|
5 |
|
|
-- Copyright (C) 2013 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 |
|
|
-- G.729a ASIP Instruction Fecthing Logic
|
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.G729A_ASIP_PKG.all;
|
38 |
|
|
use work.G729A_ASIP_CFG_PKG.all;
|
39 |
|
|
|
40 |
|
|
entity G729A_ASIP_FTCHLOG_2W is
|
41 |
|
|
port(
|
42 |
|
|
CLK_i : in std_logic;
|
43 |
|
|
RST_i : in std_logic;
|
44 |
|
|
STRT_i : in std_logic;
|
45 |
|
|
HALT_i : in std_logic;
|
46 |
|
|
SADR_i : in unsigned(ALEN-1 downto 0);
|
47 |
|
|
BJX_i : in std_logic;
|
48 |
|
|
BJTA_i : in unsigned(ALEN-1 downto 0);
|
49 |
|
|
LBX_i : in std_logic;
|
50 |
|
|
LBTA_i : in unsigned(ALEN-1 downto 0);
|
51 |
|
|
PSTALL_i : in std_logic;
|
52 |
|
|
|
53 |
|
|
IFV_o : out std_logic_vector(2-1 downto 0);
|
54 |
|
|
IADR0_o : out unsigned(ALEN-1 downto 0);
|
55 |
|
|
IADR1_o : out unsigned(ALEN-1 downto 0);
|
56 |
|
|
BSY_o : out std_logic
|
57 |
|
|
);
|
58 |
|
|
end G729A_ASIP_FTCHLOG_2W;
|
59 |
|
|
|
60 |
|
|
architecture ARC of G729A_ASIP_FTCHLOG_2W is
|
61 |
|
|
|
62 |
|
|
component G729A_ASIP_ADDERU is
|
63 |
|
|
generic(
|
64 |
|
|
WIDTH : integer := 16
|
65 |
|
|
);
|
66 |
|
|
port(
|
67 |
|
|
OPA_i : in unsigned(WIDTH-1 downto 0);
|
68 |
|
|
OPB_i : in unsigned(WIDTH-1 downto 0);
|
69 |
|
|
CI_i : in std_logic;
|
70 |
|
|
|
71 |
|
|
SUM_o : out unsigned(WIDTH-1 downto 0)
|
72 |
|
|
);
|
73 |
|
|
end component;
|
74 |
|
|
|
75 |
|
|
component G729A_ASIP_ADDER_F is
|
76 |
|
|
generic(
|
77 |
|
|
LEN1 : integer := 16;
|
78 |
|
|
LEN2 : integer := 16
|
79 |
|
|
);
|
80 |
|
|
port(
|
81 |
|
|
OPA_i : in signed(LEN1+LEN2-1 downto 0);
|
82 |
|
|
OPB_i : in signed(LEN1+LEN2-1 downto 0);
|
83 |
|
|
CI_i : in std_logic;
|
84 |
|
|
|
85 |
|
|
SUM_o : out signed(LEN1+LEN2-1 downto 0)
|
86 |
|
|
);
|
87 |
|
|
end component;
|
88 |
|
|
|
89 |
|
|
signal SZERO : unsigned(ALEN-1 downto 0) := (others => '0');
|
90 |
|
|
signal ONE : std_logic := '1';
|
91 |
|
|
signal PC,PC_q : unsigned(ALEN-2 downto 0);
|
92 |
|
|
signal PC_NS : unsigned(ALEN-2 downto 0);
|
93 |
|
|
signal PCP1,PCP1_q : unsigned(ALEN-2 downto 0);
|
94 |
|
|
signal HALT_q : std_logic;
|
95 |
|
|
signal EVEN_PC : std_logic;
|
96 |
|
|
signal EVEN_PC_NS : std_logic;
|
97 |
|
|
|
98 |
|
|
begin
|
99 |
|
|
|
100 |
|
|
-- Halt flag register
|
101 |
|
|
process(CLK_i)
|
102 |
|
|
begin
|
103 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
104 |
|
|
if(RST_i = '1' or HALT_i = '1') then
|
105 |
|
|
HALT_q <= '1';
|
106 |
|
|
elsif(STRT_i = '1') then
|
107 |
|
|
HALT_q <= '0';
|
108 |
|
|
end if;
|
109 |
|
|
end if;
|
110 |
|
|
end process;
|
111 |
|
|
|
112 |
|
|
BSY_o <= not(HALT_q);
|
113 |
|
|
|
114 |
|
|
-- Fetched instruction #0 is always valid, unless processor is
|
115 |
|
|
-- halted or fetch address is odd.
|
116 |
|
|
|
117 |
|
|
IFV_o(0) <= (not(HALT_q) or STRT_i) and EVEN_PC;
|
118 |
|
|
|
119 |
|
|
-- Fetched instruction #1 is always valid, unless processor is
|
120 |
|
|
-- halted.
|
121 |
|
|
|
122 |
|
|
IFV_o(1) <= (not(HALT_q) or STRT_i);
|
123 |
|
|
|
124 |
|
|
-- Program Counter register
|
125 |
|
|
process(CLK_i)
|
126 |
|
|
begin
|
127 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
128 |
|
|
if(RST_i = '1') then
|
129 |
|
|
PC_q <= (others => '0');
|
130 |
|
|
PCP1_q <= (1 => '1',others => '0');
|
131 |
|
|
elsif(PC_q < ((IMEM_SIZE/2)-2) or STRT_i = '1') then
|
132 |
|
|
PC_q <= PC;
|
133 |
|
|
PCP1_q <= PCP1;
|
134 |
|
|
end if;
|
135 |
|
|
end if;
|
136 |
|
|
end process;
|
137 |
|
|
|
138 |
|
|
PCP1 <= PC_NS + 1 when (PSTALL_i = '0') else PCP1_q;
|
139 |
|
|
|
140 |
|
|
-- Note: a branch/jump in IX stage is older than a loop closing
|
141 |
|
|
-- instruction in IF stage and therefore takes priority over it.
|
142 |
|
|
|
143 |
|
|
-- PC is a double word address, and therefore is one bit shorter
|
144 |
|
|
-- than actual fetch addresses.
|
145 |
|
|
|
146 |
|
|
process(STRT_i,BJX_i,BJTA_i,LBX_i,SADR_i,LBTA_i,PCP1_q)
|
147 |
|
|
begin
|
148 |
|
|
if(BJX_i = '1') then -- and PSTALL_i = '0') then
|
149 |
|
|
PC_NS <= BJTA_i(ALEN-1 downto 1);
|
150 |
|
|
EVEN_PC_NS <= not(BJTA_i(0));
|
151 |
|
|
elsif(LBX_i = '1') then -- and PSTALL_i = '0') then
|
152 |
|
|
PC_NS <= LBTA_i(ALEN-1 downto 1);
|
153 |
|
|
EVEN_PC_NS <= not(LBTA_i(0));
|
154 |
|
|
elsif(STRT_i = '1') then
|
155 |
|
|
PC_NS <= SADR_i(ALEN-1 downto 1);
|
156 |
|
|
EVEN_PC_NS <= not(SADR_i(0));
|
157 |
|
|
else
|
158 |
|
|
PC_NS <= PCP1_q;
|
159 |
|
|
EVEN_PC_NS <= '1';
|
160 |
|
|
end if;
|
161 |
|
|
end process;
|
162 |
|
|
|
163 |
|
|
PC <= PC_NS when (PSTALL_i = '0') else PC_q;
|
164 |
|
|
EVEN_PC <= EVEN_PC_NS when (PSTALL_i = '0') else '1';
|
165 |
|
|
|
166 |
|
|
-- Fetch addresses
|
167 |
|
|
|
168 |
|
|
-- instruction #0 address is always an even address, while
|
169 |
|
|
-- instruction #1 address is always an odd one.
|
170 |
|
|
|
171 |
|
|
IADR0_o <= PC & '0';
|
172 |
|
|
IADR1_o <= PC & '1';
|
173 |
|
|
|
174 |
|
|
end ARC;
|