utility.hh revision 6757
16019Shines@cs.fsu.edu/*
26019Shines@cs.fsu.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
36019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University
46019Shines@cs.fsu.edu * All rights reserved.
56019Shines@cs.fsu.edu *
66019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
76019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
86019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
96019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
106019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
116019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
126019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
136019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
146019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
156019Shines@cs.fsu.edu * this software without specific prior written permission.
166019Shines@cs.fsu.edu *
176019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286019Shines@cs.fsu.edu *
296019Shines@cs.fsu.edu * Authors: Korey Sewell
306019Shines@cs.fsu.edu *          Stephen Hines
316019Shines@cs.fsu.edu */
326019Shines@cs.fsu.edu
336019Shines@cs.fsu.edu#ifndef __ARCH_ARM_UTILITY_HH__
346019Shines@cs.fsu.edu#define __ARCH_ARM_UTILITY_HH__
356019Shines@cs.fsu.edu
366242Sgblack@eecs.umich.edu#include "arch/arm/miscregs.hh"
376019Shines@cs.fsu.edu#include "arch/arm/types.hh"
386251Sgblack@eecs.umich.edu#include "base/hashmap.hh"
396216Snate@binkert.org#include "base/types.hh"
406019Shines@cs.fsu.edu#include "cpu/thread_context.hh"
416019Shines@cs.fsu.edu
426251Sgblack@eecs.umich.edunamespace __hash_namespace {
436251Sgblack@eecs.umich.edu    template<>
446251Sgblack@eecs.umich.edu    struct hash<ArmISA::ExtMachInst> : public hash<uint32_t> {
456251Sgblack@eecs.umich.edu        size_t operator()(const ArmISA::ExtMachInst &emi) const {
466251Sgblack@eecs.umich.edu            return hash<uint32_t>::operator()((uint32_t)emi);
476251Sgblack@eecs.umich.edu        };
486251Sgblack@eecs.umich.edu    };
496251Sgblack@eecs.umich.edu}
506251Sgblack@eecs.umich.edu
516019Shines@cs.fsu.edunamespace ArmISA {
526019Shines@cs.fsu.edu
536242Sgblack@eecs.umich.edu    inline bool
546242Sgblack@eecs.umich.edu    testPredicate(CPSR cpsr, ConditionCode code)
556242Sgblack@eecs.umich.edu    {
566242Sgblack@eecs.umich.edu        switch (code)
576242Sgblack@eecs.umich.edu        {
586242Sgblack@eecs.umich.edu            case COND_EQ: return  cpsr.z;
596242Sgblack@eecs.umich.edu            case COND_NE: return !cpsr.z;
606242Sgblack@eecs.umich.edu            case COND_CS: return  cpsr.c;
616242Sgblack@eecs.umich.edu            case COND_CC: return !cpsr.c;
626242Sgblack@eecs.umich.edu            case COND_MI: return  cpsr.n;
636242Sgblack@eecs.umich.edu            case COND_PL: return !cpsr.n;
646242Sgblack@eecs.umich.edu            case COND_VS: return  cpsr.v;
656242Sgblack@eecs.umich.edu            case COND_VC: return !cpsr.v;
666242Sgblack@eecs.umich.edu            case COND_HI: return  (cpsr.c && !cpsr.z);
676242Sgblack@eecs.umich.edu            case COND_LS: return !(cpsr.c && !cpsr.z);
686242Sgblack@eecs.umich.edu            case COND_GE: return !(cpsr.n ^ cpsr.v);
696242Sgblack@eecs.umich.edu            case COND_LT: return  (cpsr.n ^ cpsr.v);
706242Sgblack@eecs.umich.edu            case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z);
716242Sgblack@eecs.umich.edu            case COND_LE: return  (cpsr.n ^ cpsr.v || cpsr.z);
726242Sgblack@eecs.umich.edu            case COND_AL: return true;
736242Sgblack@eecs.umich.edu            case COND_NV: return false;
746242Sgblack@eecs.umich.edu            default:
756242Sgblack@eecs.umich.edu                panic("Unhandled predicate condition: %d\n", code);
766242Sgblack@eecs.umich.edu        }
776242Sgblack@eecs.umich.edu    }
786242Sgblack@eecs.umich.edu
796019Shines@cs.fsu.edu    /**
806019Shines@cs.fsu.edu     * Function to insure ISA semantics about 0 registers.
816019Shines@cs.fsu.edu     * @param tc The thread context.
826019Shines@cs.fsu.edu     */
836019Shines@cs.fsu.edu    template <class TC>
846019Shines@cs.fsu.edu    void zeroRegisters(TC *tc);
856019Shines@cs.fsu.edu
866019Shines@cs.fsu.edu    // Instruction address compression hooks
876019Shines@cs.fsu.edu    static inline Addr realPCToFetchPC(const Addr &addr) {
886019Shines@cs.fsu.edu        return addr;
896019Shines@cs.fsu.edu    }
906019Shines@cs.fsu.edu
916019Shines@cs.fsu.edu    static inline Addr fetchPCToRealPC(const Addr &addr) {
926019Shines@cs.fsu.edu        return addr;
936019Shines@cs.fsu.edu    }
946019Shines@cs.fsu.edu
956019Shines@cs.fsu.edu    // the size of "fetched" instructions
966019Shines@cs.fsu.edu    static inline size_t fetchInstSize() {
976019Shines@cs.fsu.edu        return sizeof(MachInst);
986019Shines@cs.fsu.edu    }
996019Shines@cs.fsu.edu
1006019Shines@cs.fsu.edu    static inline MachInst makeRegisterCopy(int dest, int src) {
1016019Shines@cs.fsu.edu        panic("makeRegisterCopy not implemented");
1026019Shines@cs.fsu.edu        return 0;
1036019Shines@cs.fsu.edu    }
1046019Shines@cs.fsu.edu
1056019Shines@cs.fsu.edu    inline void startupCPU(ThreadContext *tc, int cpuId)
1066019Shines@cs.fsu.edu    {
1076019Shines@cs.fsu.edu        tc->activate(0);
1086019Shines@cs.fsu.edu    }
1096246Sgblack@eecs.umich.edu
1106246Sgblack@eecs.umich.edu    template <class XC>
1116246Sgblack@eecs.umich.edu    Fault
1126246Sgblack@eecs.umich.edu    checkFpEnableFault(XC *xc)
1136246Sgblack@eecs.umich.edu    {
1146246Sgblack@eecs.umich.edu        return NoFault;
1156246Sgblack@eecs.umich.edu    }
1166329Sgblack@eecs.umich.edu
1176329Sgblack@eecs.umich.edu    static inline void
1186329Sgblack@eecs.umich.edu    copyRegs(ThreadContext *src, ThreadContext *dest)
1196329Sgblack@eecs.umich.edu    {
1206329Sgblack@eecs.umich.edu        panic("Copy Regs Not Implemented Yet\n");
1216329Sgblack@eecs.umich.edu    }
1226329Sgblack@eecs.umich.edu
1236329Sgblack@eecs.umich.edu    static inline void
1246329Sgblack@eecs.umich.edu    copyMiscRegs(ThreadContext *src, ThreadContext *dest)
1256329Sgblack@eecs.umich.edu    {
1266329Sgblack@eecs.umich.edu        panic("Copy Misc. Regs Not Implemented Yet\n");
1276329Sgblack@eecs.umich.edu    }
1286757SAli.Saidi@ARM.com
1296757SAli.Saidi@ARM.com    void initCPU(ThreadContext *tc, int cpuId);
1306757SAli.Saidi@ARM.com
1316757SAli.Saidi@ARM.com    static inline bool
1326757SAli.Saidi@ARM.com    inUserMode(ThreadContext *tc)
1336757SAli.Saidi@ARM.com    {
1346757SAli.Saidi@ARM.com        return (tc->readMiscRegNoEffect(MISCREG_CPSR) & 0x1f) == MODE_USER;
1356757SAli.Saidi@ARM.com    }
1366757SAli.Saidi@ARM.com
1376757SAli.Saidi@ARM.comuint64_t getArgument(ThreadContext *tc, int number, bool fp);
1386757SAli.Saidi@ARM.com
1396019Shines@cs.fsu.edu};
1406019Shines@cs.fsu.edu
1416019Shines@cs.fsu.edu
1426019Shines@cs.fsu.edu#endif
143