isa.hh revision 9180
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__ 447404SAli.Saidi@ARM.com#define __ARCH_ARM_ISA_HH__ 456313Sgblack@eecs.umich.edu 466333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh" 477404SAli.Saidi@ARM.com#include "arch/arm/tlb.hh" 486313Sgblack@eecs.umich.edu#include "arch/arm/types.hh" 498232Snate@binkert.org#include "debug/Checkpoint.hh" 506313Sgblack@eecs.umich.edu 516333Sgblack@eecs.umich.educlass ThreadContext; 526313Sgblack@eecs.umich.educlass Checkpoint; 536313Sgblack@eecs.umich.educlass EventManager; 546313Sgblack@eecs.umich.edu 556313Sgblack@eecs.umich.edunamespace ArmISA 566313Sgblack@eecs.umich.edu{ 576313Sgblack@eecs.umich.edu class ISA 586313Sgblack@eecs.umich.edu { 596313Sgblack@eecs.umich.edu protected: 606333Sgblack@eecs.umich.edu MiscReg miscRegs[NumMiscRegs]; 616718Sgblack@eecs.umich.edu const IntRegIndex *intRegMap; 626718Sgblack@eecs.umich.edu 636718Sgblack@eecs.umich.edu void 646718Sgblack@eecs.umich.edu updateRegMap(CPSR cpsr) 656718Sgblack@eecs.umich.edu { 666718Sgblack@eecs.umich.edu switch (cpsr.mode) { 676718Sgblack@eecs.umich.edu case MODE_USER: 686718Sgblack@eecs.umich.edu case MODE_SYSTEM: 696718Sgblack@eecs.umich.edu intRegMap = IntRegUsrMap; 706718Sgblack@eecs.umich.edu break; 716718Sgblack@eecs.umich.edu case MODE_FIQ: 726718Sgblack@eecs.umich.edu intRegMap = IntRegFiqMap; 736718Sgblack@eecs.umich.edu break; 746718Sgblack@eecs.umich.edu case MODE_IRQ: 756718Sgblack@eecs.umich.edu intRegMap = IntRegIrqMap; 766718Sgblack@eecs.umich.edu break; 776718Sgblack@eecs.umich.edu case MODE_SVC: 786718Sgblack@eecs.umich.edu intRegMap = IntRegSvcMap; 796718Sgblack@eecs.umich.edu break; 806723Sgblack@eecs.umich.edu case MODE_MON: 816723Sgblack@eecs.umich.edu intRegMap = IntRegMonMap; 826723Sgblack@eecs.umich.edu break; 836718Sgblack@eecs.umich.edu case MODE_ABORT: 846718Sgblack@eecs.umich.edu intRegMap = IntRegAbtMap; 856718Sgblack@eecs.umich.edu break; 866718Sgblack@eecs.umich.edu case MODE_UNDEFINED: 876718Sgblack@eecs.umich.edu intRegMap = IntRegUndMap; 886718Sgblack@eecs.umich.edu break; 896718Sgblack@eecs.umich.edu default: 906718Sgblack@eecs.umich.edu panic("Unrecognized mode setting in CPSR.\n"); 916718Sgblack@eecs.umich.edu } 926718Sgblack@eecs.umich.edu } 936313Sgblack@eecs.umich.edu 946313Sgblack@eecs.umich.edu public: 957427Sgblack@eecs.umich.edu void clear(); 966313Sgblack@eecs.umich.edu 977405SAli.Saidi@ARM.com MiscReg readMiscRegNoEffect(int misc_reg); 987405SAli.Saidi@ARM.com MiscReg readMiscReg(int misc_reg, ThreadContext *tc); 997405SAli.Saidi@ARM.com void setMiscRegNoEffect(int misc_reg, const MiscReg &val); 1007405SAli.Saidi@ARM.com void setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc); 1016313Sgblack@eecs.umich.edu 1026313Sgblack@eecs.umich.edu int 1036313Sgblack@eecs.umich.edu flattenIntIndex(int reg) 1046313Sgblack@eecs.umich.edu { 1056718Sgblack@eecs.umich.edu assert(reg >= 0); 1066718Sgblack@eecs.umich.edu if (reg < NUM_ARCH_INTREGS) { 1076718Sgblack@eecs.umich.edu return intRegMap[reg]; 1086726Sgblack@eecs.umich.edu } else if (reg < NUM_INTREGS) { 1096726Sgblack@eecs.umich.edu return reg; 1106718Sgblack@eecs.umich.edu } else { 1117310Sgblack@eecs.umich.edu int mode = reg / intRegsPerMode; 1127310Sgblack@eecs.umich.edu reg = reg % intRegsPerMode; 1137310Sgblack@eecs.umich.edu switch (mode) { 1147310Sgblack@eecs.umich.edu case MODE_USER: 1157310Sgblack@eecs.umich.edu case MODE_SYSTEM: 1167310Sgblack@eecs.umich.edu return INTREG_USR(reg); 1177310Sgblack@eecs.umich.edu case MODE_FIQ: 1187310Sgblack@eecs.umich.edu return INTREG_FIQ(reg); 1197310Sgblack@eecs.umich.edu case MODE_IRQ: 1207310Sgblack@eecs.umich.edu return INTREG_IRQ(reg); 1217310Sgblack@eecs.umich.edu case MODE_SVC: 1227310Sgblack@eecs.umich.edu return INTREG_SVC(reg); 1237310Sgblack@eecs.umich.edu case MODE_MON: 1247310Sgblack@eecs.umich.edu return INTREG_MON(reg); 1257310Sgblack@eecs.umich.edu case MODE_ABORT: 1267310Sgblack@eecs.umich.edu return INTREG_ABT(reg); 1277310Sgblack@eecs.umich.edu case MODE_UNDEFINED: 1287310Sgblack@eecs.umich.edu return INTREG_UND(reg); 1297310Sgblack@eecs.umich.edu default: 1307310Sgblack@eecs.umich.edu panic("Flattening into an unknown mode.\n"); 1317310Sgblack@eecs.umich.edu } 1326718Sgblack@eecs.umich.edu } 1336313Sgblack@eecs.umich.edu } 1346313Sgblack@eecs.umich.edu 1356313Sgblack@eecs.umich.edu int 1366313Sgblack@eecs.umich.edu flattenFloatIndex(int reg) 1376313Sgblack@eecs.umich.edu { 1386313Sgblack@eecs.umich.edu return reg; 1396313Sgblack@eecs.umich.edu } 1406313Sgblack@eecs.umich.edu 1417614Sminkyu.jeong@arm.com int 1427614Sminkyu.jeong@arm.com flattenMiscIndex(int reg) 1437614Sminkyu.jeong@arm.com { 1447614Sminkyu.jeong@arm.com if (reg == MISCREG_SPSR) { 1457614Sminkyu.jeong@arm.com int spsr_idx = NUM_MISCREGS; 1467614Sminkyu.jeong@arm.com CPSR cpsr = miscRegs[MISCREG_CPSR]; 1477614Sminkyu.jeong@arm.com switch (cpsr.mode) { 1487614Sminkyu.jeong@arm.com case MODE_USER: 1497614Sminkyu.jeong@arm.com warn("User mode does not have SPSR\n"); 1507614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR; 1517614Sminkyu.jeong@arm.com break; 1527614Sminkyu.jeong@arm.com case MODE_FIQ: 1537614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_FIQ; 1547614Sminkyu.jeong@arm.com break; 1557614Sminkyu.jeong@arm.com case MODE_IRQ: 1567614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_IRQ; 1577614Sminkyu.jeong@arm.com break; 1587614Sminkyu.jeong@arm.com case MODE_SVC: 1597614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_SVC; 1607614Sminkyu.jeong@arm.com break; 1617614Sminkyu.jeong@arm.com case MODE_MON: 1627614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_MON; 1637614Sminkyu.jeong@arm.com break; 1647614Sminkyu.jeong@arm.com case MODE_ABORT: 1657614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_ABT; 1667614Sminkyu.jeong@arm.com break; 1677614Sminkyu.jeong@arm.com case MODE_UNDEFINED: 1687614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR_UND; 1697614Sminkyu.jeong@arm.com break; 1707614Sminkyu.jeong@arm.com default: 1717614Sminkyu.jeong@arm.com warn("Trying to access SPSR in an invalid mode: %d\n", 1727614Sminkyu.jeong@arm.com cpsr.mode); 1737614Sminkyu.jeong@arm.com spsr_idx = MISCREG_SPSR; 1747614Sminkyu.jeong@arm.com break; 1757614Sminkyu.jeong@arm.com } 1767614Sminkyu.jeong@arm.com return spsr_idx; 1777614Sminkyu.jeong@arm.com } 1787614Sminkyu.jeong@arm.com return reg; 1797614Sminkyu.jeong@arm.com } 1807614Sminkyu.jeong@arm.com 1816678Sgblack@eecs.umich.edu void serialize(EventManager *em, std::ostream &os) 1827733SAli.Saidi@ARM.com { 1837733SAli.Saidi@ARM.com DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n"); 1847733SAli.Saidi@ARM.com SERIALIZE_ARRAY(miscRegs, NumMiscRegs); 1857733SAli.Saidi@ARM.com } 1866678Sgblack@eecs.umich.edu void unserialize(EventManager *em, Checkpoint *cp, 1876678Sgblack@eecs.umich.edu const std::string §ion) 1887733SAli.Saidi@ARM.com { 1897733SAli.Saidi@ARM.com DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n"); 1907733SAli.Saidi@ARM.com UNSERIALIZE_ARRAY(miscRegs, NumMiscRegs); 1917733SAli.Saidi@ARM.com CPSR tmp_cpsr = miscRegs[MISCREG_CPSR]; 1927733SAli.Saidi@ARM.com updateRegMap(tmp_cpsr); 1937733SAli.Saidi@ARM.com } 1946313Sgblack@eecs.umich.edu 1956313Sgblack@eecs.umich.edu ISA() 1966313Sgblack@eecs.umich.edu { 1977400SAli.Saidi@ARM.com SCTLR sctlr; 1987400SAli.Saidi@ARM.com sctlr = 0; 1997400SAli.Saidi@ARM.com miscRegs[MISCREG_SCTLR_RST] = sctlr; 2007400SAli.Saidi@ARM.com 2016313Sgblack@eecs.umich.edu clear(); 2026313Sgblack@eecs.umich.edu } 2036313Sgblack@eecs.umich.edu }; 2046313Sgblack@eecs.umich.edu} 2056313Sgblack@eecs.umich.edu 2066313Sgblack@eecs.umich.edu#endif 207