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

Subversion Repositories potato

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

Go to most recent revision | 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
                RESET_ADDRESS : std_logic_vector(31 downto 0) := x"00000000"
15
        );
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
        --signal pc, pc_next : std_logic_vector(31 downto 0);
44
        --signal acknowledge, ready : std_logic;
45
 
46
        signal pc : std_logic_vector(31 downto 0);
47
        signal pc_next : std_logic_vector(31 downto 0);
48
 
49
        signal cancel_fetch : std_logic;
50
begin
51
 
52
        imem_address <= pc_next;
53
 
54
        instruction_data <= imem_data_in;
55
        instruction_ready <= imem_ack and (not stall) and (not cancel_fetch);
56
        instruction_address <= pc;
57
 
58
        --imem_req <= '1' when cancel_fetch = '0' and 
59
 
60
        imem_req <= '1';
61
 
62
        set_pc: process(clk)
63
        begin
64
                if rising_edge(clk) then
65
                        if reset = '1' then
66
                                pc <= RESET_ADDRESS;
67
                                cancel_fetch <= '0';
68
                        else
69
                                if (exception = '1' or branch = '1') and imem_ack = '0' then
70
                                        cancel_fetch <= '1';
71
                                        pc <= pc_next;
72
                                elsif cancel_fetch = '1' and imem_ack = '1' then
73
                                        --pc <= pc_next;
74
                                        cancel_fetch <= '0';
75
                                else
76
                                        pc <= pc_next;
77
                                end if;
78
                        end if;
79
                end if;
80
        end process set_pc;
81
 
82
        calc_next_pc: process(reset, stall, branch, exception, imem_ack, branch_target, evec, pc, cancel_fetch)
83
        begin
84
                if reset = '1' then
85
                        pc_next <= RESET_ADDRESS;
86
                elsif exception = '1' then
87
                        pc_next <= evec;
88
                elsif branch = '1' then
89
                        pc_next <= branch_target;
90
                elsif imem_ack = '1' and stall = '0' and cancel_fetch = '0' then
91
                        pc_next <= std_logic_vector(unsigned(pc) + 4);
92
                else
93
                        pc_next <= pc;
94
                end if;
95
        end process calc_next_pc;
96
 
97
end architecture behaviour;

powered by: WebSVN 2.1.0

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