utility.hh revision 3577
12501SN/A/*
22501SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
32501SN/A * All rights reserved.
42501SN/A *
52501SN/A * Redistribution and use in source and binary forms, with or without
62501SN/A * modification, are permitted provided that the following conditions are
72501SN/A * met: redistributions of source code must retain the above copyright
82501SN/A * notice, this list of conditions and the following disclaimer;
92501SN/A * redistributions in binary form must reproduce the above copyright
102501SN/A * notice, this list of conditions and the following disclaimer in the
112501SN/A * documentation and/or other materials provided with the distribution;
122501SN/A * neither the name of the copyright holders nor the names of its
132501SN/A * contributors may be used to endorse or promote products derived from
142501SN/A * this software without specific prior written permission.
152501SN/A *
162501SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172501SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182501SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192501SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202501SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212501SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222501SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232501SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242501SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252501SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262501SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
292501SN/A */
302501SN/A
312501SN/A#ifndef __ARCH_SPARC_UTILITY_HH__
322501SN/A#define __ARCH_SPARC_UTILITY_HH__
332501SN/A
343532Sgblack@eecs.umich.edu#include "arch/sparc/faults.hh"
352501SN/A#include "arch/sparc/isa_traits.hh"
362501SN/A#include "base/misc.hh"
373278Sgblack@eecs.umich.edu#include "base/bitfield.hh"
383272Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
392501SN/A
402501SN/Anamespace SparcISA
412501SN/A{
423577Sgblack@eecs.umich.edu
433577Sgblack@eecs.umich.edu    static inline bool
443577Sgblack@eecs.umich.edu    inUserMode(ThreadContext *tc)
453577Sgblack@eecs.umich.edu    {
463577Sgblack@eecs.umich.edu        return !(tc->readMiscReg(MISCREG_PSTATE & (1 << 2)) ||
473577Sgblack@eecs.umich.edu                tc->readMiscReg(MISCREG_HPSTATE & (1 << 2)));
483577Sgblack@eecs.umich.edu    }
493577Sgblack@eecs.umich.edu
502501SN/A    inline ExtMachInst
513272Sgblack@eecs.umich.edu    makeExtMI(MachInst inst, ThreadContext * xc) {
523272Sgblack@eecs.umich.edu        ExtMachInst emi = (unsigned MachInst) inst;
533272Sgblack@eecs.umich.edu        //The I bit, bit 13, is used to figure out where the ASI
543272Sgblack@eecs.umich.edu        //should come from. Use that in the ExtMachInst. This is
553272Sgblack@eecs.umich.edu        //slightly redundant, but it removes the need to put a condition
563272Sgblack@eecs.umich.edu        //into all the execute functions
573272Sgblack@eecs.umich.edu        if(inst & (1 << 13))
583272Sgblack@eecs.umich.edu            emi |= (static_cast<ExtMachInst>(xc->readMiscReg(MISCREG_ASI))
593272Sgblack@eecs.umich.edu                    << (sizeof(MachInst) * 8));
603278Sgblack@eecs.umich.edu        else
613278Sgblack@eecs.umich.edu            emi |= (static_cast<ExtMachInst>(bits(inst, 12, 5))
623278Sgblack@eecs.umich.edu                    << (sizeof(MachInst) * 8));
633272Sgblack@eecs.umich.edu        return emi;
642501SN/A    }
652501SN/A
662501SN/A    inline bool isCallerSaveIntegerRegister(unsigned int reg) {
672501SN/A        panic("register classification not implemented");
682501SN/A        return false;
692501SN/A    }
702501SN/A
712501SN/A    inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
722501SN/A        panic("register classification not implemented");
732501SN/A        return false;
742501SN/A    }
752501SN/A
762501SN/A    inline bool isCallerSaveFloatRegister(unsigned int reg) {
772501SN/A        panic("register classification not implemented");
782501SN/A        return false;
792501SN/A    }
802501SN/A
812501SN/A    inline bool isCalleeSaveFloatRegister(unsigned int reg) {
822501SN/A        panic("register classification not implemented");
832501SN/A        return false;
842501SN/A    }
852501SN/A
862501SN/A    // Instruction address compression hooks
872501SN/A    inline Addr realPCToFetchPC(const Addr &addr)
882501SN/A    {
892501SN/A        return addr;
902501SN/A    }
912501SN/A
922501SN/A    inline Addr fetchPCToRealPC(const Addr &addr)
932501SN/A    {
942501SN/A        return addr;
952501SN/A    }
962501SN/A
972501SN/A    // the size of "fetched" instructions (not necessarily the size
982501SN/A    // of real instructions for PISA)
992501SN/A    inline size_t fetchInstSize()
1002501SN/A    {
1012501SN/A        return sizeof(MachInst);
1022501SN/A    }
1032501SN/A
1042501SN/A    /**
1052501SN/A     * Function to insure ISA semantics about 0 registers.
1062680Sktlim@umich.edu     * @param tc The thread context.
1072501SN/A     */
1082680Sktlim@umich.edu    template <class TC>
1092680Sktlim@umich.edu    void zeroRegisters(TC *tc);
1102501SN/A
1113532Sgblack@eecs.umich.edu    inline void initCPU(ThreadContext *tc, int cpuId)
1123528Sgblack@eecs.umich.edu    {
1133532Sgblack@eecs.umich.edu        static Fault por = new PowerOnReset();
1143532Sgblack@eecs.umich.edu        por->invoke(tc);
1153528Sgblack@eecs.umich.edu    }
1163528Sgblack@eecs.umich.edu
1172501SN/A} // namespace SparcISA
1182501SN/A
1192501SN/A#endif
120