isa.hh revision 7270
16313Sgblack@eecs.umich.edu/* 27093Sgblack@eecs.umich.edu * Copyright (c) 2010 ARM Limited 37093Sgblack@eecs.umich.edu * All rights reserved 47093Sgblack@eecs.umich.edu * 57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 97093Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 137093Sgblack@eecs.umich.edu * 146313Sgblack@eecs.umich.edu * Copyright (c) 2009 The Regents of The University of Michigan 156313Sgblack@eecs.umich.edu * All rights reserved. 166313Sgblack@eecs.umich.edu * 176313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 186313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 196313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 206313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 216313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 226313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 236313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 246313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 256313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 266313Sgblack@eecs.umich.edu * this software without specific prior written permission. 276313Sgblack@eecs.umich.edu * 286313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 296313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 306313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 316313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 326313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 336313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 346313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 356313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 366313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 386313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 396313Sgblack@eecs.umich.edu * 406313Sgblack@eecs.umich.edu * Authors: Gabe Black 416313Sgblack@eecs.umich.edu */ 426313Sgblack@eecs.umich.edu 436313Sgblack@eecs.umich.edu#ifndef __ARCH_ARM_ISA_HH__ 446313Sgblack@eecs.umich.edu#define __ARCH_MRM_ISA_HH__ 456313Sgblack@eecs.umich.edu 466333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh" 476313Sgblack@eecs.umich.edu#include "arch/arm/types.hh" 486313Sgblack@eecs.umich.edu 496333Sgblack@eecs.umich.educlass ThreadContext; 506313Sgblack@eecs.umich.educlass Checkpoint; 516313Sgblack@eecs.umich.educlass EventManager; 526313Sgblack@eecs.umich.edu 536313Sgblack@eecs.umich.edunamespace ArmISA 546313Sgblack@eecs.umich.edu{ 556313Sgblack@eecs.umich.edu class ISA 566313Sgblack@eecs.umich.edu { 576313Sgblack@eecs.umich.edu protected: 586333Sgblack@eecs.umich.edu MiscReg miscRegs[NumMiscRegs]; 596718Sgblack@eecs.umich.edu const IntRegIndex *intRegMap; 606718Sgblack@eecs.umich.edu 616718Sgblack@eecs.umich.edu void 626718Sgblack@eecs.umich.edu updateRegMap(CPSR cpsr) 636718Sgblack@eecs.umich.edu { 646718Sgblack@eecs.umich.edu switch (cpsr.mode) { 656718Sgblack@eecs.umich.edu case MODE_USER: 666718Sgblack@eecs.umich.edu case MODE_SYSTEM: 676718Sgblack@eecs.umich.edu intRegMap = IntRegUsrMap; 686718Sgblack@eecs.umich.edu break; 696718Sgblack@eecs.umich.edu case MODE_FIQ: 706718Sgblack@eecs.umich.edu intRegMap = IntRegFiqMap; 716718Sgblack@eecs.umich.edu break; 726718Sgblack@eecs.umich.edu case MODE_IRQ: 736718Sgblack@eecs.umich.edu intRegMap = IntRegIrqMap; 746718Sgblack@eecs.umich.edu break; 756718Sgblack@eecs.umich.edu case MODE_SVC: 766718Sgblack@eecs.umich.edu intRegMap = IntRegSvcMap; 776718Sgblack@eecs.umich.edu break; 786723Sgblack@eecs.umich.edu case MODE_MON: 796723Sgblack@eecs.umich.edu intRegMap = IntRegMonMap; 806723Sgblack@eecs.umich.edu break; 816718Sgblack@eecs.umich.edu case MODE_ABORT: 826718Sgblack@eecs.umich.edu intRegMap = IntRegAbtMap; 836718Sgblack@eecs.umich.edu break; 846718Sgblack@eecs.umich.edu case MODE_UNDEFINED: 856718Sgblack@eecs.umich.edu intRegMap = IntRegUndMap; 866718Sgblack@eecs.umich.edu break; 876718Sgblack@eecs.umich.edu default: 886718Sgblack@eecs.umich.edu panic("Unrecognized mode setting in CPSR.\n"); 896718Sgblack@eecs.umich.edu } 906718Sgblack@eecs.umich.edu } 916313Sgblack@eecs.umich.edu 926313Sgblack@eecs.umich.edu public: 936333Sgblack@eecs.umich.edu void clear() 946333Sgblack@eecs.umich.edu { 956401Sgblack@eecs.umich.edu memset(miscRegs, 0, sizeof(miscRegs)); 966401Sgblack@eecs.umich.edu CPSR cpsr = 0; 976719Sgblack@eecs.umich.edu cpsr.mode = MODE_USER; 986401Sgblack@eecs.umich.edu miscRegs[MISCREG_CPSR] = cpsr; 996718Sgblack@eecs.umich.edu updateRegMap(cpsr); 1006735Sgblack@eecs.umich.edu 1016735Sgblack@eecs.umich.edu SCTLR sctlr = 0; 1026735Sgblack@eecs.umich.edu sctlr.nmfi = 1; 1036735Sgblack@eecs.umich.edu sctlr.rao1 = 1; 1046735Sgblack@eecs.umich.edu sctlr.rao2 = 1; 1056735Sgblack@eecs.umich.edu sctlr.rao3 = 1; 1066735Sgblack@eecs.umich.edu sctlr.rao4 = 1; 1077270Sgblack@eecs.umich.edu miscRegs[MISCREG_SCTLR] = sctlr; 1086735Sgblack@eecs.umich.edu 1096401Sgblack@eecs.umich.edu //XXX We need to initialize the rest of the state. 1106333Sgblack@eecs.umich.edu } 1116313Sgblack@eecs.umich.edu 1126333Sgblack@eecs.umich.edu MiscReg 1136333Sgblack@eecs.umich.edu readMiscRegNoEffect(int misc_reg) 1146333Sgblack@eecs.umich.edu { 1156333Sgblack@eecs.umich.edu assert(misc_reg < NumMiscRegs); 1166745Sgblack@eecs.umich.edu if (misc_reg == MISCREG_SPSR) { 1176745Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[MISCREG_CPSR]; 1186745Sgblack@eecs.umich.edu switch (cpsr.mode) { 1196745Sgblack@eecs.umich.edu case MODE_USER: 1206745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR]; 1216745Sgblack@eecs.umich.edu case MODE_FIQ: 1226745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_FIQ]; 1236745Sgblack@eecs.umich.edu case MODE_IRQ: 1246745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_IRQ]; 1256745Sgblack@eecs.umich.edu case MODE_SVC: 1266745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_SVC]; 1276745Sgblack@eecs.umich.edu case MODE_MON: 1286745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_MON]; 1296745Sgblack@eecs.umich.edu case MODE_ABORT: 1306745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_ABT]; 1316745Sgblack@eecs.umich.edu case MODE_UNDEFINED: 1326745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_UND]; 1336745Sgblack@eecs.umich.edu default: 1346745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR]; 1356745Sgblack@eecs.umich.edu } 1366745Sgblack@eecs.umich.edu } 1376333Sgblack@eecs.umich.edu return miscRegs[misc_reg]; 1386333Sgblack@eecs.umich.edu } 1396313Sgblack@eecs.umich.edu 1406333Sgblack@eecs.umich.edu MiscReg 1416333Sgblack@eecs.umich.edu readMiscReg(int misc_reg, ThreadContext *tc) 1426333Sgblack@eecs.umich.edu { 1437093Sgblack@eecs.umich.edu if (misc_reg == MISCREG_CPSR) { 1447093Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[misc_reg]; 1457093Sgblack@eecs.umich.edu Addr pc = tc->readPC(); 1467093Sgblack@eecs.umich.edu if (pc & (ULL(1) << PcJBitShift)) 1477093Sgblack@eecs.umich.edu cpsr.j = 1; 1487093Sgblack@eecs.umich.edu else 1497093Sgblack@eecs.umich.edu cpsr.j = 0; 1507093Sgblack@eecs.umich.edu if (pc & (ULL(1) << PcTBitShift)) 1517093Sgblack@eecs.umich.edu cpsr.t = 1; 1527093Sgblack@eecs.umich.edu else 1537093Sgblack@eecs.umich.edu cpsr.t = 0; 1547093Sgblack@eecs.umich.edu return cpsr; 1557093Sgblack@eecs.umich.edu } 1567259Sgblack@eecs.umich.edu if (misc_reg >= MISCREG_CP15_UNIMP_START && 1577259Sgblack@eecs.umich.edu misc_reg < MISCREG_CP15_END) { 1587259Sgblack@eecs.umich.edu panic("Unimplemented CP15 register %s read.\n", 1597259Sgblack@eecs.umich.edu miscRegName[misc_reg]); 1607259Sgblack@eecs.umich.edu } 1616745Sgblack@eecs.umich.edu return readMiscRegNoEffect(misc_reg); 1626333Sgblack@eecs.umich.edu } 1636333Sgblack@eecs.umich.edu 1646333Sgblack@eecs.umich.edu void 1656333Sgblack@eecs.umich.edu setMiscRegNoEffect(int misc_reg, const MiscReg &val) 1666333Sgblack@eecs.umich.edu { 1676333Sgblack@eecs.umich.edu assert(misc_reg < NumMiscRegs); 1686745Sgblack@eecs.umich.edu if (misc_reg == MISCREG_SPSR) { 1696745Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[MISCREG_CPSR]; 1706745Sgblack@eecs.umich.edu switch (cpsr.mode) { 1716745Sgblack@eecs.umich.edu case MODE_USER: 1726745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR] = val; 1736745Sgblack@eecs.umich.edu return; 1746745Sgblack@eecs.umich.edu case MODE_FIQ: 1756745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_FIQ] = val; 1766745Sgblack@eecs.umich.edu return; 1776745Sgblack@eecs.umich.edu case MODE_IRQ: 1786745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_IRQ] = val; 1796745Sgblack@eecs.umich.edu return; 1806745Sgblack@eecs.umich.edu case MODE_SVC: 1816745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_SVC] = val; 1826745Sgblack@eecs.umich.edu return; 1836745Sgblack@eecs.umich.edu case MODE_MON: 1846745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_MON] = val; 1856745Sgblack@eecs.umich.edu return; 1866745Sgblack@eecs.umich.edu case MODE_ABORT: 1876745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_ABT] = val; 1886745Sgblack@eecs.umich.edu return; 1896745Sgblack@eecs.umich.edu case MODE_UNDEFINED: 1906745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_UND] = val; 1916745Sgblack@eecs.umich.edu return; 1926745Sgblack@eecs.umich.edu default: 1936745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR] = val; 1946745Sgblack@eecs.umich.edu return; 1956745Sgblack@eecs.umich.edu } 1966745Sgblack@eecs.umich.edu } 1976333Sgblack@eecs.umich.edu miscRegs[misc_reg] = val; 1986333Sgblack@eecs.umich.edu } 1996333Sgblack@eecs.umich.edu 2006333Sgblack@eecs.umich.edu void 2016333Sgblack@eecs.umich.edu setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 2026333Sgblack@eecs.umich.edu { 2036718Sgblack@eecs.umich.edu if (misc_reg == MISCREG_CPSR) { 2046718Sgblack@eecs.umich.edu updateRegMap(val); 2057093Sgblack@eecs.umich.edu CPSR cpsr = val; 2067093Sgblack@eecs.umich.edu Addr npc = tc->readNextPC() & ~PcModeMask; 2077093Sgblack@eecs.umich.edu if (cpsr.j) 2087093Sgblack@eecs.umich.edu npc = npc | (ULL(1) << PcJBitShift); 2097093Sgblack@eecs.umich.edu if (cpsr.t) 2107093Sgblack@eecs.umich.edu npc = npc | (ULL(1) << PcTBitShift); 2117093Sgblack@eecs.umich.edu 2127093Sgblack@eecs.umich.edu tc->setNextPC(npc); 2136718Sgblack@eecs.umich.edu } 2147259Sgblack@eecs.umich.edu if (misc_reg >= MISCREG_CP15_UNIMP_START && 2157259Sgblack@eecs.umich.edu misc_reg < MISCREG_CP15_END) { 2167259Sgblack@eecs.umich.edu panic("Unimplemented CP15 register %s wrote with %#x.\n", 2177259Sgblack@eecs.umich.edu miscRegName[misc_reg], val); 2187259Sgblack@eecs.umich.edu } 2196745Sgblack@eecs.umich.edu return setMiscRegNoEffect(misc_reg, val); 2206333Sgblack@eecs.umich.edu } 2216313Sgblack@eecs.umich.edu 2226313Sgblack@eecs.umich.edu int 2236313Sgblack@eecs.umich.edu flattenIntIndex(int reg) 2246313Sgblack@eecs.umich.edu { 2256718Sgblack@eecs.umich.edu assert(reg >= 0); 2266718Sgblack@eecs.umich.edu if (reg < NUM_ARCH_INTREGS) { 2276718Sgblack@eecs.umich.edu return intRegMap[reg]; 2286726Sgblack@eecs.umich.edu } else if (reg < NUM_INTREGS) { 2296726Sgblack@eecs.umich.edu return reg; 2306718Sgblack@eecs.umich.edu } else { 2316726Sgblack@eecs.umich.edu reg -= NUM_INTREGS; 2326726Sgblack@eecs.umich.edu assert(reg < NUM_ARCH_INTREGS); 2336718Sgblack@eecs.umich.edu return reg; 2346718Sgblack@eecs.umich.edu } 2356313Sgblack@eecs.umich.edu } 2366313Sgblack@eecs.umich.edu 2376313Sgblack@eecs.umich.edu int 2386313Sgblack@eecs.umich.edu flattenFloatIndex(int reg) 2396313Sgblack@eecs.umich.edu { 2406313Sgblack@eecs.umich.edu return reg; 2416313Sgblack@eecs.umich.edu } 2426313Sgblack@eecs.umich.edu 2436678Sgblack@eecs.umich.edu void serialize(EventManager *em, std::ostream &os) 2446333Sgblack@eecs.umich.edu {} 2456678Sgblack@eecs.umich.edu void unserialize(EventManager *em, Checkpoint *cp, 2466678Sgblack@eecs.umich.edu const std::string §ion) 2476333Sgblack@eecs.umich.edu {} 2486313Sgblack@eecs.umich.edu 2496313Sgblack@eecs.umich.edu ISA() 2506313Sgblack@eecs.umich.edu { 2516313Sgblack@eecs.umich.edu clear(); 2526313Sgblack@eecs.umich.edu } 2536313Sgblack@eecs.umich.edu }; 2546313Sgblack@eecs.umich.edu} 2556313Sgblack@eecs.umich.edu 2566313Sgblack@eecs.umich.edu#endif 257