summaryrefslogtreecommitdiff
path: root/cpu/beta_cpu/ras.cc
blob: 23ca45b3ace832d44ed1da5f3552c9f35744650a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "cpu/beta_cpu/ras.hh"

ReturnAddrStack::ReturnAddrStack(unsigned _numEntries)
    : numEntries(_numEntries), usedEntries(0),
      tos(0)
{
    addrStack = new Addr[numEntries];

    for (int i = 0; i < numEntries; ++i)
        addrStack[i] = 0;
}

void
ReturnAddrStack::push(const Addr &return_addr)
{
    incrTos();

    addrStack[tos] = return_addr;

    if (usedEntries != numEntries) {
        ++usedEntries;
    }
}

void
ReturnAddrStack::pop()
{
    // Not sure it's possible to really track usedEntries properly.
//    assert(usedEntries > 0);

    if (usedEntries > 0) {
        --usedEntries;
    }

    decrTos();
}

void
ReturnAddrStack::restore(unsigned top_entry_idx,
                         const Addr &restored_target)
{
    tos = top_entry_idx;

    addrStack[tos] = restored_target;
}