utility.hh revision 8829
16019Shines@cs.fsu.edu/*
27111Sgblack@eecs.umich.edu * Copyright (c) 2010 ARM Limited
37111Sgblack@eecs.umich.edu * All rights reserved
47111Sgblack@eecs.umich.edu *
57111Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67111Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77111Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87111Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97111Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107111Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117111Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127111Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137111Sgblack@eecs.umich.edu *
146019Shines@cs.fsu.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
156019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University
166019Shines@cs.fsu.edu * All rights reserved.
176019Shines@cs.fsu.edu *
186019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
196019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
206019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
216019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
226019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
236019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
246019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
256019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
266019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
276019Shines@cs.fsu.edu * this software without specific prior written permission.
286019Shines@cs.fsu.edu *
296019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406019Shines@cs.fsu.edu *
416019Shines@cs.fsu.edu * Authors: Korey Sewell
426019Shines@cs.fsu.edu *          Stephen Hines
436019Shines@cs.fsu.edu */
446019Shines@cs.fsu.edu
456019Shines@cs.fsu.edu#ifndef __ARCH_ARM_UTILITY_HH__
466019Shines@cs.fsu.edu#define __ARCH_ARM_UTILITY_HH__
476019Shines@cs.fsu.edu
487692SAli.Saidi@ARM.com#include "arch/arm/isa_traits.hh"
496242Sgblack@eecs.umich.edu#include "arch/arm/miscregs.hh"
506019Shines@cs.fsu.edu#include "arch/arm/types.hh"
517678Sgblack@eecs.umich.edu#include "base/misc.hh"
527408Sgblack@eecs.umich.edu#include "base/trace.hh"
536216Snate@binkert.org#include "base/types.hh"
547720Sgblack@eecs.umich.edu#include "cpu/static_inst.hh"
556019Shines@cs.fsu.edu#include "cpu/thread_context.hh"
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.edunamespace ArmISA {
586019Shines@cs.fsu.edu
597751SAli.Saidi@ARM.cominline PCState
607751SAli.Saidi@ARM.combuildRetPC(const PCState &curPC, const PCState &callPC)
617751SAli.Saidi@ARM.com{
627751SAli.Saidi@ARM.com    PCState retPC = callPC;
637751SAli.Saidi@ARM.com    retPC.uEnd();
647751SAli.Saidi@ARM.com    return retPC;
657751SAli.Saidi@ARM.com}
667751SAli.Saidi@ARM.com
677751SAli.Saidi@ARM.cominline bool
688303SAli.Saidi@ARM.comtestPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
697751SAli.Saidi@ARM.com{
708303SAli.Saidi@ARM.com    bool n = (nz & 0x2);
718303SAli.Saidi@ARM.com    bool z = (nz & 0x1);
728303SAli.Saidi@ARM.com
737751SAli.Saidi@ARM.com    switch (code)
747720Sgblack@eecs.umich.edu    {
758303SAli.Saidi@ARM.com        case COND_EQ: return  z;
768303SAli.Saidi@ARM.com        case COND_NE: return !z;
778303SAli.Saidi@ARM.com        case COND_CS: return  c;
788303SAli.Saidi@ARM.com        case COND_CC: return !c;
798303SAli.Saidi@ARM.com        case COND_MI: return  n;
808303SAli.Saidi@ARM.com        case COND_PL: return !n;
818303SAli.Saidi@ARM.com        case COND_VS: return  v;
828303SAli.Saidi@ARM.com        case COND_VC: return !v;
838303SAli.Saidi@ARM.com        case COND_HI: return  (c && !z);
848303SAli.Saidi@ARM.com        case COND_LS: return !(c && !z);
858303SAli.Saidi@ARM.com        case COND_GE: return !(n ^ v);
868303SAli.Saidi@ARM.com        case COND_LT: return  (n ^ v);
878303SAli.Saidi@ARM.com        case COND_GT: return !(n ^ v || z);
888303SAli.Saidi@ARM.com        case COND_LE: return  (n ^ v || z);
897751SAli.Saidi@ARM.com        case COND_AL: return true;
907751SAli.Saidi@ARM.com        case COND_UC: return true;
917751SAli.Saidi@ARM.com        default:
927751SAli.Saidi@ARM.com            panic("Unhandled predicate condition: %d\n", code);
937720Sgblack@eecs.umich.edu    }
947751SAli.Saidi@ARM.com}
957720Sgblack@eecs.umich.edu
967751SAli.Saidi@ARM.com/**
977751SAli.Saidi@ARM.com * Function to insure ISA semantics about 0 registers.
987751SAli.Saidi@ARM.com * @param tc The thread context.
997751SAli.Saidi@ARM.com */
1007751SAli.Saidi@ARM.comtemplate <class TC>
1017751SAli.Saidi@ARM.comvoid zeroRegisters(TC *tc);
1026242Sgblack@eecs.umich.edu
1037751SAli.Saidi@ARM.cominline void startupCPU(ThreadContext *tc, int cpuId)
1047751SAli.Saidi@ARM.com{
1057751SAli.Saidi@ARM.com    tc->activate(0);
1067751SAli.Saidi@ARM.com}
1076019Shines@cs.fsu.edu
1087751SAli.Saidi@ARM.comvoid copyRegs(ThreadContext *src, ThreadContext *dest);
1096246Sgblack@eecs.umich.edu
1107751SAli.Saidi@ARM.comstatic inline void
1117751SAli.Saidi@ARM.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest)
1127751SAli.Saidi@ARM.com{
1137751SAli.Saidi@ARM.com    panic("Copy Misc. Regs Not Implemented Yet\n");
1147751SAli.Saidi@ARM.com}
1156329Sgblack@eecs.umich.edu
1167751SAli.Saidi@ARM.comvoid initCPU(ThreadContext *tc, int cpuId);
1176757SAli.Saidi@ARM.com
1187751SAli.Saidi@ARM.comstatic inline bool
1197751SAli.Saidi@ARM.cominUserMode(CPSR cpsr)
1207751SAli.Saidi@ARM.com{
1217751SAli.Saidi@ARM.com    return cpsr.mode == MODE_USER;
1227751SAli.Saidi@ARM.com}
1237638Sgblack@eecs.umich.edu
1247751SAli.Saidi@ARM.comstatic inline bool
1257751SAli.Saidi@ARM.cominUserMode(ThreadContext *tc)
1267751SAli.Saidi@ARM.com{
1277751SAli.Saidi@ARM.com    return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR));
1287751SAli.Saidi@ARM.com}
1297638Sgblack@eecs.umich.edu
1307751SAli.Saidi@ARM.comstatic inline bool
1317751SAli.Saidi@ARM.cominPrivilegedMode(CPSR cpsr)
1327751SAli.Saidi@ARM.com{
1337751SAli.Saidi@ARM.com    return !inUserMode(cpsr);
1347751SAli.Saidi@ARM.com}
1357638Sgblack@eecs.umich.edu
1367751SAli.Saidi@ARM.comstatic inline bool
1377751SAli.Saidi@ARM.cominPrivilegedMode(ThreadContext *tc)
1387751SAli.Saidi@ARM.com{
1397751SAli.Saidi@ARM.com    return !inUserMode(tc);
1407751SAli.Saidi@ARM.com}
1416757SAli.Saidi@ARM.com
1427751SAli.Saidi@ARM.comstatic inline bool
1437751SAli.Saidi@ARM.comvfpEnabled(CPACR cpacr, CPSR cpsr)
1447751SAli.Saidi@ARM.com{
1457751SAli.Saidi@ARM.com    return cpacr.cp10 == 0x3 ||
1467751SAli.Saidi@ARM.com        (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr));
1477751SAli.Saidi@ARM.com}
1487640Sgblack@eecs.umich.edu
1497751SAli.Saidi@ARM.comstatic inline bool
1507751SAli.Saidi@ARM.comvfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1517751SAli.Saidi@ARM.com{
1528206SWilliam.Wang@arm.com    if ((cpacr.cp11 == 0x3) ||
1538206SWilliam.Wang@arm.com        ((cpacr.cp11 == 0x1) && inPrivilegedMode(cpsr)))
1548206SWilliam.Wang@arm.com        return fpexc.en && vfpEnabled(cpacr, cpsr);
1558206SWilliam.Wang@arm.com    else
1568206SWilliam.Wang@arm.com        return fpexc.en && vfpEnabled(cpacr, cpsr) &&
1578206SWilliam.Wang@arm.com            (cpacr.cp11 == cpacr.cp10);
1587751SAli.Saidi@ARM.com}
1597640Sgblack@eecs.umich.edu
1607751SAli.Saidi@ARM.comstatic inline bool
1617751SAli.Saidi@ARM.comneonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1627751SAli.Saidi@ARM.com{
1637751SAli.Saidi@ARM.com    return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc);
1647751SAli.Saidi@ARM.com}
1657640Sgblack@eecs.umich.edu
1667707Sgblack@eecs.umich.eduuint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
1676757SAli.Saidi@ARM.com
1687693SAli.Saidi@ARM.comvoid skipFunction(ThreadContext *tc);
1697693SAli.Saidi@ARM.com
1707720Sgblack@eecs.umich.eduinline void
1717720Sgblack@eecs.umich.eduadvancePC(PCState &pc, const StaticInstPtr inst)
1727720Sgblack@eecs.umich.edu{
1737720Sgblack@eecs.umich.edu    inst->advancePC(pc);
1747720Sgblack@eecs.umich.edu}
1757720Sgblack@eecs.umich.edu
1767752SWilliam.Wang@arm.comAddr truncPage(Addr addr);
1777752SWilliam.Wang@arm.comAddr roundPage(Addr addr);
1787752SWilliam.Wang@arm.com
1798300Schander.sudanthi@arm.cominline uint64_t
1808300Schander.sudanthi@arm.comgetExecutingAsid(ThreadContext *tc)
1818300Schander.sudanthi@arm.com{
1828300Schander.sudanthi@arm.com    return tc->readMiscReg(MISCREG_CONTEXTIDR);
1838300Schander.sudanthi@arm.com}
1848300Schander.sudanthi@arm.com
1856019Shines@cs.fsu.edu};
1866019Shines@cs.fsu.edu
1876019Shines@cs.fsu.edu#endif
188