utility.hh revision 7878
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
687751SAli.Saidi@ARM.comtestPredicate(CPSR cpsr, ConditionCode code)
697751SAli.Saidi@ARM.com{
707751SAli.Saidi@ARM.com    switch (code)
717720Sgblack@eecs.umich.edu    {
727751SAli.Saidi@ARM.com        case COND_EQ: return  cpsr.z;
737751SAli.Saidi@ARM.com        case COND_NE: return !cpsr.z;
747751SAli.Saidi@ARM.com        case COND_CS: return  cpsr.c;
757751SAli.Saidi@ARM.com        case COND_CC: return !cpsr.c;
767751SAli.Saidi@ARM.com        case COND_MI: return  cpsr.n;
777751SAli.Saidi@ARM.com        case COND_PL: return !cpsr.n;
787751SAli.Saidi@ARM.com        case COND_VS: return  cpsr.v;
797751SAli.Saidi@ARM.com        case COND_VC: return !cpsr.v;
807751SAli.Saidi@ARM.com        case COND_HI: return  (cpsr.c && !cpsr.z);
817751SAli.Saidi@ARM.com        case COND_LS: return !(cpsr.c && !cpsr.z);
827751SAli.Saidi@ARM.com        case COND_GE: return !(cpsr.n ^ cpsr.v);
837751SAli.Saidi@ARM.com        case COND_LT: return  (cpsr.n ^ cpsr.v);
847751SAli.Saidi@ARM.com        case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z);
857751SAli.Saidi@ARM.com        case COND_LE: return  (cpsr.n ^ cpsr.v || cpsr.z);
867751SAli.Saidi@ARM.com        case COND_AL: return true;
877751SAli.Saidi@ARM.com        case COND_UC: return true;
887751SAli.Saidi@ARM.com        default:
897751SAli.Saidi@ARM.com            panic("Unhandled predicate condition: %d\n", code);
907720Sgblack@eecs.umich.edu    }
917751SAli.Saidi@ARM.com}
927720Sgblack@eecs.umich.edu
937751SAli.Saidi@ARM.com/**
947751SAli.Saidi@ARM.com * Function to insure ISA semantics about 0 registers.
957751SAli.Saidi@ARM.com * @param tc The thread context.
967751SAli.Saidi@ARM.com */
977751SAli.Saidi@ARM.comtemplate <class TC>
987751SAli.Saidi@ARM.comvoid zeroRegisters(TC *tc);
996242Sgblack@eecs.umich.edu
1007751SAli.Saidi@ARM.cominline void startupCPU(ThreadContext *tc, int cpuId)
1017751SAli.Saidi@ARM.com{
1027751SAli.Saidi@ARM.com    tc->activate(0);
1037751SAli.Saidi@ARM.com}
1046019Shines@cs.fsu.edu
1057751SAli.Saidi@ARM.comvoid copyRegs(ThreadContext *src, ThreadContext *dest);
1066246Sgblack@eecs.umich.edu
1077751SAli.Saidi@ARM.comstatic inline void
1087751SAli.Saidi@ARM.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest)
1097751SAli.Saidi@ARM.com{
1107751SAli.Saidi@ARM.com    panic("Copy Misc. Regs Not Implemented Yet\n");
1117751SAli.Saidi@ARM.com}
1126329Sgblack@eecs.umich.edu
1137751SAli.Saidi@ARM.comvoid initCPU(ThreadContext *tc, int cpuId);
1146757SAli.Saidi@ARM.com
1157751SAli.Saidi@ARM.comstatic inline bool
1167751SAli.Saidi@ARM.cominUserMode(CPSR cpsr)
1177751SAli.Saidi@ARM.com{
1187751SAli.Saidi@ARM.com    return cpsr.mode == MODE_USER;
1197751SAli.Saidi@ARM.com}
1207638Sgblack@eecs.umich.edu
1217751SAli.Saidi@ARM.comstatic inline bool
1227751SAli.Saidi@ARM.cominUserMode(ThreadContext *tc)
1237751SAli.Saidi@ARM.com{
1247751SAli.Saidi@ARM.com    return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR));
1257751SAli.Saidi@ARM.com}
1267638Sgblack@eecs.umich.edu
1277751SAli.Saidi@ARM.comstatic inline bool
1287751SAli.Saidi@ARM.cominPrivilegedMode(CPSR cpsr)
1297751SAli.Saidi@ARM.com{
1307751SAli.Saidi@ARM.com    return !inUserMode(cpsr);
1317751SAli.Saidi@ARM.com}
1327638Sgblack@eecs.umich.edu
1337751SAli.Saidi@ARM.comstatic inline bool
1347751SAli.Saidi@ARM.cominPrivilegedMode(ThreadContext *tc)
1357751SAli.Saidi@ARM.com{
1367751SAli.Saidi@ARM.com    return !inUserMode(tc);
1377751SAli.Saidi@ARM.com}
1386757SAli.Saidi@ARM.com
1397751SAli.Saidi@ARM.comstatic inline bool
1407751SAli.Saidi@ARM.comvfpEnabled(CPACR cpacr, CPSR cpsr)
1417751SAli.Saidi@ARM.com{
1427751SAli.Saidi@ARM.com    return cpacr.cp10 == 0x3 ||
1437751SAli.Saidi@ARM.com        (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr));
1447751SAli.Saidi@ARM.com}
1457640Sgblack@eecs.umich.edu
1467751SAli.Saidi@ARM.comstatic inline bool
1477751SAli.Saidi@ARM.comvfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1487751SAli.Saidi@ARM.com{
1497751SAli.Saidi@ARM.com    return fpexc.en && vfpEnabled(cpacr, cpsr);
1507751SAli.Saidi@ARM.com}
1517640Sgblack@eecs.umich.edu
1527751SAli.Saidi@ARM.comstatic inline bool
1537751SAli.Saidi@ARM.comneonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc)
1547751SAli.Saidi@ARM.com{
1557751SAli.Saidi@ARM.com    return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc);
1567751SAli.Saidi@ARM.com}
1577640Sgblack@eecs.umich.edu
1587707Sgblack@eecs.umich.eduuint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
1596759SAli.Saidi@ARM.com
1606759SAli.Saidi@ARM.comFault setCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
1616759SAli.Saidi@ARM.comFault readCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
1626757SAli.Saidi@ARM.com
1637693SAli.Saidi@ARM.comvoid skipFunction(ThreadContext *tc);
1647693SAli.Saidi@ARM.com
1657720Sgblack@eecs.umich.eduinline void
1667720Sgblack@eecs.umich.eduadvancePC(PCState &pc, const StaticInstPtr inst)
1677720Sgblack@eecs.umich.edu{
1687720Sgblack@eecs.umich.edu    inst->advancePC(pc);
1697720Sgblack@eecs.umich.edu}
1707720Sgblack@eecs.umich.edu
1717752SWilliam.Wang@arm.comAddr truncPage(Addr addr);
1727752SWilliam.Wang@arm.comAddr roundPage(Addr addr);
1737752SWilliam.Wang@arm.com
1746019Shines@cs.fsu.edu};
1756019Shines@cs.fsu.edu
1766019Shines@cs.fsu.edu
1776019Shines@cs.fsu.edu#endif
178