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

Subversion Repositories ion

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

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 30 ja_rd
-- last modified: Jan/31/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
        data_rd_addr    : out std_logic_vector(31 downto 0);
56
        data_rd         : in std_logic_vector(31 downto 0);
57
        data_rd_vma     : out std_logic;
58
 
59
        code_rd_addr    : out std_logic_vector(31 downto 2);
60
        code_rd         : in std_logic_vector(31 downto 0);
61
        code_rd_vma     : out std_logic;
62
 
63
        data_wr_addr    : out std_logic_vector(31 downto 2);
64
        byte_we         : out std_logic_vector(3 downto 0);
65
        data_wr         : out std_logic_vector(31 downto 0);
66 28 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 35 ja_rd
-- FIXME we should not output the lowest 2 bits
474 2 ja_rd
data_rd_addr <= p1_data_addr(31 downto 0);
475
 
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
data_wr_addr <= p1_data_addr(31 downto 2);
483
 
484
-- compute target of J/JR instructions
485
p0_pc_jump <=   p1_rs(31 downto 2) when p1_do_reg_jump='1' else
486
                p0_pc_reg(31 downto 28) & p1_ir_reg(25 downto 0);
487
 
488
-- compute target of relative branch instructions
489
p1_branch_offset_sex <= (others => p1_ir_reg(15));
490
p1_branch_offset <= p1_branch_offset_sex & p1_ir_reg(15 downto 0);
491
-- p0_pc_reg is the addr of the instruction in delay slot
492
p0_pc_branch <= p0_pc_reg + p1_branch_offset;
493
 
494
-- decide which jump target is to be used
495 62 ja_rd
p0_pc_target <=
496
    TRAP_VECTOR(31 downto 2)    when p1_exception='1' else
497
    p0_pc_jump                  when p1_jump_type(0)='1' else
498
    p0_pc_branch;
499 2 ja_rd
 
500
 
501
--##############################################################################
502
-- Instruction decoding and IR
503
 
504
instruction_register:
505
process(clk)
506
begin
507
    if clk'event and clk='1' then
508
        if reset='1' then
509
            p1_ir_reg <= (others => '0');
510
        elsif stall_pipeline='0' then
511
            p1_ir_reg <= code_rd;
512
        end if;
513
    end if;
514
end process instruction_register;
515
 
516
-- 'Extract' main fields from IR, for convenience
517
p1_ir_op <= p1_ir_reg(31 downto 26);
518
p1_ir_fn <= p1_ir_reg(5 downto 0);
519
 
520
-- Decode jump type, if any, for instructions with op/=0
521
with p1_ir_op select p1_jump_type_set0 <=
522
    -- FIXME weed out invalid instructions
523
    "10" when "000001", -- BLTZ, BGEZ, BLTZAL, BGTZAL
524
    "11" when "000010", -- J
525
    "11" when "000011", -- JAL
526
    "10" when "000100", -- BEQ
527
    "10" when "000101", -- BNE
528
    "10" when "000110", -- BLEZ
529
    "10" when "000111", -- BGTZ
530
    "00" when others;   -- no jump
531
 
532
-- Decode jump type, if any, for instructions with op=0
533
p1_jump_type_set1 <= "11" when p1_op_special='1' and
534
                               p1_ir_reg(5 downto 1)="00100"
535
                     else "00";
536
 
537
-- Decode jump type for the instruction in IR (composite of two formats)
538
p1_jump_type <= p1_jump_type_set0 or p1_jump_type_set1;
539
 
540
p1_link <= '1' when (p1_ir_op="000000" and p1_ir_reg(5 downto 0)="001001") or
541
                    (p1_ir_op="000001" and p1_ir_reg(20)='1') or
542
                    (p1_ir_op="000011")
543
           else '0';
544
 
545
-- Decode jump condition: encode a mux control signal from IR...
546
p1_jump_cond_sel <=
547
    "001" when p1_ir_op="000001" and p1_ir_reg(16)='0' else --   op1 < 0   BLTZ*
548
    "101" when p1_ir_op="000001" and p1_ir_reg(16)='1' else -- !(op1 < 0) BNLTZ*
549
    "010" when p1_ir_op="000100" else                       --   op1 == op2  BEQ
550
    "110" when p1_ir_op="000101" else                       -- !(op1 == op2) BNE
551
    "011" when p1_ir_op="000110" else                       --   op1 <= 0   BLEZ
552
    "111" when p1_ir_op="000111" else                       -- !(op1 <= 0)  BGTZ
553
    "000";                                                  -- always
554
 
555
-- ... and use mux control signal to select the condition value
556
with p1_jump_cond_sel select p0_jump_cond_value <=
557
        p1_alu_flags.inp1_lt_zero       when "001",
558
    not p1_alu_flags.inp1_lt_zero       when "101",
559
        p1_alu_flags.inp1_eq_inp2       when "010",
560
    not p1_alu_flags.inp1_eq_inp2       when "110",
561
        (p1_alu_flags.inp1_lt_inp2 or
562
         p1_alu_flags.inp1_eq_inp2)     when "011",
563
    not (p1_alu_flags.inp1_lt_inp2 or
564
         p1_alu_flags.inp1_eq_inp2)     when "111",
565
    '1'                                 when others;
566
 
567
-- Decode instructions that launch exceptions
568 23 ja_rd
p1_exception <= '1' when
569
    (p1_op_special='1' and p1_ir_reg(5 downto 1)="00110") or
570
    p1_unknown_opcode='1'
571
    else '0';
572 2 ja_rd
 
573
-- Decode MTC0/MFC0 instructions
574
p1_set_cp0 <= '1' when p1_ir_reg(31 downto 21)="01000000100" else '0';
575
p1_get_cp0 <= '1' when p1_ir_reg(31 downto 21)="01000000000" else '0';
576
 
577
-- FIXME elaborate and explain this
578
 
579
p1_op_special <= '1' when p1_ir_op="000000" else '0';
580
 
581
p1_do_reg_jump <= '1' when p1_op_special='1' and p1_ir_fn(5 downto 1)="00100" else '0';
582
p1_do_zero_ext_imm <= '1' when (p1_ir_op(31 downto 28)="0011") else '0';
583
 
584
-- Decode input data mux control (LW, LH, LB, LBU, LHU) and load enable
585 30 ja_rd
p1_do_load <= '1' when
586
    p1_ir_op(31 downto 29)="100" and
587
    p1_ir_op(28 downto 26)/="010" and -- LWL
588
    p1_ir_op(28 downto 26)/="110" and -- LWR
589
    p1_ir_op(28 downto 26)/="111" and -- LWR
590
    p2_exception='0'  -- abort load if previous instruction triggered trap
591
    else '0';
592 2 ja_rd
 
593
p1_load_alu_set0 <= '1'
594
    when p1_op_special='1' and
595
        ((p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="00") or
596
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="10") or
597
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="11") or
598
         (p1_ir_op(31 downto 29)="000" and p1_ir_op(27 downto 26)="00") or
599
         (p1_ir_op(31 downto 28)="0100" and p1_ir_op(27 downto 26)="00") or
600
         (p1_ir_op(31 downto 28)="0100" and p1_ir_op(27 downto 26)="10") or
601
         (p1_ir_op(31 downto 28)="1000") or
602
         (p1_ir_op(31 downto 28)="1001") or
603
         (p1_ir_op(31 downto 28)="1010" and p1_ir_op(27 downto 26)="10") or
604
         (p1_ir_op(31 downto 28)="1010" and p1_ir_op(27 downto 26)="11") or
605
         (p1_ir_op(31 downto 28)="0010" and p1_ir_op(27 downto 26)="01"))
606
    else '0';
607
 
608
with p1_ir_op select p1_load_alu_set1 <=
609 28 ja_rd
    '1' when "001000",  -- addi
610
    '1' when "001001",  -- addiu
611
    '1' when "001010",  -- slti
612
    '1' when "001011",  -- sltiu
613
    '1' when "001100",  -- andi
614
    '1' when "001101",  -- ori
615
    '1' when "001110",  -- xori
616
    '1' when "001111",  -- lui
617 2 ja_rd
    '0' when others;
618 28 ja_rd
p1_load_alu <= (p1_load_alu_set0 or p1_load_alu_set1) and
619
                not p1_unknown_opcode;
620 2 ja_rd
 
621
p1_ld_upper_hword <= p1_ir_op(27); -- use input upper hword vs. sign extend/zero
622
p1_ld_upper_byte <= p1_ir_op(26);  -- use input upper byte vs. sign extend/zero
623
p1_ld_unsigned <= p1_ir_op(28);    -- sign extend vs. zero extend
624
 
625
-- ALU input-2 selection: use external data for 2x opcodes (loads)
626
p1_alu_op2_sel_set0 <=
627
    "11" when    p1_ir_op(31 downto 30)="10" or p1_ir_op(29)='1' else
628
    "00";
629
 
630
-- ALU input-2 selection: use registers Hi and Lo for MFHI, MFLO
631 22 ja_rd
p1_alu_op2_sel_set1 <=
632
    "01" when p1_op_special='1' and (p1_ir_fn="010000" or p1_ir_fn="010010")
633
    else "00";
634 2 ja_rd
 
635
-- ALU input-2 final selection
636
p1_alu_op2_sel <= p1_alu_op2_sel_set0 or p1_alu_op2_sel_set1;
637
 
638
-- Decode store operations
639 30 ja_rd
p1_do_store <= '1' when
640
    p1_ir_op(31 downto 29)="101" and
641
    (p1_ir_op(28 downto 26)="000" or -- SB
642
     p1_ir_op(28 downto 26)="001" or -- SH
643
     p1_ir_op(28 downto 26)="011") and -- SWH
644 28 ja_rd
    p2_exception='0'    -- abort when previous instruction triggered exception
645
    else '0';
646 2 ja_rd
p1_store_size <= p1_ir_op(27 downto 26);
647
 
648
 
649 28 ja_rd
-- Extract source and destination C0 register indices
650
p1_c0_rs_num <= p1_ir_reg(15 downto 11);
651 2 ja_rd
 
652
-- Decode ALU control dignals
653
 
654
p1_ac.use_slt <= '1' when (p1_ir_op="000001" and p1_ir_reg(20 downto 17)="01000") or
655
                        (p1_ir_op="000000" and p1_ir_reg(5 downto 1)="10101") or
656
                        p1_ir_op="001010" or p1_ir_op="001011"
657
               else '0';
658 83 ja_rd
p1_ac.arith_unsigned <= p1_ac.use_slt and (p1_ir_reg(0) or p1_ir_op(26));
659 2 ja_rd
 
660
p1_ac.use_logic(0) <= '1' when (p1_op_special='1' and p1_ir_fn(5 downto 3)/="000") or
661
                    -- all immediate arith and logic
662
                    p1_ir_op(31 downto 29)="001"
663
                 else '0';
664
p1_ac.use_logic(1) <= '1' when (p1_op_special='1' and p1_ir_fn="100111") else '0';
665
 
666
p1_ac.use_arith <= '1' when p1_ir_op(31 downto 28)="0010" or
667
                            (p1_op_special='1' and
668
                                (p1_ir_fn(5 downto 2)="1000" or
669
                                p1_ir_fn(5 downto 2)="1010"))
670
                 else '0';
671
 
672
-- selection of 2nd internal alu operand: {i2, /i2, i2<<16, 0x0}
673
p1_ac.neg_sel(1)<= '1' when p1_ir_op(29 downto 26) = "1111" else '0';
674
p1_ac.neg_sel(0)<= '1' when   p1_ir_op="001010" or
675
                            p1_ir_op="001011" or
676
                            p1_ir_op(31 downto 28)="0001" or
677
                            (p1_op_special='1' and
678
                                (p1_ir_fn="100010" or
679
                                 p1_ir_fn="100011" or
680
                                 p1_ir_fn(5 downto 2)="1010"))
681
                 else '0';
682
p1_ac.cy_in <= p1_ac.neg_sel(0);
683
 
684
p1_ac.shift_sel <= p1_ir_fn(1 downto 0);
685
 
686
p1_ac.logic_sel <= "00" when (p1_op_special='1' and p1_ir_fn="100100") else
687
                 "01" when (p1_op_special='1' and p1_ir_fn="100101") else
688
                 "10" when (p1_op_special='1' and p1_ir_fn="100110") else
689
                 "01" when (p1_op_special='1' and p1_ir_fn="100111") else
690
                 "00" when (p1_ir_op="001100") else
691
                 "01" when (p1_ir_op="001101") else
692
                 "10" when (p1_ir_op="001110") else
693
                 "11";
694
 
695
p1_ac.shift_amount <= p1_ir_reg(10 downto 6) when p1_ir_fn(2)='0' else p1_rs(4 downto 0);
696
 
697 23 ja_rd
 
698 2 ja_rd
--------------------------------------------------------------------------------
699 23 ja_rd
-- Decoding of unimplemented and privileged instructions
700 2 ja_rd
 
701 23 ja_rd
-- Unimplemented instructions include:
702
--  1.- All instructions above architecture MIPS-I except:
703
--      1.1.- eret
704
--  2.- Unaligned stores and loads (LWL,LWR,SWL,SWR)
705
--  3.- All CP0 instructions other than mfc0 and mtc0
706
--  4.- All CPi instructions
707
--  5.- All cache instructions
708
-- For the time being, we'll decode them all together.
709
 
710
-- FIXME: some of these should trap but others should just NOP (e.g. EHB)
711
 
712
p1_unknown_opcode <= '1' when
713
    -- decode by 'opcode' field
714
    p1_ir_op(31 downto 29)="011" or
715
    p1_ir_op(31 downto 29)="110" or
716
    p1_ir_op(31 downto 29)="111" or
717
    (p1_ir_op(31 downto 29)="010" and p1_ir_op(28 downto 26)/="000") or
718
    p1_ir_op="101111" or    -- CACHE
719
    p1_ir_op="100010" or    -- LWL
720
    p1_ir_op="100110" or    -- LWR
721
    p1_ir_op="101010" or    -- SWL
722
    p1_ir_op="101110" or    -- SWR
723
    p1_ir_op="100111" or
724
    p1_ir_op="101100" or
725
    p1_ir_op="101101" or
726
    -- decode instructions in the 'special' opcode group
727
    (p1_ir_op="000000" and
728
                (p1_ir_fn(5 downto 4)="11" or
729
                 p1_ir_fn="000001" or
730
                 p1_ir_fn="000101" or
731
                 p1_ir_fn="001010" or
732
                 p1_ir_fn="001011" or
733
                 p1_ir_fn="001110" or
734
                 p1_ir_fn(5 downto 2)="0101" or
735
                 p1_ir_fn(5 downto 2)="0111" or
736
                 p1_ir_fn(5 downto 2)="1011")) or
737
    -- decode instructions in the 'regimm' opcode group
738
    (p1_ir_op="000001" and
739
                (p1_ir_reg(20 downto 16)/="00000" and -- BLTZ is valid
740
                 p1_ir_reg(20 downto 16)/="00001" and -- BGEZ is valid
741
                 p1_ir_reg(20 downto 16)/="10000" and -- BLTZAL is valid 
742
                 p1_ir_reg(20 downto 16)/="10001")) -- BGEZAL is valid
743
 
744
    else '0';
745
 
746
--------------------------------------------------------------------------------
747
 
748 2 ja_rd
-- Stage 1 pipeline register. Involved in ALU control.
749
pipeline_stage1_register:
750
process(clk)
751
begin
752
    if clk'event and clk='1' then
753
        if reset='1' then
754
            p1_rbank_rs_hazard <= '0';
755
            p1_rbank_rt_hazard <= '0';
756
        elsif stall_pipeline='0' then
757
            p1_rbank_rs_hazard <= p0_rbank_rs_hazard;
758
            p1_rbank_rt_hazard <= p0_rbank_rt_hazard;
759
        end if;
760
    end if;
761
end process pipeline_stage1_register;
762
 
763 12 ja_rd
pipeline_stage1_register2:
764
process(clk)
765
begin
766
    if clk'event and clk='1' then
767
        if reset='1' then
768
            p2_muldiv_started <= '0';
769
        else
770
            p2_muldiv_started <= p1_muldiv_running;
771
        end if;
772
    end if;
773
end process pipeline_stage1_register2;
774 6 ja_rd
 
775 12 ja_rd
 
776 6 ja_rd
-- Stage 2 pipeline register. Split in two for convenience.
777 2 ja_rd
-- This register deals with two kinds of stalls:
778
-- * When the pipeline stalls because of a load interlock, this register is 
779
--   allowed to update so that the load operation can complete while the rest of
780
--   the pipeline is frozen.
781
-- * When the stall is caused by any other reason, this register freezes with 
782
--   the rest of the machine.
783 6 ja_rd
 
784
-- Part of stage 2 register that controls load operation
785
pipeline_stage2_register_load_control:
786 2 ja_rd
process(clk)
787
begin
788
    if clk'event and clk='1' then
789 6 ja_rd
        -- Clear load control, effectively preventing load, at reset or if
790
        -- the previous instruction raised an exception.
791
        if reset='1' or p2_exception='1' then
792 2 ja_rd
            p2_do_load <= '0';
793
            p2_ld_upper_hword <= '0';
794
            p2_ld_upper_byte <= '0';
795
            p2_ld_unsigned <= '0';
796
            p2_load_target <= "00000";
797 6 ja_rd
 
798
        -- Load signals from previous stage only if there is no pipeline stall
799
        -- unless the stall is caused by interlock (@note1).
800
        elsif (stall_pipeline='0' or load_interlock='1') then
801
            -- Disable reg bank writeback if pipeline is stalled; this prevents
802
            -- duplicate writes in case the stall is a mem_wait.
803 2 ja_rd
            if pipeline_stalled='0' then
804
                p2_do_load <= p1_do_load;
805
            else
806
                p2_do_load <= '0';
807
            end if;
808
            p2_load_target <= p1_rd_num;
809
            p2_ld_upper_hword <= p1_ld_upper_hword;
810
            p2_ld_upper_byte <= p1_ld_upper_byte;
811
            p2_ld_unsigned <= p1_ld_unsigned;
812 6 ja_rd
        end if;
813
    end if;
814
end process pipeline_stage2_register_load_control;
815
 
816
-- All the rest of the stage 2 register
817
pipeline_stage2_register_others:
818
process(clk)
819
begin
820
    if clk'event and clk='1' then
821
        if reset='1' then
822
            p2_exception <= '0';
823
 
824
        -- Load signals from previous stage only if there is no pipeline stall
825
        -- unless the stall is caused by interlock (@note1).
826
        elsif (stall_pipeline='0' or load_interlock='1') then
827 2 ja_rd
            p2_rd_addr <= p1_data_addr(1 downto 0);
828 6 ja_rd
            p2_exception <= p1_exception;
829 2 ja_rd
        end if;
830
    end if;
831 6 ja_rd
end process pipeline_stage2_register_others;
832 2 ja_rd
 
833
--------------------------------------------------------------------------------
834
 
835
-- FIXME stall when needed: mem pause, mdiv pause and load interlock
836
 
837 46 ja_rd
 
838
-- FIXME make sure this combinational will not have bad glitches
839
stall_pipeline <= mem_wait or load_interlock or p1_muldiv_stall;
840
 
841
 
842
-- FIXME load interlock should happen only if the instruction following 
843
-- the load actually uses the load target register. Something like this:
844
-- (p1_do_load='1' and (p1_rd_num=p0_rs_num or p1_rd_num=p0_rt_num))
845
load_interlock <= '1' when
846
    p1_do_load='1' and      -- this is a load instruction
847
    pipeline_stalled='0' and -- not already stalled (i.e. assert for 1 cycle)
848
    (p1_rs1_hazard='1' or p1_rs2_hazard='1')
849
    else '0';
850
 
851
 
852
 
853
 
854
pipeline_stalled <= stalled_interlock or stalled_memwait or stalled_muldiv;
855
 
856 2 ja_rd
pipeline_stall_registers:
857
process(clk)
858
begin
859
    if clk'event and clk='1' then
860
        if reset='1' then
861 46 ja_rd
            stalled_interlock <= '0';
862
            stalled_memwait <= '0';
863
            stalled_muldiv <= '0';
864 2 ja_rd
        else
865 46 ja_rd
            if mem_wait='1' then
866
                stalled_memwait <= '1';
867 2 ja_rd
            else
868 46 ja_rd
                stalled_memwait <= '0';
869 2 ja_rd
            end if;
870 35 ja_rd
 
871 46 ja_rd
            if p1_muldiv_stall='1' then
872
                stalled_muldiv <= '1';
873
            else
874
                stalled_muldiv <= '0';
875
            end if;
876
 
877 35 ja_rd
            -- stalls caused by mem_wait and load_interlock are independent and
878
            -- must not overlap; so when mem_wait='1' the cache stall takes
879
            -- precedence and the loa interlock must wait.
880
            if mem_wait='0' then
881
                if load_interlock='1' then
882 46 ja_rd
                    stalled_interlock <= '1';
883 35 ja_rd
                else
884 46 ja_rd
                    stalled_interlock <= '0';
885 35 ja_rd
                end if;
886 2 ja_rd
            end if;
887
        end if;
888
    end if;
889
end process pipeline_stall_registers;
890
 
891 28 ja_rd
p1_rs1_hazard <= '1'; --'1' when p0_uses_rs1='1' and p1_rd_num=p0_rs_num else '0';
892
p1_rs2_hazard <= '1'; --'1' when p0_uses_rs2='1' and p1_rd_num=p0_rt_num else '0';
893
 
894
with p1_ir_op select p0_uses_rs1 <=
895
    '0' when "000010",
896
    '0' when "000011",
897
    '0' when "001111",
898
    '0' when "001000",
899
    '1' when others;
900
 
901
with p1_ir_op select p0_uses_rs2 <=
902
    '1' when "000000",
903
    '1' when "000100",
904
    '1' when "000101",
905
    '1' when "000110",
906
    '1' when "000111",
907
    '1' when "010000",
908
    '1' when "101000",
909
    '1' when "101001",
910
    '1' when "101010",
911
    '1' when "101011",
912
    '1' when "101110",
913
    '0' when others;
914
 
915
 
916 2 ja_rd
--------------------------------------------------------------------------------
917
 
918
p1_data_offset(31 downto 16) <= (others => p1_data_imm(15));
919
p1_data_offset(15 downto 0) <= p1_data_imm(15 downto 0);
920
 
921
p1_data_addr <= p1_rs + p1_data_offset;
922
 
923
--------------------------------------------------------------------------------
924
 
925
-- byte_we is a function of the write size and alignment
926
-- size = {00=1,01=2,11=4}; we 3 is MSB, 0 is LSB; big endian => 00 is msb
927
p1_we_control <= pipeline_stalled & p1_do_store & p1_store_size & p1_data_addr(1 downto 0);
928
 
929
with p1_we_control select byte_we <=
930
    "1000"  when "010000",    -- SB %0
931
    "0100"  when "010001",    -- SB %1
932
    "0010"  when "010010",    -- SB %2
933
    "0001"  when "010011",    -- SB %3
934
    "1100"  when "010100",    -- SH %0
935
    "0011"  when "010110",    -- SH %2
936
    "1111"  when "011100",    -- SW %4
937
    "0000"  when others; -- all other combinations are spurious so don't write
938
 
939
-- Data to be stored always comes straight from the reg bank, but it needs to 
940
-- be shifted so that the LSB is aligned to the write address:
941
 
942
data_wr(7 downto 0) <= p1_rt(7 downto 0);
943
 
944
with p1_we_control select data_wr(15 downto 8) <=
945
    p1_rt( 7 downto  0) when "010010",  -- SB %2
946
    p1_rt(15 downto  8) when others;
947
 
948
with p1_we_control select data_wr(23 downto 16) <=
949
    p1_rt( 7 downto  0) when "010001",  -- SB %1
950
    p1_rt( 7 downto  0) when "010100",  -- SH %0
951
    p1_rt(23 downto 16) when others;
952
 
953
with p1_we_control select data_wr(31 downto 24) <=
954
    p1_rt( 7 downto  0) when "010000",  -- SB %0
955
    p1_rt(15 downto  8) when "010100",  -- SH %0
956
    p1_rt(31 downto 24) when others;
957
 
958
 
959
--##############################################################################
960
-- CP0 (what little is implemented of it)
961
 
962
process(clk)
963
begin
964
    if clk'event and clk='1' then
965
        if reset='1' then
966
            -- "10" => mode=kernel; ints=disabled
967
            cp0_status <= "10";
968 28 ja_rd
            cp0_cause_exc_code <= "00000";
969
            cp0_cause_bd <= '0';
970 2 ja_rd
        else
971
            -- no need to check for stall cycles when loading these
972
            if p1_set_cp0='1' then
973
                -- FIXME check for CP0 reg index
974
                cp0_status <= p1_rs(cp0_status'high downto 0);
975
            end if;
976 62 ja_rd
            if p1_exception='1' and pipeline_stalled='0' then
977 8 ja_rd
                cp0_epc <= p0_pc_restart;
978 28 ja_rd
 
979
                if p1_unknown_opcode='1' then
980
                    cp0_cause_exc_code <= "01010"; -- bad opcode
981
                else
982
                    if p1_ir_fn(0)='0' then
983
                        cp0_cause_exc_code <= "01000"; -- syscall
984
                    else
985
                        cp0_cause_exc_code <= "01001"; -- break
986
                    end if;
987
                end if;
988
 
989
                cp0_cause_bd <= cp0_in_delay_slot;
990 2 ja_rd
            end if;
991
        end if;
992
    end if;
993
end process;
994
 
995 28 ja_rd
cp0_cause_ce <= "00"; -- FIXME CP* traps merged with unimplemented opcode traps
996
cp0_cause <= cp0_cause_bd & '0' & cp0_cause_ce &
997
             X"00000" & "000" &
998
             cp0_cause_exc_code;
999
 
1000 2 ja_rd
-- FIXME the mux should mask to zero for any unused reg index
1001 28 ja_rd
with p1_c0_rs_num select cp0_reg_read <=
1002
    X"0000000" & "00" & cp0_status  when "01100",
1003
    cp0_cause                       when "01101",
1004
    cp0_epc & "00"                  when others;
1005 2 ja_rd
 
1006 28 ja_rd
 
1007 2 ja_rd
end architecture rtl;
1008
 
1009
--------------------------------------------------------------------------------
1010
-- Implementation notes
1011
--------------------------------------------------------------------------------
1012
-- @note1 : 
1013
--
1014
-- This is the meaning of these two signals:
1015 46 ja_rd
-- pipeline_stalled & stalled_interlock =>
1016 2 ja_rd
--  "00" => normal state
1017
--  "01" => normal state (makes for easier decoding)
1018
--  "10" => all stages of pipeline stalled, including rbank
1019
--  "11" => all stages of pipeline stalled, except reg bank write port
1020
-- 
1021
-- Just to clarify, 'stage X stalled' here means that the registers named 
1022
-- pX_* don't load.
1023
--
1024
-- The register bank WE is enabled when the pipeline is not stalled and when 
1025
-- it is stalled because of a load interlock; so that in case of interlock the
1026
-- load operation can complete while the rest of the pipeline is frozen.
1027
--------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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