utility.hh revision 8229
16892SBrad.Beckmann@amd.com/* 26892SBrad.Beckmann@amd.com * Copyright (c) 2010 ARM Limited 36892SBrad.Beckmann@amd.com * All rights reserved 46892SBrad.Beckmann@amd.com * 56892SBrad.Beckmann@amd.com * The license below extends only to copyright in the software and shall 66892SBrad.Beckmann@amd.com * not be construed as granting a license to any other intellectual 76892SBrad.Beckmann@amd.com * property including but not limited to intellectual property relating 86892SBrad.Beckmann@amd.com * to a hardware implementation of the functionality of the software 96892SBrad.Beckmann@amd.com * licensed hereunder. You may use the software subject to the license 106892SBrad.Beckmann@amd.com * terms below provided that you ensure that this notice is replicated 116892SBrad.Beckmann@amd.com * unmodified and in its entirety in all distributions of the software, 126892SBrad.Beckmann@amd.com * modified or unmodified, in source code or in binary form. 136892SBrad.Beckmann@amd.com * 146892SBrad.Beckmann@amd.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 156892SBrad.Beckmann@amd.com * Copyright (c) 2007-2008 The Florida State University 166892SBrad.Beckmann@amd.com * All rights reserved. 176892SBrad.Beckmann@amd.com * 186892SBrad.Beckmann@amd.com * Redistribution and use in source and binary forms, with or without 196892SBrad.Beckmann@amd.com * modification, are permitted provided that the following conditions are 206892SBrad.Beckmann@amd.com * met: redistributions of source code must retain the above copyright 216892SBrad.Beckmann@amd.com * notice, this list of conditions and the following disclaimer; 226892SBrad.Beckmann@amd.com * redistributions in binary form must reproduce the above copyright 236892SBrad.Beckmann@amd.com * notice, this list of conditions and the following disclaimer in the 246892SBrad.Beckmann@amd.com * documentation and/or other materials provided with the distribution; 256892SBrad.Beckmann@amd.com * neither the name of the copyright holders nor the names of its 266892SBrad.Beckmann@amd.com * contributors may be used to endorse or promote products derived from 276892SBrad.Beckmann@amd.com * this software without specific prior written permission. 286892SBrad.Beckmann@amd.com * 296892SBrad.Beckmann@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 306892SBrad.Beckmann@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 316892SBrad.Beckmann@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326892SBrad.Beckmann@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336892SBrad.Beckmann@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 346892SBrad.Beckmann@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 356892SBrad.Beckmann@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 366915SBrad.Beckmann@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 376911SBrad.Beckmann@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 386906SBrad.Beckmann@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 396908SBrad.Beckmann@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 406892SBrad.Beckmann@amd.com * 416893SBrad.Beckmann@amd.com * Authors: Korey Sewell 426892SBrad.Beckmann@amd.com * Stephen Hines 436892SBrad.Beckmann@amd.com */ 446892SBrad.Beckmann@amd.com 456892SBrad.Beckmann@amd.com#ifndef __ARCH_ARM_UTILITY_HH__ 466893SBrad.Beckmann@amd.com#define __ARCH_ARM_UTILITY_HH__ 476893SBrad.Beckmann@amd.com 486893SBrad.Beckmann@amd.com#include "arch/arm/isa_traits.hh" 496893SBrad.Beckmann@amd.com#include "arch/arm/miscregs.hh" 506893SBrad.Beckmann@amd.com#include "arch/arm/types.hh" 516915SBrad.Beckmann@amd.com#include "base/misc.hh" 526915SBrad.Beckmann@amd.com#include "base/trace.hh" 536915SBrad.Beckmann@amd.com#include "base/types.hh" 546915SBrad.Beckmann@amd.com#include "cpu/static_inst.hh" 556915SBrad.Beckmann@amd.com#include "cpu/thread_context.hh" 566915SBrad.Beckmann@amd.com 576911SBrad.Beckmann@amd.comnamespace ArmISA { 586911SBrad.Beckmann@amd.com 596911SBrad.Beckmann@amd.cominline PCState 606911SBrad.Beckmann@amd.combuildRetPC(const PCState &curPC, const PCState &callPC) 616911SBrad.Beckmann@amd.com{ 626911SBrad.Beckmann@amd.com PCState retPC = callPC; 636906SBrad.Beckmann@amd.com retPC.uEnd(); 646906SBrad.Beckmann@amd.com return retPC; 656906SBrad.Beckmann@amd.com} 666906SBrad.Beckmann@amd.com 676906SBrad.Beckmann@amd.cominline bool 686906SBrad.Beckmann@amd.comtestPredicate(CPSR cpsr, ConditionCode code) 696908SBrad.Beckmann@amd.com{ 706908SBrad.Beckmann@amd.com switch (code) 716908SBrad.Beckmann@amd.com { 726908SBrad.Beckmann@amd.com case COND_EQ: return cpsr.z; 736908SBrad.Beckmann@amd.com case COND_NE: return !cpsr.z; 746908SBrad.Beckmann@amd.com case COND_CS: return cpsr.c; 756892SBrad.Beckmann@amd.com case COND_CC: return !cpsr.c; 766892SBrad.Beckmann@amd.com case COND_MI: return cpsr.n; 776892SBrad.Beckmann@amd.com case COND_PL: return !cpsr.n; 786892SBrad.Beckmann@amd.com case COND_VS: return cpsr.v; 796892SBrad.Beckmann@amd.com case COND_VC: return !cpsr.v; 806892SBrad.Beckmann@amd.com case COND_HI: return (cpsr.c && !cpsr.z); 816892SBrad.Beckmann@amd.com case COND_LS: return !(cpsr.c && !cpsr.z); 826892SBrad.Beckmann@amd.com case COND_GE: return !(cpsr.n ^ cpsr.v); 836916SBrad.Beckmann@amd.com case COND_LT: return (cpsr.n ^ cpsr.v); 846916SBrad.Beckmann@amd.com case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z); 856916SBrad.Beckmann@amd.com case COND_LE: return (cpsr.n ^ cpsr.v || cpsr.z); 866916SBrad.Beckmann@amd.com case COND_AL: return true; 876916SBrad.Beckmann@amd.com case COND_UC: return true; 886916SBrad.Beckmann@amd.com default: 896916SBrad.Beckmann@amd.com panic("Unhandled predicate condition: %d\n", code); 906916SBrad.Beckmann@amd.com } 916916SBrad.Beckmann@amd.com} 926916SBrad.Beckmann@amd.com 936916SBrad.Beckmann@amd.com/** 946892SBrad.Beckmann@amd.com * Function to insure ISA semantics about 0 registers. 956903SBrad.Beckmann@amd.com * @param tc The thread context. 966905SBrad.Beckmann@amd.com */ 976905SBrad.Beckmann@amd.comtemplate <class TC> 986903SBrad.Beckmann@amd.comvoid zeroRegisters(TC *tc); 996903SBrad.Beckmann@amd.com 1006903SBrad.Beckmann@amd.cominline void startupCPU(ThreadContext *tc, int cpuId) 1016903SBrad.Beckmann@amd.com{ 1026905SBrad.Beckmann@amd.com tc->activate(0); 1036905SBrad.Beckmann@amd.com} 1046892SBrad.Beckmann@amd.com 1056897SBrad.Beckmann@amd.comvoid copyRegs(ThreadContext *src, ThreadContext *dest); 1066892SBrad.Beckmann@amd.com 1076893SBrad.Beckmann@amd.comstatic inline void 1086892SBrad.Beckmann@amd.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest) 1096892SBrad.Beckmann@amd.com{ 1106892SBrad.Beckmann@amd.com panic("Copy Misc. Regs Not Implemented Yet\n"); 1116892SBrad.Beckmann@amd.com} 1126892SBrad.Beckmann@amd.com 1136892SBrad.Beckmann@amd.comvoid initCPU(ThreadContext *tc, int cpuId); 1146903SBrad.Beckmann@amd.com 1156892SBrad.Beckmann@amd.comstatic inline bool 1166893SBrad.Beckmann@amd.cominUserMode(CPSR cpsr) 1176892SBrad.Beckmann@amd.com{ 1186892SBrad.Beckmann@amd.com return cpsr.mode == MODE_USER; 119} 120 121static inline bool 122inUserMode(ThreadContext *tc) 123{ 124 return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR)); 125} 126 127static inline bool 128inPrivilegedMode(CPSR cpsr) 129{ 130 return !inUserMode(cpsr); 131} 132 133static inline bool 134inPrivilegedMode(ThreadContext *tc) 135{ 136 return !inUserMode(tc); 137} 138 139static inline bool 140vfpEnabled(CPACR cpacr, CPSR cpsr) 141{ 142 return cpacr.cp10 == 0x3 || 143 (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr)); 144} 145 146static inline bool 147vfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 148{ 149 if ((cpacr.cp11 == 0x3) || 150 ((cpacr.cp11 == 0x1) && inPrivilegedMode(cpsr))) 151 return fpexc.en && vfpEnabled(cpacr, cpsr); 152 else 153 return fpexc.en && vfpEnabled(cpacr, cpsr) && 154 (cpacr.cp11 == cpacr.cp10); 155} 156 157static inline bool 158neonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 159{ 160 return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc); 161} 162 163uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp); 164 165void skipFunction(ThreadContext *tc); 166 167inline void 168advancePC(PCState &pc, const StaticInstPtr inst) 169{ 170 inst->advancePC(pc); 171} 172 173Addr truncPage(Addr addr); 174Addr roundPage(Addr addr); 175 176}; 177 178 179#endif 180