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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_cpu.vhdl] - Blame information for rev 96

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

Line No. Rev Author Line
1 2 ja_rd
--------------------------------------------------------------------------------
2
-- ion_cpu.vhdl -- MIPS-I(tm) compatible CPU core
3
--------------------------------------------------------------------------------
4
-- project:       ION (http://www.opencores.org/project,ion_cpu)
5
-- author:        Jose A. Ruiz (ja_rd@hotmail.com)
6
-- created:       Jan/11/2011
7 96 ja_rd
-- last modified: Mar/03/2011 (ja_rd@hotmail.com)
8 2 ja_rd
--------------------------------------------------------------------------------
9
-- Software placed into the public domain by the author. Use under the terms of
10
-- the GPL.
11
-- Software 'as is' without warranty.  Author liable for nothing.
12
--
13
--------------------------------------------------------------------------------
14
--### MIPS-I things not implemented
15 28 ja_rd
--  # Invalid instruction trapping:
16 30 ja_rd
--      * invalid opcodes do trap but the logic that prevents bad opcodes from
17
--        having side affects has not been tested yet.
18 2 ja_rd
--  # Kernel/user status
19 30 ja_rd
--  # RTE instruction (or ERET)
20 2 ja_rd
--  # Most of the CP0 registers and of course all of the CP1
21
--  # External interrupts
22
--
23
--### Things implemented but not tested
24 62 ja_rd
--  # Memory pause input -- only tested with stub cache
25 2 ja_rd
--
26
--### Things with provisional implementation
27
-- 
28
-- 1.- Load interlocks: the pipeline is stalled for every load instruction, even
29
--     if the target register is not used in the following instruction. So that
30
--     every load takes two cycles.
31
--     The interlock logic should check register indices.
32
--
33
--------------------------------------------------------------------------------
34
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.std_logic_arith.all;
38
use ieee.std_logic_unsigned.all;
39
use work.mips_pkg.all;
40
 
41
entity mips_cpu is
42
    generic(
43 62 ja_rd
        -- Reset vector address minus 4
44
        RESET_VECTOR_M4 : t_word    := RESET_VECTOR_M4;
45
        -- Trap vector address
46
        TRAP_VECTOR : t_word        := TRAP_VECTOR;
47
        -- Type of memory to be used for register bank in xilinx HW
48
        XILINX_REGBANK  : string    := "distributed" -- {distributed|block}
49 2 ja_rd
    );
50
    port(
51
        clk             : in std_logic;
52
        reset           : in std_logic;
53
        interrupt       : in std_logic;
54
 
55 96 ja_rd
        data_addr       : out std_logic_vector(31 downto 0);
56
 
57 2 ja_rd
        data_rd         : in std_logic_vector(31 downto 0);
58
        data_rd_vma     : out std_logic;
59 96 ja_rd
 
60
        byte_we         : out std_logic_vector(3 downto 0);
61
        data_wr         : out std_logic_vector(31 downto 0);
62 2 ja_rd
 
63
        code_rd_addr    : out std_logic_vector(31 downto 2);
64
        code_rd         : in std_logic_vector(31 downto 0);
65
        code_rd_vma     : out std_logic;
66 96 ja_rd
 
67 2 ja_rd
        mem_wait        : in std_logic
68
    );
69
end; --entity mips_cpu
70
 
71
architecture rtl of mips_cpu is
72
 
73
--------------------------------------------------------------------------------
74
-- Pipeline stage 0
75
 
76
signal p0_pc_reg :          t_pc;
77 8 ja_rd
signal p0_pc_restart :      t_pc;
78 2 ja_rd
signal p0_pc_incremented :  t_pc;
79
signal p0_pc_jump :         t_pc;
80
signal p0_pc_branch :       t_pc;
81
signal p0_pc_target :       t_pc;
82
signal p0_pc_next :         t_pc;
83
signal p0_rs_num :          t_regnum;
84
signal p0_rt_num :          t_regnum;
85
signal p0_jump_cond_value : std_logic;
86
signal p0_rbank_rs_hazard : std_logic;
87
signal p0_rbank_rt_hazard : std_logic;
88 28 ja_rd
signal p0_uses_rs1 :        std_logic;
89
signal p0_uses_rs2 :        std_logic;
90 2 ja_rd
 
91 28 ja_rd
signal p1_rs1_hazard :      std_logic;
92
signal p1_rs2_hazard :      std_logic;
93
 
94 2 ja_rd
--------------------------------------------------------------------------------
95
-- Pipeline stage 1
96
 
97
 
98
signal p1_rbank :           t_rbank := (others => X"00000000");
99
 
100
-- IMPORTANT: This attribute is used by Xilinx tools to select how to implement
101
-- the register bank. If we don't use it, by default XST would infer 2 BRAMs for
102
-- the 1024-bit 3-port reg bank, which you probably don't want.
103
-- This can take the values {distributed|block}.
104
attribute ram_style :       string;
105 30 ja_rd
attribute ram_style of p1_rbank : signal is XILINX_REGBANK;
106 2 ja_rd
 
107
signal p1_rs, p1_rt :       t_word;
108
signal p1_rs_rbank :        t_word;
109
signal p1_rt_rbank :        t_word;
110
signal p1_rbank_forward :   t_word;
111
signal p1_rd_num :          t_regnum;
112 28 ja_rd
signal p1_c0_rs_num :       t_regnum;
113 2 ja_rd
signal p1_rbank_wr_addr :   t_regnum;
114
signal p1_rbank_we :        std_logic;
115
signal p1_rbank_wr_data :   t_word;
116
signal p1_alu_inp1 :        t_word;
117
signal p1_alu_inp2 :        t_word;
118
signal p1_alu_outp :        t_word;
119
-- ALU control inputs (shortened name for brevity in expressions)
120
signal p1_ac :              t_alu_control;
121
-- ALU flag outputs (comparison results)
122
signal p1_alu_flags :       t_alu_flags;
123
-- immediate data, sign- or zero-extended as required by IR
124
signal p1_data_imm :        t_word;
125
signal p1_branch_offset :   t_pc;
126
signal p1_branch_offset_sex:std_logic_vector(31 downto 18);
127
signal p1_rbank_rs_hazard : std_logic;
128
signal p1_rbank_rt_hazard : std_logic;
129
signal p1_jump_type_set0 :  std_logic_vector(1 downto 0);
130
signal p1_jump_type_set1 :  std_logic_vector(1 downto 0);
131
signal p1_ir_reg :          std_logic_vector(31 downto 0);
132
signal p1_ir_op :           std_logic_vector(31 downto 26);
133
signal p1_ir_fn :           std_logic_vector(5 downto 0);
134
signal p1_op_special :      std_logic;
135
signal p1_exception :       std_logic;
136
signal p1_do_reg_jump :     std_logic;
137
signal p1_do_zero_ext_imm : std_logic;
138
signal p1_set_cp0 :         std_logic;
139
signal p1_get_cp0 :         std_logic;
140
signal p1_alu_op2_sel :     std_logic_vector(1 downto 0);
141
signal p1_alu_op2_sel_set0: std_logic_vector(1 downto 0);
142
signal p1_alu_op2_sel_set1: std_logic_vector(1 downto 0);
143
signal p1_do_load :         std_logic;
144
signal p1_do_store :        std_logic;
145
signal p1_store_size :      std_logic_vector(1 downto 0);
146
signal p1_we_control :      std_logic_vector(5 downto 0);
147
signal p1_load_alu :        std_logic;
148
signal p1_load_alu_set0 :   std_logic;
149
signal p1_load_alu_set1 :   std_logic;
150
signal p1_ld_upper_hword :  std_logic;
151
signal p1_ld_upper_byte :   std_logic;
152
signal p1_ld_unsigned :     std_logic;
153
signal p1_jump_type :       std_logic_vector(1 downto 0);
154
signal p1_link :            std_logic;
155
signal p1_jump_cond_sel :   std_logic_vector(2 downto 0);
156
signal p1_data_addr :       t_addr;
157
signal p1_data_offset :     t_addr;
158
 
159 12 ja_rd
signal p1_muldiv_result :   t_word;
160
signal p1_muldiv_func :     t_mult_function;
161
signal p1_muldiv_running :  std_logic;
162
signal p1_muldiv_started :  std_logic;
163
signal p1_muldiv_stall :    std_logic;
164
 
165 23 ja_rd
signal p1_unknown_opcode :  std_logic;
166 12 ja_rd
 
167 2 ja_rd
--------------------------------------------------------------------------------
168
-- Pipeline stage 2
169
 
170 12 ja_rd
signal p2_muldiv_started :  std_logic;
171 2 ja_rd
signal p2_exception :       std_logic;
172
signal p2_rd_addr :         std_logic_vector(1 downto 0);
173
signal p2_rd_mux_control :  std_logic_vector(3 downto 0);
174
signal p2_load_target :     t_regnum;
175
signal p2_do_load :         std_logic;
176
signal p2_ld_upper_hword :  std_logic;
177
signal p2_ld_upper_byte :   std_logic;
178
signal p2_ld_unsigned :     std_logic;
179
signal p2_wback_mux_sel :   std_logic_vector(1 downto 0);
180
signal p2_data_word_rd :    t_word;
181
signal p2_data_word_ext :   std_logic;
182
 
183
--------------------------------------------------------------------------------
184
-- Global control signals 
185
 
186
signal load_interlock :     std_logic;
187
signal stall_pipeline :     std_logic;
188
-- pipeline is stalled for any reason
189
signal pipeline_stalled :   std_logic;
190 46 ja_rd
 
191
signal stalled_memwait :    std_logic;
192
signal stalled_muldiv :     std_logic;
193 2 ja_rd
-- pipeline is stalled because of a load instruction interlock
194 46 ja_rd
signal stalled_interlock :  std_logic;
195 2 ja_rd
 
196 46 ja_rd
 
197 2 ja_rd
--------------------------------------------------------------------------------
198
-- CP0 registers and signals
199
 
200
-- CP0[12]: status register 
201
signal cp0_status :         std_logic_vector(1 downto 0);
202
-- Output of CP0 register bank (only a few regs are implemented)
203
signal cp0_reg_read :       t_word;
204
-- CP0[14]: EPC register (PC value saved at exceptions)
205
signal cp0_epc :            t_pc;
206 28 ja_rd
-- CP0[13]: 'Cause' register (cause and attributes of exception)
207
signal cp0_cause :          t_word;
208
signal cp0_in_delay_slot :  std_logic;
209
signal cp0_cause_bd :       std_logic;
210
signal cp0_cause_ce :       std_logic_vector(1 downto 0);
211
signal cp0_cause_exc_code : std_logic_vector(4 downto 0);
212 2 ja_rd
 
213
begin
214
 
215
--##############################################################################
216
-- Register bank & datapath
217
 
218
-- Register indices are 'decoded' out of the instruction word BEFORE loading IR
219
p0_rs_num <= std_logic_vector(code_rd(25 downto 21));
220
with p1_ir_reg(31 downto 26) select p1_rd_num <=
221
    p1_ir_reg(15 downto 11)    when "000000",
222
    p1_ir_reg(20 downto 16)    when others;
223
 
224
p0_rt_num <= std_logic_vector(code_rd(20 downto 16)); -- also called rs2 in the docs
225
 
226
--------------------------------------------------------------------------------
227
-- Data input shifter & masker (LB,LBU,LH,LHU,LW)
228
 
229
p2_rd_mux_control <= p2_ld_upper_hword & p2_ld_upper_byte & p2_rd_addr;
230
 
231
-- Extension for unused bits will be zero or the sign (bit 7 or bit 15)
232 35 ja_rd
p2_data_word_ext <= '0'          when p2_ld_unsigned='1' else
233 83 ja_rd
                    -- LH
234
                    data_rd(31)  when p2_ld_upper_byte='1' and p2_rd_addr="00" else
235
                    data_rd(15)  when p2_ld_upper_byte='1' and p2_rd_addr="10" else
236
                    -- LB
237
                    data_rd(7)  when p2_rd_addr="11" else
238 2 ja_rd
                    data_rd(15)  when p2_rd_addr="10" else
239 83 ja_rd
                    data_rd(23)  when p2_rd_addr="01" else
240
                    data_rd(31);
241 2 ja_rd
 
242 83 ja_rd
--                    data_rd(15)  when p2_ld_upper_byte='1' else
243
--                    data_rd(7)   when p2_rd_addr="11" else
244
--                    data_rd(15)  when p2_rd_addr="10" else
245
--                    data_rd(23);
246
 
247 2 ja_rd
-- byte 0 may come from any of the 4 bytes of the input word
248
with p2_rd_mux_control select p2_data_word_rd(7 downto 0) <=
249
    data_rd(31 downto 24)        when "0000",
250
    data_rd(23 downto 16)        when "0001",
251
    data_rd(23 downto 16)        when "0100",
252
    data_rd(15 downto  8)        when "0010",
253
    data_rd( 7 downto  0)        when others;
254
 
255
-- byte 1 may come from input bytes 1 or 3 or may be extended for LB, LBU
256
with p2_rd_mux_control select p2_data_word_rd(15 downto 8) <=
257
    data_rd(31 downto 24)        when "0100",
258
    data_rd(15 downto  8)        when "0110",
259
    data_rd(15 downto  8)        when "1100",
260
    data_rd(15 downto  8)        when "1101",
261
    data_rd(15 downto  8)        when "1110",
262
    data_rd(15 downto  8)        when "1111",
263
    (others => p2_data_word_ext) when others;
264
 
265
-- bytes 2,3 come straight from input or are extended for LH,LHU
266
with p2_ld_upper_hword select p2_data_word_rd(31 downto 16) <=
267 46 ja_rd
    (others => p2_data_word_ext) when '0',
268
    data_rd(31 downto 16)        when others;
269 2 ja_rd
 
270
-- Select which data is to be written back to the reg bank and where
271
p1_rbank_wr_addr <= p1_rd_num   when p2_do_load='0' and p1_link='0' else
272
                    "11111"     when p2_do_load='0' and p1_link='1' else
273
                    p2_load_target;
274
 
275
p2_wback_mux_sel <=
276
    "00" when p2_do_load='0' and p1_get_cp0='0' and p1_link='0' else
277
    "01" when p2_do_load='1' and p1_get_cp0='0' and p1_link='0' else
278
    "10" when p2_do_load='0' and p1_get_cp0='1' and p1_link='0' else
279
    "11";
280
 
281
with (p2_wback_mux_sel) select p1_rbank_wr_data <=
282
    p1_alu_outp                when "00",
283
    p2_data_word_rd            when "01",
284
    p0_pc_incremented & "00"   when "11",
285
    cp0_reg_read               when others;
286
 
287
p1_rbank_we <= '1' when (p2_do_load='1' or p1_load_alu='1' or
288
                        p1_link='1' or p1_get_cp0='1') and
289 35 ja_rd
                        -- If target register is $zero, ignore write
290 2 ja_rd
                        p1_rbank_wr_addr/="00000" and
291 35 ja_rd
                        -- if the cache controller keeps the cpu stopped, do
292
                        -- not writeback
293
                        mem_wait='0' and
294 46 ja_rd
                        -- if stalled because of muldiv, block writeback
295
                        stalled_muldiv='0' and --@note1
296 2 ja_rd
                        -- on exception, abort next instruction (by preventing 
297
                        -- regbank writeback).
298
                        p2_exception='0'
299
                else '0';
300
 
301
-- Register bank as triple-port RAM. Should synth to 2 BRAMs unless you use
302
-- synth attributes to prevent it (see 'ram_style' attribute above) or your
303
-- FPGA has 3-port BRAMS, or has none.
304
synchronous_reg_bank:
305
process(clk)
306
begin
307
    if clk'event and clk='1' then
308 46 ja_rd
        if p1_rbank_we='1' then
309 2 ja_rd
            p1_rbank(conv_integer(p1_rbank_wr_addr)) <= p1_rbank_wr_data;
310
        end if;
311 46 ja_rd
        -- the rbank read port loads in the same conditions as the IR: don't
312
        -- update Rs or Rt if the pipeline is frozen
313
        if stall_pipeline='0' then
314
            p1_rt_rbank <= p1_rbank(conv_integer(p0_rt_num));
315
            p1_rs_rbank <= p1_rbank(conv_integer(p0_rs_num));
316
        end if;
317 2 ja_rd
    end if;
318
end process synchronous_reg_bank;
319
 
320
-- Register writeback data in case it needs to be forwarded.
321
data_forward_register:
322
process(clk)
323
begin
324
    if clk'event and clk='1' then
325
        if p1_rbank_we='1' then -- no need to check for stall cycles
326
            p1_rbank_forward <= p1_rbank_wr_data;
327
        end if;
328
    end if;
329
end process data_forward_register;
330
 
331
-- Bypass sync RAM if we're reading and writing to the same address. This saves
332
-- 1 stall cycle and fixes the data hazard.
333
p0_rbank_rs_hazard <= '1' when p1_rbank_wr_addr=p0_rs_num and p1_rbank_we='1'
334
                      else '0';
335
p0_rbank_rt_hazard <= '1' when p1_rbank_wr_addr=p0_rt_num and p1_rbank_we='1'
336
                      else '0';
337
 
338
p1_rs <= p1_rs_rbank when p1_rbank_rs_hazard='0' else p1_rbank_forward;
339
p1_rt <= p1_rt_rbank when p1_rbank_rt_hazard='0' else p1_rbank_forward;
340
 
341
-- Zero extension/Sign extension for instruction immediate data
342
p1_data_imm(15 downto 0)  <= p1_ir_reg(15 downto 0);
343
 
344
with p1_do_zero_ext_imm select p1_data_imm(31 downto 16) <=
345
    (others => '0')             when '1',
346
    (others => p1_ir_reg(15))   when others;
347
 
348
 
349
--------------------------------------------------------------------------------
350
-- ALU & ALU input multiplexors
351
 
352
p1_alu_inp1 <= p1_rs;
353
 
354
with p1_alu_op2_sel select p1_alu_inp2 <=
355 12 ja_rd
    p1_data_imm         when "11",
356 23 ja_rd
    p1_muldiv_result    when "01",
357
    --p1_muldiv_result    when "10", -- FIXME mux input wasted!
358 12 ja_rd
    p1_rt               when others;
359 2 ja_rd
 
360
alu_inst : entity work.mips_alu
361
    port map (
362
        clk             => clk,
363
        reset           => reset,
364
        ac              => p1_ac,
365
        flags           => p1_alu_flags,
366
 
367
        inp1            => p1_alu_inp1,
368
        inp2            => p1_alu_inp2,
369
        outp            => p1_alu_outp
370
    );
371
 
372
 
373
--------------------------------------------------------------------------------
374
-- Mul/Div block interface
375
 
376 12 ja_rd
-- Compute the mdiv block function word. If p1_muldiv_func has any value other
377
-- than MULT_NOTHING a new mdiv operation will start, truncating whatever other
378
-- operation that may have been in course.
379
-- So we encode here the function to be performed and make sure the value stays
380
-- there for only one cycle (the first ALU cycle of the mul/div instruction).
381 2 ja_rd
 
382 12 ja_rd
-- This will be '1' for all mul/div operations other than NOP...
383
p1_muldiv_func(3) <= '1' when p1_op_special='1' and
384
                              p1_ir_fn(5 downto 4)="01" and
385
                              -- ...but only if the mdiv is not already running
386
                              p2_muldiv_started = '0' and
387
                              p1_muldiv_running ='0'
388
                      else '0';
389 2 ja_rd
 
390 12 ja_rd
-- When bit(3) is zero, the rest are zeroed too. Otherwise, they come from IR
391
p1_muldiv_func(2 downto 0) <=
392
    p1_ir_fn(3) & p1_ir_fn(1 downto 0) when p1_muldiv_func(3)='1'
393
    else "000";
394 2 ja_rd
 
395 12 ja_rd
mult_div: entity work.mips_mult
396
    port map (
397
        a           => p1_rs,
398
        b           => p1_rt,
399
        c_mult      => p1_muldiv_result,
400
        pause_out   => p1_muldiv_running,
401
        mult_func   => p1_muldiv_func,
402
        clk         => clk,
403
        reset_in    => reset
404
    );
405
 
406
-- Active only for the 1st ALU cycle of any mul/div instruction
407
p1_muldiv_started <= '1' when p1_op_special='1' and
408
                              p1_ir_fn(5 downto 3)="011" and
409
                              -- 
410
                              p1_muldiv_running='0'
411
                      else '0';
412
 
413
-- Stall the pipeline to enable mdiv operation completion.
414
-- We need p2_muldiv_started to distinguish the cycle before p1_muldiv_running
415
-- is asserted and the cycle after it deasserts.
416
-- Otherwise we would reexecute the same muldiv endlessly instruction after 
417
-- deassertion of p1_muldiv_running, since the IR was stalled and still contains 
418
-- the mul opcode...
419
p1_muldiv_stall <= '1' when
420
        -- Active for the cycle immediately before p1_muldiv_running asserts
421
        -- and NOT for the cycle after it deasserts
422
        (p1_muldiv_started='1' and p2_muldiv_started='0') or
423
        -- Active until operation is complete
424
        p1_muldiv_running = '1'
425
        else '0';
426
 
427
 
428 2 ja_rd
--##############################################################################
429
-- PC register and branch logic
430
 
431
-- p0_pc_reg will not be incremented on stall cycles
432
p0_pc_incremented <= p0_pc_reg + (not stall_pipeline);
433
 
434
-- main pc mux: jump or continue
435
p0_pc_next <=
436
    p0_pc_target when
437
        -- We jump on jump instructions whose condition is met...
438 6 ja_rd
        ((p1_jump_type(1)='1' and p0_jump_cond_value='1' and
439
        -- ...except we abort any jump that follows the victim of an exception
440
          p2_exception='0') or
441
        -- We jump on exceptions too...
442 2 ja_rd
        p1_exception='1')
443 6 ja_rd
        -- ... but we only jump at all if the pipeline is not stalled
444 2 ja_rd
        and stall_pipeline='0'
445
    else p0_pc_incremented;
446
 
447
pc_register:
448
process(clk)
449
begin
450
    if clk'event and clk='1' then
451
        if reset='1' then
452 62 ja_rd
            -- reset to <vector>-4 so that 1st fetch addr is <vector>
453
            p0_pc_reg <= RESET_VECTOR_M4(31 downto 2);
454 2 ja_rd
        else
455
            -- p0_pc_reg holds the same value as external sync ram addr register
456
            p0_pc_reg <= p0_pc_next;
457 8 ja_rd
            -- p0_pc_restart = addr saved to EPC on interrupts (@note2)
458 28 ja_rd
            -- It's the addr of the instruction triggering the exception,
459
            -- except when the triggering instruction is in a delay slot. In 
460
            -- that case, this is the previous jump instruction address.
461
            -- I.e. all as per the mips-1 specs.
462 8 ja_rd
            if (p1_jump_type="00" or p0_jump_cond_value='0') then
463
                p0_pc_restart <= p0_pc_reg;
464 28 ja_rd
                -- remember if we are in a delay slot, in case there's a trap
465
                cp0_in_delay_slot <= '0'; -- NOT in a delay slot
466
            else
467
                cp0_in_delay_slot <= '1'; -- in a delay slot
468 8 ja_rd
            end if;
469 2 ja_rd
        end if;
470
    end if;
471
end process pc_register;
472
 
473 96 ja_rd
-- Common rd/wr address; lowest 2 bits are output as debugging aid only
474
data_addr <= p1_data_addr(31 downto 0);
475 2 ja_rd
 
476
-- FIXME these two need to pushed behind a register, they are glitch-prone
477
data_rd_vma <= p1_do_load and not pipeline_stalled; -- FIXME register
478 28 ja_rd
code_rd_vma <= not stall_pipeline; -- FIXME register
479 2 ja_rd
 
480
code_rd_addr <= p0_pc_next;
481
 
482
 
483
-- compute target of J/JR instructions
484
p0_pc_jump <=   p1_rs(31 downto 2) when p1_do_reg_jump='1' else
485
                p0_pc_reg(31 downto 28) & p1_ir_reg(25 downto 0);
486
 
487
-- compute target of relative branch instructions
488
p1_branch_offset_sex <= (others => p1_ir_reg(15));
489
p1_branch_offset <= p1_branch_offset_sex & p1_ir_reg(15 downto 0);
490
-- p0_pc_reg is the addr of the instruction in delay slot
491
p0_pc_branch <= p0_pc_reg + p1_branch_offset;
492
 
493
-- decide which jump target is to be used
494 62 ja_rd
p0_pc_target <=
495
    TRAP_VECTOR(31 downto 2)    when p1_exception='1' else
496
    p0_pc_jump                  when p1_jump_type(0)='1' else
497
    p0_pc_branch;
498 2 ja_rd
 
499
 
500
--##############################################################################
501
-- Instruction decoding and IR
502
 
503
instruction_register:
504
process(clk)
505
begin
506
    if clk'event and clk='1' then
507
        if reset='1' then
508
            p1_ir_reg <= (others => '0');
509
        elsif stall_pipeline='0' then
510
            p1_ir_reg <= code_rd;
511
        end if;
512
    end if;
513
end process instruction_register;
514
 
515
-- 'Extract' main fields from IR, for convenience
516
p1_ir_op <= p1_ir_reg(31 downto 26);
517
p1_ir_fn <= p1_ir_reg(5 downto 0);
518
 
519
-- Decode jump type, if any, for instructions with op/=0
520
with p1_ir_op select p1_jump_type_set0 <=
521
    -- FIXME weed out invalid instructions
522
    "10" when "000001", -- BLTZ, BGEZ, BLTZAL, BGTZAL
523
    "11" when "000010", -- J
524
    "11" when "000011", -- JAL
525
    "10" when "000100", -- BEQ
526
    "10" when "000101", -- BNE
527
    "10" when "000110", -- BLEZ
528
    "10" when "000111", -- BGTZ
529
    "00" when others;   -- no jump
530
 
531
-- Decode jump type, if any, for instructions with op=0
532
p1_jump_type_set1 <= "11" when p1_op_special='1' and
533
                               p1_ir_reg(5 downto 1)="00100"
534
                     else "00";
535
 
536
-- Decode jump type for the instruction in IR (composite of two formats)
537
p1_jump_type <= p1_jump_type_set0 or p1_jump_type_set1;
538
 
539
p1_link <= '1' when (p1_ir_op="000000" and p1_ir_reg(5 downto 0)="001001") or
540
                    (p1_ir_op="000001" and p1_ir_reg(20)='1') or
541
                    (p1_ir_op="000011")
542
           else '0';
543
 
544
-- Decode jump condition: encode a mux control signal from IR...
545
p1_jump_cond_sel <=
546
    "001" when p1_ir_op="000001" and p1_ir_reg(16)='0' else --   op1 < 0   BLTZ*
547
    "101" when p1_ir_op="000001" and p1_ir_reg(16)='1' else -- !(op1 < 0) BNLTZ*
548
    "010" when p1_ir_op="000100" else                       --   op1 == op2  BEQ
549
    "110" when p1_ir_op="000101" else                       -- !(op1 == op2) BNE
550
    "011" when p1_ir_op="000110" else                       --   op1 <= 0   BLEZ
551
    "111" when p1_ir_op="000111" else                       -- !(op1 <= 0)  BGTZ
552
    "000";                                                  -- always
553
 
554
-- ... and use mux control signal to select the condition value
555
with p1_jump_cond_sel select p0_jump_cond_value <=
556
        p1_alu_flags.inp1_lt_zero       when "001",
557
    not p1_alu_flags.inp1_lt_zero       when "101",
558
        p1_alu_flags.inp1_eq_inp2       when "010",
559
    not p1_alu_flags.inp1_eq_inp2       when "110",
560
        (p1_alu_flags.inp1_lt_inp2 or
561
         p1_alu_flags.inp1_eq_inp2)     when "011",
562
    not (p1_alu_flags.inp1_lt_inp2 or
563
         p1_alu_flags.inp1_eq_inp2)     when "111",
564
    '1'                                 when others;
565
 
566
-- Decode instructions that launch exceptions
567 23 ja_rd
p1_exception <= '1' when
568
    (p1_op_special='1' and p1_ir_reg(5 downto 1)="00110") or
569
    p1_unknown_opcode='1'
570
    else '0';
571 2 ja_rd
 
572
-- Decode MTC0/MFC0 instructions
573
p1_set_cp0 <= '1' when p1_ir_reg(31 downto 21)="01000000100" else '0';
574
p1_get_cp0 <= '1' when p1_ir_reg(31 downto 21)="01000000000" else '0';
575
 
576
-- FIXME elaborate and explain this
577
 
578
p1_op_special <= '1' when p1_ir_op="000000" else '0';
579
 
580
p1_do_reg_jump <= '1' when p1_op_special='1' and p1_ir_fn(5 downto 1)="00100" else '0';
581
p1_do_zero_ext_imm <= '1' when (p1_ir_op(31 downto 28)="0011") else '0';
582
 
583
-- Decode input data mux control (LW, LH, LB, LBU, LHU) and load enable
584 30 ja_rd
p1_do_load <= '1' when
585
    p1_ir_op(31 downto 29)="100" and
586
    p1_ir_op(28 downto 26)/="010" and -- LWL
587
    p1_ir_op(28 downto 26)/="110" and -- LWR
588
    p1_ir_op(28 downto 26)/="111" and -- LWR
589
    p2_exception='0'  -- abort load if previous instruction triggered trap
590
    else '0';
591 2 ja_rd
 
592
p1_load_alu_set0 <= '1'
593
    when p1_op_special='1' and
594
        ((p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="00") or
595
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="10") or
596
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="11") or
597
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="00") or
598
         (p1_ir_op(31 downto 28)="0100" and p1_ir_op(27 downto 26)="00") or
599
         (p1_ir_op(31 downto 28)="0100" and p1_ir_op(27 downto 26)="10") or
600
         (p1_ir_op(31 downto 28)="1000") or
601
         (p1_ir_op(31 downto 28)="1001") or
602
         (p1_ir_op(31 downto 28)="1010" and p1_ir_op(27 downto 26)="10") or
603
         (p1_ir_op(31 downto 28)="1010" and p1_ir_op(27 downto 26)="11") or
604
         (p1_ir_op(31 downto 28)="0010" and p1_ir_op(27 downto 26)="01"))
605
    else '0';
606
 
607
with p1_ir_op select p1_load_alu_set1 <=
608 28 ja_rd
    '1' when "001000",  -- addi
609
    '1' when "001001",  -- addiu
610
    '1' when "001010",  -- slti
611
    '1' when "001011",  -- sltiu
612
    '1' when "001100",  -- andi
613
    '1' when "001101",  -- ori
614
    '1' when "001110",  -- xori
615
    '1' when "001111",  -- lui
616 2 ja_rd
    '0' when others;
617 28 ja_rd
p1_load_alu <= (p1_load_alu_set0 or p1_load_alu_set1) and
618
                not p1_unknown_opcode;
619 2 ja_rd
 
620
p1_ld_upper_hword <= p1_ir_op(27); -- use input upper hword vs. sign extend/zero
621
p1_ld_upper_byte <= p1_ir_op(26);  -- use input upper byte vs. sign extend/zero
622
p1_ld_unsigned <= p1_ir_op(28);    -- sign extend vs. zero extend
623
 
624
-- ALU input-2 selection: use external data for 2x opcodes (loads)
625
p1_alu_op2_sel_set0 <=
626
    "11" when    p1_ir_op(31 downto 30)="10" or p1_ir_op(29)='1' else
627
    "00";
628
 
629
-- ALU input-2 selection: use registers Hi and Lo for MFHI, MFLO
630 22 ja_rd
p1_alu_op2_sel_set1 <=
631
    "01" when p1_op_special='1' and (p1_ir_fn="010000" or p1_ir_fn="010010")
632
    else "00";
633 2 ja_rd
 
634
-- ALU input-2 final selection
635
p1_alu_op2_sel <= p1_alu_op2_sel_set0 or p1_alu_op2_sel_set1;
636
 
637
-- Decode store operations
638 30 ja_rd
p1_do_store <= '1' when
639
    p1_ir_op(31 downto 29)="101" and
640
    (p1_ir_op(28 downto 26)="000" or -- SB
641
     p1_ir_op(28 downto 26)="001" or -- SH
642
     p1_ir_op(28 downto 26)="011") and -- SWH
643 28 ja_rd
    p2_exception='0'    -- abort when previous instruction triggered exception
644
    else '0';
645 2 ja_rd
p1_store_size <= p1_ir_op(27 downto 26);
646
 
647
 
648 28 ja_rd
-- Extract source and destination C0 register indices
649
p1_c0_rs_num <= p1_ir_reg(15 downto 11);
650 2 ja_rd
 
651
-- Decode ALU control dignals
652
 
653
p1_ac.use_slt <= '1' when (p1_ir_op="000001" and p1_ir_reg(20 downto 17)="01000") or
654
                        (p1_ir_op="000000" and p1_ir_reg(5 downto 1)="10101") or
655
                        p1_ir_op="001010" or p1_ir_op="001011"
656
               else '0';
657 83 ja_rd
p1_ac.arith_unsigned <= p1_ac.use_slt and (p1_ir_reg(0) or p1_ir_op(26));
658 2 ja_rd
 
659
p1_ac.use_logic(0) <= '1' when (p1_op_special='1' and p1_ir_fn(5 downto 3)/="000") or
660
                    -- all immediate arith and logic
661
                    p1_ir_op(31 downto 29)="001"
662
                 else '0';
663
p1_ac.use_logic(1) <= '1' when (p1_op_special='1' and p1_ir_fn="100111") else '0';
664
 
665
p1_ac.use_arith <= '1' when p1_ir_op(31 downto 28)="0010" or
666
                            (p1_op_special='1' and
667
                                (p1_ir_fn(5 downto 2)="1000" or
668
                                p1_ir_fn(5 downto 2)="1010"))
669
                 else '0';
670
 
671
-- selection of 2nd internal alu operand: {i2, /i2, i2<<16, 0x0}
672
p1_ac.neg_sel(1)<= '1' when p1_ir_op(29 downto 26) = "1111" else '0';
673
p1_ac.neg_sel(0)<= '1' when   p1_ir_op="001010" or
674
                            p1_ir_op="001011" or
675
                            p1_ir_op(31 downto 28)="0001" or
676
                            (p1_op_special='1' and
677
                                (p1_ir_fn="100010" or
678
                                 p1_ir_fn="100011" or
679
                                 p1_ir_fn(5 downto 2)="1010"))
680
                 else '0';
681
p1_ac.cy_in <= p1_ac.neg_sel(0);
682
 
683
p1_ac.shift_sel <= p1_ir_fn(1 downto 0);
684
 
685
p1_ac.logic_sel <= "00" when (p1_op_special='1' and p1_ir_fn="100100") else
686
                 "01" when (p1_op_special='1' and p1_ir_fn="100101") else
687
                 "10" when (p1_op_special='1' and p1_ir_fn="100110") else
688
                 "01" when (p1_op_special='1' and p1_ir_fn="100111") else
689
                 "00" when (p1_ir_op="001100") else
690
                 "01" when (p1_ir_op="001101") else
691
                 "10" when (p1_ir_op="001110") else
692
                 "11";
693
 
694
p1_ac.shift_amount <= p1_ir_reg(10 downto 6) when p1_ir_fn(2)='0' else p1_rs(4 downto 0);
695
 
696 23 ja_rd
 
697 2 ja_rd
--------------------------------------------------------------------------------
698 23 ja_rd
-- Decoding of unimplemented and privileged instructions
699 2 ja_rd
 
700 23 ja_rd
-- Unimplemented instructions include:
701
--  1.- All instructions above architecture MIPS-I except:
702
--      1.1.- eret
703
--  2.- Unaligned stores and loads (LWL,LWR,SWL,SWR)
704
--  3.- All CP0 instructions other than mfc0 and mtc0
705
--  4.- All CPi instructions
706
--  5.- All cache instructions
707
-- For the time being, we'll decode them all together.
708
 
709
-- FIXME: some of these should trap but others should just NOP (e.g. EHB)
710
 
711
p1_unknown_opcode <= '1' when
712
    -- decode by 'opcode' field
713
    p1_ir_op(31 downto 29)="011" or
714
    p1_ir_op(31 downto 29)="110" or
715
    p1_ir_op(31 downto 29)="111" or
716
    (p1_ir_op(31 downto 29)="010" and p1_ir_op(28 downto 26)/="000") or
717
    p1_ir_op="101111" or    -- CACHE
718
    p1_ir_op="100010" or    -- LWL
719
    p1_ir_op="100110" or    -- LWR
720
    p1_ir_op="101010" or    -- SWL
721
    p1_ir_op="101110" or    -- SWR
722
    p1_ir_op="100111" or
723
    p1_ir_op="101100" or
724
    p1_ir_op="101101" or
725
    -- decode instructions in the 'special' opcode group
726
    (p1_ir_op="000000" and
727
                (p1_ir_fn(5 downto 4)="11" or
728
                 p1_ir_fn="000001" or
729
                 p1_ir_fn="000101" or
730
                 p1_ir_fn="001010" or
731
                 p1_ir_fn="001011" or
732
                 p1_ir_fn="001110" or
733
                 p1_ir_fn(5 downto 2)="0101" or
734
                 p1_ir_fn(5 downto 2)="0111" or
735
                 p1_ir_fn(5 downto 2)="1011")) or
736
    -- decode instructions in the 'regimm' opcode group
737
    (p1_ir_op="000001" and
738
                (p1_ir_reg(20 downto 16)/="00000" and -- BLTZ is valid
739
                 p1_ir_reg(20 downto 16)/="00001" and -- BGEZ is valid
740
                 p1_ir_reg(20 downto 16)/="10000" and -- BLTZAL is valid 
741
                 p1_ir_reg(20 downto 16)/="10001")) -- BGEZAL is valid
742
 
743
    else '0';
744
 
745
--------------------------------------------------------------------------------
746
 
747 2 ja_rd
-- Stage 1 pipeline register. Involved in ALU control.
748
pipeline_stage1_register:
749
process(clk)
750
begin
751
    if clk'event and clk='1' then
752
        if reset='1' then
753
            p1_rbank_rs_hazard <= '0';
754
            p1_rbank_rt_hazard <= '0';
755
        elsif stall_pipeline='0' then
756
            p1_rbank_rs_hazard <= p0_rbank_rs_hazard;
757
            p1_rbank_rt_hazard <= p0_rbank_rt_hazard;
758
        end if;
759
    end if;
760
end process pipeline_stage1_register;
761
 
762 12 ja_rd
pipeline_stage1_register2:
763
process(clk)
764
begin
765
    if clk'event and clk='1' then
766
        if reset='1' then
767
            p2_muldiv_started <= '0';
768
        else
769
            p2_muldiv_started <= p1_muldiv_running;
770
        end if;
771
    end if;
772
end process pipeline_stage1_register2;
773 6 ja_rd
 
774 12 ja_rd
 
775 6 ja_rd
-- Stage 2 pipeline register. Split in two for convenience.
776 2 ja_rd
-- This register deals with two kinds of stalls:
777
-- * When the pipeline stalls because of a load interlock, this register is 
778
--   allowed to update so that the load operation can complete while the rest of
779
--   the pipeline is frozen.
780
-- * When the stall is caused by any other reason, this register freezes with 
781
--   the rest of the machine.
782 6 ja_rd
 
783
-- Part of stage 2 register that controls load operation
784
pipeline_stage2_register_load_control:
785 2 ja_rd
process(clk)
786
begin
787
    if clk'event and clk='1' then
788 6 ja_rd
        -- Clear load control, effectively preventing load, at reset or if
789
        -- the previous instruction raised an exception.
790
        if reset='1' or p2_exception='1' then
791 2 ja_rd
            p2_do_load <= '0';
792
            p2_ld_upper_hword <= '0';
793
            p2_ld_upper_byte <= '0';
794
            p2_ld_unsigned <= '0';
795
            p2_load_target <= "00000";
796 6 ja_rd
 
797
        -- Load signals from previous stage only if there is no pipeline stall
798
        -- unless the stall is caused by interlock (@note1).
799
        elsif (stall_pipeline='0' or load_interlock='1') then
800
            -- Disable reg bank writeback if pipeline is stalled; this prevents
801
            -- duplicate writes in case the stall is a mem_wait.
802 2 ja_rd
            if pipeline_stalled='0' then
803
                p2_do_load <= p1_do_load;
804
            else
805
                p2_do_load <= '0';
806
            end if;
807
            p2_load_target <= p1_rd_num;
808
            p2_ld_upper_hword <= p1_ld_upper_hword;
809
            p2_ld_upper_byte <= p1_ld_upper_byte;
810
            p2_ld_unsigned <= p1_ld_unsigned;
811 6 ja_rd
        end if;
812
    end if;
813
end process pipeline_stage2_register_load_control;
814
 
815
-- All the rest of the stage 2 register
816
pipeline_stage2_register_others:
817
process(clk)
818
begin
819
    if clk'event and clk='1' then
820
        if reset='1' then
821
            p2_exception <= '0';
822
 
823
        -- Load signals from previous stage only if there is no pipeline stall
824
        -- unless the stall is caused by interlock (@note1).
825
        elsif (stall_pipeline='0' or load_interlock='1') then
826 2 ja_rd
            p2_rd_addr <= p1_data_addr(1 downto 0);
827 6 ja_rd
            p2_exception <= p1_exception;
828 2 ja_rd
        end if;
829
    end if;
830 6 ja_rd
end process pipeline_stage2_register_others;
831 2 ja_rd
 
832
--------------------------------------------------------------------------------
833
 
834
-- FIXME stall when needed: mem pause, mdiv pause and load interlock
835
 
836 46 ja_rd
 
837
-- FIXME make sure this combinational will not have bad glitches
838
stall_pipeline <= mem_wait or load_interlock or p1_muldiv_stall;
839
 
840
 
841
-- FIXME load interlock should happen only if the instruction following 
842
-- the load actually uses the load target register. Something like this:
843
-- (p1_do_load='1' and (p1_rd_num=p0_rs_num or p1_rd_num=p0_rt_num))
844
load_interlock <= '1' when
845
    p1_do_load='1' and      -- this is a load instruction
846
    pipeline_stalled='0' and -- not already stalled (i.e. assert for 1 cycle)
847
    (p1_rs1_hazard='1' or p1_rs2_hazard='1')
848
    else '0';
849
 
850
 
851
 
852
 
853
pipeline_stalled <= stalled_interlock or stalled_memwait or stalled_muldiv;
854
 
855 2 ja_rd
pipeline_stall_registers:
856
process(clk)
857
begin
858
    if clk'event and clk='1' then
859
        if reset='1' then
860 46 ja_rd
            stalled_interlock <= '0';
861
            stalled_memwait <= '0';
862
            stalled_muldiv <= '0';
863 2 ja_rd
        else
864 46 ja_rd
            if mem_wait='1' then
865
                stalled_memwait <= '1';
866 2 ja_rd
            else
867 46 ja_rd
                stalled_memwait <= '0';
868 2 ja_rd
            end if;
869 35 ja_rd
 
870 46 ja_rd
            if p1_muldiv_stall='1' then
871
                stalled_muldiv <= '1';
872
            else
873
                stalled_muldiv <= '0';
874
            end if;
875
 
876 35 ja_rd
            -- stalls caused by mem_wait and load_interlock are independent and
877
            -- must not overlap; so when mem_wait='1' the cache stall takes
878
            -- precedence and the loa interlock must wait.
879
            if mem_wait='0' then
880
                if load_interlock='1' then
881 46 ja_rd
                    stalled_interlock <= '1';
882 35 ja_rd
                else
883 46 ja_rd
                    stalled_interlock <= '0';
884 35 ja_rd
                end if;
885 2 ja_rd
            end if;
886
        end if;
887
    end if;
888
end process pipeline_stall_registers;
889
 
890 28 ja_rd
p1_rs1_hazard <= '1'; --'1' when p0_uses_rs1='1' and p1_rd_num=p0_rs_num else '0';
891
p1_rs2_hazard <= '1'; --'1' when p0_uses_rs2='1' and p1_rd_num=p0_rt_num else '0';
892
 
893
with p1_ir_op select p0_uses_rs1 <=
894
    '0' when "000010",
895
    '0' when "000011",
896
    '0' when "001111",
897
    '0' when "001000",
898
    '1' when others;
899
 
900
with p1_ir_op select p0_uses_rs2 <=
901
    '1' when "000000",
902
    '1' when "000100",
903
    '1' when "000101",
904
    '1' when "000110",
905
    '1' when "000111",
906
    '1' when "010000",
907
    '1' when "101000",
908
    '1' when "101001",
909
    '1' when "101010",
910
    '1' when "101011",
911
    '1' when "101110",
912
    '0' when others;
913
 
914
 
915 2 ja_rd
--------------------------------------------------------------------------------
916
 
917
p1_data_offset(31 downto 16) <= (others => p1_data_imm(15));
918
p1_data_offset(15 downto 0) <= p1_data_imm(15 downto 0);
919
 
920
p1_data_addr <= p1_rs + p1_data_offset;
921
 
922
--------------------------------------------------------------------------------
923
 
924
-- byte_we is a function of the write size and alignment
925
-- size = {00=1,01=2,11=4}; we 3 is MSB, 0 is LSB; big endian => 00 is msb
926
p1_we_control <= pipeline_stalled & p1_do_store & p1_store_size & p1_data_addr(1 downto 0);
927
 
928
with p1_we_control select byte_we <=
929
    "1000"  when "010000",    -- SB %0
930
    "0100"  when "010001",    -- SB %1
931
    "0010"  when "010010",    -- SB %2
932
    "0001"  when "010011",    -- SB %3
933
    "1100"  when "010100",    -- SH %0
934
    "0011"  when "010110",    -- SH %2
935
    "1111"  when "011100",    -- SW %4
936
    "0000"  when others; -- all other combinations are spurious so don't write
937
 
938
-- Data to be stored always comes straight from the reg bank, but it needs to 
939
-- be shifted so that the LSB is aligned to the write address:
940
 
941
data_wr(7 downto 0) <= p1_rt(7 downto 0);
942
 
943
with p1_we_control select data_wr(15 downto 8) <=
944
    p1_rt( 7 downto  0) when "010010",  -- SB %2
945
    p1_rt(15 downto  8) when others;
946
 
947
with p1_we_control select data_wr(23 downto 16) <=
948
    p1_rt( 7 downto  0) when "010001",  -- SB %1
949
    p1_rt( 7 downto  0) when "010100",  -- SH %0
950
    p1_rt(23 downto 16) when others;
951
 
952
with p1_we_control select data_wr(31 downto 24) <=
953
    p1_rt( 7 downto  0) when "010000",  -- SB %0
954
    p1_rt(15 downto  8) when "010100",  -- SH %0
955
    p1_rt(31 downto 24) when others;
956
 
957
 
958
--##############################################################################
959
-- CP0 (what little is implemented of it)
960
 
961
process(clk)
962
begin
963
    if clk'event and clk='1' then
964
        if reset='1' then
965
            -- "10" => mode=kernel; ints=disabled
966
            cp0_status <= "10";
967 28 ja_rd
            cp0_cause_exc_code <= "00000";
968
            cp0_cause_bd <= '0';
969 2 ja_rd
        else
970
            -- no need to check for stall cycles when loading these
971
            if p1_set_cp0='1' then
972
                -- FIXME check for CP0 reg index
973
                cp0_status <= p1_rs(cp0_status'high downto 0);
974
            end if;
975 62 ja_rd
            if p1_exception='1' and pipeline_stalled='0' then
976 8 ja_rd
                cp0_epc <= p0_pc_restart;
977 28 ja_rd
 
978
                if p1_unknown_opcode='1' then
979
                    cp0_cause_exc_code <= "01010"; -- bad opcode
980
                else
981
                    if p1_ir_fn(0)='0' then
982
                        cp0_cause_exc_code <= "01000"; -- syscall
983
                    else
984
                        cp0_cause_exc_code <= "01001"; -- break
985
                    end if;
986
                end if;
987
 
988
                cp0_cause_bd <= cp0_in_delay_slot;
989 2 ja_rd
            end if;
990
        end if;
991
    end if;
992
end process;
993
 
994 28 ja_rd
cp0_cause_ce <= "00"; -- FIXME CP* traps merged with unimplemented opcode traps
995
cp0_cause <= cp0_cause_bd & '0' & cp0_cause_ce &
996
             X"00000" & "000" &
997
             cp0_cause_exc_code;
998
 
999 2 ja_rd
-- FIXME the mux should mask to zero for any unused reg index
1000 28 ja_rd
with p1_c0_rs_num select cp0_reg_read <=
1001
    X"0000000" & "00" & cp0_status  when "01100",
1002
    cp0_cause                       when "01101",
1003
    cp0_epc & "00"                  when others;
1004 2 ja_rd
 
1005 28 ja_rd
 
1006 2 ja_rd
end architecture rtl;
1007
 
1008
--------------------------------------------------------------------------------
1009
-- Implementation notes
1010
--------------------------------------------------------------------------------
1011
-- @note1 : 
1012
--
1013
-- This is the meaning of these two signals:
1014 46 ja_rd
-- pipeline_stalled & stalled_interlock =>
1015 2 ja_rd
--  "00" => normal state
1016
--  "01" => normal state (makes for easier decoding)
1017
--  "10" => all stages of pipeline stalled, including rbank
1018
--  "11" => all stages of pipeline stalled, except reg bank write port
1019
-- 
1020
-- Just to clarify, 'stage X stalled' here means that the registers named 
1021
-- pX_* don't load.
1022
--
1023
-- The register bank WE is enabled when the pipeline is not stalled and when 
1024
-- it is stalled because of a load interlock; so that in case of interlock the
1025
-- load operation can complete while the rest of the pipeline is frozen.
1026
--------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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