1 |
22 |
mcwaccent |
--
|
2 |
|
|
--
|
3 |
|
|
-- This file is a part of JOP, the Java Optimized Processor
|
4 |
|
|
--
|
5 |
|
|
-- Copyright (C) 2001-2008, Martin Schoeberl (martin@jopdesign.com)
|
6 |
|
|
--
|
7 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
8 |
|
|
-- it under the terms of the GNU General Public License as published by
|
9 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
10 |
|
|
-- (at your option) any later version.
|
11 |
|
|
--
|
12 |
|
|
-- This program is distributed in the hope that it will be useful,
|
13 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
-- GNU General Public License for more details.
|
16 |
|
|
--
|
17 |
|
|
-- You should have received a copy of the GNU General Public License
|
18 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
|
|
--
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
--
|
23 |
|
|
-- core.vhd
|
24 |
|
|
--
|
25 |
|
|
-- cpu core of JOP3
|
26 |
|
|
--
|
27 |
|
|
-- stack, pc connections
|
28 |
|
|
-- decode
|
29 |
|
|
--
|
30 |
|
|
-- resources on ACEX1K30-3
|
31 |
|
|
--
|
32 |
|
|
--
|
33 |
|
|
-- 596 LCs, 54.3 MHz hirarchy preserve, opt. delay
|
34 |
|
|
--
|
35 |
|
|
-- 917 LCs, 44.4 MHz hirarchy preserve, opt. delay
|
36 |
|
|
--
|
37 |
|
|
-- 1069 LCs, xx.x MHz jtbl, no opt.
|
38 |
|
|
-- 1045 LCs, xx.x MHz cp removed
|
39 |
|
|
-- 1019 LCs, 26.4 MHz 2001-12-05 (???)
|
40 |
|
|
-- 1030 LCs, 29.4 MHz instruction set change
|
41 |
|
|
--
|
42 |
|
|
-- todo:
|
43 |
|
|
--
|
44 |
|
|
--
|
45 |
|
|
-- 2001-05-14 first version
|
46 |
|
|
-- 2001-05-16 first instructions working, download of a blinking LED to ACEX
|
47 |
|
|
-- 2001-05-26 delayed branch!!!
|
48 |
|
|
-- 2001-07-03 adapted for jop3
|
49 |
|
|
-- 2001-10-28 ldjpc, stjpc
|
50 |
|
|
-- 2001-10-31 stbc (write content of jbc)
|
51 |
|
|
-- 2001-12-04 cp removed
|
52 |
|
|
-- 2001-12-08 instruction set changed to 8 bit
|
53 |
|
|
-- 2002-03-24 shifter to stack
|
54 |
|
|
-- 2003-08-14 moved bcfetch from fetch to core
|
55 |
|
|
-- 2004-10-07 new alu selection with sel_sub, sel_amux and ena_a
|
56 |
|
|
-- 2004-10-08 mul operands from a and b, single instruction
|
57 |
|
|
-- 2006-01-12 new ar for local memory addressing
|
58 |
|
|
-- 2006-12-29 changed rom size to 2K
|
59 |
|
|
-- 2007-09-01 use ram_width from jop_config instead of parameter
|
60 |
|
|
--
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
library ieee ;
|
64 |
|
|
use ieee.std_logic_1164.all ;
|
65 |
|
|
use ieee.numeric_std.all ;
|
66 |
|
|
|
67 |
|
|
use work.jop_types.all;
|
68 |
|
|
use work.jop_config.all;
|
69 |
|
|
|
70 |
|
|
entity core is
|
71 |
|
|
|
72 |
|
|
generic (
|
73 |
|
|
jpc_width : integer; -- address bits of java bytecode pc
|
74 |
|
|
|
75 |
|
|
width : integer := 32; -- one data word
|
76 |
|
|
pc_width : integer := 11; -- address bits of internal instruction rom (upper half)
|
77 |
|
|
i_width : integer := 8 -- instruction width
|
78 |
|
|
);
|
79 |
|
|
|
80 |
|
|
port (
|
81 |
|
|
clk, reset : in std_logic;
|
82 |
|
|
|
83 |
|
|
-- memio connection
|
84 |
|
|
|
85 |
|
|
bsy : in std_logic;
|
86 |
|
|
din : in std_logic_vector(width-1 downto 0);
|
87 |
|
|
ext_addr : out std_logic_vector(EXTA_WIDTH-1 downto 0);
|
88 |
|
|
rd, wr : out std_logic;
|
89 |
|
|
|
90 |
|
|
-- jbc connections
|
91 |
|
|
|
92 |
|
|
jbc_addr : out std_logic_vector(jpc_width-1 downto 0);
|
93 |
|
|
jbc_data : in std_logic_vector(7 downto 0);
|
94 |
|
|
|
95 |
|
|
-- interrupt from io
|
96 |
|
|
|
97 |
|
|
irq_in : in irq_bcf_type;
|
98 |
|
|
irq_out : out irq_ack_type;
|
99 |
|
|
|
100 |
|
|
sp_ov : out std_logic;
|
101 |
|
|
|
102 |
|
|
aout : out std_logic_vector(width-1 downto 0);
|
103 |
|
|
bout : out std_logic_vector(width-1 downto 0)
|
104 |
|
|
);
|
105 |
|
|
end core;
|
106 |
|
|
|
107 |
|
|
architecture rtl of core is
|
108 |
|
|
|
109 |
|
|
--
|
110 |
|
|
-- components:
|
111 |
|
|
--
|
112 |
|
|
component bcfetch is
|
113 |
|
|
generic (jpc_width : integer; pc_width : integer);
|
114 |
|
|
port (
|
115 |
|
|
clk, reset : in std_logic;
|
116 |
|
|
|
117 |
|
|
jpc_out : out std_logic_vector(jpc_width downto 0); -- jpc read
|
118 |
|
|
din : in std_logic_vector(31 downto 0); -- A from stack
|
119 |
|
|
jpc_wr : in std_logic;
|
120 |
|
|
|
121 |
|
|
-- connection to bytecode cache
|
122 |
|
|
|
123 |
|
|
jbc_addr : out std_logic_vector(jpc_width-1 downto 0);
|
124 |
|
|
jbc_data : in std_logic_vector(7 downto 0);
|
125 |
|
|
|
126 |
|
|
jfetch : in std_logic;
|
127 |
|
|
jopdfetch : in std_logic;
|
128 |
|
|
|
129 |
|
|
zf, nf : in std_logic;
|
130 |
|
|
eq, lt : in std_logic;
|
131 |
|
|
|
132 |
|
|
jbr : in std_logic;
|
133 |
|
|
|
134 |
|
|
irq_in : in irq_bcf_type;
|
135 |
|
|
irq_out : out irq_ack_type;
|
136 |
|
|
|
137 |
|
|
jpaddr : out std_logic_vector(pc_width-1 downto 0); -- address for JVM
|
138 |
|
|
opd : out std_logic_vector(15 downto 0) -- operands
|
139 |
|
|
);
|
140 |
|
|
end component;
|
141 |
|
|
|
142 |
|
|
component fetch is
|
143 |
|
|
generic (pc_width : integer; i_width : integer);
|
144 |
|
|
port (
|
145 |
|
|
clk, reset : in std_logic;
|
146 |
|
|
|
147 |
|
|
nxt, opd : out std_logic; -- jfetch and jopdfetch from table
|
148 |
|
|
|
149 |
|
|
br : in std_logic;
|
150 |
|
|
bsy : in std_logic;
|
151 |
|
|
jpaddr : in std_logic_vector(pc_width-1 downto 0);
|
152 |
|
|
|
153 |
|
|
dout : out std_logic_vector(i_width-1 downto 0) -- internal instruction (rom)
|
154 |
|
|
);
|
155 |
|
|
end component;
|
156 |
|
|
|
157 |
|
|
component stack is
|
158 |
|
|
generic (width : integer; jpc_width : integer);
|
159 |
|
|
port (
|
160 |
|
|
clk, reset : in std_logic;
|
161 |
|
|
|
162 |
|
|
din : in std_logic_vector(width-1 downto 0);
|
163 |
|
|
dir : in std_logic_vector(ram_width-1 downto 0);
|
164 |
|
|
opd : in std_logic_vector(15 downto 0); -- index for vp load opd
|
165 |
|
|
jpc : in std_logic_vector(jpc_width downto 0); -- jpc read
|
166 |
|
|
|
167 |
|
|
sel_sub : in std_logic; -- 0..add, 1..sub
|
168 |
|
|
sel_amux : in std_logic; -- 0..sum, 1..lmux
|
169 |
|
|
ena_a : in std_logic; -- 1..store new value
|
170 |
|
|
sel_bmux : in std_logic; -- 0..a, 1..mem
|
171 |
|
|
sel_log : in std_logic_vector(1 downto 0); -- pop/st, and, or, xor
|
172 |
|
|
sel_shf : in std_logic_vector(1 downto 0); -- sr, sl, sra, (sr)
|
173 |
|
|
sel_lmux : in std_logic_vector(2 downto 0); -- log, shl, mem, io, reg
|
174 |
|
|
sel_imux : in std_logic_vector(1 downto 0); -- java opds
|
175 |
|
|
sel_rmux : in std_logic_vector(1 downto 0); -- sp, vp, jpc
|
176 |
|
|
sel_smux : in std_logic_vector(1 downto 0); -- sp, a, sp-1, sp+1
|
177 |
|
|
|
178 |
|
|
sel_mmux : in std_logic; -- 0..a, 1..b
|
179 |
|
|
sel_rda : in std_logic_vector(2 downto 0); --
|
180 |
|
|
sel_wra : in std_logic_vector(2 downto 0); --
|
181 |
|
|
|
182 |
|
|
wr_ena : in std_logic;
|
183 |
|
|
|
184 |
|
|
ena_b : in std_logic;
|
185 |
|
|
ena_vp : in std_logic;
|
186 |
|
|
ena_ar : in std_logic;
|
187 |
|
|
|
188 |
|
|
sp_ov : out std_logic;
|
189 |
|
|
|
190 |
|
|
zf : out std_logic;
|
191 |
|
|
nf : out std_logic;
|
192 |
|
|
eq : out std_logic;
|
193 |
|
|
lt : out std_logic;
|
194 |
|
|
aout : out std_logic_vector(width-1 downto 0);
|
195 |
|
|
bout : out std_logic_vector(width-1 downto 0)
|
196 |
|
|
);
|
197 |
|
|
end component;
|
198 |
|
|
|
199 |
|
|
component decode is
|
200 |
|
|
generic (i_width : integer);
|
201 |
|
|
port (
|
202 |
|
|
clk, reset : in std_logic;
|
203 |
|
|
|
204 |
|
|
instr : in std_logic_vector(i_width-1 downto 0);
|
205 |
|
|
zf, nf : in std_logic;
|
206 |
|
|
eq, lt : in std_logic;
|
207 |
|
|
|
208 |
|
|
br : out std_logic;
|
209 |
|
|
jbr : out std_logic;
|
210 |
|
|
|
211 |
|
|
ext_addr : out std_logic_vector(EXTA_WIDTH-1 downto 0);
|
212 |
|
|
rd, wr : out std_logic;
|
213 |
|
|
|
214 |
|
|
dir : out std_logic_vector(ram_width-1 downto 0);
|
215 |
|
|
|
216 |
|
|
sel_sub : out std_logic; -- 0..add, 1..sub
|
217 |
|
|
sel_amux : out std_logic; -- 0..sum, 1..lmux
|
218 |
|
|
ena_a : out std_logic; -- 1..store new value
|
219 |
|
|
sel_bmux : out std_logic; -- 0..a, 1..mem
|
220 |
|
|
sel_log : out std_logic_vector(1 downto 0); -- pop/st, and, or, xor
|
221 |
|
|
sel_shf : out std_logic_vector(1 downto 0); -- sr, sl, sra, (sr)
|
222 |
|
|
sel_lmux : out std_logic_vector(2 downto 0); -- log, shl, mem, io, reg
|
223 |
|
|
sel_imux : out std_logic_vector(1 downto 0); -- java opds
|
224 |
|
|
sel_rmux : out std_logic_vector(1 downto 0); -- sp, vp, jpc
|
225 |
|
|
sel_smux : out std_logic_vector(1 downto 0); -- sp, a, sp-1, sp+1
|
226 |
|
|
|
227 |
|
|
sel_mmux : out std_logic; -- 0..a, 1..b
|
228 |
|
|
sel_rda : out std_logic_vector(2 downto 0); --
|
229 |
|
|
sel_wra : out std_logic_vector(2 downto 0); --
|
230 |
|
|
|
231 |
|
|
wr_ena : out std_logic;
|
232 |
|
|
|
233 |
|
|
ena_b : out std_logic;
|
234 |
|
|
ena_vp : out std_logic;
|
235 |
|
|
ena_jpc : out std_logic;
|
236 |
|
|
ena_ar : out std_logic
|
237 |
|
|
);
|
238 |
|
|
end component;
|
239 |
|
|
|
240 |
|
|
--
|
241 |
|
|
-- Signals
|
242 |
|
|
--
|
243 |
|
|
|
244 |
|
|
--
|
245 |
|
|
-- (bc)fetch connections
|
246 |
|
|
--
|
247 |
|
|
signal br : std_logic;
|
248 |
|
|
signal jbr : std_logic;
|
249 |
|
|
|
250 |
|
|
signal jfetch : std_logic;
|
251 |
|
|
signal jopdfetch : std_logic;
|
252 |
|
|
|
253 |
|
|
signal jpaddr : std_logic_vector(pc_width-1 downto 0);
|
254 |
|
|
|
255 |
|
|
signal opd : std_logic_vector(15 downto 0);
|
256 |
|
|
signal jpc_out : std_logic_vector(jpc_width downto 0);
|
257 |
|
|
signal instr : std_logic_vector(i_width-1 downto 0);
|
258 |
|
|
signal ena_jpc : std_logic;
|
259 |
|
|
|
260 |
|
|
--
|
261 |
|
|
-- stack connections
|
262 |
|
|
--
|
263 |
|
|
signal dir : std_logic_vector(ram_width-1 downto 0);
|
264 |
|
|
|
265 |
|
|
signal sel_sub : std_logic; -- 0..add, 1..sub
|
266 |
|
|
signal sel_amux : std_logic; -- 0..sum, 1..lmux
|
267 |
|
|
signal ena_a : std_logic; -- 1..store new value
|
268 |
|
|
signal sel_bmux : std_logic; -- 0..a, 1..mem
|
269 |
|
|
signal sel_log : std_logic_vector(1 downto 0); -- ld, and, or, xor
|
270 |
|
|
signal sel_shf : std_logic_vector(1 downto 0); -- sr, sl, sra, (sr)
|
271 |
|
|
signal sel_lmux : std_logic_vector(2 downto 0); -- log, shl, mem, io, reg
|
272 |
|
|
signal sel_imux : std_logic_vector(1 downto 0); -- java opds
|
273 |
|
|
signal sel_rmux : std_logic_vector(1 downto 0); -- sp, vp, jpc
|
274 |
|
|
signal sel_smux : std_logic_vector(1 downto 0); -- sp, a, sp-1, sp+1
|
275 |
|
|
|
276 |
|
|
signal sel_mmux : std_logic; -- 0..a, 1..b
|
277 |
|
|
signal sel_rda : std_logic_vector(2 downto 0); --
|
278 |
|
|
signal sel_wra : std_logic_vector(2 downto 0); --
|
279 |
|
|
|
280 |
|
|
signal wr_ena : std_logic;
|
281 |
|
|
|
282 |
|
|
signal ena_b : std_logic;
|
283 |
|
|
signal ena_vp : std_logic;
|
284 |
|
|
signal ena_ar : std_logic;
|
285 |
|
|
|
286 |
|
|
signal stk_zf : std_logic;
|
287 |
|
|
signal stk_nf : std_logic;
|
288 |
|
|
signal stk_eq : std_logic;
|
289 |
|
|
signal stk_lt : std_logic;
|
290 |
|
|
signal stk_aout : std_logic_vector(width-1 downto 0);
|
291 |
|
|
signal stk_bout : std_logic_vector(width-1 downto 0);
|
292 |
|
|
|
293 |
|
|
begin
|
294 |
|
|
|
295 |
|
|
cmp_bcf: bcfetch generic map(jpc_width, pc_width)
|
296 |
|
|
port map (clk, reset, jpc_out, stk_aout, ena_jpc,
|
297 |
|
|
jbc_addr, jbc_data,
|
298 |
|
|
jfetch, jopdfetch,
|
299 |
|
|
stk_zf, stk_nf, stk_eq, stk_lt, jbr,
|
300 |
|
|
irq_in, irq_out,
|
301 |
|
|
jpaddr, opd);
|
302 |
|
|
|
303 |
|
|
cmp_fch: fetch generic map (pc_width, i_width)
|
304 |
|
|
port map (clk, reset, jfetch, jopdfetch,
|
305 |
|
|
br, bsy, jpaddr, instr);
|
306 |
|
|
|
307 |
|
|
cmp_stk: stack generic map (width, jpc_width)
|
308 |
|
|
port map (clk, reset, din, dir, opd, jpc_out,
|
309 |
|
|
sel_sub, sel_amux, ena_a,
|
310 |
|
|
sel_bmux, sel_log, sel_shf, sel_lmux, sel_imux, sel_rmux, sel_smux,
|
311 |
|
|
sel_mmux, sel_rda, sel_wra,
|
312 |
|
|
wr_ena, ena_b, ena_vp, ena_ar,
|
313 |
|
|
sp_ov,
|
314 |
|
|
stk_zf, stk_nf, stk_eq, stk_lt, stk_aout, stk_bout);
|
315 |
|
|
|
316 |
|
|
cmp_dec: decode generic map (i_width)
|
317 |
|
|
port map (clk, reset, instr, stk_zf, stk_nf, stk_eq, stk_lt,
|
318 |
|
|
br, jbr,
|
319 |
|
|
ext_addr, rd, wr,
|
320 |
|
|
dir,
|
321 |
|
|
sel_sub, sel_amux, ena_a,
|
322 |
|
|
sel_bmux, sel_log, sel_shf, sel_lmux, sel_imux, sel_rmux, sel_smux,
|
323 |
|
|
sel_mmux, sel_rda, sel_wra,
|
324 |
|
|
wr_ena, ena_b, ena_vp, ena_jpc, ena_ar);
|
325 |
|
|
|
326 |
|
|
aout <= stk_aout;
|
327 |
|
|
bout <= stk_bout;
|
328 |
|
|
|
329 |
|
|
end rtl;
|