ras.hh revision 2307
13985Sgblack@eecs.umich.edu/*
22632Sstever@eecs.umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
32632Sstever@eecs.umich.edu * All rights reserved.
42632Sstever@eecs.umich.edu *
52632Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
62632Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are
72632Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright
82632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
92632Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
102632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
112632Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution;
122632Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its
132632Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
142632Sstever@eecs.umich.edu * this software without specific prior written permission.
152632Sstever@eecs.umich.edu *
162632Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172632Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182632Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192632Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202632Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212632Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222632Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232632Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242632Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252632Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262632Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272632Sstever@eecs.umich.edu */
282632Sstever@eecs.umich.edu
292632Sstever@eecs.umich.edu#ifndef __CPU_O3_RAS_HH__
302022SN/A#define __CPU_O3_RAS_HH__
312022SN/A
322022SN/A// For Addr type.
332022SN/A#include "arch/isa_traits.hh"
342022SN/A#include <vector>
352022SN/A
362022SN/A/** Return address stack class, implements a simple RAS. */
372516SN/Aclass ReturnAddrStack
382022SN/A{
392022SN/A  public:
402022SN/A    /** Creates a return address stack, but init() must be called prior to
412224SN/A     *  use.
422224SN/A     */
434253Sgblack@eecs.umich.edu    ReturnAddrStack() {}
442224SN/A
452224SN/A    /** Initializes RAS with a specified number of entries.
462224SN/A     *  @param numEntries Number of entries in the RAS.
472022SN/A     */
482224SN/A    void init(unsigned numEntries);
492224SN/A
502022SN/A    void reset();
512516SN/A
522516SN/A    /** Returns the top address on the RAS. */
532516SN/A    Addr top()
542516SN/A    { return addrStack[tos]; }
552516SN/A
562516SN/A    /** Returns the index of the top of the RAS. */
572516SN/A    unsigned topIdx()
582516SN/A    { return tos; }
594253Sgblack@eecs.umich.edu
602516SN/A    /** Pushes an address onto the RAS. */
612516SN/A    void push(const Addr &return_addr);
622516SN/A
632516SN/A    /** Pops the top address from the RAS. */
642516SN/A    void pop();
652516SN/A
662516SN/A    /** Changes index to the top of the RAS, and replaces the top address with
672516SN/A     *  a new target.
682516SN/A     *  @param top_entry_idx The index of the RAS that will now be the top.
692516SN/A     *  @param restored_target The new target address of the new top of the RAS.
702516SN/A     */
712516SN/A    void restore(unsigned top_entry_idx, const Addr &restored_target);
722944Sgblack@eecs.umich.edu
732516SN/A  private:
742944Sgblack@eecs.umich.edu    /** Increments the top of stack index. */
752944Sgblack@eecs.umich.edu    inline void incrTos()
762516SN/A    { if (++tos == numEntries) tos = 0; }
772516SN/A
782516SN/A    /** Decrements the top of stack index. */
794253Sgblack@eecs.umich.edu    inline void decrTos()
802516SN/A    { tos = (tos == 0 ? numEntries - 1 : tos - 1); }
812516SN/A
822516SN/A    /** The RAS itself. */
833273Sgblack@eecs.umich.edu    std::vector<Addr> addrStack;
842516SN/A
852516SN/A    /** The number of entries in the RAS. */
862516SN/A    unsigned numEntries;
872516SN/A
882516SN/A    /** The number of used entries in the RAS. */
892516SN/A    unsigned usedEntries;
902516SN/A
912516SN/A    /** The top of stack index. */
922516SN/A    unsigned tos;
932516SN/A};
944253Sgblack@eecs.umich.edu
952516SN/A#endif // __CPU_O3_RAS_HH__
962516SN/A