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

Subversion Repositories marca

[/] [marca/] [tags/] [INITIAL/] [vhdl/] [fetch.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jeunes2
--  This file is part of the marca processor.
2
--  Copyright (C) 2007 Wolfgang Puffitsch
3
 
4
--  This program is free software; you can redistribute it and/or modify it
5
--  under the terms of the GNU Library General Public License as published
6
--  by the Free Software Foundation; either version 2, or (at your option)
7
--  any later version.
8
 
9
--  This program is distributed in the hope that it will be useful,
10
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
--  Library General Public License for more details.
13
 
14
--  You should have received a copy of the GNU Library General Public
15
--  License along with this program; if not, write to the Free Software
16
--  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
17
 
18
-------------------------------------------------------------------------------
19
-- MARCA fetch stage
20
-------------------------------------------------------------------------------
21
-- architecture for the instruction-fetch pipeline stage
22
-------------------------------------------------------------------------------
23
 
24
-------------------------------------------------------------------------------
25
-- Wolfgang Puffitsch
26
-- Computer Architecture Lab, Group 3
27
-------------------------------------------------------------------------------
28
 
29
library IEEE;
30
use IEEE.std_logic_1164.all;
31
use IEEE.numeric_std.all;
32
 
33
use work.marca_pkg.all;
34
 
35
architecture behaviour of fetch is
36
 
37
component code_memory
38
  generic (
39
    init_file : string);
40
  port (
41
    clken   : in std_logic;
42
    clock   : in std_logic;
43
    address : in std_logic_vector (PADDR_WIDTH-1 downto 0);
44
    q       : out std_logic_vector (PDATA_WIDTH-1 downto 0));
45
end component;
46
 
47
signal enable : std_logic;
48
 
49
signal address : std_logic_vector(PADDR_WIDTH-1 downto 0);
50
signal data    : std_logic_vector(PDATA_WIDTH-1 downto 0);
51
 
52
signal pc_reg  : std_logic_vector(REG_WIDTH-1 downto 0);
53
signal next_pc : std_logic_vector(REG_WIDTH-1 downto 0);
54
 
55
signal next_pc_out : std_logic_vector(REG_WIDTH-1 downto 0);
56
 
57
begin  -- behaviour
58
 
59
  enable <= not hold;
60
  pc_out <= pc_reg;
61
 
62
  code_memory_unit : code_memory
63
    generic map (
64
      init_file => "../vhdl/code.mif")
65
    port map (
66
      address   => address(PADDR_WIDTH-1 downto 0),
67
      clken     => enable,
68
      clock     => clock,
69
      q         => data);
70
 
71
  syn_proc: process (clock, reset)
72
  begin  -- process syn_proc
73
    if reset = RESET_ACTIVE then                 -- asynchronous reset (active low)
74
      pc_reg <= (others => '0');
75
    elsif clock'event and clock = '1' then  -- rising clock edge
76
      if hold = '0' then
77
        pc_reg <= next_pc;
78
      end if;
79
    end if;
80
  end process syn_proc;
81
 
82
  increment: process (pc_reg, pc_in, pcena, data)
83
  begin  -- process increment
84
    if pcena = '1' then
85
      next_pc <= pc_in;
86
    else
87
      -- "predict" hard branches
88
      if data(PDATA_WIDTH-1 downto PDATA_WIDTH-8) = OPC_PFX_C & OPC_BR then
89
        next_pc <= std_logic_vector(signed(pc_reg) + signed(data(7 downto 0)));
90
      else
91
        next_pc <= std_logic_vector(unsigned(pc_reg) + 1);
92
      end if;
93
    end if;
94
  end process increment;
95
 
96
  forward: process (pc_reg, pc_in, pcena, data, reset)
97
  begin  -- process forward
98
    if reset = RESET_ACTIVE then
99
      address <= (others => '0');
100
    else
101
      if pcena = '1' then
102
        address <= pc_in(PADDR_WIDTH-1 downto 0);
103
      else
104
        if data(PDATA_WIDTH-1 downto PDATA_WIDTH-8) = OPC_PFX_C & OPC_BR then
105
          address <= std_logic_vector(signed(pc_reg) + signed(data(7 downto 0)))(PADDR_WIDTH-1 downto 0);
106
        else
107
          address <= std_logic_vector(unsigned(pc_reg) + 1)(PADDR_WIDTH-1 downto 0);
108
        end if;
109
      end if;
110
    end if;
111
  end process forward;
112
 
113
  spread: process (data)
114
  begin  -- process spread
115
    src1 <= data(3 downto 0);
116
    src2 <= data(7 downto 4);
117
    dest <= data(11 downto 8);
118
    instr <= data;
119
  end process spread;
120
 
121
end behaviour;

powered by: WebSVN 2.1.0

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