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/] [decode.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
--      decode.vhd
24
--
25
--      cpu decode of JOP3
26
--      
27
--      generate control for pc and stack
28
--
29
--
30
--      resources on ACEX1K30-3
31
--      
32
--              xxx LCs, 42.0 MHz       
33
--
34
--      todo:
35
--
36
--
37
--      2001-07-03      extracted from core.vhd
38
--      2001-10-28      ldjpc, stjpc
39
--      2001-10-31      stbc
40
--      2001-12-04      cp removed
41
--      2001-12-05      sel_rda, sel_wra: logic from ir (not registered)
42
--                              sel_smux: logic from ir (not registered, no mix addr/rd-ex: nop befor stsp)
43
--      2001-12-06      moved ir from decode to fetch, jbr unregistered
44
--      2001-12-07      moved jbr decode to bcfetch, ldi loads consts from ram (addr > 31), jp removed
45
--      2001-12-08      instruction set changed to 8 bit
46
--      2002-03-24      new shift instructions
47
--      2002-12-02      wait instruction for memory
48
--      2003-02-12      added instruction ld_opd_8u/16u
49
--      2004-10-07      new alu selection with sel_sub, sel_amux and ena_a
50
--      2004-10-08      moved bsy/pcwait from decode to fetch
51
--      2006-01-12      new ar for local memory addressing: star, ldmi, stmi
52
--                              stioa, stiod, ldiod removed
53
--      2007-08-31      use addr_width for signal dir
54
--      2007-09-01      use ram_width from jop_config instead of parameter
55
--
56
 
57
 
58
library ieee ;
59
use ieee.std_logic_1164.all ;
60
use ieee.numeric_std.all ;
61
 
62
use work.jop_config.all;
63
use work.jop_types.all;
64
 
65
entity decode is
66
generic (
67
        i_width         : integer               -- instruction width
68
);
69
 
70
port (
71
        clk, reset      : in std_logic;
72
 
73
        instr           : in std_logic_vector(i_width-1 downto 0);
74
        zf, nf          : in std_logic;         -- nf, eq and lt not used (only brz, brnz)
75
        eq, lt          : in std_logic;
76
 
77
        br                      : out std_logic;
78
        jbr                     : out std_logic;
79
 
80
        ext_addr        : out std_logic_vector(EXTA_WIDTH-1 downto 0);
81
        rd, wr          : out std_logic;
82
 
83
        dir                     : out std_logic_vector(ram_width-1 downto 0);
84
 
85
        sel_sub         : out std_logic;                                                -- 0..add, 1..sub
86
        sel_amux        : out std_logic;                                                -- 0..sum, 1..lmux
87
        ena_a           : out std_logic;                                                -- 1..store new value
88
        sel_bmux        : out std_logic;                                                -- 0..a, 1..mem
89
        sel_log         : out std_logic_vector(1 downto 0);              -- pop/st, and, or, xor
90
        sel_shf         : out std_logic_vector(1 downto 0);              -- sr, sl, sra, (sr)
91
        sel_lmux        : out std_logic_vector(2 downto 0);              -- log, shift, mem, io, reg
92
        sel_imux        : out std_logic_vector(1 downto 0);              -- java opds
93
        sel_rmux        : out std_logic_vector(1 downto 0);              -- sp, vp, jpc
94
        sel_smux        : out std_logic_vector(1 downto 0);              -- sp, a, sp-1, sp+1
95
 
96
        sel_mmux        : out std_logic;                                                -- 0..a, 1..b
97
        sel_rda         : out std_logic_vector(2 downto 0);              -- 
98
        sel_wra         : out std_logic_vector(2 downto 0);              -- 
99
 
100
        wr_ena          : out std_logic;
101
 
102
        ena_b           : out std_logic;
103
        ena_vp          : out std_logic;
104
        ena_jpc         : out std_logic;
105
        ena_ar          : out std_logic
106
);
107
end decode;
108
 
109
architecture rtl of decode is
110
 
111
--
112
--      Signals
113
--
114
 
115
--
116
-- intruction register, shortcut
117
--
118
--      signal ir               : std_logic_vector(i_width-1 downto 0);         -- Xilinx does not like this... instruction register
119
        signal ir               : std_logic_vector(7 downto 0);          -- instruction register
120
 
121
begin
122
 
123
        ir <= instr;            -- registered in fetch
124
 
125
        ext_addr <= ir(EXTA_WIDTH-1 downto 0);   -- address for extension select
126
 
127
--
128
--      branch, jbranch
129
--
130
 
131
process(clk, reset, ir, zf)
132
begin
133
        if (reset='1') then
134
                br <= '0';
135
        elsif rising_edge(clk) then
136
 
137
                br <= '0';
138
                if((ir(7 downto 5)="010" and zf='1') or         -- bz
139
                        (ir(7 downto 5)="011" and zf='0')) then  -- bnz
140
                        br <= '1';
141
                end if;
142
 
143
        end if;
144
end process;
145
 
146
--      wait is decoded direct in fetch.vhd!
147
 
148
process(ir)
149
begin
150
 
151
        jbr <= '0';
152
        if (ir="10000010") then         -- jbr: goto and if_xxx
153
                jbr <= '1';
154
        end if;
155
 
156
end process;
157
 
158
--
159
--      addr, read stage:
160
--              decode from ir (only logic, no register)
161
--
162
process(ir)
163
begin
164
 
165
-- ram wraddress and wrena are registered
166
 
167
        wr_ena <= '0';
168
        if (ir(7 downto 5)="101" or                     -- 'push' instructions
169
                ir(7 downto 5)="110" or
170
                ir(7 downto 5)="111" or
171
                ir(7 downto 5)="001" or                 -- stm
172
                ir(7 downto 3)="00010") then    -- st, stn, stmi
173
 
174
                wr_ena <= '1';
175
        end if;
176
 
177
        rd <= '0';
178
        if ir(7 downto 3)="11100" then          -- ld memio
179
                rd <= '1';
180
        end if;
181
        wr <= '0';
182
        if ir(7 downto 0)="00000110"
183
                or ir(7 downto 0)="00000111"
184
                or ir(7 downto 3)="00001" then -- st memio
185
                wr <= '1';
186
        end if;
187
 
188
        sel_imux <= ir(1 downto 0);                      -- ld opd_x
189
 
190
-- select for rd/wr address muxes
191
 
192
        dir <= std_logic_vector(to_unsigned(0, ram_width-5)) & ir(4 downto 0);
193
 
194
        sel_rda <= "110";                                       -- sp
195
        if (ir(7 downto 3)="11101") then        -- ld, ldn, ldmi
196
                sel_rda <= ir(2 downto 0);
197
        end if;
198
        if (ir(7 downto 5)="101") then          -- ldm
199
                sel_rda <= "111";
200
        end if;
201
        if (ir(7 downto 5)="110") then          -- ldi
202
                sel_rda <= "111";
203
                dir <= std_logic_vector(to_unsigned(1, ram_width-5)) &
204
                        ir(4 downto 0);  -- addr > 31 constants
205
        end if;
206
 
207
        sel_wra <= "110";                                       -- spp
208
        if ir(7 downto 3)="00010" then          -- st, stn, stmi
209
                sel_wra <= ir(2 downto 0);
210
        end if;
211
        if ir(7 downto 5)="001" then            -- stm
212
                sel_wra <= "111";
213
        end if;
214
 
215
-- select for sp update
216
 
217
        sel_smux <= "00";                               -- sp = sp
218
        if(ir(7)='0') then                       -- 'pop' instruction
219
                sel_smux <= "01";                       -- --sp
220
        end if;
221
        if(ir(7 downto 5)="101" or      -- 'push' instruction
222
                ir(7 downto 5)="110" or
223
                ir(7 downto 5)="111") then
224
                sel_smux <= "10";                       -- ++sp
225
        end if;
226
        if (ir="00011011") then                 -- st sp
227
                sel_smux <= "11";                       -- sp = a
228
        end if;
229
 
230
end process;
231
 
232
--
233
--      ex stage
234
--
235
 
236
process(clk, reset)
237
begin
238
 
239
        if (reset='1') then
240
                sel_sub <= '0';
241
                sel_amux <= '0';
242
                ena_a <= '0';
243
                sel_bmux <= '0';
244
                sel_log <= "00";
245
                sel_shf <= "00";
246
                sel_lmux <= "000";
247
                sel_rmux <= "00";
248
                sel_mmux <= '0';
249
                ena_b <= '0';
250
                ena_vp <= '0';
251
                ena_jpc <= '0';
252
                ena_ar <= '0';
253
 
254
        elsif rising_edge(clk) then
255
 
256
                sel_log <= "00";
257
                if (ir(7 downto 2)="000000") then               -- pop, and, or, xor
258
                        sel_log <= ir(1 downto 0);
259
                end if;
260
 
261
                sel_shf <= ir(1 downto 0);
262
 
263
                sel_sub <= '1';                 -- default is subtract for lt-flag
264
                sel_amux <= '1';                        -- default is lmux
265
                ena_a <= '1';                   -- default is enable
266
                ena_vp <= '0';
267
                ena_jpc <= '0';
268
                ena_ar <= '0';
269
 
270
                case ir is
271
 
272
                        when "00000000" =>                              -- pop
273
                        when "00000001" =>                              -- and
274
                        when "00000010" =>                              -- or
275
                        when "00000011" =>                              -- xor
276
                        when "00000100" =>                              -- add
277
                                        sel_sub <= '0';
278
                                        sel_amux <= '0';
279
                        when "00000101" =>                              -- sub
280
                                        sel_amux <= '0';
281
                        when "00001010" =>                              -- stmra
282
                        when "00001011" =>                              -- stmwa
283
                        when "00001100" =>                              -- stmwd
284
                        when "00001101" =>                              -- stopa
285
                        when "00001110" =>                              -- stopb
286
                        when "00010000" =>                              -- st0
287
                        when "00010001" =>                              -- st1
288
                        when "00010010" =>                              -- st2
289
                        when "00010011" =>                              -- st3
290
                        when "00010100" =>                              -- st
291
                        when "00010101" =>                              -- stmi
292
                        when "00011000" =>                              -- stvp
293
                                        ena_vp <= '1';
294
                        when "00011001" =>                              -- stjpc
295
                                        ena_jpc <= '1';
296
                        when "00011010" =>                              -- star
297
                                        ena_ar <= '1';
298
                        when "00011011" =>                              -- stsp
299
                        when "00011100" =>                              -- ushr
300
                        when "00011101" =>                              -- shl
301
                        when "00011110" =>                              -- shr
302
--                      when "001-----" =>                              -- stm
303
--                      when "010-----" =>                              -- bz
304
--                      when "011-----" =>                              -- bnz
305
                        when "10000000" =>                              -- nop
306
                                        ena_a <= '0';
307
                        when "10000001" =>                              -- wait
308
                                        ena_a <= '0';
309
                        when "10000010" =>                              -- jbr
310
                                        ena_a <= '0';
311
--                      when "101-----" =>                              -- ldm
312
--                      when "110-----" =>                              -- ldi
313
                        when "11100010" =>                              -- ldmrd
314
                        when "11100011" =>                              -- ldmbsy
315
                        when "11100101" =>                              -- ldmul
316
                        when "11101000" =>                              -- ld0
317
                        when "11101001" =>                              -- ld1
318
                        when "11101010" =>                              -- ld2
319
                        when "11101011" =>                              -- ld3
320
                        when "11101100" =>                              -- ld
321
                        when "11101101" =>                              -- ldmi
322
                        when "11110000" =>                              -- ldsp
323
                        when "11110001" =>                              -- ldvp
324
                        when "11110010" =>                              -- ldjpc
325
                        when "11110100" =>                              -- ld_opd_8u
326
                        when "11110101" =>                              -- ld_opd_8s
327
                        when "11110110" =>                              -- ld_opd_16u
328
                        when "11110111" =>                              -- ld_opd_16s
329
                        when "11111000" =>                              -- dup
330
                                        ena_a <= '0';
331
 
332
                        when others =>
333
                                null;
334
                end case;
335
 
336
 
337
                sel_lmux <= "000";              -- log
338
 
339
                if ir(7 downto 2)="000111" then                         -- ushr, shl, shr
340
                        sel_lmux <= "001";
341
                end if;
342
 
343
                if ir(7 downto 5)="101" then                            -- ldm
344
                        sel_lmux <= "010";
345
                end if;
346
                if ir(7 downto 5)="110" then                            -- ldi
347
                        sel_lmux <= "010";
348
                end if;
349
 
350
                if ir(7 downto 3)="11101" then                          -- ld, ldn, ldmi
351
                        sel_lmux <= "010";
352
                end if;
353
 
354
                if ir(7 downto 2)="111101" then                         -- ld_opd_x
355
                        sel_lmux <= "011";
356
                end if;
357
 
358
                if ir(7 downto 3)="11100" then                          -- ld io
359
                        sel_lmux <= "100";
360
                end if;
361
 
362
                if ir(7 downto 2)="111100" then                         -- ldsp, ldvp, ldjpc
363
                        sel_lmux <= "101";
364
                end if;
365
 
366
                                                                        -- default 'pop'
367
                sel_bmux <= '1';                        -- mem
368
                sel_mmux <= '0';                 -- a
369
                if (ir(7)='1') then             -- 'push' and 'no stack change'
370
                        sel_bmux <= '0';         -- a
371
                        sel_mmux <= '1';                -- b
372
                end if;
373
 
374
                ena_b <= '1';
375
                if (ir(7 downto 5)="100") then  -- 'no stack change' (nop, jbr)
376
                        ena_b <= '0';
377
                end if;
378
 
379
                sel_rmux <= ir(1 downto 0);                      -- ldsp, ldvp, ldjpc
380
 
381
        end if;
382
end process;
383
 
384
end rtl;

powered by: WebSVN 2.1.0

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