utility.hh revision 8829
1793SN/A/* 29957SN/A * Copyright (c) 2010 ARM Limited 39957SN/A * All rights reserved 49957SN/A * 59957SN/A * The license below extends only to copyright in the software and shall 69957SN/A * not be construed as granting a license to any other intellectual 79957SN/A * property including but not limited to intellectual property relating 89957SN/A * to a hardware implementation of the functionality of the software 99957SN/A * licensed hereunder. You may use the software subject to the license 109957SN/A * terms below provided that you ensure that this notice is replicated 119957SN/A * unmodified and in its entirety in all distributions of the software, 129957SN/A * modified or unmodified, in source code or in binary form. 139957SN/A * 141762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 15793SN/A * Copyright (c) 2007-2008 The Florida State University 16793SN/A * All rights reserved. 17793SN/A * 18793SN/A * Redistribution and use in source and binary forms, with or without 19793SN/A * modification, are permitted provided that the following conditions are 20793SN/A * met: redistributions of source code must retain the above copyright 21793SN/A * notice, this list of conditions and the following disclaimer; 22793SN/A * redistributions in binary form must reproduce the above copyright 23793SN/A * notice, this list of conditions and the following disclaimer in the 24793SN/A * documentation and/or other materials provided with the distribution; 25793SN/A * neither the name of the copyright holders nor the names of its 26793SN/A * contributors may be used to endorse or promote products derived from 27793SN/A * this software without specific prior written permission. 28793SN/A * 29793SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30793SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31793SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32793SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33793SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34793SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35793SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36793SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37793SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38793SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392665SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665SN/A * 412665SN/A * Authors: Korey Sewell 422665SN/A * Stephen Hines 43793SN/A */ 44793SN/A 45793SN/A#ifndef __ARCH_ARM_UTILITY_HH__ 46845SN/A#define __ARCH_ARM_UTILITY_HH__ 47793SN/A 48793SN/A#include "arch/arm/isa_traits.hh" 4911260Sandreas.sandberg@arm.com#include "arch/arm/miscregs.hh" 5011260Sandreas.sandberg@arm.com#include "arch/arm/types.hh" 51793SN/A#include "base/misc.hh" 523918SN/A#include "base/trace.hh" 539957SN/A#include "base/types.hh" 543918SN/A#include "cpu/static_inst.hh" 559016SN/A#include "cpu/thread_context.hh" 5611244SN/A 5711260Sandreas.sandberg@arm.comnamespace ArmISA { 584762SN/A 593348SN/Ainline PCState 60795SN/AbuildRetPC(const PCState &curPC, const PCState &callPC) 611817SN/A{ 621817SN/A PCState retPC = callPC; 631817SN/A retPC.uEnd(); 641817SN/A return retPC; 651817SN/A} 661817SN/A 67795SN/Ainline bool 683083SN/AtestPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code) 69793SN/A{ 709807SN/A bool n = (nz & 0x2); 71793SN/A bool z = (nz & 0x1); 7211244SN/A 7311244SN/A switch (code) 742846SN/A { 754982SN/A case COND_EQ: return z; 76793SN/A case COND_NE: return !z; 7711244SN/A case COND_CS: return c; 789957SN/A case COND_CC: return !c; 799957SN/A case COND_MI: return n; 809957SN/A case COND_PL: return !n; 819957SN/A case COND_VS: return v; 8210479SN/A case COND_VC: return !v; 8310479SN/A case COND_HI: return (c && !z); 8410479SN/A case COND_LS: return !(c && !z); 859957SN/A case COND_GE: return !(n ^ v); 869957SN/A case COND_LT: return (n ^ v); 879957SN/A case COND_GT: return !(n ^ v || z); 889957SN/A case COND_LE: return (n ^ v || z); 899957SN/A case COND_AL: return true; 909957SN/A case COND_UC: return true; 9110479SN/A default: 9210479SN/A panic("Unhandled predicate condition: %d\n", code); 9310479SN/A } 9410479SN/A} 9510479SN/A 9610479SN/A/** 9710479SN/A * Function to insure ISA semantics about 0 registers. 9810479SN/A * @param tc The thread context. 999957SN/A */ 1009957SN/Atemplate <class TC> 1019957SN/Avoid zeroRegisters(TC *tc); 1029957SN/A 1039957SN/Ainline void startupCPU(ThreadContext *tc, int cpuId) 1049957SN/A{ 1059957SN/A tc->activate(0); 1069957SN/A} 1079957SN/A 108885SN/Avoid copyRegs(ThreadContext *src, ThreadContext *dest); 109885SN/A 110793SN/Astatic inline void 111885SN/AcopyMiscRegs(ThreadContext *src, ThreadContext *dest) 112885SN/A{ 113795SN/A panic("Copy Misc. Regs Not Implemented Yet\n"); 114793SN/A} 1155834SN/A 1165834SN/Avoid initCPU(ThreadContext *tc, int cpuId); 1175834SN/A 1183083SN/Astatic inline bool 1193083SN/AinUserMode(CPSR cpsr) 1203083SN/A{ 1213083SN/A return cpsr.mode == MODE_USER; 1221992SN/A} 1231992SN/A 1241992SN/Astatic inline bool 1251992SN/AinUserMode(ThreadContext *tc) 1261992SN/A{ 1271992SN/A return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR)); 1281992SN/A} 1293083SN/A 1303083SN/Astatic inline bool 1313083SN/AinPrivilegedMode(CPSR cpsr) 1323083SN/A{ 1331992SN/A return !inUserMode(cpsr); 1341992SN/A} 1351992SN/A 1361992SN/Astatic inline bool 1371992SN/AinPrivilegedMode(ThreadContext *tc) 1381992SN/A{ 1391992SN/A return !inUserMode(tc); 1401992SN/A} 1411992SN/A 1421992SN/Astatic inline bool 1433083SN/AvfpEnabled(CPACR cpacr, CPSR cpsr) 1443083SN/A{ 1453083SN/A return cpacr.cp10 == 0x3 || 1463083SN/A (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr)); 1473083SN/A} 1483083SN/A 1493083SN/Astatic inline bool 1503083SN/AvfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 1513083SN/A{ 1521992SN/A if ((cpacr.cp11 == 0x3) || 1533083SN/A ((cpacr.cp11 == 0x1) && inPrivilegedMode(cpsr))) 1541992SN/A return fpexc.en && vfpEnabled(cpacr, cpsr); 1553083SN/A else 1561992SN/A return fpexc.en && vfpEnabled(cpacr, cpsr) && 1571992SN/A (cpacr.cp11 == cpacr.cp10); 1581992SN/A} 1593083SN/A 1601992SN/Astatic inline bool 1611992SN/AneonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 1621992SN/A{ 1631992SN/A return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc); 16411244SN/A} 1652846SN/A 1662846SN/Auint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp); 1672846SN/A 1682846SN/Avoid skipFunction(ThreadContext *tc); 1692846SN/A 1702846SN/Ainline void 1713349SN/AadvancePC(PCState &pc, const StaticInstPtr inst) 1722846SN/A{ 1732846SN/A inst->advancePC(pc); 1742846SN/A} 1752846SN/A 1762846SN/AAddr truncPage(Addr addr); 1772846SN/AAddr roundPage(Addr addr); 1782846SN/A 1792846SN/Ainline uint64_t 1803349SN/AgetExecutingAsid(ThreadContext *tc) 1811149SN/A{ 18211244SN/A return tc->readMiscReg(MISCREG_CONTEXTIDR); 18311244SN/A} 18411244SN/A 18511244SN/A}; 18611244SN/A 18711244SN/A#endif 1881149SN/A