blob: 0ba09bfae7e4c2013ce0065d8803007dcb610cf5 [file] [log] [blame]
Kevin Lim2a859312005-05-26 23:30:12 -04001/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ali Saidicb0cf2d2006-05-31 19:26:56 -040027 *
28 * Authors: Kevin Lim
Kevin Lim2a859312005-05-26 23:30:12 -040029 */
30
Nathan Binkert4e342662009-06-04 21:50:20 -070031#include "cpu/pred/ras.hh"
Kevin Lim2fb632d2004-10-21 18:02:36 -040032
Kevin Lima8b03e42006-04-22 18:26:48 -040033void
34ReturnAddrStack::init(unsigned _numEntries)
Kevin Lim2fb632d2004-10-21 18:02:36 -040035{
Kevin Lima8b03e42006-04-22 18:26:48 -040036 numEntries = _numEntries;
Kevin Lima8b03e42006-04-22 18:26:48 -040037 addrStack.resize(numEntries);
Gabe Black6f4bd2c2010-10-31 00:07:20 -070038 reset();
Kevin Lim2fb632d2004-10-21 18:02:36 -040039}
40
41void
Kevin Limf3358e52006-05-04 11:36:20 -040042ReturnAddrStack::reset()
43{
44 usedEntries = 0;
45 tos = 0;
Nathan Binkert6faf3772009-06-04 23:21:12 -070046 for (unsigned i = 0; i < numEntries; ++i)
Gabe Black6f4bd2c2010-10-31 00:07:20 -070047 addrStack[i].set(0);
Kevin Limf3358e52006-05-04 11:36:20 -040048}
49
50void
Gabe Black6f4bd2c2010-10-31 00:07:20 -070051ReturnAddrStack::push(const TheISA::PCState &return_addr)
Kevin Lim2fb632d2004-10-21 18:02:36 -040052{
53 incrTos();
54
55 addrStack[tos] = return_addr;
56
57 if (usedEntries != numEntries) {
58 ++usedEntries;
59 }
60}
61
62void
63ReturnAddrStack::pop()
64{
Kevin Lim2fb632d2004-10-21 18:02:36 -040065 if (usedEntries > 0) {
66 --usedEntries;
67 }
68
69 decrTos();
70}
71
72void
73ReturnAddrStack::restore(unsigned top_entry_idx,
Gabe Black6f4bd2c2010-10-31 00:07:20 -070074 const TheISA::PCState &restored)
Kevin Lim2fb632d2004-10-21 18:02:36 -040075{
76 tos = top_entry_idx;
77
Gabe Black6f4bd2c2010-10-31 00:07:20 -070078 addrStack[tos] = restored;
Kevin Lim2fb632d2004-10-21 18:02:36 -040079}