isa.hh revision 7400
12810SN/A/* 29614Srene.dejong@arm.com * Copyright (c) 2010 ARM Limited 38856Sandreas.hansson@arm.com * All rights reserved 48856Sandreas.hansson@arm.com * 58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98856Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138856Sandreas.hansson@arm.com * 142810SN/A * Copyright (c) 2009 The Regents of The University of Michigan 152810SN/A * All rights reserved. 162810SN/A * 172810SN/A * Redistribution and use in source and binary forms, with or without 182810SN/A * modification, are permitted provided that the following conditions are 192810SN/A * met: redistributions of source code must retain the above copyright 202810SN/A * notice, this list of conditions and the following disclaimer; 212810SN/A * redistributions in binary form must reproduce the above copyright 222810SN/A * notice, this list of conditions and the following disclaimer in the 232810SN/A * documentation and/or other materials provided with the distribution; 242810SN/A * neither the name of the copyright holders nor the names of its 252810SN/A * contributors may be used to endorse or promote products derived from 262810SN/A * this software without specific prior written permission. 272810SN/A * 282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392810SN/A * 402810SN/A * Authors: Gabe Black 412810SN/A */ 422810SN/A 432810SN/A#ifndef __ARCH_ARM_ISA_HH__ 442810SN/A#define __ARCH_MRM_ISA_HH__ 452810SN/A 462810SN/A#include "arch/arm/registers.hh" 472810SN/A#include "arch/arm/types.hh" 488232Snate@binkert.org 499152Satgutier@umich.educlass ThreadContext; 509795Sandreas.hansson@arm.comclass Checkpoint; 519795Sandreas.hansson@arm.comclass EventManager; 5210263Satgutier@umich.edu 535338Sstever@gmail.comnamespace ArmISA 549795Sandreas.hansson@arm.com{ 555338Sstever@gmail.com class ISA 568786Sgblack@eecs.umich.edu { 572810SN/A protected: 582810SN/A MiscReg miscRegs[NumMiscRegs]; 592810SN/A const IntRegIndex *intRegMap; 608856Sandreas.hansson@arm.com 618856Sandreas.hansson@arm.com void 628856Sandreas.hansson@arm.com updateRegMap(CPSR cpsr) 638922Swilliam.wang@arm.com { 648914Sandreas.hansson@arm.com switch (cpsr.mode) { 658856Sandreas.hansson@arm.com case MODE_USER: 668856Sandreas.hansson@arm.com case MODE_SYSTEM: 674475SN/A intRegMap = IntRegUsrMap; 6811053Sandreas.hansson@arm.com break; 695034SN/A case MODE_FIQ: 7010360Sandreas.hansson@arm.com intRegMap = IntRegFiqMap; 7111377Sandreas.hansson@arm.com break; 7211377Sandreas.hansson@arm.com case MODE_IRQ: 7311053Sandreas.hansson@arm.com intRegMap = IntRegIrqMap; 7410693SMarco.Balboni@ARM.com break; 7510693SMarco.Balboni@ARM.com case MODE_SVC: 7610693SMarco.Balboni@ARM.com intRegMap = IntRegSvcMap; 779263Smrinmoy.ghosh@arm.com break; 785034SN/A case MODE_MON: 7911331Sandreas.hansson@arm.com intRegMap = IntRegMonMap; 8010884Sandreas.hansson@arm.com break; 814626SN/A case MODE_ABORT: 8210360Sandreas.hansson@arm.com intRegMap = IntRegAbtMap; 8311484Snikos.nikoleris@arm.com break; 845034SN/A case MODE_UNDEFINED: 858883SAli.Saidi@ARM.com intRegMap = IntRegUndMap; 868833Sdam.sunwoo@arm.com break; 874458SN/A default: 8811377Sandreas.hansson@arm.com panic("Unrecognized mode setting in CPSR.\n"); 8911377Sandreas.hansson@arm.com } 9011377Sandreas.hansson@arm.com } 9111377Sandreas.hansson@arm.com 9211377Sandreas.hansson@arm.com public: 9311377Sandreas.hansson@arm.com void clear() 9411331Sandreas.hansson@arm.com { 9511331Sandreas.hansson@arm.com SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST]; 962810SN/A 972810SN/A memset(miscRegs, 0, sizeof(miscRegs)); 983013SN/A CPSR cpsr = 0; 998856Sandreas.hansson@arm.com cpsr.mode = MODE_USER; 1002810SN/A miscRegs[MISCREG_CPSR] = cpsr; 1013013SN/A updateRegMap(cpsr); 10210714Sandreas.hansson@arm.com 1032810SN/A SCTLR sctlr = 0; 1049614Srene.dejong@arm.com sctlr.nmfi = (bool)sctlr_rst.nmfi; 1059614Srene.dejong@arm.com sctlr.v = (bool)sctlr_rst.v; 1069614Srene.dejong@arm.com sctlr.u = 1; 10710345SCurtis.Dunham@arm.com sctlr.rao1 = 1; 10810714Sandreas.hansson@arm.com sctlr.rao2 = 1; 10910345SCurtis.Dunham@arm.com sctlr.rao3 = 1; 1109614Srene.dejong@arm.com sctlr.rao4 = 1; 1112810SN/A miscRegs[MISCREG_SCTLR] = sctlr; 1122810SN/A miscRegs[MISCREG_SCTLR_RST] = sctlr_rst; 1132810SN/A 1148856Sandreas.hansson@arm.com 1152810SN/A /* 1163013SN/A * Technically this should be 0, but we don't support those 11710714Sandreas.hansson@arm.com * settings. 1183013SN/A */ 1198856Sandreas.hansson@arm.com CPACR cpacr = 0; 12010714Sandreas.hansson@arm.com // Enable CP 10, 11 1218922Swilliam.wang@arm.com cpacr.cp10 = 0x3; 1222897SN/A cpacr.cp11 = 0x3; 1232810SN/A miscRegs[MISCREG_CPACR] = cpacr; 1242810SN/A 12510344Sandreas.hansson@arm.com /* Start with an event in the mailbox */ 12610344Sandreas.hansson@arm.com miscRegs[MISCREG_SEV_MAILBOX] = 1; 12710344Sandreas.hansson@arm.com 12810714Sandreas.hansson@arm.com /* 12910344Sandreas.hansson@arm.com * Implemented = '5' from "M5", 13010344Sandreas.hansson@arm.com * Variant = 0, 13110344Sandreas.hansson@arm.com */ 13210713Sandreas.hansson@arm.com miscRegs[MISCREG_MIDR] = 13310344Sandreas.hansson@arm.com (0x35 << 24) | //Implementor is '5' from "M5" 1342844SN/A (0 << 20) | //Variant 1352810SN/A (0xf << 16) | //Architecture from CPUID scheme 1362858SN/A (0 << 4) | //Primary part number 1372858SN/A (0 << 0) | //Revision 1388856Sandreas.hansson@arm.com 0; 1398922Swilliam.wang@arm.com 1408711Sandreas.hansson@arm.com // Separate Instruction and Data TLBs. 14111331Sandreas.hansson@arm.com miscRegs[MISCREG_TLBTR] = 1; 1422858SN/A 1432858SN/A MVFR0 mvfr0 = 0; 1449294Sandreas.hansson@arm.com mvfr0.advSimdRegisters = 2; 1459294Sandreas.hansson@arm.com mvfr0.singlePrecision = 2; 1468922Swilliam.wang@arm.com mvfr0.doublePrecision = 2; 1478922Swilliam.wang@arm.com mvfr0.vfpExceptionTrapping = 0; 1488922Swilliam.wang@arm.com mvfr0.divide = 1; 1498922Swilliam.wang@arm.com mvfr0.squareRoot = 1; 1508922Swilliam.wang@arm.com mvfr0.shortVectors = 1; 1518922Swilliam.wang@arm.com mvfr0.roundingModes = 1; 1528922Swilliam.wang@arm.com miscRegs[MISCREG_MVFR0] = mvfr0; 1538922Swilliam.wang@arm.com 1549294Sandreas.hansson@arm.com MVFR1 mvfr1 = 0; 1559294Sandreas.hansson@arm.com mvfr1.flushToZero = 1; 1568922Swilliam.wang@arm.com mvfr1.defaultNaN = 1; 1578922Swilliam.wang@arm.com mvfr1.advSimdLoadStore = 1; 1588922Swilliam.wang@arm.com mvfr1.advSimdInteger = 1; 1598922Swilliam.wang@arm.com mvfr1.advSimdSinglePrecision = 1; 1608922Swilliam.wang@arm.com mvfr1.advSimdHalfPrecision = 1; 1618922Swilliam.wang@arm.com mvfr1.vfpHalfPrecision = 1; 1628922Swilliam.wang@arm.com miscRegs[MISCREG_MVFR1] = mvfr1; 1634628SN/A 16410821Sandreas.hansson@arm.com miscRegs[MISCREG_MPIDR] = 0; 16510821Sandreas.hansson@arm.com 16610821Sandreas.hansson@arm.com //XXX We need to initialize the rest of the state. 16710821Sandreas.hansson@arm.com } 16810821Sandreas.hansson@arm.com 16910821Sandreas.hansson@arm.com MiscReg 17010821Sandreas.hansson@arm.com readMiscRegNoEffect(int misc_reg) 17110821Sandreas.hansson@arm.com { 17210821Sandreas.hansson@arm.com assert(misc_reg < NumMiscRegs); 17310821Sandreas.hansson@arm.com if (misc_reg == MISCREG_SPSR) { 17410821Sandreas.hansson@arm.com CPSR cpsr = miscRegs[MISCREG_CPSR]; 1752858SN/A switch (cpsr.mode) { 1762810SN/A case MODE_USER: 1772810SN/A return miscRegs[MISCREG_SPSR]; 1782810SN/A case MODE_FIQ: 1792810SN/A return miscRegs[MISCREG_SPSR_FIQ]; 1802810SN/A case MODE_IRQ: 1814022SN/A return miscRegs[MISCREG_SPSR_IRQ]; 1824022SN/A case MODE_SVC: 1834022SN/A return miscRegs[MISCREG_SPSR_SVC]; 1842810SN/A case MODE_MON: 1852810SN/A return miscRegs[MISCREG_SPSR_MON]; 1868833Sdam.sunwoo@arm.com case MODE_ABORT: 1872810SN/A return miscRegs[MISCREG_SPSR_ABT]; 1882810SN/A case MODE_UNDEFINED: 1892810SN/A return miscRegs[MISCREG_SPSR_UND]; 1902810SN/A default: 1918833Sdam.sunwoo@arm.com return miscRegs[MISCREG_SPSR]; 1928833Sdam.sunwoo@arm.com } 1938833Sdam.sunwoo@arm.com } 1942810SN/A return miscRegs[misc_reg]; 1952810SN/A } 1964871SN/A 1974871SN/A MiscReg 1984871SN/A readMiscReg(int misc_reg, ThreadContext *tc) 1994871SN/A { 20011455Sandreas.hansson@arm.com if (misc_reg == MISCREG_CPSR) { 20110885Sandreas.hansson@arm.com CPSR cpsr = miscRegs[misc_reg]; 2024871SN/A Addr pc = tc->readPC(); 2034871SN/A if (pc & (ULL(1) << PcJBitShift)) 2044871SN/A cpsr.j = 1; 2054871SN/A else 2064871SN/A cpsr.j = 0; 2072810SN/A if (pc & (ULL(1) << PcTBitShift)) 2082810SN/A cpsr.t = 1; 2092810SN/A else 2108833Sdam.sunwoo@arm.com cpsr.t = 0; 2112810SN/A return cpsr; 2124871SN/A } 2138833Sdam.sunwoo@arm.com if (misc_reg >= MISCREG_CP15_UNIMP_START && 2148833Sdam.sunwoo@arm.com misc_reg < MISCREG_CP15_END) { 2158833Sdam.sunwoo@arm.com panic("Unimplemented CP15 register %s read.\n", 2162810SN/A miscRegName[misc_reg]); 2172810SN/A } 2182810SN/A switch (misc_reg) { 2192810SN/A case MISCREG_CLIDR: 2208833Sdam.sunwoo@arm.com warn("The clidr register always reports 0 caches.\n"); 2212810SN/A break; 2224871SN/A case MISCREG_CCSIDR: 2238833Sdam.sunwoo@arm.com warn("The ccsidr register isn't implemented and " 2248833Sdam.sunwoo@arm.com "always reads as 0.\n"); 2258833Sdam.sunwoo@arm.com break; 2262810SN/A } 2272810SN/A return readMiscRegNoEffect(misc_reg); 2284022SN/A } 2294022SN/A 2304022SN/A void 2312810SN/A setMiscRegNoEffect(int misc_reg, const MiscReg &val) 2322810SN/A { 2338833Sdam.sunwoo@arm.com assert(misc_reg < NumMiscRegs); 2342810SN/A if (misc_reg == MISCREG_SPSR) { 2352810SN/A CPSR cpsr = miscRegs[MISCREG_CPSR]; 2362810SN/A switch (cpsr.mode) { 2372810SN/A case MODE_USER: 2388833Sdam.sunwoo@arm.com miscRegs[MISCREG_SPSR] = val; 2398833Sdam.sunwoo@arm.com return; 2408833Sdam.sunwoo@arm.com case MODE_FIQ: 2412810SN/A miscRegs[MISCREG_SPSR_FIQ] = val; 2422810SN/A return; 2432810SN/A case MODE_IRQ: 2442810SN/A miscRegs[MISCREG_SPSR_IRQ] = val; 2452810SN/A return; 2468833Sdam.sunwoo@arm.com case MODE_SVC: 2472810SN/A miscRegs[MISCREG_SPSR_SVC] = val; 2484871SN/A return; 2498833Sdam.sunwoo@arm.com case MODE_MON: 2508833Sdam.sunwoo@arm.com miscRegs[MISCREG_SPSR_MON] = val; 2518833Sdam.sunwoo@arm.com return; 2522810SN/A case MODE_ABORT: 2532810SN/A miscRegs[MISCREG_SPSR_ABT] = val; 2542810SN/A return; 2552810SN/A case MODE_UNDEFINED: 2568833Sdam.sunwoo@arm.com miscRegs[MISCREG_SPSR_UND] = val; 2572810SN/A return; 2584871SN/A default: 2598833Sdam.sunwoo@arm.com miscRegs[MISCREG_SPSR] = val; 2608833Sdam.sunwoo@arm.com return; 2618833Sdam.sunwoo@arm.com } 2622810SN/A } 2632810SN/A miscRegs[misc_reg] = val; 2644022SN/A } 2654022SN/A 2664022SN/A void 2672810SN/A setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 2682810SN/A { 2698833Sdam.sunwoo@arm.com MiscReg newVal = val; 2702810SN/A if (misc_reg == MISCREG_CPSR) { 2712810SN/A updateRegMap(val); 2722810SN/A CPSR cpsr = val; 2732810SN/A DPRINTF(Arm, "Updating CPSR to %#x f:%d i:%d a:%d mode:%#x\n", 2748833Sdam.sunwoo@arm.com cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 2758833Sdam.sunwoo@arm.com Addr npc = tc->readNextPC() & ~PcModeMask; 2768833Sdam.sunwoo@arm.com if (cpsr.j) 2772810SN/A npc = npc | (ULL(1) << PcJBitShift); 2782810SN/A if (cpsr.t) 2792810SN/A npc = npc | (ULL(1) << PcTBitShift); 2802810SN/A 2812810SN/A tc->setNextPC(npc); 2828833Sdam.sunwoo@arm.com } 2832810SN/A if (misc_reg >= MISCREG_CP15_UNIMP_START && 2844871SN/A misc_reg < MISCREG_CP15_END) { 2858833Sdam.sunwoo@arm.com panic("Unimplemented CP15 register %s wrote with %#x.\n", 2868833Sdam.sunwoo@arm.com miscRegName[misc_reg], val); 2878833Sdam.sunwoo@arm.com } 2882810SN/A switch (misc_reg) { 2892810SN/A case MISCREG_CPACR: 2902810SN/A { 2912810SN/A CPACR newCpacr = 0; 2928833Sdam.sunwoo@arm.com CPACR valCpacr = val; 2932810SN/A newCpacr.cp10 = valCpacr.cp10; 2944871SN/A newCpacr.cp11 = valCpacr.cp11; 2958833Sdam.sunwoo@arm.com if (newCpacr.cp10 != 0x3 || newCpacr.cp11 != 3) { 2968833Sdam.sunwoo@arm.com panic("Disabling coprocessors isn't implemented.\n"); 2978833Sdam.sunwoo@arm.com } 2982810SN/A newVal = newCpacr; 2992810SN/A } 3004022SN/A break; 3014022SN/A case MISCREG_CSSELR: 3024022SN/A warn("The csselr register isn't implemented.\n"); 3032810SN/A break; 3042810SN/A case MISCREG_FPSCR: 3052810SN/A { 3062810SN/A const uint32_t ones = (uint32_t)(-1); 3072810SN/A FPSCR fpscrMask = 0; 3082810SN/A fpscrMask.ioc = ones; 3098833Sdam.sunwoo@arm.com fpscrMask.dzc = ones; 3102810SN/A fpscrMask.ofc = ones; 3118833Sdam.sunwoo@arm.com fpscrMask.ufc = ones; 3128833Sdam.sunwoo@arm.com fpscrMask.ixc = ones; 3138833Sdam.sunwoo@arm.com fpscrMask.idc = ones; 3142810SN/A fpscrMask.len = ones; 3152810SN/A fpscrMask.stride = ones; 3162810SN/A fpscrMask.rMode = ones; 3172810SN/A fpscrMask.fz = ones; 3182810SN/A fpscrMask.dn = ones; 3198833Sdam.sunwoo@arm.com fpscrMask.ahp = ones; 3202810SN/A fpscrMask.qc = ones; 3212810SN/A fpscrMask.v = ones; 3228833Sdam.sunwoo@arm.com fpscrMask.c = ones; 3238833Sdam.sunwoo@arm.com fpscrMask.z = ones; 3248833Sdam.sunwoo@arm.com fpscrMask.n = ones; 3252810SN/A newVal = (newVal & (uint32_t)fpscrMask) | 3262810SN/A (miscRegs[MISCREG_FPSCR] & ~(uint32_t)fpscrMask); 3272810SN/A } 3282810SN/A break; 3298833Sdam.sunwoo@arm.com case MISCREG_FPEXC: 3302810SN/A { 3312810SN/A const uint32_t fpexcMask = 0x60000000; 3328833Sdam.sunwoo@arm.com newVal = (newVal & fpexcMask) | 3338833Sdam.sunwoo@arm.com (miscRegs[MISCREG_FPEXC] & ~fpexcMask); 3348833Sdam.sunwoo@arm.com } 3352810SN/A break; 3362810SN/A case MISCREG_SCTLR: 3374022SN/A { 3384022SN/A SCTLR sctlr = miscRegs[MISCREG_SCTLR]; 3394022SN/A SCTLR new_sctlr = newVal; 3402810SN/A new_sctlr.nmfi = (bool)sctlr.nmfi; 3412810SN/A miscRegs[MISCREG_SCTLR] = (MiscReg)new_sctlr; 3422810SN/A return; 3432810SN/A } 3442810SN/A case MISCREG_TLBTR: 3452810SN/A case MISCREG_MVFR0: 3468833Sdam.sunwoo@arm.com case MISCREG_MVFR1: 3472810SN/A case MISCREG_MPIDR: 3488833Sdam.sunwoo@arm.com case MISCREG_FPSID: 3498833Sdam.sunwoo@arm.com return; 3508833Sdam.sunwoo@arm.com } 3512810SN/A setMiscRegNoEffect(misc_reg, newVal); 3522810SN/A } 3532810SN/A 3542810SN/A int 3552810SN/A flattenIntIndex(int reg) 3568833Sdam.sunwoo@arm.com { 3572810SN/A assert(reg >= 0); 3582810SN/A if (reg < NUM_ARCH_INTREGS) { 3598833Sdam.sunwoo@arm.com return intRegMap[reg]; 3608833Sdam.sunwoo@arm.com } else if (reg < NUM_INTREGS) { 3618833Sdam.sunwoo@arm.com return reg; 3622810SN/A } else { 3632810SN/A int mode = reg / intRegsPerMode; 3642810SN/A reg = reg % intRegsPerMode; 3652810SN/A switch (mode) { 3668833Sdam.sunwoo@arm.com case MODE_USER: 3672810SN/A case MODE_SYSTEM: 3682810SN/A return INTREG_USR(reg); 3698833Sdam.sunwoo@arm.com case MODE_FIQ: 3708833Sdam.sunwoo@arm.com return INTREG_FIQ(reg); 3718833Sdam.sunwoo@arm.com case MODE_IRQ: 3722810SN/A return INTREG_IRQ(reg); 3732810SN/A case MODE_SVC: 3744022SN/A return INTREG_SVC(reg); 3754022SN/A case MODE_MON: 3764022SN/A return INTREG_MON(reg); 3772810SN/A case MODE_ABORT: 3782810SN/A return INTREG_ABT(reg); 3792810SN/A case MODE_UNDEFINED: 3802810SN/A return INTREG_UND(reg); 3812810SN/A default: 3822810SN/A panic("Flattening into an unknown mode.\n"); 3832810SN/A } 3842810SN/A } 3858833Sdam.sunwoo@arm.com } 3868833Sdam.sunwoo@arm.com 3878833Sdam.sunwoo@arm.com int 3888833Sdam.sunwoo@arm.com flattenFloatIndex(int reg) 3892810SN/A { 3902810SN/A return reg; 3912810SN/A } 3922810SN/A 3932810SN/A void serialize(EventManager *em, std::ostream &os) 3948833Sdam.sunwoo@arm.com {} 3952810SN/A void unserialize(EventManager *em, Checkpoint *cp, 3962810SN/A const std::string §ion) 3978833Sdam.sunwoo@arm.com {} 3988833Sdam.sunwoo@arm.com 3998833Sdam.sunwoo@arm.com ISA() 4002810SN/A { 4012810SN/A SCTLR sctlr; 4022810SN/A sctlr = 0; 4032810SN/A miscRegs[MISCREG_SCTLR_RST] = sctlr; 4048833Sdam.sunwoo@arm.com 4052810SN/A clear(); 4062810SN/A } 4078833Sdam.sunwoo@arm.com }; 4088833Sdam.sunwoo@arm.com} 4098833Sdam.sunwoo@arm.com 4102810SN/A#endif 4112810SN/A