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

Subversion Repositories nanoblaze

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

Go to most recent revision | 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
 
46
END branchStack ;
47
 
48
--==============================================================================
49
 
50
ARCHITECTURE RTL OF branchStack IS
51
 
52
  subtype progCounterType is unsigned(progCounter'range);
53
  type progCounterArrayType is array (0 to 2**stackPointerBitNb) of progCounterType;
54
  signal progCounterArray : progCounterArrayType;
55
 
56
  signal writePointer : unsigned(stackPointerBitNb-1 downto 0);
57
  signal readPointer  : unsigned(stackPointerBitNb-1 downto 0);
58
 
59
BEGIN
60
  ------------------------------------------------------------------------------
61
                                                               -- stack pointers
62
  updateStackPointer: process(reset, clock)
63
  begin
64
    if reset = '1' then
65
      writePointer <= (others => '0');
66
    elsif rising_edge(clock) then
67
      if storePC = '1' then
68
        writePointer <= writePointer + 1;
69
      elsif prevPC = '1' then
70
        writePointer <= writePointer - 1;
71
      end if;
72
    end if;
73
  end process updateStackPointer;
74
 
75
  readPointer <= writePointer - 1;
76
 
77
  ------------------------------------------------------------------------------
78
                                                       -- program counters stack
79
  updateStack: process(reset, clock)
80
  begin
81
    if rising_edge(clock) then
82
      if storePc = '1' then
83
        progCounterArray(to_integer(writePointer)) <= progCounter;
84
      end if;
85
      storedProgCounter <= progCounterArray(to_integer(readPointer));
86
    end if;
87
  end process updateStack;
88
 
89
END ARCHITECTURE RTL;

powered by: WebSVN 2.1.0

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