16019Shines@cs.fsu.edu/*
214169Sgiacomo.travaglini@arm.com * Copyright (c) 2010, 2012-2013, 2016-2019 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"
5112334Sgabeblack@google.com#include "base/logging.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
5710037SARM gem5 Developersclass ArmSystem;
5810037SARM gem5 Developers
596019Shines@cs.fsu.edunamespace ArmISA {
606019Shines@cs.fsu.edu
617751SAli.Saidi@ARM.cominline PCState
627751SAli.Saidi@ARM.combuildRetPC(const PCState &curPC, const PCState &callPC)
637751SAli.Saidi@ARM.com{
647751SAli.Saidi@ARM.com    PCState retPC = callPC;
657751SAli.Saidi@ARM.com    retPC.uEnd();
667751SAli.Saidi@ARM.com    return retPC;
677751SAli.Saidi@ARM.com}
687751SAli.Saidi@ARM.com
697751SAli.Saidi@ARM.cominline bool
708303SAli.Saidi@ARM.comtestPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
717751SAli.Saidi@ARM.com{
728303SAli.Saidi@ARM.com    bool n = (nz & 0x2);
738303SAli.Saidi@ARM.com    bool z = (nz & 0x1);
748303SAli.Saidi@ARM.com
757751SAli.Saidi@ARM.com    switch (code)
767720Sgblack@eecs.umich.edu    {
778303SAli.Saidi@ARM.com        case COND_EQ: return  z;
788303SAli.Saidi@ARM.com        case COND_NE: return !z;
798303SAli.Saidi@ARM.com        case COND_CS: return  c;
808303SAli.Saidi@ARM.com        case COND_CC: return !c;
818303SAli.Saidi@ARM.com        case COND_MI: return  n;
828303SAli.Saidi@ARM.com        case COND_PL: return !n;
838303SAli.Saidi@ARM.com        case COND_VS: return  v;
848303SAli.Saidi@ARM.com        case COND_VC: return !v;
858303SAli.Saidi@ARM.com        case COND_HI: return  (c && !z);
868303SAli.Saidi@ARM.com        case COND_LS: return !(c && !z);
878303SAli.Saidi@ARM.com        case COND_GE: return !(n ^ v);
888303SAli.Saidi@ARM.com        case COND_LT: return  (n ^ v);
898303SAli.Saidi@ARM.com        case COND_GT: return !(n ^ v || z);
908303SAli.Saidi@ARM.com        case COND_LE: return  (n ^ v || z);
917751SAli.Saidi@ARM.com        case COND_AL: return true;
927751SAli.Saidi@ARM.com        case COND_UC: return true;
937751SAli.Saidi@ARM.com        default:
947751SAli.Saidi@ARM.com            panic("Unhandled predicate condition: %d\n", code);
957720Sgblack@eecs.umich.edu    }
967751SAli.Saidi@ARM.com}
977720Sgblack@eecs.umich.edu
987751SAli.Saidi@ARM.com/**
997751SAli.Saidi@ARM.com * Function to insure ISA semantics about 0 registers.
1007751SAli.Saidi@ARM.com * @param tc The thread context.
1017751SAli.Saidi@ARM.com */
1027751SAli.Saidi@ARM.comtemplate <class TC>
1037751SAli.Saidi@ARM.comvoid zeroRegisters(TC *tc);
1046242Sgblack@eecs.umich.edu
1057751SAli.Saidi@ARM.cominline void startupCPU(ThreadContext *tc, int cpuId)
1067751SAli.Saidi@ARM.com{
10710407Smitch.hayenga@arm.com    tc->activate();
1087751SAli.Saidi@ARM.com}
1096019Shines@cs.fsu.edu
1107751SAli.Saidi@ARM.comvoid copyRegs(ThreadContext *src, ThreadContext *dest);
1116246Sgblack@eecs.umich.edu
1127751SAli.Saidi@ARM.comstatic inline void
1137751SAli.Saidi@ARM.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest)
1147751SAli.Saidi@ARM.com{
1157751SAli.Saidi@ARM.com    panic("Copy Misc. Regs Not Implemented Yet\n");
1167751SAli.Saidi@ARM.com}
1176329Sgblack@eecs.umich.edu
1187751SAli.Saidi@ARM.comvoid initCPU(ThreadContext *tc, int cpuId);
1196757SAli.Saidi@ARM.com
1207751SAli.Saidi@ARM.comstatic inline bool
1217751SAli.Saidi@ARM.cominUserMode(CPSR cpsr)
1227751SAli.Saidi@ARM.com{
12310037SARM gem5 Developers    return cpsr.mode == MODE_USER || cpsr.mode == MODE_EL0T;
1247751SAli.Saidi@ARM.com}
1257638Sgblack@eecs.umich.edu
1267751SAli.Saidi@ARM.comstatic inline bool
1277751SAli.Saidi@ARM.cominUserMode(ThreadContext *tc)
1287751SAli.Saidi@ARM.com{
1297751SAli.Saidi@ARM.com    return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR));
1307751SAli.Saidi@ARM.com}
1317638Sgblack@eecs.umich.edu
1327751SAli.Saidi@ARM.comstatic inline bool
1337751SAli.Saidi@ARM.cominPrivilegedMode(CPSR cpsr)
1347751SAli.Saidi@ARM.com{
1357751SAli.Saidi@ARM.com    return !inUserMode(cpsr);
1367751SAli.Saidi@ARM.com}
1377638Sgblack@eecs.umich.edu
1387751SAli.Saidi@ARM.comstatic inline bool
1397751SAli.Saidi@ARM.cominPrivilegedMode(ThreadContext *tc)
1407751SAli.Saidi@ARM.com{
1417751SAli.Saidi@ARM.com    return !inUserMode(tc);
1427751SAli.Saidi@ARM.com}
1436757SAli.Saidi@ARM.com
14410037SARM gem5 Developersbool inAArch64(ThreadContext *tc);
14510037SARM gem5 Developers
14610037SARM gem5 Developersstatic inline OperatingMode
14710037SARM gem5 DeveloperscurrOpMode(ThreadContext *tc)
1487751SAli.Saidi@ARM.com{
14910037SARM gem5 Developers    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
15010037SARM gem5 Developers    return (OperatingMode) (uint8_t) cpsr.mode;
1517751SAli.Saidi@ARM.com}
1527640Sgblack@eecs.umich.edu
15310037SARM gem5 Developersstatic inline ExceptionLevel
15410037SARM gem5 DeveloperscurrEL(ThreadContext *tc)
1557751SAli.Saidi@ARM.com{
15614169Sgiacomo.travaglini@arm.com    return opModeToEL(currOpMode(tc));
1577751SAli.Saidi@ARM.com}
1587640Sgblack@eecs.umich.edu
15914170Sgiacomo.travaglini@arm.cominline ExceptionLevel
16014170Sgiacomo.travaglini@arm.comcurrEL(CPSR cpsr)
16114170Sgiacomo.travaglini@arm.com{
16214170Sgiacomo.travaglini@arm.com    return opModeToEL((OperatingMode) (uint8_t)cpsr.mode);
16314170Sgiacomo.travaglini@arm.com}
16414170Sgiacomo.travaglini@arm.com
16512496Sgiacomo.travaglini@arm.com/**
16612496Sgiacomo.travaglini@arm.com * This function checks whether selected EL provided as an argument
16712496Sgiacomo.travaglini@arm.com * is using the AArch32 ISA. This information might be unavailable
16812496Sgiacomo.travaglini@arm.com * at the current EL status: it hence returns a pair of boolean values:
16912496Sgiacomo.travaglini@arm.com * a first boolean, true if information is available (known),
17012496Sgiacomo.travaglini@arm.com * and a second one, true if EL is using AArch32, false for AArch64.
17112496Sgiacomo.travaglini@arm.com *
17212496Sgiacomo.travaglini@arm.com * @param tc The thread context.
17312496Sgiacomo.travaglini@arm.com * @param el The target exception level.
17412496Sgiacomo.travaglini@arm.com * @retval known is FALSE for EL0 if the current Exception level
17512496Sgiacomo.travaglini@arm.com *               is not EL0 and EL1 is using AArch64, since it cannot
17612496Sgiacomo.travaglini@arm.com *               determine the state of EL0; TRUE otherwise.
17712496Sgiacomo.travaglini@arm.com * @retval aarch32 is TRUE if the specified Exception level is using AArch32;
17812496Sgiacomo.travaglini@arm.com *                 FALSE otherwise.
17912496Sgiacomo.travaglini@arm.com */
18012496Sgiacomo.travaglini@arm.comstd::pair<bool, bool>
18112496Sgiacomo.travaglini@arm.comELUsingAArch32K(ThreadContext *tc, ExceptionLevel el);
18212496Sgiacomo.travaglini@arm.com
18312494Schuan.zhu@arm.combool ELIs32(ThreadContext *tc, ExceptionLevel el);
18412494Schuan.zhu@arm.com
18510037SARM gem5 Developersbool ELIs64(ThreadContext *tc, ExceptionLevel el);
18610037SARM gem5 Developers
18713759Sgiacomo.gabrielli@arm.com/**
18813759Sgiacomo.gabrielli@arm.com * Returns true if the current exception level `el` is executing a Host OS or
18913759Sgiacomo.gabrielli@arm.com * an application of a Host OS (Armv8.1 Virtualization Host Extensions).
19013759Sgiacomo.gabrielli@arm.com */
19113759Sgiacomo.gabrielli@arm.combool ELIsInHost(ThreadContext *tc, ExceptionLevel el);
19213759Sgiacomo.gabrielli@arm.com
19310037SARM gem5 Developersbool isBigEndian64(ThreadContext *tc);
19410037SARM gem5 Developers
19512788Sgiacomo.travaglini@arm.com/**
19612788Sgiacomo.travaglini@arm.com * badMode is checking if the execution mode provided as an argument is
19712788Sgiacomo.travaglini@arm.com * valid and implemented for AArch32
19812788Sgiacomo.travaglini@arm.com *
19912788Sgiacomo.travaglini@arm.com * @param tc ThreadContext
20012788Sgiacomo.travaglini@arm.com * @param mode OperatingMode to check
20112788Sgiacomo.travaglini@arm.com * @return false if mode is valid and implemented, true otherwise
20212788Sgiacomo.travaglini@arm.com */
20312788Sgiacomo.travaglini@arm.combool badMode32(ThreadContext *tc, OperatingMode mode);
20412788Sgiacomo.travaglini@arm.com
20512788Sgiacomo.travaglini@arm.com/**
20612788Sgiacomo.travaglini@arm.com * badMode is checking if the execution mode provided as an argument is
20712788Sgiacomo.travaglini@arm.com * valid and implemented.
20812788Sgiacomo.travaglini@arm.com *
20912788Sgiacomo.travaglini@arm.com * @param tc ThreadContext
21012788Sgiacomo.travaglini@arm.com * @param mode OperatingMode to check
21112788Sgiacomo.travaglini@arm.com * @return false if mode is valid and implemented, true otherwise
21212788Sgiacomo.travaglini@arm.com */
21312788Sgiacomo.travaglini@arm.combool badMode(ThreadContext *tc, OperatingMode mode);
21412788Sgiacomo.travaglini@arm.com
21511514Sandreas.sandberg@arm.comstatic inline uint8_t
21611514Sandreas.sandberg@arm.comitState(CPSR psr)
21711514Sandreas.sandberg@arm.com{
21811514Sandreas.sandberg@arm.com    ITSTATE it = 0;
21911514Sandreas.sandberg@arm.com    it.top6 = psr.it2;
22011514Sandreas.sandberg@arm.com    it.bottom2 = psr.it1;
22111514Sandreas.sandberg@arm.com
22211514Sandreas.sandberg@arm.com    return (uint8_t)it;
22311514Sandreas.sandberg@arm.com}
22411514Sandreas.sandberg@arm.com
22510037SARM gem5 Developers/**
22610037SARM gem5 Developers * Removes the tag from tagged addresses if that mode is enabled.
22710037SARM gem5 Developers * @param addr The address to be purified.
22810037SARM gem5 Developers * @param tc The thread context.
22910037SARM gem5 Developers * @param el The controlled exception level.
23010037SARM gem5 Developers * @return The purified address.
23110037SARM gem5 Developers */
23210854SNathanael.Premillieu@arm.comAddr purifyTaggedAddr(Addr addr, ThreadContext *tc, ExceptionLevel el,
23310854SNathanael.Premillieu@arm.com                      TTBCR tcr);
23410037SARM gem5 DevelopersAddr purifyTaggedAddr(Addr addr, ThreadContext *tc, ExceptionLevel el);
23510037SARM gem5 Developers
2367751SAli.Saidi@ARM.comstatic inline bool
23710037SARM gem5 DevelopersinSecureState(SCR scr, CPSR cpsr)
2387751SAli.Saidi@ARM.com{
23910037SARM gem5 Developers    switch ((OperatingMode) (uint8_t) cpsr.mode) {
24010037SARM gem5 Developers      case MODE_MON:
24110037SARM gem5 Developers      case MODE_EL3T:
24210037SARM gem5 Developers      case MODE_EL3H:
24310037SARM gem5 Developers        return true;
24410037SARM gem5 Developers      case MODE_HYP:
24510037SARM gem5 Developers      case MODE_EL2T:
24610037SARM gem5 Developers      case MODE_EL2H:
24710037SARM gem5 Developers        return false;
24810037SARM gem5 Developers      default:
24910037SARM gem5 Developers        return !scr.ns;
25010037SARM gem5 Developers    }
2517751SAli.Saidi@ARM.com}
2527640Sgblack@eecs.umich.edu
25312495Sgiacomo.travaglini@arm.combool inSecureState(ThreadContext *tc);
25412495Sgiacomo.travaglini@arm.com
25512495Sgiacomo.travaglini@arm.com/**
25612495Sgiacomo.travaglini@arm.com * Return TRUE if an Exception level below EL3 is in Secure state.
25712495Sgiacomo.travaglini@arm.com * Differs from inSecureState in that it ignores the current EL
25812495Sgiacomo.travaglini@arm.com * or Mode in considering security state.
25912495Sgiacomo.travaglini@arm.com */
26012495Sgiacomo.travaglini@arm.cominline bool isSecureBelowEL3(ThreadContext *tc);
26112495Sgiacomo.travaglini@arm.com
26210037SARM gem5 Developersbool longDescFormatInUse(ThreadContext *tc);
26310037SARM gem5 Developers
26413550Sgiacomo.travaglini@arm.com/** This helper function is either returing the value of
26513550Sgiacomo.travaglini@arm.com * MPIDR_EL1 (by calling getMPIDR), or it is issuing a read
26613550Sgiacomo.travaglini@arm.com * to VMPIDR_EL2 (as it happens in virtualized systems) */
26713585Sgabeblack@google.comRegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
26813550Sgiacomo.travaglini@arm.com
26913550Sgiacomo.travaglini@arm.com/** This helper function is returing the value of MPIDR_EL1 */
27013585Sgabeblack@google.comRegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
27110037SARM gem5 Developers
27210037SARM gem5 Developersstatic inline uint32_t
27310037SARM gem5 DevelopersmcrMrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, uint32_t crn,
27410037SARM gem5 Developers               uint32_t opc1, uint32_t opc2)
27510037SARM gem5 Developers{
27610037SARM gem5 Developers    return (isRead <<  0) |
27710037SARM gem5 Developers           (crm    <<  1) |
27810037SARM gem5 Developers           (rt     <<  5) |
27910037SARM gem5 Developers           (crn    << 10) |
28010037SARM gem5 Developers           (opc1   << 14) |
28110037SARM gem5 Developers           (opc2   << 17);
28210037SARM gem5 Developers}
28310037SARM gem5 Developers
28410037SARM gem5 Developersstatic inline void
28510037SARM gem5 DevelopersmcrMrcIssExtract(uint32_t iss, bool &isRead, uint32_t &crm, IntRegIndex &rt,
28610037SARM gem5 Developers                 uint32_t &crn, uint32_t &opc1, uint32_t &opc2)
28710037SARM gem5 Developers{
28810037SARM gem5 Developers    isRead = (iss >>  0) & 0x1;
28910037SARM gem5 Developers    crm    = (iss >>  1) & 0xF;
29010037SARM gem5 Developers    rt     = (IntRegIndex) ((iss >>  5) & 0xF);
29110037SARM gem5 Developers    crn    = (iss >> 10) & 0xF;
29210037SARM gem5 Developers    opc1   = (iss >> 14) & 0x7;
29310037SARM gem5 Developers    opc2   = (iss >> 17) & 0x7;
29410037SARM gem5 Developers}
29510037SARM gem5 Developers
29610037SARM gem5 Developersstatic inline uint32_t
29710037SARM gem5 DevelopersmcrrMrrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, IntRegIndex rt2,
29810037SARM gem5 Developers                 uint32_t opc1)
29910037SARM gem5 Developers{
30010037SARM gem5 Developers    return (isRead <<  0) |
30110037SARM gem5 Developers           (crm    <<  1) |
30210037SARM gem5 Developers           (rt     <<  5) |
30310037SARM gem5 Developers           (rt2    << 10) |
30410037SARM gem5 Developers           (opc1   << 16);
30510037SARM gem5 Developers}
30610037SARM gem5 Developers
30710037SARM gem5 Developersstatic inline uint32_t
30810037SARM gem5 DevelopersmsrMrs64IssBuild(bool isRead, uint32_t op0, uint32_t op1, uint32_t crn,
30910037SARM gem5 Developers                 uint32_t crm, uint32_t op2, IntRegIndex rt)
31010037SARM gem5 Developers{
31110037SARM gem5 Developers    return isRead |
31210037SARM gem5 Developers        (crm << 1) |
31310037SARM gem5 Developers        (rt << 5) |
31410037SARM gem5 Developers        (crn << 10) |
31510037SARM gem5 Developers        (op1 << 14) |
31610037SARM gem5 Developers        (op2 << 17) |
31710037SARM gem5 Developers        (op0 << 20);
31810037SARM gem5 Developers}
31910037SARM gem5 Developers
32010037SARM gem5 Developersbool
32113999Sgiacomo.travaglini@arm.commcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss);
32213999Sgiacomo.travaglini@arm.com
32310037SARM gem5 Developersbool
32410037SARM gem5 DevelopersmcrMrc14TrapToHyp(const MiscRegIndex miscReg, HCR hcr, CPSR cpsr, SCR scr,
32510037SARM gem5 Developers                  HDCR hdcr, HSTR hstr, HCPTR hcptr, uint32_t iss);
32610037SARM gem5 Developersbool
32710037SARM gem5 DevelopersmcrrMrrc15TrapToHyp(const MiscRegIndex miscReg, CPSR cpsr, SCR scr, HSTR hstr,
32810037SARM gem5 Developers                    HCR hcr, uint32_t iss);
32910037SARM gem5 Developers
33010037SARM gem5 Developersbool SPAlignmentCheckEnabled(ThreadContext* tc);
33110037SARM gem5 Developers
3327707Sgblack@eecs.umich.eduuint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
3336757SAli.Saidi@ARM.com
3347693SAli.Saidi@ARM.comvoid skipFunction(ThreadContext *tc);
3357693SAli.Saidi@ARM.com
3367720Sgblack@eecs.umich.eduinline void
33710417Sandreas.hansson@arm.comadvancePC(PCState &pc, const StaticInstPtr &inst)
3387720Sgblack@eecs.umich.edu{
3397720Sgblack@eecs.umich.edu    inst->advancePC(pc);
3407720Sgblack@eecs.umich.edu}
3417720Sgblack@eecs.umich.edu
3427752SWilliam.Wang@arm.comAddr truncPage(Addr addr);
3437752SWilliam.Wang@arm.comAddr roundPage(Addr addr);
3447752SWilliam.Wang@arm.com
3458300Schander.sudanthi@arm.cominline uint64_t
3468300Schander.sudanthi@arm.comgetExecutingAsid(ThreadContext *tc)
3478300Schander.sudanthi@arm.com{
3488300Schander.sudanthi@arm.com    return tc->readMiscReg(MISCREG_CONTEXTIDR);
3498300Schander.sudanthi@arm.com}
3508300Schander.sudanthi@arm.com
35110037SARM gem5 Developers// Decodes the register index to access based on the fields used in a MSR
35210037SARM gem5 Developers// or MRS instruction
35310037SARM gem5 Developersbool
35410037SARM gem5 DevelopersdecodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx,
35510037SARM gem5 Developers                      CPSR cpsr, SCR scr, NSACR nsacr,
35610037SARM gem5 Developers                      bool checkSecurity = true);
35710037SARM gem5 Developers
35810037SARM gem5 Developers// This wrapper function is used to turn the register index into a source
35910037SARM gem5 Developers// parameter for the instruction. See Operands.isa
36010037SARM gem5 Developersstatic inline int
36110037SARM gem5 DevelopersdecodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
36210037SARM gem5 Developers{
36310037SARM gem5 Developers    int  regIdx;
36410037SARM gem5 Developers    bool isIntReg;
36510037SARM gem5 Developers    bool validReg;
36610037SARM gem5 Developers
36710037SARM gem5 Developers    validReg = decodeMrsMsrBankedReg(sysM, r, isIntReg, regIdx, 0, 0, 0, false);
36810037SARM gem5 Developers    return (validReg && isIntReg) ? regIdx : INTREG_DUMMY;
36910037SARM gem5 Developers}
37010037SARM gem5 Developers
37110037SARM gem5 Developers/**
37210037SARM gem5 Developers * Returns the n. of PA bits corresponding to the specified encoding.
37310037SARM gem5 Developers */
37410037SARM gem5 Developersint decodePhysAddrRange64(uint8_t pa_enc);
37510037SARM gem5 Developers
37610037SARM gem5 Developers/**
37710037SARM gem5 Developers * Returns the encoding corresponding to the specified n. of PA bits.
37810037SARM gem5 Developers */
37910037SARM gem5 Developersuint8_t encodePhysAddrRange64(int pa_size);
38010037SARM gem5 Developers
38112526Schuan.zhu@arm.cominline ByteOrder byteOrder(ThreadContext *tc)
38212526Schuan.zhu@arm.com{
38312526Schuan.zhu@arm.com    return isBigEndian64(tc) ? BigEndianByteOrder : LittleEndianByteOrder;
38412526Schuan.zhu@arm.com};
38512526Schuan.zhu@arm.com
3868902Sandreas.hansson@arm.com}
3876019Shines@cs.fsu.edu
3886019Shines@cs.fsu.edu#endif
389