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

Subversion Repositories potato

[/] [potato/] [trunk/] [src/] [pp_fetch.vhd] - Blame information for rev 58

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.numeric_std.all;
8
 
9
use work.pp_constants.all;
10
 
11
--! @brief Instruction fetch unit.
12
entity pp_fetch is
13
        generic(
14 58 skordal
                RESET_ADDRESS : std_logic_vector(31 downto 0)
15 2 skordal
        );
16
        port(
17
                clk    : in std_logic;
18
                reset  : in std_logic;
19
 
20
                -- Instruction memory connections:
21
                imem_address : out std_logic_vector(31 downto 0);
22
                imem_data_in : in  std_logic_vector(31 downto 0);
23
                imem_req     : out std_logic;
24
                imem_ack     : in  std_logic;
25
 
26
                -- Control inputs:
27
                stall     : in std_logic;
28
                flush     : in std_logic;
29
                branch    : in std_logic;
30
                exception : in std_logic;
31
 
32
                branch_target : in std_logic_vector(31 downto 0);
33
                evec          : in std_logic_vector(31 downto 0);
34
 
35
                -- Outputs to the instruction decode unit:
36
                instruction_data    : out std_logic_vector(31 downto 0);
37
                instruction_address : out std_logic_vector(31 downto 0);
38
                instruction_ready   : out std_logic
39
        );
40
end entity pp_fetch;
41
 
42
architecture behaviour of pp_fetch is
43 45 skordal
        signal pc           : std_logic_vector(31 downto 0);
44
        signal pc_next      : std_logic_vector(31 downto 0);
45 2 skordal
        signal cancel_fetch : std_logic;
46
begin
47
 
48 45 skordal
        imem_address <= pc_next when cancel_fetch = '0' else pc;
49 2 skordal
 
50
        instruction_data <= imem_data_in;
51
        instruction_ready <= imem_ack and (not stall) and (not cancel_fetch);
52
        instruction_address <= pc;
53
 
54
        imem_req <= '1';
55
 
56
        set_pc: process(clk)
57
        begin
58
                if rising_edge(clk) then
59
                        if reset = '1' then
60
                                pc <= RESET_ADDRESS;
61
                                cancel_fetch <= '0';
62
                        else
63
                                if (exception = '1' or branch = '1') and imem_ack = '0' then
64
                                        cancel_fetch <= '1';
65
                                        pc <= pc_next;
66
                                elsif cancel_fetch = '1' and imem_ack = '1' then
67
                                        --pc <= pc_next;
68
                                        cancel_fetch <= '0';
69
                                else
70
                                        pc <= pc_next;
71
                                end if;
72
                        end if;
73
                end if;
74
        end process set_pc;
75
 
76
        calc_next_pc: process(reset, stall, branch, exception, imem_ack, branch_target, evec, pc, cancel_fetch)
77
        begin
78 45 skordal
                if exception = '1' then
79 2 skordal
                        pc_next <= evec;
80
                elsif branch = '1' then
81
                        pc_next <= branch_target;
82
                elsif imem_ack = '1' and stall = '0' and cancel_fetch = '0' then
83
                        pc_next <= std_logic_vector(unsigned(pc) + 4);
84
                else
85
                        pc_next <= pc;
86
                end if;
87
        end process calc_next_pc;
88
 
89
end architecture behaviour;

powered by: WebSVN 2.1.0

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