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

Subversion Repositories arm4u

[/] [arm4u/] [trunk/] [hdl/] [fetch.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Bregalad
-- This file is part of ARM4U CPU
2
-- 
3
-- This is a creation of the Laboratory of Processor Architecture
4
-- of Ecole Polytechnique Fédérale de Lausanne ( http://lap.epfl.ch )
5
--
6
-- fetch.vhd  --  Descrption of the fetch pipeline stage
7
--
8
-- Written By -  Jonathan Masur and Xavier Jimenez (2013)
9
--
10
-- This program is free software; you can redistribute it and/or modify it
11
-- under the terms of the GNU General Public License as published by the
12
-- Free Software Foundation; either version 2, or (at your option) any
13
-- later version.
14
--
15
-- This program is distributed in the hope that it will be useful,
16
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
-- GNU General Public License for more details.
19
--
20
-- In other words, you are welcome to use, share and improve this program.
21
-- You are forbidden to forbid anyone else to use, share and improve
22
-- what you give them.   Help stamp out software-hoarding!
23
 
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.numeric_std.all;
28
 
29
entity fetch is
30
        port(
31
                clk                     : in std_logic;
32
                n_reset         : in std_logic;
33
 
34
                -- port to write to the programm counter
35
                pc_wr           : in std_logic := '0';
36
                pc_wrdata       : in unsigned(31 downto 0) := (others => '0');
37
 
38
                -- enable the fetch stage
39
                fetch_stage_en : in std_logic;
40
 
41
                -- flush output for following pipeline stages
42
                -- (activated on PC writes)
43
                flush   : out std_logic;
44
 
45
                -- enable the next stage (out)
46
                decode_stage_valid : out std_logic;
47
                dec_pc_plus_8 : out unsigned(31 downto 0);
48
                dec_pc_plus_4 : out unsigned(31 downto 0);
49
 
50
                -- memory bus
51
                inst_cache_adr : out std_logic_vector(31 downto 0);
52
                inst_cache_rd : out std_logic;
53
 
54
                -- enable signal for latch after the fetch stage
55
                fetch_latch_enable : in std_logic
56
        );
57
end entity;
58
 
59
architecture rtl of fetch is
60
        signal pc : unsigned(31 downto 0);
61
        signal pc4 : unsigned(31 downto 0);
62
        signal cur_pc : unsigned(31 downto 0);
63
        signal flush_r, flush_s : std_logic;
64
begin
65
        flush <= flush_s;
66
        -- flush the pipeline on writes (including reset and cases when a flush occurs during a miss)
67
        flush_s <= '1' when pc_wr = '1' or flush_r = '1' else '0';
68
 
69
        cur_pc <= pc_wrdata when pc_wr = '1' else pc;
70
        inst_cache_adr <= std_logic_vector(cur_pc);
71
 
72
        -- handles the reading of the instruction cache memory
73
        inst_cache_rd <= fetch_stage_en;
74
 
75
        -- computation of next PC value (async)
76
        pc4 <= cur_pc + 4;
77
 
78
        dec_pc_plus_8 <= pc4;
79
        dec_pc_plus_4 <= pc;
80
 
81
        -- handles resets and fetch latch at output of the stage
82
        fetchlatch:
83
        process(n_reset, clk) is
84
        begin
85
                if n_reset='0'
86
                then
87
                        pc <= (others => '0');                                   -- reset address is 0x000000
88
                        decode_stage_valid <= '0';
89
                        flush_r <= '0';
90
                elsif rising_edge(clk)
91
                then
92
                        if fetch_stage_en = '1'
93
                        then
94
                                pc <= pc4;
95
                        else
96
                                pc <= cur_pc;
97
                        end if;
98
 
99
                        if fetch_latch_enable = '1'
100
                        then
101
                                flush_r <= '0';
102
                                decode_stage_valid <= fetch_stage_en;
103
                        else
104
                                flush_r <= flush_s;
105
                        end if;
106
                end if;
107
        end process;
108
 
109
end architecture;

powered by: WebSVN 2.1.0

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