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

Subversion Repositories the_wizardry_project

[/] [the_wizardry_project/] [trunk/] [Wizardry/] [VHDL/] [Wizardry Top Level/] [Address Generation/] [JOP/] [bcfetch.vhd] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
--      bcfetch.vhd
24
--
25
--      Java bc fetch and address translation for JVM
26
--
27
--      resources on ACEX1K30-3
28
--
29
--              bytecode LCs, max ca. xx MHz
30
--
31
--      todo:
32
--
33
--      2001-11-16      split from fetch.vhd, register jpaddr instead of jinstr
34
--      2001-12-06      unregistered!!! jpaddr, jbr registered (moved from decode)
35
--      2001-12-07      removed mux befor jbc ram, jbr unregistered selects addr. for jpc
36
--                              decode goto and if_bytecode from jinstr
37
--      2002-03-24      autoincrement of jpc on bc_wr
38
--      2002-10-21      added if(non)null
39
--      2003-02-22      registered jbc ram
40
--      2003-08-14      move wr-addr load and autoincrement to ajbc.vhd (now 32 bit interface)
41
--      2003-08-15      interrupt handling
42
--      2004-04-06      removed signal jfetch from interrupt mux (is in fetch allready)
43
--                              different mux for jpc and jbc rdaddr, register jump address calculation
44
--      2004-09-11      move jbc to mem
45
--      2005-01-17      move interrupt mux to jtbl.vhd (mux after the table)
46
--      2007-12-01      move most interrupt processing to sc_sys
47
--
48
--      TODO:   use 'running' bit and generate jbr here!
49
--
50
 
51
 
52
library ieee;
53
use ieee.std_logic_1164.all;
54
use ieee.numeric_std.all;
55
 
56
use work.jop_types.all;
57
 
58
entity bcfetch is
59
 
60
generic (
61
        jpc_width       : integer;              -- address bits of java byte code pc
62
        pc_width        : integer               -- address bits of internal instruction rom
63
);
64
port (
65
        clk, reset      : in std_logic;
66
 
67
        jpc_out         : out std_logic_vector(jpc_width downto 0);      -- jpc read
68
        din                     : in std_logic_vector(31 downto 0);                      -- A from stack
69
        jpc_wr          : in std_logic;
70
 
71
--      connection to bytecode cache
72
 
73
        jbc_addr        : out std_logic_vector(jpc_width-1 downto 0);
74
        jbc_data        : in std_logic_vector(7 downto 0);
75
 
76
        jfetch          : in std_logic;
77
        jopdfetch       : in std_logic;
78
 
79
        zf, nf          : in std_logic;
80
        eq, lt          : in std_logic;
81
 
82
        jbr                     : in std_logic;
83
 
84
        irq_in          : in irq_bcf_type;
85
        irq_out         : out irq_ack_type;
86
 
87
        jpaddr          : out std_logic_vector(pc_width-1 downto 0);     -- address for JVM
88
        opd                     : out std_logic_vector(15 downto 0)                              -- operands
89
);
90
end bcfetch;
91
 
92
architecture rtl of bcfetch is
93
 
94
--
95
--      jtbl component (generated vhdl file from Jopa!)
96
--
97
--      logic rom (unregistered)
98
--
99
component jtbl is
100
port (
101
        bcode   : in std_logic_vector(7 downto 0);
102
        int_pend        : in  std_logic;
103
        exc_pend        : in  std_logic;
104
        q               : out std_logic_vector(pc_width-1 downto 0)
105
);
106
end component;
107
 
108
 
109
        signal jbc_mux  : std_logic_vector(jpc_width downto 0);
110
        signal jbc_q    : std_logic_vector(7 downto 0);
111
 
112
        signal jpc              : std_logic_vector(jpc_width downto 0);
113
        signal jpc_br   : std_logic_vector(jpc_width downto 0);
114
        signal jmp_addr : std_logic_vector(jpc_width downto 0);
115
 
116
        signal jinstr   : std_logic_vector(7 downto 0);
117
        signal tp               : std_logic_vector(3 downto 0);
118
        signal jmp              : std_logic;
119
 
120
        signal jopd             : std_logic_vector(15 downto 0);
121
 
122
--
123
--      signals for interrupt handling
124
--
125
        signal int_pend         : std_logic;
126
        signal int_req          : std_logic;
127
        signal int_taken        : std_logic;
128
 
129
        signal exc_pend         : std_logic;
130
        signal exc_taken        : std_logic;
131
 
132
        signal bytecode         : std_logic_vector(7 downto 0);
133
 
134
-- synthesis translate_off 
135
-- synthesis translate_on 
136
 
137
begin
138
 
139
--
140
--      interrupt processing at bytecode fetch level
141
--
142
process(clk, reset) begin
143
 
144
        if (reset='1') then
145
                int_pend <= '0';
146
                exc_pend <= '0';
147
 
148
        elsif rising_edge(clk) then
149
 
150
                if irq_in.irq='1' then
151
                        int_pend <= '1';
152
                elsif int_taken='1' then
153
                        int_pend <= '0';
154
                end if;
155
 
156
                if irq_in.exc='1' then
157
                        exc_pend <= '1';
158
                elsif exc_taken='1' then
159
                        exc_pend <= '0';
160
                end if;
161
        end if;
162
 
163
end process;
164
 
165
--
166
--      TODO: exception and int in the same cycle: int gets lost
167
--
168
        int_req <= int_pend and irq_in.ena;
169
        int_taken <= int_req and jfetch;
170
        exc_taken <= exc_pend and jfetch;
171
 
172
        irq_out.ack_irq <= int_taken;
173
        irq_out.ack_exc <= exc_taken;
174
 
175
--
176
--      bytecode mux on interrupt
177
--              jpc is one too high after generating int_taken
178
--              this is corrected in jvm.asm
179
--
180
 
181
--
182
--      java byte code fetch and branch
183
--              interrupt and exception mux are in jtbl
184
--
185
 
186
        bytecode <= jbc_q;              -- register this for an additional pipeline stage
187
 
188
        cmp_jtbl: jtbl port map(bytecode, int_req, exc_pend, jpaddr);
189
 
190
        jbc_addr <= jbc_mux(jpc_width-1 downto 0);
191
        jbc_q <= jbc_data;
192
 
193
 
194
--
195
--      decode if and goto byte codes
196
--
197
process(clk, jinstr) begin
198
 
199
        if rising_edge(clk) then
200
                case jinstr is
201
 
202
--                      when "10011001" => tp <= "1001";        -- ifeq
203
--                      when "10011010" => tp <= "1010";        -- ifne
204
--                      when "10011011" => tp <= "1011";        -- iflt
205
--                      when "10011100" => tp <= "1100";        -- ifge
206
--                      when "10011101" => tp <= "1101";        -- ifgt
207
--                      when "10011110" => tp <= "1110";        -- ifle
208
 
209
--                      when "10011111" => tp <= "1111";        -- if_icmpeq
210
--                      when "10100000" => tp <= "0000";        -- if_icmpne
211
--                      when "10100001" => tp <= "0001";        -- if_icmplt
212
--                      when "10100010" => tp <= "0010";        -- if_icmpge
213
--                      when "10100011" => tp <= "0011";        -- if_icmpgt
214
--                      when "10100100" => tp <= "0100";        -- if_icmple
215
 
216
                        when "10100101" => tp <= "1111";        -- if_acmpeq
217
                        when "10100110" => tp <= "0000";        -- if_acmpne
218
--                      when "10100111" => tp <= "0111";        -- goto
219
 
220
                        when "11000110" => tp <= "1001";        -- ifnull
221
                        when "11000111" => tp <= "1010";        -- ifnonnull
222
 
223
                        when others => tp <= jinstr(3 downto 0);
224
                end case;
225
        end if;
226
 
227
end process;
228
 
229
process(tp, jbr, zf, nf, eq, lt)
230
begin
231
 
232
        jmp <= '0';
233
        if (jbr='1') then
234
                case tp is
235
                        when "1001" =>                  -- ifeq, ifnull
236
                                if (zf='1') then
237
                                        jmp <= '1';
238
                                end if;
239
                        when "1010" =>                  -- ifne, ifnonnull
240
                                if (zf='0') then
241
                                        jmp <= '1';
242
                                end if;
243
                        when "1011" =>                  -- iflt
244
                                if (nf='1') then
245
                                        jmp <= '1';
246
                                end if;
247
                        when "1100" =>                  -- ifge
248
                                if (nf='0') then
249
                                        jmp <= '1';
250
                                end if;
251
                        when "1101" =>                  -- ifgt
252
                                if (zf='0' and nf='0') then
253
                                        jmp <= '1';
254
                                end if;
255
                        when "1110" =>                  -- ifle
256
                                if (zf='1' or nf='1') then
257
                                        jmp <= '1';
258
                                end if;
259
 
260
                        when "1111" =>                  -- if_icmpeq, if_acmpeq
261
                                if (eq='1') then
262
                                        jmp <= '1';
263
                                end if;
264
                        when "0000" =>                  -- if_icmpne, if_acmpne
265
                                if (eq='0') then
266
                                        jmp <= '1';
267
                                end if;
268
                        when "0001" =>                  -- if_icmplt
269
                                if (lt='1') then
270
                                        jmp <= '1';
271
                                end if;
272
                        when "0010" =>                  -- if_icmpge
273
                                if (lt='0') then
274
                                        jmp <= '1';
275
                                end if;
276
                        when "0011" =>                  -- if_icmpgt
277
                                if (eq='0' and lt='0') then
278
                                        jmp <= '1';
279
                                end if;
280
                        when "0100" =>                  -- if_icmple
281
                                if (eq='1' or lt='1') then
282
                                        jmp <= '1';
283
                                end if;
284
 
285
                        when "0111" =>                  -- goto
286
                                jmp <= '1';
287
 
288
                        when others =>
289
                                null;
290
                end case;
291
        end if;
292
 
293
end process;
294
 
295
--
296
--      jbc read address mux (is registered in ram)
297
--              no write from din
298
--
299
process(din, jpc, jmp_addr, jopd, jfetch, jopdfetch, jmp)
300
 
301
begin
302
 
303
        if (jmp='1') then
304
                jbc_mux <= jmp_addr;
305
        elsif (jfetch='1' or jopdfetch='1') then
306
                jbc_mux <= std_logic_vector(unsigned(jpc) + 1);
307
        else
308
                jbc_mux <= jpc;
309
        end if;
310
 
311
end process;
312
 
313
--
314
--      jpc mux conatins also din
315
--
316
process(clk, reset)
317
 
318
begin
319
        if (reset='1') then
320
 
321
                jpc <= std_logic_vector(to_unsigned(0, jpc_width+1));
322
 
323
        elsif rising_edge(clk) then
324
 
325
                if (jpc_wr='1') then
326
                        jpc <= din(jpc_width downto 0);
327
                elsif (jmp='1') then
328
                        jpc <= jmp_addr;
329
                elsif (jfetch='1' or jopdfetch='1') then
330
                        jpc <= std_logic_vector(unsigned(jpc) + 1);
331
                else
332
                        jpc <= jpc;
333
                end if;
334
 
335
        end if;
336
end process;
337
 
338
        jpc_out <= jpc;
339
 
340
 
341
--
342
--      use this without register
343
--
344
--              jmp_addr <= std_logic_vector(unsigned(jpc_br) +
345
--                      unsigned(jopd(jpc_width-1 downto 0)));
346
 
347
process(clk)
348
begin
349
        if rising_edge(clk) then
350
 
351
                -- from jbc_q + jopd low!
352
                jmp_addr <= std_logic_vector(unsigned(jpc_br) +
353
                        unsigned(jopd(jpc_width-8 downto 0) & jbc_q));
354
 
355
                if (jfetch='1') then
356
                        jpc_br <= jpc;          -- save start address of instruction for branch
357
                        jinstr <= jbc_q;
358
                end if;
359
 
360
        end if;
361
end process;
362
 
363
process(clk, reset)
364
 
365
begin
366
        if (reset='1') then
367
                jopd <= (others => '0');
368
        elsif rising_edge(clk) then
369
                jopd(7 downto 0) <= jbc_q;
370
                if (jopdfetch='1') then
371
                        jopd(15 downto 8) <= jopd(7 downto 0);
372
                end if;
373
        end if;
374
end process;
375
 
376
        opd <= jopd;
377
 
378
-- synthesis translate_off 
379
        -- show jinstr with bytecode mnemonic
380
        bc: entity work.bytecode port map(jinstr);
381
-- synthesis translate_on 
382
 
383
end rtl;
384
 

powered by: WebSVN 2.1.0

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