16184SN/A/* 26184SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 36184SN/A * All rights reserved. 46184SN/A * 56184SN/A * Redistribution and use in source and binary forms, with or without 66184SN/A * modification, are permitted provided that the following conditions are 76184SN/A * met: redistributions of source code must retain the above copyright 86184SN/A * notice, this list of conditions and the following disclaimer; 96184SN/A * redistributions in binary form must reproduce the above copyright 106184SN/A * notice, this list of conditions and the following disclaimer in the 116184SN/A * documentation and/or other materials provided with the distribution; 126184SN/A * neither the name of the copyright holders nor the names of its 136184SN/A * contributors may be used to endorse or promote products derived from 146184SN/A * this software without specific prior written permission. 156184SN/A * 166184SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176184SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186184SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196184SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206184SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216184SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226184SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236184SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246184SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256184SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266184SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276184SN/A * 286184SN/A * Authors: Kevin Lim 296184SN/A */ 306184SN/A 316226Snate@binkert.org#include "cpu/pred/ras.hh" 326184SN/A 336184SN/Avoid 346184SN/AReturnAddrStack::init(unsigned _numEntries) 356184SN/A{ 366184SN/A numEntries = _numEntries; 376184SN/A addrStack.resize(numEntries); 387720Sgblack@eecs.umich.edu reset(); 396184SN/A} 406184SN/A 416184SN/Avoid 426184SN/AReturnAddrStack::reset() 436184SN/A{ 446184SN/A usedEntries = 0; 456184SN/A tos = 0; 466227Snate@binkert.org for (unsigned i = 0; i < numEntries; ++i) 477720Sgblack@eecs.umich.edu addrStack[i].set(0); 486184SN/A} 496184SN/A 506184SN/Avoid 517720Sgblack@eecs.umich.eduReturnAddrStack::push(const TheISA::PCState &return_addr) 526184SN/A{ 536184SN/A incrTos(); 546184SN/A 556184SN/A addrStack[tos] = return_addr; 566184SN/A 576184SN/A if (usedEntries != numEntries) { 586184SN/A ++usedEntries; 596184SN/A } 606184SN/A} 616184SN/A 626184SN/Avoid 636184SN/AReturnAddrStack::pop() 646184SN/A{ 656184SN/A if (usedEntries > 0) { 666184SN/A --usedEntries; 676184SN/A } 686184SN/A 696184SN/A decrTos(); 706184SN/A} 716184SN/A 726184SN/Avoid 736184SN/AReturnAddrStack::restore(unsigned top_entry_idx, 747720Sgblack@eecs.umich.edu const TheISA::PCState &restored) 756184SN/A{ 766184SN/A tos = top_entry_idx; 776184SN/A 787720Sgblack@eecs.umich.edu addrStack[tos] = restored; 796184SN/A} 80