misc.isa revision 10501
17199Sgblack@eecs.umich.edu// -*- mode:c++ -*- 27199Sgblack@eecs.umich.edu 310037SARM gem5 Developers// Copyright (c) 2010-2013 ARM Limited 47199Sgblack@eecs.umich.edu// All rights reserved 57199Sgblack@eecs.umich.edu// 67199Sgblack@eecs.umich.edu// The license below extends only to copyright in the software and shall 77199Sgblack@eecs.umich.edu// not be construed as granting a license to any other intellectual 87199Sgblack@eecs.umich.edu// property including but not limited to intellectual property relating 97199Sgblack@eecs.umich.edu// to a hardware implementation of the functionality of the software 107199Sgblack@eecs.umich.edu// licensed hereunder. You may use the software subject to the license 117199Sgblack@eecs.umich.edu// terms below provided that you ensure that this notice is replicated 127199Sgblack@eecs.umich.edu// unmodified and in its entirety in all distributions of the software, 137199Sgblack@eecs.umich.edu// modified or unmodified, in source code or in binary form. 147199Sgblack@eecs.umich.edu// 157199Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without 167199Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are 177199Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright 187199Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer; 197199Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright 207199Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the 217199Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution; 227199Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its 237199Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from 247199Sgblack@eecs.umich.edu// this software without specific prior written permission. 257199Sgblack@eecs.umich.edu// 267199Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 277199Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 287199Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 297199Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 307199Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 317199Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 327199Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 337199Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 347199Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 357199Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 367199Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 377199Sgblack@eecs.umich.edu// 387199Sgblack@eecs.umich.edu// Authors: Gabe Black 397199Sgblack@eecs.umich.edu 407199Sgblack@eecs.umich.edulet {{ 417199Sgblack@eecs.umich.edu 427199Sgblack@eecs.umich.edu svcCode = ''' 4310474Sandreas.hansson@arm.com fault = std::make_shared<SupervisorCall>(machInst, imm); 4410037SARM gem5 Developers ''' 4510037SARM gem5 Developers 4610037SARM gem5 Developers svcIop = InstObjParams("svc", "Svc", "ImmOp", 4710037SARM gem5 Developers { "code": svcCode, 4810037SARM gem5 Developers "predicate_test": predicateTest }, 4910037SARM gem5 Developers ["IsSyscall", "IsNonSpeculative", "IsSerializeAfter"]) 5010037SARM gem5 Developers header_output = ImmOpDeclare.subst(svcIop) 5110037SARM gem5 Developers decoder_output = ImmOpConstructor.subst(svcIop) 5210037SARM gem5 Developers exec_output = PredOpExecute.subst(svcIop) 5310037SARM gem5 Developers 5410037SARM gem5 Developers smcCode = ''' 5510037SARM gem5 Developers HCR hcr = Hcr; 5610037SARM gem5 Developers CPSR cpsr = Cpsr; 5710037SARM gem5 Developers SCR scr = Scr; 5810037SARM gem5 Developers 5910037SARM gem5 Developers if ((cpsr.mode != MODE_USER) && FullSystem) { 6010037SARM gem5 Developers if (ArmSystem::haveVirtualization(xc->tcBase()) && 6110037SARM gem5 Developers !inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP) && hcr.tsc) { 6210474Sandreas.hansson@arm.com fault = std::make_shared<HypervisorTrap>(machInst, 0, 6310474Sandreas.hansson@arm.com EC_SMC_TO_HYP); 6410037SARM gem5 Developers } else { 6510037SARM gem5 Developers if (scr.scd) { 6610037SARM gem5 Developers fault = disabledFault(); 6710037SARM gem5 Developers } else { 6810474Sandreas.hansson@arm.com fault = std::make_shared<SecureMonitorCall>(machInst); 6910037SARM gem5 Developers } 7010037SARM gem5 Developers } 718782Sgblack@eecs.umich.edu } else { 7210037SARM gem5 Developers fault = disabledFault(); 738782Sgblack@eecs.umich.edu } 747199Sgblack@eecs.umich.edu ''' 757199Sgblack@eecs.umich.edu 7610037SARM gem5 Developers smcIop = InstObjParams("smc", "Smc", "PredOp", 7710037SARM gem5 Developers { "code": smcCode, 788628SAli.Saidi@ARM.com "predicate_test": predicateTest }, 7910037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 8010037SARM gem5 Developers header_output += BasicDeclare.subst(smcIop) 8110037SARM gem5 Developers decoder_output += BasicConstructor.subst(smcIop) 8210037SARM gem5 Developers exec_output += PredOpExecute.subst(smcIop) 8310037SARM gem5 Developers 8410037SARM gem5 Developers hvcCode = ''' 8510037SARM gem5 Developers CPSR cpsr = Cpsr; 8610037SARM gem5 Developers SCR scr = Scr; 8710037SARM gem5 Developers 8810037SARM gem5 Developers // Filter out the various cases where this instruction isn't defined 8910037SARM gem5 Developers if (!FullSystem || !ArmSystem::haveVirtualization(xc->tcBase()) || 9010037SARM gem5 Developers (cpsr.mode == MODE_USER) || 9110037SARM gem5 Developers (ArmSystem::haveSecurity(xc->tcBase()) && (!scr.ns || !scr.hce))) { 9210037SARM gem5 Developers fault = disabledFault(); 9310037SARM gem5 Developers } else { 9410474Sandreas.hansson@arm.com fault = std::make_shared<HypervisorCall>(machInst, imm); 9510037SARM gem5 Developers } 9610037SARM gem5 Developers ''' 9710037SARM gem5 Developers 9810037SARM gem5 Developers hvcIop = InstObjParams("hvc", "Hvc", "ImmOp", 9910037SARM gem5 Developers { "code": hvcCode, 10010037SARM gem5 Developers "predicate_test": predicateTest }, 10110037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 10210037SARM gem5 Developers header_output += ImmOpDeclare.subst(hvcIop) 10310037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(hvcIop) 10410037SARM gem5 Developers exec_output += PredOpExecute.subst(hvcIop) 10510037SARM gem5 Developers 10610037SARM gem5 Developers eretCode = ''' 10710037SARM gem5 Developers SCTLR sctlr = Sctlr; 10810037SARM gem5 Developers CPSR old_cpsr = Cpsr; 10910037SARM gem5 Developers old_cpsr.nz = CondCodesNZ; 11010037SARM gem5 Developers old_cpsr.c = CondCodesC; 11110037SARM gem5 Developers old_cpsr.v = CondCodesV; 11210037SARM gem5 Developers old_cpsr.ge = CondCodesGE; 11310037SARM gem5 Developers 11410037SARM gem5 Developers CPSR new_cpsr = cpsrWriteByInstr(old_cpsr, Spsr, Scr, Nsacr, 0xF, 11510037SARM gem5 Developers true, sctlr.nmfi, xc->tcBase()); 11610037SARM gem5 Developers Cpsr = ~CondCodesMask & new_cpsr; 11710037SARM gem5 Developers CondCodesNZ = new_cpsr.nz; 11810037SARM gem5 Developers CondCodesC = new_cpsr.c; 11910037SARM gem5 Developers CondCodesV = new_cpsr.v; 12010037SARM gem5 Developers CondCodesGE = new_cpsr.ge; 12110037SARM gem5 Developers 12210037SARM gem5 Developers NextThumb = (new_cpsr).t; 12310037SARM gem5 Developers NextJazelle = (new_cpsr).j; 12410037SARM gem5 Developers NextItState = (((new_cpsr).it2 << 2) & 0xFC) 12510037SARM gem5 Developers | ((new_cpsr).it1 & 0x3); 12610037SARM gem5 Developers 12710037SARM gem5 Developers NPC = (old_cpsr.mode == MODE_HYP) ? ElrHyp : LR; 12810037SARM gem5 Developers ''' 12910037SARM gem5 Developers 13010037SARM gem5 Developers eretIop = InstObjParams("eret", "Eret", "PredOp", 13110037SARM gem5 Developers { "code": eretCode, 13210037SARM gem5 Developers "predicate_test": predicateTest }, 13310037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 13410037SARM gem5 Developers header_output += BasicDeclare.subst(eretIop) 13510037SARM gem5 Developers decoder_output += BasicConstructor.subst(eretIop) 13610037SARM gem5 Developers exec_output += PredOpExecute.subst(eretIop) 13710037SARM gem5 Developers 13810037SARM gem5 Developers 1397199Sgblack@eecs.umich.edu 1407199Sgblack@eecs.umich.edu}}; 1417202Sgblack@eecs.umich.edu 1427202Sgblack@eecs.umich.edulet {{ 1437202Sgblack@eecs.umich.edu 1447202Sgblack@eecs.umich.edu header_output = decoder_output = exec_output = "" 1457202Sgblack@eecs.umich.edu 1468301SAli.Saidi@ARM.com mrsCpsrCode = ''' 1478303SAli.Saidi@ARM.com CPSR cpsr = Cpsr; 1488303SAli.Saidi@ARM.com cpsr.nz = CondCodesNZ; 1498303SAli.Saidi@ARM.com cpsr.c = CondCodesC; 1508303SAli.Saidi@ARM.com cpsr.v = CondCodesV; 1518303SAli.Saidi@ARM.com cpsr.ge = CondCodesGE; 1528303SAli.Saidi@ARM.com Dest = cpsr & 0xF8FF03DF 1538301SAli.Saidi@ARM.com ''' 1548301SAli.Saidi@ARM.com 1557202Sgblack@eecs.umich.edu mrsCpsrIop = InstObjParams("mrs", "MrsCpsr", "MrsOp", 1567202Sgblack@eecs.umich.edu { "code": mrsCpsrCode, 1577599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 1587783SGiacomo.Gabrielli@arm.com ["IsSerializeBefore"]) 1597202Sgblack@eecs.umich.edu header_output += MrsDeclare.subst(mrsCpsrIop) 1607202Sgblack@eecs.umich.edu decoder_output += MrsConstructor.subst(mrsCpsrIop) 1617202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrsCpsrIop) 1627202Sgblack@eecs.umich.edu 1637202Sgblack@eecs.umich.edu mrsSpsrCode = "Dest = Spsr" 1647202Sgblack@eecs.umich.edu mrsSpsrIop = InstObjParams("mrs", "MrsSpsr", "MrsOp", 1657202Sgblack@eecs.umich.edu { "code": mrsSpsrCode, 1667599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 1677783SGiacomo.Gabrielli@arm.com ["IsSerializeBefore"]) 1687202Sgblack@eecs.umich.edu header_output += MrsDeclare.subst(mrsSpsrIop) 1697202Sgblack@eecs.umich.edu decoder_output += MrsConstructor.subst(mrsSpsrIop) 1707202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrsSpsrIop) 1717202Sgblack@eecs.umich.edu 17210037SARM gem5 Developers mrsBankedRegCode = ''' 17310037SARM gem5 Developers bool isIntReg; 17410037SARM gem5 Developers int regIdx; 17510037SARM gem5 Developers 17610037SARM gem5 Developers if (decodeMrsMsrBankedReg(byteMask, r, isIntReg, regIdx, Cpsr, Scr, Nsacr)) { 17710037SARM gem5 Developers if (isIntReg) { 17810037SARM gem5 Developers Dest = DecodedBankedIntReg; 17910037SARM gem5 Developers } else { 18010037SARM gem5 Developers Dest = xc->readMiscReg(regIdx); 18110037SARM gem5 Developers } 18210037SARM gem5 Developers } else { 18310474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 18410474Sandreas.hansson@arm.com mnemonic); 18510037SARM gem5 Developers } 18610037SARM gem5 Developers ''' 18710037SARM gem5 Developers mrsBankedRegIop = InstObjParams("mrs", "MrsBankedReg", "MrsOp", 18810037SARM gem5 Developers { "code": mrsBankedRegCode, 18910037SARM gem5 Developers "predicate_test": predicateTest }, 19010037SARM gem5 Developers ["IsSerializeBefore"]) 19110037SARM gem5 Developers header_output += MrsBankedRegDeclare.subst(mrsBankedRegIop) 19210037SARM gem5 Developers decoder_output += MrsBankedRegConstructor.subst(mrsBankedRegIop) 19310037SARM gem5 Developers exec_output += PredOpExecute.subst(mrsBankedRegIop) 19410037SARM gem5 Developers 19510037SARM gem5 Developers msrBankedRegCode = ''' 19610037SARM gem5 Developers bool isIntReg; 19710037SARM gem5 Developers int regIdx; 19810037SARM gem5 Developers 19910037SARM gem5 Developers if (decodeMrsMsrBankedReg(byteMask, r, isIntReg, regIdx, Cpsr, Scr, Nsacr)) { 20010037SARM gem5 Developers if (isIntReg) { 20110037SARM gem5 Developers // This is a bit nasty, you would have thought that 20210037SARM gem5 Developers // DecodedBankedIntReg wouldn't be written to unless the 20310037SARM gem5 Developers // conditions on the IF statements above are met, however if 20410037SARM gem5 Developers // you look at the generated C code you'll find that they are. 20510037SARM gem5 Developers // However this is safe as DecodedBankedIntReg (which is used 20610037SARM gem5 Developers // in operands.isa to get the index of DecodedBankedIntReg) 20710037SARM gem5 Developers // will return INTREG_DUMMY if its not a valid integer 20810037SARM gem5 Developers // register, so redirecting the write to somewhere we don't 20910037SARM gem5 Developers // care about. 21010037SARM gem5 Developers DecodedBankedIntReg = Op1; 21110037SARM gem5 Developers } else { 21210037SARM gem5 Developers xc->setMiscReg(regIdx, Op1); 21310037SARM gem5 Developers } 21410037SARM gem5 Developers } else { 21510474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 21610474Sandreas.hansson@arm.com mnemonic); 21710037SARM gem5 Developers } 21810037SARM gem5 Developers ''' 21910037SARM gem5 Developers msrBankedRegIop = InstObjParams("msr", "MsrBankedReg", "MsrRegOp", 22010037SARM gem5 Developers { "code": msrBankedRegCode, 22110037SARM gem5 Developers "predicate_test": predicateTest }, 22210501Sakash.bagdia@ARM.com ["IsSerializeAfter", "IsNonSpeculative"]) 22310037SARM gem5 Developers header_output += MsrBankedRegDeclare.subst(msrBankedRegIop) 22410037SARM gem5 Developers decoder_output += MsrBankedRegConstructor.subst(msrBankedRegIop) 22510037SARM gem5 Developers exec_output += PredOpExecute.subst(msrBankedRegIop) 22610037SARM gem5 Developers 2277202Sgblack@eecs.umich.edu msrCpsrRegCode = ''' 2287400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 2298303SAli.Saidi@ARM.com CPSR old_cpsr = Cpsr; 2308303SAli.Saidi@ARM.com old_cpsr.nz = CondCodesNZ; 2318303SAli.Saidi@ARM.com old_cpsr.c = CondCodesC; 2328303SAli.Saidi@ARM.com old_cpsr.v = CondCodesV; 2338303SAli.Saidi@ARM.com old_cpsr.ge = CondCodesGE; 2348303SAli.Saidi@ARM.com 2358303SAli.Saidi@ARM.com CPSR new_cpsr = 23610037SARM gem5 Developers cpsrWriteByInstr(old_cpsr, Op1, Scr, Nsacr, byteMask, false, 23710037SARM gem5 Developers sctlr.nmfi, xc->tcBase()); 2388303SAli.Saidi@ARM.com Cpsr = ~CondCodesMask & new_cpsr; 2398303SAli.Saidi@ARM.com CondCodesNZ = new_cpsr.nz; 2408303SAli.Saidi@ARM.com CondCodesC = new_cpsr.c; 2418303SAli.Saidi@ARM.com CondCodesV = new_cpsr.v; 2428303SAli.Saidi@ARM.com CondCodesGE = new_cpsr.ge; 2437202Sgblack@eecs.umich.edu ''' 2447202Sgblack@eecs.umich.edu msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp", 2457202Sgblack@eecs.umich.edu { "code": msrCpsrRegCode, 2467599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 2477599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2487202Sgblack@eecs.umich.edu header_output += MsrRegDeclare.subst(msrCpsrRegIop) 2497202Sgblack@eecs.umich.edu decoder_output += MsrRegConstructor.subst(msrCpsrRegIop) 2507202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrCpsrRegIop) 2517202Sgblack@eecs.umich.edu 2527202Sgblack@eecs.umich.edu msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);" 2537202Sgblack@eecs.umich.edu msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp", 2547202Sgblack@eecs.umich.edu { "code": msrSpsrRegCode, 2557599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 2567599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2577202Sgblack@eecs.umich.edu header_output += MsrRegDeclare.subst(msrSpsrRegIop) 2587202Sgblack@eecs.umich.edu decoder_output += MsrRegConstructor.subst(msrSpsrRegIop) 2597202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrSpsrRegIop) 2607202Sgblack@eecs.umich.edu 2617202Sgblack@eecs.umich.edu msrCpsrImmCode = ''' 2627400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 2638303SAli.Saidi@ARM.com CPSR old_cpsr = Cpsr; 2648303SAli.Saidi@ARM.com old_cpsr.nz = CondCodesNZ; 2658303SAli.Saidi@ARM.com old_cpsr.c = CondCodesC; 2668303SAli.Saidi@ARM.com old_cpsr.v = CondCodesV; 2678303SAli.Saidi@ARM.com old_cpsr.ge = CondCodesGE; 2688303SAli.Saidi@ARM.com CPSR new_cpsr = 26910037SARM gem5 Developers cpsrWriteByInstr(old_cpsr, imm, Scr, Nsacr, byteMask, false, 27010037SARM gem5 Developers sctlr.nmfi, xc->tcBase()); 2718303SAli.Saidi@ARM.com Cpsr = ~CondCodesMask & new_cpsr; 2728303SAli.Saidi@ARM.com CondCodesNZ = new_cpsr.nz; 2738303SAli.Saidi@ARM.com CondCodesC = new_cpsr.c; 2748303SAli.Saidi@ARM.com CondCodesV = new_cpsr.v; 2758303SAli.Saidi@ARM.com CondCodesGE = new_cpsr.ge; 2767202Sgblack@eecs.umich.edu ''' 2777202Sgblack@eecs.umich.edu msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp", 2787202Sgblack@eecs.umich.edu { "code": msrCpsrImmCode, 2797599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 2807599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2817202Sgblack@eecs.umich.edu header_output += MsrImmDeclare.subst(msrCpsrImmIop) 2827202Sgblack@eecs.umich.edu decoder_output += MsrImmConstructor.subst(msrCpsrImmIop) 2837202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrCpsrImmIop) 2847202Sgblack@eecs.umich.edu 2857202Sgblack@eecs.umich.edu msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);" 2867202Sgblack@eecs.umich.edu msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp", 2877202Sgblack@eecs.umich.edu { "code": msrSpsrImmCode, 2887599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 2897599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2907202Sgblack@eecs.umich.edu header_output += MsrImmDeclare.subst(msrSpsrImmIop) 2917202Sgblack@eecs.umich.edu decoder_output += MsrImmConstructor.subst(msrSpsrImmIop) 2927202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrSpsrImmIop) 2937209Sgblack@eecs.umich.edu 2947209Sgblack@eecs.umich.edu revCode = ''' 2957209Sgblack@eecs.umich.edu uint32_t val = Op1; 2967209Sgblack@eecs.umich.edu Dest = swap_byte(val); 2977209Sgblack@eecs.umich.edu ''' 2987261Sgblack@eecs.umich.edu revIop = InstObjParams("rev", "Rev", "RegRegOp", 2997209Sgblack@eecs.umich.edu { "code": revCode, 3007209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3017261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(revIop) 3027261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(revIop) 3037209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(revIop) 3047209Sgblack@eecs.umich.edu 3057209Sgblack@eecs.umich.edu rev16Code = ''' 3067209Sgblack@eecs.umich.edu uint32_t val = Op1; 3077209Sgblack@eecs.umich.edu Dest = (bits(val, 15, 8) << 0) | 3087209Sgblack@eecs.umich.edu (bits(val, 7, 0) << 8) | 3097209Sgblack@eecs.umich.edu (bits(val, 31, 24) << 16) | 3107209Sgblack@eecs.umich.edu (bits(val, 23, 16) << 24); 3117209Sgblack@eecs.umich.edu ''' 3127261Sgblack@eecs.umich.edu rev16Iop = InstObjParams("rev16", "Rev16", "RegRegOp", 3137209Sgblack@eecs.umich.edu { "code": rev16Code, 3147209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3157261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(rev16Iop) 3167261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(rev16Iop) 3177209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(rev16Iop) 3187209Sgblack@eecs.umich.edu 3197209Sgblack@eecs.umich.edu revshCode = ''' 3207209Sgblack@eecs.umich.edu uint16_t val = Op1; 3217209Sgblack@eecs.umich.edu Dest = sext<16>(swap_byte(val)); 3227209Sgblack@eecs.umich.edu ''' 3237261Sgblack@eecs.umich.edu revshIop = InstObjParams("revsh", "Revsh", "RegRegOp", 3247209Sgblack@eecs.umich.edu { "code": revshCode, 3257209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3267261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(revshIop) 3277261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(revshIop) 3287209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(revshIop) 3297226Sgblack@eecs.umich.edu 3307249Sgblack@eecs.umich.edu rbitCode = ''' 3317249Sgblack@eecs.umich.edu uint8_t *opBytes = (uint8_t *)&Op1; 3327249Sgblack@eecs.umich.edu uint32_t resTemp; 3337249Sgblack@eecs.umich.edu uint8_t *destBytes = (uint8_t *)&resTemp; 3347249Sgblack@eecs.umich.edu // This reverses the bytes and bits of the input, or so says the 3357249Sgblack@eecs.umich.edu // internet. 3367249Sgblack@eecs.umich.edu for (int i = 0; i < 4; i++) { 3377249Sgblack@eecs.umich.edu uint32_t temp = opBytes[i]; 3387249Sgblack@eecs.umich.edu temp = (temp * 0x0802 & 0x22110) | (temp * 0x8020 & 0x88440); 3397249Sgblack@eecs.umich.edu destBytes[3 - i] = (temp * 0x10101) >> 16; 3407249Sgblack@eecs.umich.edu } 3417249Sgblack@eecs.umich.edu Dest = resTemp; 3427249Sgblack@eecs.umich.edu ''' 3437261Sgblack@eecs.umich.edu rbitIop = InstObjParams("rbit", "Rbit", "RegRegOp", 3447249Sgblack@eecs.umich.edu { "code": rbitCode, 3457249Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3467261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(rbitIop) 3477261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(rbitIop) 3487249Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(rbitIop) 3497249Sgblack@eecs.umich.edu 3507251Sgblack@eecs.umich.edu clzCode = ''' 3517251Sgblack@eecs.umich.edu Dest = (Op1 == 0) ? 32 : (31 - findMsbSet(Op1)); 3527251Sgblack@eecs.umich.edu ''' 3537261Sgblack@eecs.umich.edu clzIop = InstObjParams("clz", "Clz", "RegRegOp", 3547251Sgblack@eecs.umich.edu { "code": clzCode, 3557251Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3567261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(clzIop) 3577261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(clzIop) 3587251Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(clzIop) 3597251Sgblack@eecs.umich.edu 3607226Sgblack@eecs.umich.edu ssatCode = ''' 3617226Sgblack@eecs.umich.edu int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0); 3627226Sgblack@eecs.umich.edu int32_t res; 3637232Sgblack@eecs.umich.edu if (satInt(res, operand, imm)) 3648302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3657226Sgblack@eecs.umich.edu Dest = res; 3667226Sgblack@eecs.umich.edu ''' 3677232Sgblack@eecs.umich.edu ssatIop = InstObjParams("ssat", "Ssat", "RegImmRegShiftOp", 3687226Sgblack@eecs.umich.edu { "code": ssatCode, 3698304SAli.Saidi@ARM.com "predicate_test": pickPredicate(ssatCode) }, []) 3707232Sgblack@eecs.umich.edu header_output += RegImmRegShiftOpDeclare.subst(ssatIop) 3717232Sgblack@eecs.umich.edu decoder_output += RegImmRegShiftOpConstructor.subst(ssatIop) 3727226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ssatIop) 3737226Sgblack@eecs.umich.edu 3747226Sgblack@eecs.umich.edu usatCode = ''' 3757226Sgblack@eecs.umich.edu int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0); 3767226Sgblack@eecs.umich.edu int32_t res; 3777232Sgblack@eecs.umich.edu if (uSatInt(res, operand, imm)) 3788302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3797226Sgblack@eecs.umich.edu Dest = res; 3807226Sgblack@eecs.umich.edu ''' 3817232Sgblack@eecs.umich.edu usatIop = InstObjParams("usat", "Usat", "RegImmRegShiftOp", 3827226Sgblack@eecs.umich.edu { "code": usatCode, 3838304SAli.Saidi@ARM.com "predicate_test": pickPredicate(usatCode) }, []) 3847232Sgblack@eecs.umich.edu header_output += RegImmRegShiftOpDeclare.subst(usatIop) 3857232Sgblack@eecs.umich.edu decoder_output += RegImmRegShiftOpConstructor.subst(usatIop) 3867226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usatIop) 3877226Sgblack@eecs.umich.edu 3887226Sgblack@eecs.umich.edu ssat16Code = ''' 3897226Sgblack@eecs.umich.edu int32_t res; 3907226Sgblack@eecs.umich.edu uint32_t resTemp = 0; 3917226Sgblack@eecs.umich.edu int32_t argLow = sext<16>(bits(Op1, 15, 0)); 3927226Sgblack@eecs.umich.edu int32_t argHigh = sext<16>(bits(Op1, 31, 16)); 3937232Sgblack@eecs.umich.edu if (satInt(res, argLow, imm)) 3948302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3957226Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, res); 3967232Sgblack@eecs.umich.edu if (satInt(res, argHigh, imm)) 3978302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3987226Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, res); 3997226Sgblack@eecs.umich.edu Dest = resTemp; 4007226Sgblack@eecs.umich.edu ''' 4017232Sgblack@eecs.umich.edu ssat16Iop = InstObjParams("ssat16", "Ssat16", "RegImmRegOp", 4027226Sgblack@eecs.umich.edu { "code": ssat16Code, 4038304SAli.Saidi@ARM.com "predicate_test": pickPredicate(ssat16Code) }, []) 4047232Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(ssat16Iop) 4057232Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(ssat16Iop) 4067226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ssat16Iop) 4077226Sgblack@eecs.umich.edu 4087226Sgblack@eecs.umich.edu usat16Code = ''' 4097226Sgblack@eecs.umich.edu int32_t res; 4107226Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4117226Sgblack@eecs.umich.edu int32_t argLow = sext<16>(bits(Op1, 15, 0)); 4127226Sgblack@eecs.umich.edu int32_t argHigh = sext<16>(bits(Op1, 31, 16)); 4137232Sgblack@eecs.umich.edu if (uSatInt(res, argLow, imm)) 4148302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 4157226Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, res); 4167232Sgblack@eecs.umich.edu if (uSatInt(res, argHigh, imm)) 4178302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 4187226Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, res); 4197226Sgblack@eecs.umich.edu Dest = resTemp; 4207226Sgblack@eecs.umich.edu ''' 4217232Sgblack@eecs.umich.edu usat16Iop = InstObjParams("usat16", "Usat16", "RegImmRegOp", 4227226Sgblack@eecs.umich.edu { "code": usat16Code, 4238304SAli.Saidi@ARM.com "predicate_test": pickPredicate(usat16Code) }, []) 4247232Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(usat16Iop) 4257232Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(usat16Iop) 4267226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usat16Iop) 4277234Sgblack@eecs.umich.edu 4287234Sgblack@eecs.umich.edu sxtbIop = InstObjParams("sxtb", "Sxtb", "RegImmRegOp", 4297234Sgblack@eecs.umich.edu { "code": 4308588Sgblack@eecs.umich.edu "Dest = sext<8>((uint8_t)(Op1_ud >> imm));", 4317234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4327234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxtbIop) 4337234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxtbIop) 4347234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtbIop) 4357234Sgblack@eecs.umich.edu 4367234Sgblack@eecs.umich.edu sxtabIop = InstObjParams("sxtab", "Sxtab", "RegRegRegImmOp", 4377234Sgblack@eecs.umich.edu { "code": 4387234Sgblack@eecs.umich.edu ''' 4398588Sgblack@eecs.umich.edu Dest = sext<8>((uint8_t)(Op2_ud >> imm)) + 4407234Sgblack@eecs.umich.edu Op1; 4417234Sgblack@eecs.umich.edu ''', 4427234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4437234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtabIop) 4447234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtabIop) 4457234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtabIop) 4467234Sgblack@eecs.umich.edu 4477234Sgblack@eecs.umich.edu sxtb16Code = ''' 4487234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4497234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, sext<8>(bits(Op1, imm + 7, imm))); 4507234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 4517234Sgblack@eecs.umich.edu sext<8>(bits(Op1, (imm + 23) % 32, (imm + 16) % 32))); 4527234Sgblack@eecs.umich.edu Dest = resTemp; 4537234Sgblack@eecs.umich.edu ''' 4547234Sgblack@eecs.umich.edu sxtb16Iop = InstObjParams("sxtb16", "Sxtb16", "RegImmRegOp", 4557234Sgblack@eecs.umich.edu { "code": sxtb16Code, 4567234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4577234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxtb16Iop) 4587234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxtb16Iop) 4597234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtb16Iop) 4607234Sgblack@eecs.umich.edu 4617234Sgblack@eecs.umich.edu sxtab16Code = ''' 4627234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4637234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, sext<8>(bits(Op2, imm + 7, imm)) + 4647234Sgblack@eecs.umich.edu bits(Op1, 15, 0)); 4657234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 4667234Sgblack@eecs.umich.edu sext<8>(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) + 4677234Sgblack@eecs.umich.edu bits(Op1, 31, 16)); 4687234Sgblack@eecs.umich.edu Dest = resTemp; 4697234Sgblack@eecs.umich.edu ''' 4707234Sgblack@eecs.umich.edu sxtab16Iop = InstObjParams("sxtab16", "Sxtab16", "RegRegRegImmOp", 4717234Sgblack@eecs.umich.edu { "code": sxtab16Code, 4727234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4737234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtab16Iop) 4747234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtab16Iop) 4757234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtab16Iop) 4767234Sgblack@eecs.umich.edu 4777234Sgblack@eecs.umich.edu sxthCode = ''' 4787234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op1; 4797234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 4807234Sgblack@eecs.umich.edu Dest = sext<16>((uint16_t)rotated); 4817234Sgblack@eecs.umich.edu ''' 4827234Sgblack@eecs.umich.edu sxthIop = InstObjParams("sxth", "Sxth", "RegImmRegOp", 4837234Sgblack@eecs.umich.edu { "code": sxthCode, 4847234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4857234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxthIop) 4867234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxthIop) 4877234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxthIop) 4887234Sgblack@eecs.umich.edu 4897234Sgblack@eecs.umich.edu sxtahCode = ''' 4907234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op2; 4917234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 4927234Sgblack@eecs.umich.edu Dest = sext<16>((uint16_t)rotated) + Op1; 4937234Sgblack@eecs.umich.edu ''' 4947234Sgblack@eecs.umich.edu sxtahIop = InstObjParams("sxtah", "Sxtah", "RegRegRegImmOp", 4957234Sgblack@eecs.umich.edu { "code": sxtahCode, 4967234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4977234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtahIop) 4987234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtahIop) 4997234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtahIop) 5007234Sgblack@eecs.umich.edu 5017234Sgblack@eecs.umich.edu uxtbIop = InstObjParams("uxtb", "Uxtb", "RegImmRegOp", 5028588Sgblack@eecs.umich.edu { "code": "Dest = (uint8_t)(Op1_ud >> imm);", 5037234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5047234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxtbIop) 5057234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxtbIop) 5067234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtbIop) 5077234Sgblack@eecs.umich.edu 5087234Sgblack@eecs.umich.edu uxtabIop = InstObjParams("uxtab", "Uxtab", "RegRegRegImmOp", 5097234Sgblack@eecs.umich.edu { "code": 5108588Sgblack@eecs.umich.edu "Dest = (uint8_t)(Op2_ud >> imm) + Op1;", 5117234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5127234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtabIop) 5137234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtabIop) 5147234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtabIop) 5157234Sgblack@eecs.umich.edu 5167234Sgblack@eecs.umich.edu uxtb16Code = ''' 5177234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5187234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op1, imm + 7, imm))); 5197234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 5207234Sgblack@eecs.umich.edu (uint8_t)(bits(Op1, (imm + 23) % 32, (imm + 16) % 32))); 5217234Sgblack@eecs.umich.edu Dest = resTemp; 5227234Sgblack@eecs.umich.edu ''' 5237234Sgblack@eecs.umich.edu uxtb16Iop = InstObjParams("uxtb16", "Uxtb16", "RegImmRegOp", 5247234Sgblack@eecs.umich.edu { "code": uxtb16Code, 5257234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5267234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxtb16Iop) 5277234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxtb16Iop) 5287234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtb16Iop) 5297234Sgblack@eecs.umich.edu 5307234Sgblack@eecs.umich.edu uxtab16Code = ''' 5317234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5327234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op2, imm + 7, imm)) + 5337234Sgblack@eecs.umich.edu bits(Op1, 15, 0)); 5347234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 5357234Sgblack@eecs.umich.edu (uint8_t)(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) + 5367234Sgblack@eecs.umich.edu bits(Op1, 31, 16)); 5377234Sgblack@eecs.umich.edu Dest = resTemp; 5387234Sgblack@eecs.umich.edu ''' 5397234Sgblack@eecs.umich.edu uxtab16Iop = InstObjParams("uxtab16", "Uxtab16", "RegRegRegImmOp", 5407234Sgblack@eecs.umich.edu { "code": uxtab16Code, 5417234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5427234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtab16Iop) 5437234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtab16Iop) 5447234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtab16Iop) 5457234Sgblack@eecs.umich.edu 5467234Sgblack@eecs.umich.edu uxthCode = ''' 5477234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op1; 5487234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 5497234Sgblack@eecs.umich.edu Dest = (uint16_t)rotated; 5507234Sgblack@eecs.umich.edu ''' 5517234Sgblack@eecs.umich.edu uxthIop = InstObjParams("uxth", "Uxth", "RegImmRegOp", 5527234Sgblack@eecs.umich.edu { "code": uxthCode, 5537234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5547234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxthIop) 5557234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxthIop) 5567234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxthIop) 5577234Sgblack@eecs.umich.edu 5587234Sgblack@eecs.umich.edu uxtahCode = ''' 5597234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op2; 5607234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 5617234Sgblack@eecs.umich.edu Dest = (uint16_t)rotated + Op1; 5627234Sgblack@eecs.umich.edu ''' 5637234Sgblack@eecs.umich.edu uxtahIop = InstObjParams("uxtah", "Uxtah", "RegRegRegImmOp", 5647234Sgblack@eecs.umich.edu { "code": uxtahCode, 5657234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5667234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtahIop) 5677234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtahIop) 5687234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtahIop) 5697239Sgblack@eecs.umich.edu 5707239Sgblack@eecs.umich.edu selCode = ''' 5717239Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5727239Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 5737239Sgblack@eecs.umich.edu int low = i * 8; 5747239Sgblack@eecs.umich.edu int high = low + 7; 5757239Sgblack@eecs.umich.edu replaceBits(resTemp, high, low, 5768303SAli.Saidi@ARM.com bits(CondCodesGE, i) ? 5777239Sgblack@eecs.umich.edu bits(Op1, high, low) : bits(Op2, high, low)); 5787239Sgblack@eecs.umich.edu } 5797239Sgblack@eecs.umich.edu Dest = resTemp; 5807239Sgblack@eecs.umich.edu ''' 5817239Sgblack@eecs.umich.edu selIop = InstObjParams("sel", "Sel", "RegRegRegOp", 5827239Sgblack@eecs.umich.edu { "code": selCode, 5838303SAli.Saidi@ARM.com "predicate_test": predicateTest }, []) 5847239Sgblack@eecs.umich.edu header_output += RegRegRegOpDeclare.subst(selIop) 5857239Sgblack@eecs.umich.edu decoder_output += RegRegRegOpConstructor.subst(selIop) 5867239Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(selIop) 5877242Sgblack@eecs.umich.edu 5887242Sgblack@eecs.umich.edu usad8Code = ''' 5897242Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5907242Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 5917242Sgblack@eecs.umich.edu int low = i * 8; 5927242Sgblack@eecs.umich.edu int high = low + 7; 5937242Sgblack@eecs.umich.edu int32_t diff = bits(Op1, high, low) - 5947242Sgblack@eecs.umich.edu bits(Op2, high, low); 5957242Sgblack@eecs.umich.edu resTemp += ((diff < 0) ? -diff : diff); 5967242Sgblack@eecs.umich.edu } 5977242Sgblack@eecs.umich.edu Dest = resTemp; 5987242Sgblack@eecs.umich.edu ''' 5997242Sgblack@eecs.umich.edu usad8Iop = InstObjParams("usad8", "Usad8", "RegRegRegOp", 6007242Sgblack@eecs.umich.edu { "code": usad8Code, 6017242Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 6027242Sgblack@eecs.umich.edu header_output += RegRegRegOpDeclare.subst(usad8Iop) 6037242Sgblack@eecs.umich.edu decoder_output += RegRegRegOpConstructor.subst(usad8Iop) 6047242Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usad8Iop) 6057242Sgblack@eecs.umich.edu 6067242Sgblack@eecs.umich.edu usada8Code = ''' 6077242Sgblack@eecs.umich.edu uint32_t resTemp = 0; 6087242Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 6097242Sgblack@eecs.umich.edu int low = i * 8; 6107242Sgblack@eecs.umich.edu int high = low + 7; 6117242Sgblack@eecs.umich.edu int32_t diff = bits(Op1, high, low) - 6127242Sgblack@eecs.umich.edu bits(Op2, high, low); 6137242Sgblack@eecs.umich.edu resTemp += ((diff < 0) ? -diff : diff); 6147242Sgblack@eecs.umich.edu } 6157242Sgblack@eecs.umich.edu Dest = Op3 + resTemp; 6167242Sgblack@eecs.umich.edu ''' 6177242Sgblack@eecs.umich.edu usada8Iop = InstObjParams("usada8", "Usada8", "RegRegRegRegOp", 6187242Sgblack@eecs.umich.edu { "code": usada8Code, 6197242Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 6207242Sgblack@eecs.umich.edu header_output += RegRegRegRegOpDeclare.subst(usada8Iop) 6217242Sgblack@eecs.umich.edu decoder_output += RegRegRegRegOpConstructor.subst(usada8Iop) 6227242Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usada8Iop) 6237247Sgblack@eecs.umich.edu 62410474Sandreas.hansson@arm.com bkptCode = 'return std::make_shared<PrefetchAbort>(PC, ArmFault::DebugEvent);\n' 6257848SAli.Saidi@ARM.com bkptIop = InstObjParams("bkpt", "BkptInst", "PredOp", bkptCode) 6267410Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(bkptIop) 6277410Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(bkptIop) 6287410Sgblack@eecs.umich.edu exec_output += BasicExecute.subst(bkptIop) 6297410Sgblack@eecs.umich.edu 63010037SARM gem5 Developers nopIop = InstObjParams("nop", "NopInst", "ArmStaticInst", "", ['IsNop']) 6317247Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(nopIop) 63210037SARM gem5 Developers decoder_output += BasicConstructor64.subst(nopIop) 63310037SARM gem5 Developers exec_output += BasicExecute.subst(nopIop) 6347408Sgblack@eecs.umich.edu 6357418Sgblack@eecs.umich.edu yieldIop = InstObjParams("yield", "YieldInst", "PredOp", \ 6367418Sgblack@eecs.umich.edu { "code" : "", "predicate_test" : predicateTest }) 6377418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(yieldIop) 6387418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(yieldIop) 6397418Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(yieldIop) 6407418Sgblack@eecs.umich.edu 6417418Sgblack@eecs.umich.edu wfeCode = ''' 64210037SARM gem5 Developers HCR hcr = Hcr; 64310037SARM gem5 Developers CPSR cpsr = Cpsr; 64410037SARM gem5 Developers SCR scr = Scr64; 64510037SARM gem5 Developers SCTLR sctlr = Sctlr; 64610037SARM gem5 Developers 64710037SARM gem5 Developers // WFE Sleeps if SevMailbox==0 and no unmasked interrupts are pending, 64810037SARM gem5 Developers ThreadContext *tc = xc->tcBase(); 6498285SPrakash.Ramrakhyani@arm.com if (SevMailbox == 1) { 6507418Sgblack@eecs.umich.edu SevMailbox = 0; 65110037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65210037SARM gem5 Developers } else if (tc->getCpuPtr()->getInterruptController()->checkInterrupts(tc)) { 65310037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65410037SARM gem5 Developers } else if (cpsr.el == EL0 && !sctlr.ntwe) { 65510037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65610474Sandreas.hansson@arm.com fault = std::make_shared<SupervisorTrap>(machInst, 0x1E00001, 65710474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 65810037SARM gem5 Developers } else if (ArmSystem::haveVirtualization(tc) && 65910037SARM gem5 Developers !inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP) && 66010037SARM gem5 Developers hcr.twe) { 66110037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 66210474Sandreas.hansson@arm.com fault = std::make_shared<HypervisorTrap>(machInst, 0x1E00001, 66310474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 66410037SARM gem5 Developers } else if (ArmSystem::haveSecurity(tc) && cpsr.el != EL3 && scr.twe) { 66510037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 66610474Sandreas.hansson@arm.com fault = std::make_shared<SecureMonitorTrap>(machInst, 0x1E00001, 66710474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 6688285SPrakash.Ramrakhyani@arm.com } else { 66910037SARM gem5 Developers PseudoInst::quiesce(tc); 6708142SAli.Saidi@ARM.com } 6717418Sgblack@eecs.umich.edu ''' 6728518Sgeoffrey.blake@arm.com wfePredFixUpCode = ''' 6738518Sgeoffrey.blake@arm.com // WFE is predicated false, reset SevMailbox to reduce spurious sleeps 6748518Sgeoffrey.blake@arm.com // and SEV interrupts 6758518Sgeoffrey.blake@arm.com SevMailbox = 1; 6768518Sgeoffrey.blake@arm.com ''' 6777418Sgblack@eecs.umich.edu wfeIop = InstObjParams("wfe", "WfeInst", "PredOp", \ 6788518Sgeoffrey.blake@arm.com { "code" : wfeCode, 6798518Sgeoffrey.blake@arm.com "pred_fixup" : wfePredFixUpCode, 6808518Sgeoffrey.blake@arm.com "predicate_test" : predicateTest }, 6818733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsQuiesce", 6828733Sgeoffrey.blake@arm.com "IsSerializeAfter", "IsUnverifiable"]) 6837418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(wfeIop) 6847418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(wfeIop) 6858518Sgeoffrey.blake@arm.com exec_output += QuiescePredOpExecuteWithFixup.subst(wfeIop) 6867418Sgblack@eecs.umich.edu 6877418Sgblack@eecs.umich.edu wfiCode = ''' 68810037SARM gem5 Developers HCR hcr = Hcr; 68910037SARM gem5 Developers CPSR cpsr = Cpsr; 69010037SARM gem5 Developers SCR scr = Scr64; 69110037SARM gem5 Developers SCTLR sctlr = Sctlr; 69210037SARM gem5 Developers 6938285SPrakash.Ramrakhyani@arm.com // WFI doesn't sleep if interrupts are pending (masked or not) 69410037SARM gem5 Developers ThreadContext *tc = xc->tcBase(); 69510037SARM gem5 Developers if (tc->getCpuPtr()->getInterruptController()->checkWfiWake(hcr, cpsr, 69610037SARM gem5 Developers scr)) { 69710037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 69810037SARM gem5 Developers } else if (cpsr.el == EL0 && !sctlr.ntwi) { 69910037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 70010474Sandreas.hansson@arm.com fault = std::make_shared<SupervisorTrap>(machInst, 0x1E00000, 70110474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 70210037SARM gem5 Developers } else if (ArmSystem::haveVirtualization(tc) && hcr.twi && 70310037SARM gem5 Developers (cpsr.mode != MODE_HYP) && !inSecureState(scr, cpsr)) { 70410037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 70510474Sandreas.hansson@arm.com fault = std::make_shared<HypervisorTrap>(machInst, 0x1E00000, 70610474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 70710037SARM gem5 Developers } else if (ArmSystem::haveSecurity(tc) && cpsr.el != EL3 && scr.twi) { 70810037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 70910474Sandreas.hansson@arm.com fault = std::make_shared<SecureMonitorTrap>(machInst, 0x1E00000, 71010474Sandreas.hansson@arm.com EC_TRAPPED_WFI_WFE); 7118285SPrakash.Ramrakhyani@arm.com } else { 71210037SARM gem5 Developers PseudoInst::quiesce(tc); 7138285SPrakash.Ramrakhyani@arm.com } 71410037SARM gem5 Developers tc->getCpuPtr()->clearInterrupt(INT_ABT, 0); 7157418Sgblack@eecs.umich.edu ''' 7167418Sgblack@eecs.umich.edu wfiIop = InstObjParams("wfi", "WfiInst", "PredOp", \ 7177418Sgblack@eecs.umich.edu { "code" : wfiCode, "predicate_test" : predicateTest }, 7188733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsQuiesce", 7198733Sgeoffrey.blake@arm.com "IsSerializeAfter", "IsUnverifiable"]) 7207418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(wfiIop) 7217418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(wfiIop) 7228142SAli.Saidi@ARM.com exec_output += QuiescePredOpExecute.subst(wfiIop) 7237418Sgblack@eecs.umich.edu 7247418Sgblack@eecs.umich.edu sevCode = ''' 7258142SAli.Saidi@ARM.com SevMailbox = 1; 7267418Sgblack@eecs.umich.edu System *sys = xc->tcBase()->getSystemPtr(); 7277418Sgblack@eecs.umich.edu for (int x = 0; x < sys->numContexts(); x++) { 7287418Sgblack@eecs.umich.edu ThreadContext *oc = sys->getThreadContext(x); 7298285SPrakash.Ramrakhyani@arm.com if (oc == xc->tcBase()) 7308285SPrakash.Ramrakhyani@arm.com continue; 7318518Sgeoffrey.blake@arm.com // Wake CPU with interrupt if they were sleeping 7328285SPrakash.Ramrakhyani@arm.com if (oc->readMiscReg(MISCREG_SEV_MAILBOX) == 0) { 7338518Sgeoffrey.blake@arm.com // Post Interrupt and wake cpu if needed 7348518Sgeoffrey.blake@arm.com oc->getCpuPtr()->postInterrupt(INT_SEV, 0); 7358142SAli.Saidi@ARM.com } 7367418Sgblack@eecs.umich.edu } 7377418Sgblack@eecs.umich.edu ''' 7387418Sgblack@eecs.umich.edu sevIop = InstObjParams("sev", "SevInst", "PredOp", \ 7397418Sgblack@eecs.umich.edu { "code" : sevCode, "predicate_test" : predicateTest }, 7408733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsSquashAfter", "IsUnverifiable"]) 7417418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(sevIop) 7427418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(sevIop) 7437418Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sevIop) 7447418Sgblack@eecs.umich.edu 74510037SARM gem5 Developers sevlCode = ''' 74610037SARM gem5 Developers SevMailbox = 1; 74710037SARM gem5 Developers ''' 74810037SARM gem5 Developers sevlIop = InstObjParams("sevl", "SevlInst", "PredOp", \ 74910037SARM gem5 Developers { "code" : sevlCode, "predicate_test" : predicateTest }, 75010037SARM gem5 Developers ["IsNonSpeculative", "IsSquashAfter", "IsUnverifiable"]) 75110037SARM gem5 Developers header_output += BasicDeclare.subst(sevlIop) 75210037SARM gem5 Developers decoder_output += BasicConstructor.subst(sevlIop) 75310037SARM gem5 Developers exec_output += BasicExecute.subst(sevlIop) 75410037SARM gem5 Developers 7557408Sgblack@eecs.umich.edu itIop = InstObjParams("it", "ItInst", "PredOp", \ 7568205SAli.Saidi@ARM.com { "code" : ";", 7578908Sgeoffrey.blake@arm.com "predicate_test" : predicateTest }, []) 7587408Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(itIop) 7597408Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(itIop) 7607408Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(itIop) 7617409Sgblack@eecs.umich.edu unknownCode = ''' 76210474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, true); 7637409Sgblack@eecs.umich.edu ''' 7647409Sgblack@eecs.umich.edu unknownIop = InstObjParams("unknown", "Unknown", "UnknownOp", \ 7657409Sgblack@eecs.umich.edu { "code": unknownCode, 7667409Sgblack@eecs.umich.edu "predicate_test": predicateTest }) 7677409Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(unknownIop) 7687409Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(unknownIop) 7697409Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(unknownIop) 7707254Sgblack@eecs.umich.edu 7717254Sgblack@eecs.umich.edu ubfxCode = ''' 7727254Sgblack@eecs.umich.edu Dest = bits(Op1, imm2, imm1); 7737254Sgblack@eecs.umich.edu ''' 7747254Sgblack@eecs.umich.edu ubfxIop = InstObjParams("ubfx", "Ubfx", "RegRegImmImmOp", 7757254Sgblack@eecs.umich.edu { "code": ubfxCode, 7767254Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7777254Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(ubfxIop) 7787254Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(ubfxIop) 7797254Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ubfxIop) 7807254Sgblack@eecs.umich.edu 7817254Sgblack@eecs.umich.edu sbfxCode = ''' 7827254Sgblack@eecs.umich.edu int32_t resTemp = bits(Op1, imm2, imm1); 7837254Sgblack@eecs.umich.edu Dest = resTemp | -(resTemp & (1 << (imm2 - imm1))); 7847254Sgblack@eecs.umich.edu ''' 7857254Sgblack@eecs.umich.edu sbfxIop = InstObjParams("sbfx", "Sbfx", "RegRegImmImmOp", 7867254Sgblack@eecs.umich.edu { "code": sbfxCode, 7877254Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7887254Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(sbfxIop) 7897254Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(sbfxIop) 7907254Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sbfxIop) 7917257Sgblack@eecs.umich.edu 7927257Sgblack@eecs.umich.edu bfcCode = ''' 7937257Sgblack@eecs.umich.edu Dest = Op1 & ~(mask(imm2 - imm1 + 1) << imm1); 7947257Sgblack@eecs.umich.edu ''' 7957257Sgblack@eecs.umich.edu bfcIop = InstObjParams("bfc", "Bfc", "RegRegImmImmOp", 7967257Sgblack@eecs.umich.edu { "code": bfcCode, 7977257Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7987257Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(bfcIop) 7997257Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(bfcIop) 8007257Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(bfcIop) 8017257Sgblack@eecs.umich.edu 8027257Sgblack@eecs.umich.edu bfiCode = ''' 8037257Sgblack@eecs.umich.edu uint32_t bitMask = (mask(imm2 - imm1 + 1) << imm1); 8047257Sgblack@eecs.umich.edu Dest = ((Op1 << imm1) & bitMask) | (Dest & ~bitMask); 8057257Sgblack@eecs.umich.edu ''' 8067257Sgblack@eecs.umich.edu bfiIop = InstObjParams("bfi", "Bfi", "RegRegImmImmOp", 8077257Sgblack@eecs.umich.edu { "code": bfiCode, 8087257Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 8097257Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(bfiIop) 8107257Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(bfiIop) 8117257Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(bfiIop) 8127262Sgblack@eecs.umich.edu 8138868SMatt.Horsnell@arm.com mrc14code = ''' 81410037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) xc->tcBase()->flattenMiscIndex(op1); 81510037SARM gem5 Developers if (!canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase())) { 81610474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 81710474Sandreas.hansson@arm.com mnemonic); 81810037SARM gem5 Developers } 81910037SARM gem5 Developers if (mcrMrc14TrapToHyp((const MiscRegIndex) op1, Hcr, Cpsr, Scr, Hdcr, 82010037SARM gem5 Developers Hstr, Hcptr, imm)) { 82110474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 82210474Sandreas.hansson@arm.com EC_TRAPPED_CP14_MCR_MRC); 8238868SMatt.Horsnell@arm.com } 8248868SMatt.Horsnell@arm.com Dest = MiscOp1; 8258868SMatt.Horsnell@arm.com ''' 8268868SMatt.Horsnell@arm.com 82710037SARM gem5 Developers mrc14Iop = InstObjParams("mrc", "Mrc14", "RegRegImmOp", 8288868SMatt.Horsnell@arm.com { "code": mrc14code, 8298868SMatt.Horsnell@arm.com "predicate_test": predicateTest }, []) 83010037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mrc14Iop) 83110037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mrc14Iop) 8328868SMatt.Horsnell@arm.com exec_output += PredOpExecute.subst(mrc14Iop) 8338868SMatt.Horsnell@arm.com 8348868SMatt.Horsnell@arm.com 8358868SMatt.Horsnell@arm.com mcr14code = ''' 83610037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest); 83710037SARM gem5 Developers if (!canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase())) { 83810474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 83910474Sandreas.hansson@arm.com mnemonic); 84010037SARM gem5 Developers } 84110037SARM gem5 Developers if (mcrMrc14TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, 84210037SARM gem5 Developers Hstr, Hcptr, imm)) { 84310474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 84410474Sandreas.hansson@arm.com EC_TRAPPED_CP14_MCR_MRC); 8458868SMatt.Horsnell@arm.com } 8468868SMatt.Horsnell@arm.com MiscDest = Op1; 8478868SMatt.Horsnell@arm.com ''' 84810037SARM gem5 Developers mcr14Iop = InstObjParams("mcr", "Mcr14", "RegRegImmOp", 8498868SMatt.Horsnell@arm.com { "code": mcr14code, 8508868SMatt.Horsnell@arm.com "predicate_test": predicateTest }, 8518868SMatt.Horsnell@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 85210037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mcr14Iop) 85310037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mcr14Iop) 8548868SMatt.Horsnell@arm.com exec_output += PredOpExecute.subst(mcr14Iop) 8558868SMatt.Horsnell@arm.com 85610037SARM gem5 Developers mrc15code = ''' 85710037SARM gem5 Developers int preFlatOp1 = flattenMiscRegNsBanked(op1, xc->tcBase()); 85810037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 85910037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatOp1); 86010037SARM gem5 Developers bool hypTrap = mcrMrc15TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, Hstr, 86110037SARM gem5 Developers Hcptr, imm); 86210037SARM gem5 Developers bool canRead = canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 8638868SMatt.Horsnell@arm.com 86410037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 86510037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 86610037SARM gem5 Developers // IS accessable. 86710188Sgeoffrey.blake@arm.com if (!canRead && !(hypTrap && !inUserMode(Cpsr) && !inSecureState(Scr, Cpsr))) { 86810474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 86910474Sandreas.hansson@arm.com mnemonic); 8708782Sgblack@eecs.umich.edu } 87110037SARM gem5 Developers if (hypTrap) { 87210474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 87310474Sandreas.hansson@arm.com EC_TRAPPED_CP15_MCR_MRC); 87410037SARM gem5 Developers } 87510037SARM gem5 Developers Dest = MiscNsBankedOp1; 8767347SAli.Saidi@ARM.com ''' 8777347SAli.Saidi@ARM.com 87810418Sandreas.hansson@arm.com mrc15Iop = InstObjParams("mrc", "Mrc15", "RegMiscRegImmOp", 8797347SAli.Saidi@ARM.com { "code": mrc15code, 8807262Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 88110418Sandreas.hansson@arm.com header_output += RegMiscRegImmOpDeclare.subst(mrc15Iop) 88210418Sandreas.hansson@arm.com decoder_output += RegMiscRegImmOpConstructor.subst(mrc15Iop) 8837262Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrc15Iop) 8847262Sgblack@eecs.umich.edu 8857347SAli.Saidi@ARM.com 8867347SAli.Saidi@ARM.com mcr15code = ''' 88710037SARM gem5 Developers int preFlatDest = flattenMiscRegNsBanked(dest, xc->tcBase()); 88810037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 88910037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatDest); 89010037SARM gem5 Developers bool hypTrap = mcrMrc15TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, Hstr, 89110037SARM gem5 Developers Hcptr, imm); 89210037SARM gem5 Developers bool canWrite = canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 89310037SARM gem5 Developers 89410037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 89510037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 89610037SARM gem5 Developers // IS accessable. 89710037SARM gem5 Developers if (!canWrite & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 89810474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 89910474Sandreas.hansson@arm.com mnemonic); 9008782Sgblack@eecs.umich.edu } 90110037SARM gem5 Developers if (hypTrap) { 90210474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 90310474Sandreas.hansson@arm.com EC_TRAPPED_CP15_MCR_MRC); 90410037SARM gem5 Developers } 90510037SARM gem5 Developers MiscNsBankedDest = Op1; 9067347SAli.Saidi@ARM.com ''' 90710418Sandreas.hansson@arm.com mcr15Iop = InstObjParams("mcr", "Mcr15", "MiscRegRegImmOp", 9087347SAli.Saidi@ARM.com { "code": mcr15code, 9097599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 9107599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 91110418Sandreas.hansson@arm.com header_output += MiscRegRegImmOpDeclare.subst(mcr15Iop) 91210418Sandreas.hansson@arm.com decoder_output += MiscRegRegImmOpConstructor.subst(mcr15Iop) 9137262Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mcr15Iop) 9147283Sgblack@eecs.umich.edu 9157420Sgblack@eecs.umich.edu 91610037SARM gem5 Developers mrrc15code = ''' 91710037SARM gem5 Developers int preFlatOp1 = flattenMiscRegNsBanked(op1, xc->tcBase()); 91810037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 91910037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatOp1); 92010037SARM gem5 Developers bool hypTrap = mcrrMrrc15TrapToHyp(miscReg, Cpsr, Scr, Hstr, Hcr, imm); 92110037SARM gem5 Developers bool canRead = canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 92210037SARM gem5 Developers 92310037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 92410037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 92510037SARM gem5 Developers // IS accessable. 92610188Sgeoffrey.blake@arm.com if (!canRead && !(hypTrap && !inUserMode(Cpsr) && !inSecureState(Scr, Cpsr))) { 92710474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 92810474Sandreas.hansson@arm.com mnemonic); 92910037SARM gem5 Developers } 93010037SARM gem5 Developers if (hypTrap) { 93110474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 93210474Sandreas.hansson@arm.com EC_TRAPPED_CP15_MCRR_MRRC); 93310037SARM gem5 Developers } 93410037SARM gem5 Developers Dest = bits(MiscNsBankedOp164, 63, 32); 93510037SARM gem5 Developers Dest2 = bits(MiscNsBankedOp164, 31, 0); 93610037SARM gem5 Developers ''' 93710037SARM gem5 Developers mrrc15Iop = InstObjParams("mrrc", "Mrrc15", "MrrcOp", 93810037SARM gem5 Developers { "code": mrrc15code, 93910037SARM gem5 Developers "predicate_test": predicateTest }, []) 94010037SARM gem5 Developers header_output += MrrcOpDeclare.subst(mrrc15Iop) 94110037SARM gem5 Developers decoder_output += MrrcOpConstructor.subst(mrrc15Iop) 94210037SARM gem5 Developers exec_output += PredOpExecute.subst(mrrc15Iop) 94310037SARM gem5 Developers 94410037SARM gem5 Developers 94510037SARM gem5 Developers mcrr15code = ''' 94610037SARM gem5 Developers int preFlatDest = flattenMiscRegNsBanked(dest, xc->tcBase()); 94710037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 94810037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatDest); 94910037SARM gem5 Developers bool hypTrap = mcrrMrrc15TrapToHyp(miscReg, Cpsr, Scr, Hstr, Hcr, imm); 95010037SARM gem5 Developers bool canWrite = canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 95110037SARM gem5 Developers 95210037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 95310037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 95410037SARM gem5 Developers // IS accessable. 95510037SARM gem5 Developers if (!canWrite & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 95610474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 95710474Sandreas.hansson@arm.com mnemonic); 95810037SARM gem5 Developers } 95910037SARM gem5 Developers if (hypTrap) { 96010474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 96110474Sandreas.hansson@arm.com EC_TRAPPED_CP15_MCRR_MRRC); 96210037SARM gem5 Developers } 96310037SARM gem5 Developers MiscNsBankedDest64 = ((uint64_t) Op1 << 32) | Op2; 96410037SARM gem5 Developers ''' 96510037SARM gem5 Developers mcrr15Iop = InstObjParams("mcrr", "Mcrr15", "McrrOp", 96610037SARM gem5 Developers { "code": mcrr15code, 96710037SARM gem5 Developers "predicate_test": predicateTest }, []) 96810037SARM gem5 Developers header_output += McrrOpDeclare.subst(mcrr15Iop) 96910037SARM gem5 Developers decoder_output += McrrOpConstructor.subst(mcrr15Iop) 97010037SARM gem5 Developers exec_output += PredOpExecute.subst(mcrr15Iop) 97110037SARM gem5 Developers 9727420Sgblack@eecs.umich.edu 9737283Sgblack@eecs.umich.edu enterxCode = ''' 9747797Sgblack@eecs.umich.edu NextThumb = true; 9757797Sgblack@eecs.umich.edu NextJazelle = true; 9767283Sgblack@eecs.umich.edu ''' 9777283Sgblack@eecs.umich.edu enterxIop = InstObjParams("enterx", "Enterx", "PredOp", 9787283Sgblack@eecs.umich.edu { "code": enterxCode, 9797283Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 9807283Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(enterxIop) 9817283Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(enterxIop) 9827283Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(enterxIop) 9837283Sgblack@eecs.umich.edu 9847283Sgblack@eecs.umich.edu leavexCode = ''' 9857797Sgblack@eecs.umich.edu NextThumb = true; 9867797Sgblack@eecs.umich.edu NextJazelle = false; 9877283Sgblack@eecs.umich.edu ''' 9887283Sgblack@eecs.umich.edu leavexIop = InstObjParams("leavex", "Leavex", "PredOp", 9897283Sgblack@eecs.umich.edu { "code": leavexCode, 9907283Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 9917283Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(leavexIop) 9927283Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(leavexIop) 9937283Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(leavexIop) 9947307Sgblack@eecs.umich.edu 9957307Sgblack@eecs.umich.edu setendCode = ''' 9967307Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 9977307Sgblack@eecs.umich.edu cpsr.e = imm; 9987307Sgblack@eecs.umich.edu Cpsr = cpsr; 9997307Sgblack@eecs.umich.edu ''' 10007307Sgblack@eecs.umich.edu setendIop = InstObjParams("setend", "Setend", "ImmOp", 10017307Sgblack@eecs.umich.edu { "code": setendCode, 10027648SAli.Saidi@ARM.com "predicate_test": predicateTest }, 10037648SAli.Saidi@ARM.com ["IsSerializeAfter","IsNonSpeculative"]) 10047307Sgblack@eecs.umich.edu header_output += ImmOpDeclare.subst(setendIop) 10057307Sgblack@eecs.umich.edu decoder_output += ImmOpConstructor.subst(setendIop) 10067307Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(setendIop) 10077315Sgblack@eecs.umich.edu 10087603SGene.Wu@arm.com clrexCode = ''' 10098209SAli.Saidi@ARM.com LLSCLock = 0; 10107603SGene.Wu@arm.com ''' 10117603SGene.Wu@arm.com clrexIop = InstObjParams("clrex", "Clrex","PredOp", 10127603SGene.Wu@arm.com { "code": clrexCode, 10137603SGene.Wu@arm.com "predicate_test": predicateTest },[]) 10148209SAli.Saidi@ARM.com header_output += BasicDeclare.subst(clrexIop) 10157603SGene.Wu@arm.com decoder_output += BasicConstructor.subst(clrexIop) 10167603SGene.Wu@arm.com exec_output += PredOpExecute.subst(clrexIop) 10177603SGene.Wu@arm.com 10187605SGene.Wu@arm.com isbCode = ''' 101910037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 102010037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15ISB, Hcr, Cpsr, Scr, 102110037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 102210474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 102310037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 102410037SARM gem5 Developers } 102510474Sandreas.hansson@arm.com fault = std::make_shared<FlushPipe>(); 10267605SGene.Wu@arm.com ''' 102710037SARM gem5 Developers isbIop = InstObjParams("isb", "Isb", "ImmOp", 10287605SGene.Wu@arm.com {"code": isbCode, 10298068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10308068SAli.Saidi@ARM.com ['IsSerializeAfter']) 103110037SARM gem5 Developers header_output += ImmOpDeclare.subst(isbIop) 103210037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(isbIop) 10337605SGene.Wu@arm.com exec_output += PredOpExecute.subst(isbIop) 10347605SGene.Wu@arm.com 10357605SGene.Wu@arm.com dsbCode = ''' 103610037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 103710037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15DSB, Hcr, Cpsr, Scr, 103810037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 103910474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 104010037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 104110037SARM gem5 Developers } 104210474Sandreas.hansson@arm.com fault = std::make_shared<FlushPipe>(); 10437605SGene.Wu@arm.com ''' 104410037SARM gem5 Developers dsbIop = InstObjParams("dsb", "Dsb", "ImmOp", 10457605SGene.Wu@arm.com {"code": dsbCode, 10468068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10478068SAli.Saidi@ARM.com ['IsMemBarrier', 'IsSerializeAfter']) 104810037SARM gem5 Developers header_output += ImmOpDeclare.subst(dsbIop) 104910037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(dsbIop) 10507605SGene.Wu@arm.com exec_output += PredOpExecute.subst(dsbIop) 10517605SGene.Wu@arm.com 10527605SGene.Wu@arm.com dmbCode = ''' 105310037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 105410037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15DMB, Hcr, Cpsr, Scr, 105510037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 105610474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>(machInst, imm, 105710037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 105810037SARM gem5 Developers } 10597605SGene.Wu@arm.com ''' 106010037SARM gem5 Developers dmbIop = InstObjParams("dmb", "Dmb", "ImmOp", 10617605SGene.Wu@arm.com {"code": dmbCode, 10628068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10638068SAli.Saidi@ARM.com ['IsMemBarrier']) 106410037SARM gem5 Developers header_output += ImmOpDeclare.subst(dmbIop) 106510037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(dmbIop) 10667605SGene.Wu@arm.com exec_output += PredOpExecute.subst(dmbIop) 10677605SGene.Wu@arm.com 10687613SGene.Wu@arm.com dbgCode = ''' 10697613SGene.Wu@arm.com ''' 10707613SGene.Wu@arm.com dbgIop = InstObjParams("dbg", "Dbg", "PredOp", 10717613SGene.Wu@arm.com {"code": dbgCode, 10727613SGene.Wu@arm.com "predicate_test": predicateTest}) 10737613SGene.Wu@arm.com header_output += BasicDeclare.subst(dbgIop) 10747613SGene.Wu@arm.com decoder_output += BasicConstructor.subst(dbgIop) 10757613SGene.Wu@arm.com exec_output += PredOpExecute.subst(dbgIop) 10767613SGene.Wu@arm.com 10777315Sgblack@eecs.umich.edu cpsCode = ''' 10787315Sgblack@eecs.umich.edu uint32_t mode = bits(imm, 4, 0); 10797315Sgblack@eecs.umich.edu uint32_t f = bits(imm, 5); 10807315Sgblack@eecs.umich.edu uint32_t i = bits(imm, 6); 10817315Sgblack@eecs.umich.edu uint32_t a = bits(imm, 7); 10827315Sgblack@eecs.umich.edu bool setMode = bits(imm, 8); 10837315Sgblack@eecs.umich.edu bool enable = bits(imm, 9); 10847315Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 10857400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 10867315Sgblack@eecs.umich.edu if (cpsr.mode != MODE_USER) { 10877315Sgblack@eecs.umich.edu if (enable) { 10887315Sgblack@eecs.umich.edu if (f) cpsr.f = 0; 10897315Sgblack@eecs.umich.edu if (i) cpsr.i = 0; 10907315Sgblack@eecs.umich.edu if (a) cpsr.a = 0; 10917315Sgblack@eecs.umich.edu } else { 10927400SAli.Saidi@ARM.com if (f && !sctlr.nmfi) cpsr.f = 1; 10937315Sgblack@eecs.umich.edu if (i) cpsr.i = 1; 10947315Sgblack@eecs.umich.edu if (a) cpsr.a = 1; 10957315Sgblack@eecs.umich.edu } 10967315Sgblack@eecs.umich.edu if (setMode) { 10977315Sgblack@eecs.umich.edu cpsr.mode = mode; 10987315Sgblack@eecs.umich.edu } 10997315Sgblack@eecs.umich.edu } 11007315Sgblack@eecs.umich.edu Cpsr = cpsr; 11017315Sgblack@eecs.umich.edu ''' 11027315Sgblack@eecs.umich.edu cpsIop = InstObjParams("cps", "Cps", "ImmOp", 11037315Sgblack@eecs.umich.edu { "code": cpsCode, 11047599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 11057599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 11067315Sgblack@eecs.umich.edu header_output += ImmOpDeclare.subst(cpsIop) 11077315Sgblack@eecs.umich.edu decoder_output += ImmOpConstructor.subst(cpsIop) 11087315Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(cpsIop) 11097202Sgblack@eecs.umich.edu}}; 1110