isa.hh revision 7350
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 1097271Sgblack@eecs.umich.edu /* 1107271Sgblack@eecs.umich.edu * Technically this should be 0, but we don't support those 1117271Sgblack@eecs.umich.edu * settings. 1127271Sgblack@eecs.umich.edu */ 1137320Sgblack@eecs.umich.edu CPACR cpacr = 0; 1147320Sgblack@eecs.umich.edu // Enable CP 10, 11 1157320Sgblack@eecs.umich.edu cpacr.cp10 = 0x3; 1167320Sgblack@eecs.umich.edu cpacr.cp11 = 0x3; 1177320Sgblack@eecs.umich.edu miscRegs[MISCREG_CPACR] = cpacr; 1187271Sgblack@eecs.umich.edu 1197298Sgblack@eecs.umich.edu /* One region, unified map. */ 1207298Sgblack@eecs.umich.edu miscRegs[MISCREG_MPUIR] = 0x100; 1217298Sgblack@eecs.umich.edu 1227350SAli.Saidi@ARM.com /* Start with an event in the mailbox */ 1237350SAli.Saidi@ARM.com miscRegs[MISCREG_SEV_MAILBOX] = 1; 1247350SAli.Saidi@ARM.com 1257298Sgblack@eecs.umich.edu /* 1267298Sgblack@eecs.umich.edu * Implemented = '5' from "M5", 1277298Sgblack@eecs.umich.edu * Variant = 0, 1287298Sgblack@eecs.umich.edu */ 1297298Sgblack@eecs.umich.edu miscRegs[MISCREG_MIDR] = 1307298Sgblack@eecs.umich.edu (0x35 << 24) | //Implementor is '5' from "M5" 1317298Sgblack@eecs.umich.edu (0 << 20) | //Variant 1327298Sgblack@eecs.umich.edu (0xf << 16) | //Architecture from CPUID scheme 1337298Sgblack@eecs.umich.edu (0 << 4) | //Primary part number 1347298Sgblack@eecs.umich.edu (0 << 0) | //Revision 1357298Sgblack@eecs.umich.edu 0; 1367298Sgblack@eecs.umich.edu 1376401Sgblack@eecs.umich.edu //XXX We need to initialize the rest of the state. 1386333Sgblack@eecs.umich.edu } 1396313Sgblack@eecs.umich.edu 1406333Sgblack@eecs.umich.edu MiscReg 1416333Sgblack@eecs.umich.edu readMiscRegNoEffect(int misc_reg) 1426333Sgblack@eecs.umich.edu { 1436333Sgblack@eecs.umich.edu assert(misc_reg < NumMiscRegs); 1446745Sgblack@eecs.umich.edu if (misc_reg == MISCREG_SPSR) { 1456745Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[MISCREG_CPSR]; 1466745Sgblack@eecs.umich.edu switch (cpsr.mode) { 1476745Sgblack@eecs.umich.edu case MODE_USER: 1486745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR]; 1496745Sgblack@eecs.umich.edu case MODE_FIQ: 1506745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_FIQ]; 1516745Sgblack@eecs.umich.edu case MODE_IRQ: 1526745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_IRQ]; 1536745Sgblack@eecs.umich.edu case MODE_SVC: 1546745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_SVC]; 1556745Sgblack@eecs.umich.edu case MODE_MON: 1566745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_MON]; 1576745Sgblack@eecs.umich.edu case MODE_ABORT: 1586745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_ABT]; 1596745Sgblack@eecs.umich.edu case MODE_UNDEFINED: 1606745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR_UND]; 1616745Sgblack@eecs.umich.edu default: 1626745Sgblack@eecs.umich.edu return miscRegs[MISCREG_SPSR]; 1636745Sgblack@eecs.umich.edu } 1646745Sgblack@eecs.umich.edu } 1656333Sgblack@eecs.umich.edu return miscRegs[misc_reg]; 1666333Sgblack@eecs.umich.edu } 1676313Sgblack@eecs.umich.edu 1686333Sgblack@eecs.umich.edu MiscReg 1696333Sgblack@eecs.umich.edu readMiscReg(int misc_reg, ThreadContext *tc) 1706333Sgblack@eecs.umich.edu { 1717093Sgblack@eecs.umich.edu if (misc_reg == MISCREG_CPSR) { 1727093Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[misc_reg]; 1737093Sgblack@eecs.umich.edu Addr pc = tc->readPC(); 1747093Sgblack@eecs.umich.edu if (pc & (ULL(1) << PcJBitShift)) 1757093Sgblack@eecs.umich.edu cpsr.j = 1; 1767093Sgblack@eecs.umich.edu else 1777093Sgblack@eecs.umich.edu cpsr.j = 0; 1787093Sgblack@eecs.umich.edu if (pc & (ULL(1) << PcTBitShift)) 1797093Sgblack@eecs.umich.edu cpsr.t = 1; 1807093Sgblack@eecs.umich.edu else 1817093Sgblack@eecs.umich.edu cpsr.t = 0; 1827093Sgblack@eecs.umich.edu return cpsr; 1837093Sgblack@eecs.umich.edu } 1847259Sgblack@eecs.umich.edu if (misc_reg >= MISCREG_CP15_UNIMP_START && 1857259Sgblack@eecs.umich.edu misc_reg < MISCREG_CP15_END) { 1867259Sgblack@eecs.umich.edu panic("Unimplemented CP15 register %s read.\n", 1877259Sgblack@eecs.umich.edu miscRegName[misc_reg]); 1887259Sgblack@eecs.umich.edu } 1897273Sgblack@eecs.umich.edu switch (misc_reg) { 1907273Sgblack@eecs.umich.edu case MISCREG_CLIDR: 1917273Sgblack@eecs.umich.edu warn("The clidr register always reports 0 caches.\n"); 1927273Sgblack@eecs.umich.edu break; 1937287Sgblack@eecs.umich.edu case MISCREG_CCSIDR: 1947287Sgblack@eecs.umich.edu warn("The ccsidr register isn't implemented and " 1957287Sgblack@eecs.umich.edu "always reads as 0.\n"); 1967287Sgblack@eecs.umich.edu break; 1977273Sgblack@eecs.umich.edu } 1986745Sgblack@eecs.umich.edu return readMiscRegNoEffect(misc_reg); 1996333Sgblack@eecs.umich.edu } 2006333Sgblack@eecs.umich.edu 2016333Sgblack@eecs.umich.edu void 2026333Sgblack@eecs.umich.edu setMiscRegNoEffect(int misc_reg, const MiscReg &val) 2036333Sgblack@eecs.umich.edu { 2046333Sgblack@eecs.umich.edu assert(misc_reg < NumMiscRegs); 2056745Sgblack@eecs.umich.edu if (misc_reg == MISCREG_SPSR) { 2066745Sgblack@eecs.umich.edu CPSR cpsr = miscRegs[MISCREG_CPSR]; 2076745Sgblack@eecs.umich.edu switch (cpsr.mode) { 2086745Sgblack@eecs.umich.edu case MODE_USER: 2096745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR] = val; 2106745Sgblack@eecs.umich.edu return; 2116745Sgblack@eecs.umich.edu case MODE_FIQ: 2126745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_FIQ] = val; 2136745Sgblack@eecs.umich.edu return; 2146745Sgblack@eecs.umich.edu case MODE_IRQ: 2156745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_IRQ] = val; 2166745Sgblack@eecs.umich.edu return; 2176745Sgblack@eecs.umich.edu case MODE_SVC: 2186745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_SVC] = val; 2196745Sgblack@eecs.umich.edu return; 2206745Sgblack@eecs.umich.edu case MODE_MON: 2216745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_MON] = val; 2226745Sgblack@eecs.umich.edu return; 2236745Sgblack@eecs.umich.edu case MODE_ABORT: 2246745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_ABT] = val; 2256745Sgblack@eecs.umich.edu return; 2266745Sgblack@eecs.umich.edu case MODE_UNDEFINED: 2276745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR_UND] = val; 2286745Sgblack@eecs.umich.edu return; 2296745Sgblack@eecs.umich.edu default: 2306745Sgblack@eecs.umich.edu miscRegs[MISCREG_SPSR] = val; 2316745Sgblack@eecs.umich.edu return; 2326745Sgblack@eecs.umich.edu } 2336745Sgblack@eecs.umich.edu } 2346333Sgblack@eecs.umich.edu miscRegs[misc_reg] = val; 2356333Sgblack@eecs.umich.edu } 2366333Sgblack@eecs.umich.edu 2376333Sgblack@eecs.umich.edu void 2386333Sgblack@eecs.umich.edu setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 2396333Sgblack@eecs.umich.edu { 2407271Sgblack@eecs.umich.edu MiscReg newVal = val; 2416718Sgblack@eecs.umich.edu if (misc_reg == MISCREG_CPSR) { 2426718Sgblack@eecs.umich.edu updateRegMap(val); 2437093Sgblack@eecs.umich.edu CPSR cpsr = val; 2447348SAli.Saidi@ARM.com DPRINTF(Arm, "Updating CPSR to %#x f:%d i:%d a:%d mode:%#x\n", 2457348SAli.Saidi@ARM.com cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 2467093Sgblack@eecs.umich.edu Addr npc = tc->readNextPC() & ~PcModeMask; 2477093Sgblack@eecs.umich.edu if (cpsr.j) 2487093Sgblack@eecs.umich.edu npc = npc | (ULL(1) << PcJBitShift); 2497093Sgblack@eecs.umich.edu if (cpsr.t) 2507093Sgblack@eecs.umich.edu npc = npc | (ULL(1) << PcTBitShift); 2517093Sgblack@eecs.umich.edu 2527093Sgblack@eecs.umich.edu tc->setNextPC(npc); 2536718Sgblack@eecs.umich.edu } 2547259Sgblack@eecs.umich.edu if (misc_reg >= MISCREG_CP15_UNIMP_START && 2557259Sgblack@eecs.umich.edu misc_reg < MISCREG_CP15_END) { 2567259Sgblack@eecs.umich.edu panic("Unimplemented CP15 register %s wrote with %#x.\n", 2577259Sgblack@eecs.umich.edu miscRegName[misc_reg], val); 2587259Sgblack@eecs.umich.edu } 2597271Sgblack@eecs.umich.edu switch (misc_reg) { 2607271Sgblack@eecs.umich.edu case MISCREG_CPACR: 2617320Sgblack@eecs.umich.edu { 2627320Sgblack@eecs.umich.edu CPACR newCpacr = 0; 2637320Sgblack@eecs.umich.edu CPACR valCpacr = val; 2647320Sgblack@eecs.umich.edu newCpacr.cp10 = valCpacr.cp10; 2657320Sgblack@eecs.umich.edu newCpacr.cp11 = valCpacr.cp11; 2667320Sgblack@eecs.umich.edu if (newCpacr.cp10 != 0x3 || newCpacr.cp11 != 3) { 2677320Sgblack@eecs.umich.edu panic("Disabling coprocessors isn't implemented.\n"); 2687320Sgblack@eecs.umich.edu } 2697320Sgblack@eecs.umich.edu newVal = newCpacr; 2707271Sgblack@eecs.umich.edu } 2717271Sgblack@eecs.umich.edu break; 2727287Sgblack@eecs.umich.edu case MISCREG_CSSELR: 2737287Sgblack@eecs.umich.edu warn("The csselr register isn't implemented.\n"); 2747287Sgblack@eecs.umich.edu break; 2757271Sgblack@eecs.umich.edu } 2767271Sgblack@eecs.umich.edu return setMiscRegNoEffect(misc_reg, newVal); 2776333Sgblack@eecs.umich.edu } 2786313Sgblack@eecs.umich.edu 2796313Sgblack@eecs.umich.edu int 2806313Sgblack@eecs.umich.edu flattenIntIndex(int reg) 2816313Sgblack@eecs.umich.edu { 2826718Sgblack@eecs.umich.edu assert(reg >= 0); 2836718Sgblack@eecs.umich.edu if (reg < NUM_ARCH_INTREGS) { 2846718Sgblack@eecs.umich.edu return intRegMap[reg]; 2856726Sgblack@eecs.umich.edu } else if (reg < NUM_INTREGS) { 2866726Sgblack@eecs.umich.edu return reg; 2876718Sgblack@eecs.umich.edu } else { 2887310Sgblack@eecs.umich.edu int mode = reg / intRegsPerMode; 2897310Sgblack@eecs.umich.edu reg = reg % intRegsPerMode; 2907310Sgblack@eecs.umich.edu switch (mode) { 2917310Sgblack@eecs.umich.edu case MODE_USER: 2927310Sgblack@eecs.umich.edu case MODE_SYSTEM: 2937310Sgblack@eecs.umich.edu return INTREG_USR(reg); 2947310Sgblack@eecs.umich.edu case MODE_FIQ: 2957310Sgblack@eecs.umich.edu return INTREG_FIQ(reg); 2967310Sgblack@eecs.umich.edu case MODE_IRQ: 2977310Sgblack@eecs.umich.edu return INTREG_IRQ(reg); 2987310Sgblack@eecs.umich.edu case MODE_SVC: 2997310Sgblack@eecs.umich.edu return INTREG_SVC(reg); 3007310Sgblack@eecs.umich.edu case MODE_MON: 3017310Sgblack@eecs.umich.edu return INTREG_MON(reg); 3027310Sgblack@eecs.umich.edu case MODE_ABORT: 3037310Sgblack@eecs.umich.edu return INTREG_ABT(reg); 3047310Sgblack@eecs.umich.edu case MODE_UNDEFINED: 3057310Sgblack@eecs.umich.edu return INTREG_UND(reg); 3067310Sgblack@eecs.umich.edu default: 3077310Sgblack@eecs.umich.edu panic("Flattening into an unknown mode.\n"); 3087310Sgblack@eecs.umich.edu } 3096718Sgblack@eecs.umich.edu } 3106313Sgblack@eecs.umich.edu } 3116313Sgblack@eecs.umich.edu 3126313Sgblack@eecs.umich.edu int 3136313Sgblack@eecs.umich.edu flattenFloatIndex(int reg) 3146313Sgblack@eecs.umich.edu { 3156313Sgblack@eecs.umich.edu return reg; 3166313Sgblack@eecs.umich.edu } 3176313Sgblack@eecs.umich.edu 3186678Sgblack@eecs.umich.edu void serialize(EventManager *em, std::ostream &os) 3196333Sgblack@eecs.umich.edu {} 3206678Sgblack@eecs.umich.edu void unserialize(EventManager *em, Checkpoint *cp, 3216678Sgblack@eecs.umich.edu const std::string §ion) 3226333Sgblack@eecs.umich.edu {} 3236313Sgblack@eecs.umich.edu 3246313Sgblack@eecs.umich.edu ISA() 3256313Sgblack@eecs.umich.edu { 3266313Sgblack@eecs.umich.edu clear(); 3276313Sgblack@eecs.umich.edu } 3286313Sgblack@eecs.umich.edu }; 3296313Sgblack@eecs.umich.edu} 3306313Sgblack@eecs.umich.edu 3316313Sgblack@eecs.umich.edu#endif 332