Kevin Lim | 2a85931 | 2005-05-26 23:30:12 -0400 | [diff] [blame] | 1 | /* |
| 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 Saidi | cb0cf2d | 2006-05-31 19:26:56 -0400 | [diff] [blame] | 27 | * |
| 28 | * Authors: Kevin Lim |
Kevin Lim | 2a85931 | 2005-05-26 23:30:12 -0400 | [diff] [blame] | 29 | */ |
| 30 | |
Nathan Binkert | 4e34266 | 2009-06-04 21:50:20 -0700 | [diff] [blame] | 31 | #include "cpu/pred/ras.hh" |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 32 | |
Kevin Lim | a8b03e4 | 2006-04-22 18:26:48 -0400 | [diff] [blame] | 33 | void |
| 34 | ReturnAddrStack::init(unsigned _numEntries) |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 35 | { |
Kevin Lim | a8b03e4 | 2006-04-22 18:26:48 -0400 | [diff] [blame] | 36 | numEntries = _numEntries; |
Kevin Lim | a8b03e4 | 2006-04-22 18:26:48 -0400 | [diff] [blame] | 37 | addrStack.resize(numEntries); |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 38 | reset(); |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
Kevin Lim | f3358e5 | 2006-05-04 11:36:20 -0400 | [diff] [blame] | 42 | ReturnAddrStack::reset() |
| 43 | { |
| 44 | usedEntries = 0; |
| 45 | tos = 0; |
Nathan Binkert | 6faf377 | 2009-06-04 23:21:12 -0700 | [diff] [blame] | 46 | for (unsigned i = 0; i < numEntries; ++i) |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 47 | addrStack[i].set(0); |
Kevin Lim | f3358e5 | 2006-05-04 11:36:20 -0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 51 | ReturnAddrStack::push(const TheISA::PCState &return_addr) |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 52 | { |
| 53 | incrTos(); |
| 54 | |
| 55 | addrStack[tos] = return_addr; |
| 56 | |
| 57 | if (usedEntries != numEntries) { |
| 58 | ++usedEntries; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | ReturnAddrStack::pop() |
| 64 | { |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 65 | if (usedEntries > 0) { |
| 66 | --usedEntries; |
| 67 | } |
| 68 | |
| 69 | decrTos(); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | ReturnAddrStack::restore(unsigned top_entry_idx, |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 74 | const TheISA::PCState &restored) |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 75 | { |
| 76 | tos = top_entry_idx; |
| 77 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 78 | addrStack[tos] = restored; |
Kevin Lim | 2fb632d | 2004-10-21 18:02:36 -0400 | [diff] [blame] | 79 | } |