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

Subversion Repositories nanoblaze

[/] [nanoblaze/] [trunk/] [Circuit/] [branchStack.vhd] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 fcorthay
--##############################################################################
2
--
3
--  branchStack
4
--      Stack of branch addresses
5
--
6
--      This is where the program counter is pushed upon a subroutine call
7
--      and popped on return.
8
--
9
--      The stack is coded in a way to be mapped into a Block RAM.
10
--
11
--------------------------------------------------------------------------------
12
--
13
--  Versions / Authors
14
--      1.0 Francois Corthay    first implementation
15
--
16
--  Provided under GNU LGPL licence: <http://www.gnu.org/copyleft/lesser.html>
17
--
18
--  by the electronics group of "HES-SO//Valais Wallis", in Switzerland:
19
--  <http://www.hevs.ch/en/rad-instituts/institut-systemes-industriels/>.
20
--
21
--------------------------------------------------------------------------------
22
--
23
--  Hierarchy
24
--      Used by "nanoblaze/nanoProcessor".
25
--
26
--##############################################################################
27
 
28
LIBRARY ieee;
29
  USE ieee.std_logic_1164.all;
30
  USE ieee.numeric_std.all;
31
 
32
ENTITY branchStack IS
33
  GENERIC(
34
    programCounterBitNb : positive := 10;
35
    stackPointerBitNb   : positive := 5
36
  );
37
  PORT(
38
    reset             : IN  std_ulogic;
39
    clock             : IN  std_ulogic;
40
    progCounter       : IN  unsigned(programCounterBitNb-1 DOWNTO 0);
41
    prevPC            : IN  std_ulogic;
42
    storePC           : IN  std_ulogic;
43
    storedProgCounter : OUT unsigned(programCounterBitNb-1 DOWNTO 0)
44
  );
45
END branchStack ;
46
 
47
--==============================================================================
48
 
49
ARCHITECTURE RTL OF branchStack IS
50
 
51
  subtype progCounterType is unsigned(progCounter'range);
52
  type progCounterArrayType is array (0 to 2**stackPointerBitNb) of progCounterType;
53
  signal progCounterArray : progCounterArrayType;
54
 
55
  signal writePointer : unsigned(stackPointerBitNb-1 downto 0);
56
  signal readPointer  : unsigned(stackPointerBitNb-1 downto 0);
57
 
58
BEGIN
59
  ------------------------------------------------------------------------------
60
                                                               -- stack pointers
61
  updateStackPointer: process(reset, clock)
62
  begin
63
    if reset = '1' then
64
      writePointer <= (others => '0');
65
    elsif rising_edge(clock) then
66
      if storePC = '1' then
67
        writePointer <= writePointer + 1;
68
      elsif prevPC = '1' then
69
        writePointer <= writePointer - 1;
70
      end if;
71
    end if;
72
  end process updateStackPointer;
73
 
74
  readPointer <= writePointer - 1;
75
 
76
  ------------------------------------------------------------------------------
77
                                                       -- program counters stack
78
  updateStack: process(reset, clock)
79
  begin
80
    if rising_edge(clock) then
81
      if storePc = '1' then
82
        progCounterArray(to_integer(writePointer)) <= progCounter;
83
      end if;
84
      storedProgCounter <= progCounterArray(to_integer(readPointer));
85
    end if;
86
  end process updateStack;
87
 
88
END ARCHITECTURE RTL;

powered by: WebSVN 2.1.0

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