utility.hh revision 7741
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 597720Sgblack@eecs.umich.edu inline PCState 607720Sgblack@eecs.umich.edu buildRetPC(const PCState &curPC, const PCState &callPC) 617720Sgblack@eecs.umich.edu { 627720Sgblack@eecs.umich.edu PCState retPC = callPC; 637720Sgblack@eecs.umich.edu retPC.uEnd(); 647720Sgblack@eecs.umich.edu return retPC; 657720Sgblack@eecs.umich.edu } 667720Sgblack@eecs.umich.edu 676242Sgblack@eecs.umich.edu inline bool 686242Sgblack@eecs.umich.edu testPredicate(CPSR cpsr, ConditionCode code) 696242Sgblack@eecs.umich.edu { 706242Sgblack@eecs.umich.edu switch (code) 716242Sgblack@eecs.umich.edu { 726242Sgblack@eecs.umich.edu case COND_EQ: return cpsr.z; 736242Sgblack@eecs.umich.edu case COND_NE: return !cpsr.z; 746242Sgblack@eecs.umich.edu case COND_CS: return cpsr.c; 756242Sgblack@eecs.umich.edu case COND_CC: return !cpsr.c; 766242Sgblack@eecs.umich.edu case COND_MI: return cpsr.n; 776242Sgblack@eecs.umich.edu case COND_PL: return !cpsr.n; 786242Sgblack@eecs.umich.edu case COND_VS: return cpsr.v; 796242Sgblack@eecs.umich.edu case COND_VC: return !cpsr.v; 806242Sgblack@eecs.umich.edu case COND_HI: return (cpsr.c && !cpsr.z); 816242Sgblack@eecs.umich.edu case COND_LS: return !(cpsr.c && !cpsr.z); 826242Sgblack@eecs.umich.edu case COND_GE: return !(cpsr.n ^ cpsr.v); 836242Sgblack@eecs.umich.edu case COND_LT: return (cpsr.n ^ cpsr.v); 846242Sgblack@eecs.umich.edu case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z); 856242Sgblack@eecs.umich.edu case COND_LE: return (cpsr.n ^ cpsr.v || cpsr.z); 866242Sgblack@eecs.umich.edu case COND_AL: return true; 877111Sgblack@eecs.umich.edu case COND_UC: return true; 886242Sgblack@eecs.umich.edu default: 896242Sgblack@eecs.umich.edu panic("Unhandled predicate condition: %d\n", code); 906242Sgblack@eecs.umich.edu } 916242Sgblack@eecs.umich.edu } 926242Sgblack@eecs.umich.edu 936019Shines@cs.fsu.edu /** 946019Shines@cs.fsu.edu * Function to insure ISA semantics about 0 registers. 956019Shines@cs.fsu.edu * @param tc The thread context. 966019Shines@cs.fsu.edu */ 976019Shines@cs.fsu.edu template <class TC> 986019Shines@cs.fsu.edu void zeroRegisters(TC *tc); 996019Shines@cs.fsu.edu 1006019Shines@cs.fsu.edu inline void startupCPU(ThreadContext *tc, int cpuId) 1016019Shines@cs.fsu.edu { 1026019Shines@cs.fsu.edu tc->activate(0); 1036019Shines@cs.fsu.edu } 1046246Sgblack@eecs.umich.edu 1056329Sgblack@eecs.umich.edu static inline void 1066329Sgblack@eecs.umich.edu copyRegs(ThreadContext *src, ThreadContext *dest) 1076329Sgblack@eecs.umich.edu { 1086329Sgblack@eecs.umich.edu panic("Copy Regs Not Implemented Yet\n"); 1096329Sgblack@eecs.umich.edu } 1106329Sgblack@eecs.umich.edu 1116329Sgblack@eecs.umich.edu static inline void 1126329Sgblack@eecs.umich.edu copyMiscRegs(ThreadContext *src, ThreadContext *dest) 1136329Sgblack@eecs.umich.edu { 1146329Sgblack@eecs.umich.edu panic("Copy Misc. Regs Not Implemented Yet\n"); 1156329Sgblack@eecs.umich.edu } 1166757SAli.Saidi@ARM.com 1176757SAli.Saidi@ARM.com void initCPU(ThreadContext *tc, int cpuId); 1186757SAli.Saidi@ARM.com 1196757SAli.Saidi@ARM.com static inline bool 1207638Sgblack@eecs.umich.edu inUserMode(CPSR cpsr) 1217638Sgblack@eecs.umich.edu { 1227638Sgblack@eecs.umich.edu return cpsr.mode == MODE_USER; 1237638Sgblack@eecs.umich.edu } 1247638Sgblack@eecs.umich.edu 1257638Sgblack@eecs.umich.edu static inline bool 1266757SAli.Saidi@ARM.com inUserMode(ThreadContext *tc) 1276757SAli.Saidi@ARM.com { 1287638Sgblack@eecs.umich.edu return inUserMode(tc->readMiscRegNoEffect(MISCREG_CPSR)); 1297638Sgblack@eecs.umich.edu } 1307638Sgblack@eecs.umich.edu 1317638Sgblack@eecs.umich.edu static inline bool 1327638Sgblack@eecs.umich.edu inPrivilegedMode(CPSR cpsr) 1337638Sgblack@eecs.umich.edu { 1347638Sgblack@eecs.umich.edu return !inUserMode(cpsr); 1357638Sgblack@eecs.umich.edu } 1367638Sgblack@eecs.umich.edu 1377638Sgblack@eecs.umich.edu static inline bool 1387638Sgblack@eecs.umich.edu inPrivilegedMode(ThreadContext *tc) 1397638Sgblack@eecs.umich.edu { 1407638Sgblack@eecs.umich.edu return !inUserMode(tc); 1416757SAli.Saidi@ARM.com } 1426757SAli.Saidi@ARM.com 1437640Sgblack@eecs.umich.edu static inline bool 1447640Sgblack@eecs.umich.edu vfpEnabled(CPACR cpacr, CPSR cpsr) 1457640Sgblack@eecs.umich.edu { 1467640Sgblack@eecs.umich.edu return cpacr.cp10 == 0x3 || 1477644Sali.saidi@arm.com (cpacr.cp10 == 0x1 && inPrivilegedMode(cpsr)); 1487640Sgblack@eecs.umich.edu } 1497640Sgblack@eecs.umich.edu 1507640Sgblack@eecs.umich.edu static inline bool 1517640Sgblack@eecs.umich.edu vfpEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 1527640Sgblack@eecs.umich.edu { 1537640Sgblack@eecs.umich.edu return fpexc.en && vfpEnabled(cpacr, cpsr); 1547640Sgblack@eecs.umich.edu } 1557640Sgblack@eecs.umich.edu 1567640Sgblack@eecs.umich.edu static inline bool 1577640Sgblack@eecs.umich.edu neonEnabled(CPACR cpacr, CPSR cpsr, FPEXC fpexc) 1587640Sgblack@eecs.umich.edu { 1597640Sgblack@eecs.umich.edu return !cpacr.asedis && vfpEnabled(cpacr, cpsr, fpexc); 1607640Sgblack@eecs.umich.edu } 1617640Sgblack@eecs.umich.edu 1627707Sgblack@eecs.umich.eduuint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp); 1636759SAli.Saidi@ARM.com 1646759SAli.Saidi@ARM.comFault setCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2); 1656759SAli.Saidi@ARM.comFault readCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2); 1666757SAli.Saidi@ARM.com 1677693SAli.Saidi@ARM.comvoid skipFunction(ThreadContext *tc); 1687693SAli.Saidi@ARM.com 1697720Sgblack@eecs.umich.eduinline void 1707720Sgblack@eecs.umich.eduadvancePC(PCState &pc, const StaticInstPtr inst) 1717720Sgblack@eecs.umich.edu{ 1727720Sgblack@eecs.umich.edu inst->advancePC(pc); 1737720Sgblack@eecs.umich.edu} 1747720Sgblack@eecs.umich.edu 1756019Shines@cs.fsu.edu}; 1766019Shines@cs.fsu.edu 1776019Shines@cs.fsu.edu 1786019Shines@cs.fsu.edu#endif 179