misc.isa revision 10037
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 = ''' 4310037SARM gem5 Developers fault = new 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) { 6210037SARM gem5 Developers fault = new HypervisorTrap(machInst, 0, EC_SMC_TO_HYP); 6310037SARM gem5 Developers } else { 6410037SARM gem5 Developers if (scr.scd) { 6510037SARM gem5 Developers fault = disabledFault(); 6610037SARM gem5 Developers } else { 6710037SARM gem5 Developers fault = new SecureMonitorCall(machInst); 6810037SARM gem5 Developers } 6910037SARM gem5 Developers } 708782Sgblack@eecs.umich.edu } else { 7110037SARM gem5 Developers fault = disabledFault(); 728782Sgblack@eecs.umich.edu } 737199Sgblack@eecs.umich.edu ''' 747199Sgblack@eecs.umich.edu 7510037SARM gem5 Developers smcIop = InstObjParams("smc", "Smc", "PredOp", 7610037SARM gem5 Developers { "code": smcCode, 778628SAli.Saidi@ARM.com "predicate_test": predicateTest }, 7810037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 7910037SARM gem5 Developers header_output += BasicDeclare.subst(smcIop) 8010037SARM gem5 Developers decoder_output += BasicConstructor.subst(smcIop) 8110037SARM gem5 Developers exec_output += PredOpExecute.subst(smcIop) 8210037SARM gem5 Developers 8310037SARM gem5 Developers hvcCode = ''' 8410037SARM gem5 Developers CPSR cpsr = Cpsr; 8510037SARM gem5 Developers SCR scr = Scr; 8610037SARM gem5 Developers 8710037SARM gem5 Developers // Filter out the various cases where this instruction isn't defined 8810037SARM gem5 Developers if (!FullSystem || !ArmSystem::haveVirtualization(xc->tcBase()) || 8910037SARM gem5 Developers (cpsr.mode == MODE_USER) || 9010037SARM gem5 Developers (ArmSystem::haveSecurity(xc->tcBase()) && (!scr.ns || !scr.hce))) { 9110037SARM gem5 Developers fault = disabledFault(); 9210037SARM gem5 Developers } else { 9310037SARM gem5 Developers fault = new HypervisorCall(machInst, imm); 9410037SARM gem5 Developers } 9510037SARM gem5 Developers ''' 9610037SARM gem5 Developers 9710037SARM gem5 Developers hvcIop = InstObjParams("hvc", "Hvc", "ImmOp", 9810037SARM gem5 Developers { "code": hvcCode, 9910037SARM gem5 Developers "predicate_test": predicateTest }, 10010037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 10110037SARM gem5 Developers header_output += ImmOpDeclare.subst(hvcIop) 10210037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(hvcIop) 10310037SARM gem5 Developers exec_output += PredOpExecute.subst(hvcIop) 10410037SARM gem5 Developers 10510037SARM gem5 Developers eretCode = ''' 10610037SARM gem5 Developers SCTLR sctlr = Sctlr; 10710037SARM gem5 Developers CPSR old_cpsr = Cpsr; 10810037SARM gem5 Developers old_cpsr.nz = CondCodesNZ; 10910037SARM gem5 Developers old_cpsr.c = CondCodesC; 11010037SARM gem5 Developers old_cpsr.v = CondCodesV; 11110037SARM gem5 Developers old_cpsr.ge = CondCodesGE; 11210037SARM gem5 Developers 11310037SARM gem5 Developers CPSR new_cpsr = cpsrWriteByInstr(old_cpsr, Spsr, Scr, Nsacr, 0xF, 11410037SARM gem5 Developers true, sctlr.nmfi, xc->tcBase()); 11510037SARM gem5 Developers Cpsr = ~CondCodesMask & new_cpsr; 11610037SARM gem5 Developers CondCodesNZ = new_cpsr.nz; 11710037SARM gem5 Developers CondCodesC = new_cpsr.c; 11810037SARM gem5 Developers CondCodesV = new_cpsr.v; 11910037SARM gem5 Developers CondCodesGE = new_cpsr.ge; 12010037SARM gem5 Developers 12110037SARM gem5 Developers NextThumb = (new_cpsr).t; 12210037SARM gem5 Developers NextJazelle = (new_cpsr).j; 12310037SARM gem5 Developers NextItState = (((new_cpsr).it2 << 2) & 0xFC) 12410037SARM gem5 Developers | ((new_cpsr).it1 & 0x3); 12510037SARM gem5 Developers 12610037SARM gem5 Developers NPC = (old_cpsr.mode == MODE_HYP) ? ElrHyp : LR; 12710037SARM gem5 Developers ''' 12810037SARM gem5 Developers 12910037SARM gem5 Developers eretIop = InstObjParams("eret", "Eret", "PredOp", 13010037SARM gem5 Developers { "code": eretCode, 13110037SARM gem5 Developers "predicate_test": predicateTest }, 13210037SARM gem5 Developers ["IsNonSpeculative", "IsSerializeAfter"]) 13310037SARM gem5 Developers header_output += BasicDeclare.subst(eretIop) 13410037SARM gem5 Developers decoder_output += BasicConstructor.subst(eretIop) 13510037SARM gem5 Developers exec_output += PredOpExecute.subst(eretIop) 13610037SARM gem5 Developers 13710037SARM gem5 Developers 1387199Sgblack@eecs.umich.edu 1397199Sgblack@eecs.umich.edu}}; 1407202Sgblack@eecs.umich.edu 1417202Sgblack@eecs.umich.edulet {{ 1427202Sgblack@eecs.umich.edu 1437202Sgblack@eecs.umich.edu header_output = decoder_output = exec_output = "" 1447202Sgblack@eecs.umich.edu 1458301SAli.Saidi@ARM.com mrsCpsrCode = ''' 1468303SAli.Saidi@ARM.com CPSR cpsr = Cpsr; 1478303SAli.Saidi@ARM.com cpsr.nz = CondCodesNZ; 1488303SAli.Saidi@ARM.com cpsr.c = CondCodesC; 1498303SAli.Saidi@ARM.com cpsr.v = CondCodesV; 1508303SAli.Saidi@ARM.com cpsr.ge = CondCodesGE; 1518303SAli.Saidi@ARM.com Dest = cpsr & 0xF8FF03DF 1528301SAli.Saidi@ARM.com ''' 1538301SAli.Saidi@ARM.com 1547202Sgblack@eecs.umich.edu mrsCpsrIop = InstObjParams("mrs", "MrsCpsr", "MrsOp", 1557202Sgblack@eecs.umich.edu { "code": mrsCpsrCode, 1567599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 1577783SGiacomo.Gabrielli@arm.com ["IsSerializeBefore"]) 1587202Sgblack@eecs.umich.edu header_output += MrsDeclare.subst(mrsCpsrIop) 1597202Sgblack@eecs.umich.edu decoder_output += MrsConstructor.subst(mrsCpsrIop) 1607202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrsCpsrIop) 1617202Sgblack@eecs.umich.edu 1627202Sgblack@eecs.umich.edu mrsSpsrCode = "Dest = Spsr" 1637202Sgblack@eecs.umich.edu mrsSpsrIop = InstObjParams("mrs", "MrsSpsr", "MrsOp", 1647202Sgblack@eecs.umich.edu { "code": mrsSpsrCode, 1657599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 1667783SGiacomo.Gabrielli@arm.com ["IsSerializeBefore"]) 1677202Sgblack@eecs.umich.edu header_output += MrsDeclare.subst(mrsSpsrIop) 1687202Sgblack@eecs.umich.edu decoder_output += MrsConstructor.subst(mrsSpsrIop) 1697202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrsSpsrIop) 1707202Sgblack@eecs.umich.edu 17110037SARM gem5 Developers mrsBankedRegCode = ''' 17210037SARM gem5 Developers bool isIntReg; 17310037SARM gem5 Developers int regIdx; 17410037SARM gem5 Developers 17510037SARM gem5 Developers if (decodeMrsMsrBankedReg(byteMask, r, isIntReg, regIdx, Cpsr, Scr, Nsacr)) { 17610037SARM gem5 Developers if (isIntReg) { 17710037SARM gem5 Developers Dest = DecodedBankedIntReg; 17810037SARM gem5 Developers } else { 17910037SARM gem5 Developers Dest = xc->readMiscReg(regIdx); 18010037SARM gem5 Developers } 18110037SARM gem5 Developers } else { 18210037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 18310037SARM gem5 Developers } 18410037SARM gem5 Developers ''' 18510037SARM gem5 Developers mrsBankedRegIop = InstObjParams("mrs", "MrsBankedReg", "MrsOp", 18610037SARM gem5 Developers { "code": mrsBankedRegCode, 18710037SARM gem5 Developers "predicate_test": predicateTest }, 18810037SARM gem5 Developers ["IsSerializeBefore"]) 18910037SARM gem5 Developers header_output += MrsBankedRegDeclare.subst(mrsBankedRegIop) 19010037SARM gem5 Developers decoder_output += MrsBankedRegConstructor.subst(mrsBankedRegIop) 19110037SARM gem5 Developers exec_output += PredOpExecute.subst(mrsBankedRegIop) 19210037SARM gem5 Developers 19310037SARM gem5 Developers msrBankedRegCode = ''' 19410037SARM gem5 Developers bool isIntReg; 19510037SARM gem5 Developers int regIdx; 19610037SARM gem5 Developers 19710037SARM gem5 Developers if (decodeMrsMsrBankedReg(byteMask, r, isIntReg, regIdx, Cpsr, Scr, Nsacr)) { 19810037SARM gem5 Developers if (isIntReg) { 19910037SARM gem5 Developers // This is a bit nasty, you would have thought that 20010037SARM gem5 Developers // DecodedBankedIntReg wouldn't be written to unless the 20110037SARM gem5 Developers // conditions on the IF statements above are met, however if 20210037SARM gem5 Developers // you look at the generated C code you'll find that they are. 20310037SARM gem5 Developers // However this is safe as DecodedBankedIntReg (which is used 20410037SARM gem5 Developers // in operands.isa to get the index of DecodedBankedIntReg) 20510037SARM gem5 Developers // will return INTREG_DUMMY if its not a valid integer 20610037SARM gem5 Developers // register, so redirecting the write to somewhere we don't 20710037SARM gem5 Developers // care about. 20810037SARM gem5 Developers DecodedBankedIntReg = Op1; 20910037SARM gem5 Developers } else { 21010037SARM gem5 Developers xc->setMiscReg(regIdx, Op1); 21110037SARM gem5 Developers } 21210037SARM gem5 Developers } else { 21310037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 21410037SARM gem5 Developers } 21510037SARM gem5 Developers ''' 21610037SARM gem5 Developers msrBankedRegIop = InstObjParams("msr", "MsrBankedReg", "MsrRegOp", 21710037SARM gem5 Developers { "code": msrBankedRegCode, 21810037SARM gem5 Developers "predicate_test": predicateTest }, 21910037SARM gem5 Developers ["IsSerializeAfter"]) 22010037SARM gem5 Developers header_output += MsrBankedRegDeclare.subst(msrBankedRegIop) 22110037SARM gem5 Developers decoder_output += MsrBankedRegConstructor.subst(msrBankedRegIop) 22210037SARM gem5 Developers exec_output += PredOpExecute.subst(msrBankedRegIop) 22310037SARM gem5 Developers 2247202Sgblack@eecs.umich.edu msrCpsrRegCode = ''' 2257400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 2268303SAli.Saidi@ARM.com CPSR old_cpsr = Cpsr; 2278303SAli.Saidi@ARM.com old_cpsr.nz = CondCodesNZ; 2288303SAli.Saidi@ARM.com old_cpsr.c = CondCodesC; 2298303SAli.Saidi@ARM.com old_cpsr.v = CondCodesV; 2308303SAli.Saidi@ARM.com old_cpsr.ge = CondCodesGE; 2318303SAli.Saidi@ARM.com 2328303SAli.Saidi@ARM.com CPSR new_cpsr = 23310037SARM gem5 Developers cpsrWriteByInstr(old_cpsr, Op1, Scr, Nsacr, byteMask, false, 23410037SARM gem5 Developers sctlr.nmfi, xc->tcBase()); 2358303SAli.Saidi@ARM.com Cpsr = ~CondCodesMask & new_cpsr; 2368303SAli.Saidi@ARM.com CondCodesNZ = new_cpsr.nz; 2378303SAli.Saidi@ARM.com CondCodesC = new_cpsr.c; 2388303SAli.Saidi@ARM.com CondCodesV = new_cpsr.v; 2398303SAli.Saidi@ARM.com CondCodesGE = new_cpsr.ge; 2407202Sgblack@eecs.umich.edu ''' 2417202Sgblack@eecs.umich.edu msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp", 2427202Sgblack@eecs.umich.edu { "code": msrCpsrRegCode, 2437599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 2447599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2457202Sgblack@eecs.umich.edu header_output += MsrRegDeclare.subst(msrCpsrRegIop) 2467202Sgblack@eecs.umich.edu decoder_output += MsrRegConstructor.subst(msrCpsrRegIop) 2477202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrCpsrRegIop) 2487202Sgblack@eecs.umich.edu 2497202Sgblack@eecs.umich.edu msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);" 2507202Sgblack@eecs.umich.edu msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp", 2517202Sgblack@eecs.umich.edu { "code": msrSpsrRegCode, 2527599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 2537599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2547202Sgblack@eecs.umich.edu header_output += MsrRegDeclare.subst(msrSpsrRegIop) 2557202Sgblack@eecs.umich.edu decoder_output += MsrRegConstructor.subst(msrSpsrRegIop) 2567202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrSpsrRegIop) 2577202Sgblack@eecs.umich.edu 2587202Sgblack@eecs.umich.edu msrCpsrImmCode = ''' 2597400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 2608303SAli.Saidi@ARM.com CPSR old_cpsr = Cpsr; 2618303SAli.Saidi@ARM.com old_cpsr.nz = CondCodesNZ; 2628303SAli.Saidi@ARM.com old_cpsr.c = CondCodesC; 2638303SAli.Saidi@ARM.com old_cpsr.v = CondCodesV; 2648303SAli.Saidi@ARM.com old_cpsr.ge = CondCodesGE; 2658303SAli.Saidi@ARM.com CPSR new_cpsr = 26610037SARM gem5 Developers cpsrWriteByInstr(old_cpsr, imm, Scr, Nsacr, byteMask, false, 26710037SARM gem5 Developers sctlr.nmfi, xc->tcBase()); 2688303SAli.Saidi@ARM.com Cpsr = ~CondCodesMask & new_cpsr; 2698303SAli.Saidi@ARM.com CondCodesNZ = new_cpsr.nz; 2708303SAli.Saidi@ARM.com CondCodesC = new_cpsr.c; 2718303SAli.Saidi@ARM.com CondCodesV = new_cpsr.v; 2728303SAli.Saidi@ARM.com CondCodesGE = new_cpsr.ge; 2737202Sgblack@eecs.umich.edu ''' 2747202Sgblack@eecs.umich.edu msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp", 2757202Sgblack@eecs.umich.edu { "code": msrCpsrImmCode, 2767599Sminkyu.jeong@arm.com "predicate_test": condPredicateTest }, 2777599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2787202Sgblack@eecs.umich.edu header_output += MsrImmDeclare.subst(msrCpsrImmIop) 2797202Sgblack@eecs.umich.edu decoder_output += MsrImmConstructor.subst(msrCpsrImmIop) 2807202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrCpsrImmIop) 2817202Sgblack@eecs.umich.edu 2827202Sgblack@eecs.umich.edu msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);" 2837202Sgblack@eecs.umich.edu msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp", 2847202Sgblack@eecs.umich.edu { "code": msrSpsrImmCode, 2857599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 2867599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 2877202Sgblack@eecs.umich.edu header_output += MsrImmDeclare.subst(msrSpsrImmIop) 2887202Sgblack@eecs.umich.edu decoder_output += MsrImmConstructor.subst(msrSpsrImmIop) 2897202Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(msrSpsrImmIop) 2907209Sgblack@eecs.umich.edu 2917209Sgblack@eecs.umich.edu revCode = ''' 2927209Sgblack@eecs.umich.edu uint32_t val = Op1; 2937209Sgblack@eecs.umich.edu Dest = swap_byte(val); 2947209Sgblack@eecs.umich.edu ''' 2957261Sgblack@eecs.umich.edu revIop = InstObjParams("rev", "Rev", "RegRegOp", 2967209Sgblack@eecs.umich.edu { "code": revCode, 2977209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 2987261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(revIop) 2997261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(revIop) 3007209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(revIop) 3017209Sgblack@eecs.umich.edu 3027209Sgblack@eecs.umich.edu rev16Code = ''' 3037209Sgblack@eecs.umich.edu uint32_t val = Op1; 3047209Sgblack@eecs.umich.edu Dest = (bits(val, 15, 8) << 0) | 3057209Sgblack@eecs.umich.edu (bits(val, 7, 0) << 8) | 3067209Sgblack@eecs.umich.edu (bits(val, 31, 24) << 16) | 3077209Sgblack@eecs.umich.edu (bits(val, 23, 16) << 24); 3087209Sgblack@eecs.umich.edu ''' 3097261Sgblack@eecs.umich.edu rev16Iop = InstObjParams("rev16", "Rev16", "RegRegOp", 3107209Sgblack@eecs.umich.edu { "code": rev16Code, 3117209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3127261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(rev16Iop) 3137261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(rev16Iop) 3147209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(rev16Iop) 3157209Sgblack@eecs.umich.edu 3167209Sgblack@eecs.umich.edu revshCode = ''' 3177209Sgblack@eecs.umich.edu uint16_t val = Op1; 3187209Sgblack@eecs.umich.edu Dest = sext<16>(swap_byte(val)); 3197209Sgblack@eecs.umich.edu ''' 3207261Sgblack@eecs.umich.edu revshIop = InstObjParams("revsh", "Revsh", "RegRegOp", 3217209Sgblack@eecs.umich.edu { "code": revshCode, 3227209Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3237261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(revshIop) 3247261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(revshIop) 3257209Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(revshIop) 3267226Sgblack@eecs.umich.edu 3277249Sgblack@eecs.umich.edu rbitCode = ''' 3287249Sgblack@eecs.umich.edu uint8_t *opBytes = (uint8_t *)&Op1; 3297249Sgblack@eecs.umich.edu uint32_t resTemp; 3307249Sgblack@eecs.umich.edu uint8_t *destBytes = (uint8_t *)&resTemp; 3317249Sgblack@eecs.umich.edu // This reverses the bytes and bits of the input, or so says the 3327249Sgblack@eecs.umich.edu // internet. 3337249Sgblack@eecs.umich.edu for (int i = 0; i < 4; i++) { 3347249Sgblack@eecs.umich.edu uint32_t temp = opBytes[i]; 3357249Sgblack@eecs.umich.edu temp = (temp * 0x0802 & 0x22110) | (temp * 0x8020 & 0x88440); 3367249Sgblack@eecs.umich.edu destBytes[3 - i] = (temp * 0x10101) >> 16; 3377249Sgblack@eecs.umich.edu } 3387249Sgblack@eecs.umich.edu Dest = resTemp; 3397249Sgblack@eecs.umich.edu ''' 3407261Sgblack@eecs.umich.edu rbitIop = InstObjParams("rbit", "Rbit", "RegRegOp", 3417249Sgblack@eecs.umich.edu { "code": rbitCode, 3427249Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3437261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(rbitIop) 3447261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(rbitIop) 3457249Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(rbitIop) 3467249Sgblack@eecs.umich.edu 3477251Sgblack@eecs.umich.edu clzCode = ''' 3487251Sgblack@eecs.umich.edu Dest = (Op1 == 0) ? 32 : (31 - findMsbSet(Op1)); 3497251Sgblack@eecs.umich.edu ''' 3507261Sgblack@eecs.umich.edu clzIop = InstObjParams("clz", "Clz", "RegRegOp", 3517251Sgblack@eecs.umich.edu { "code": clzCode, 3527251Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 3537261Sgblack@eecs.umich.edu header_output += RegRegOpDeclare.subst(clzIop) 3547261Sgblack@eecs.umich.edu decoder_output += RegRegOpConstructor.subst(clzIop) 3557251Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(clzIop) 3567251Sgblack@eecs.umich.edu 3577226Sgblack@eecs.umich.edu ssatCode = ''' 3587226Sgblack@eecs.umich.edu int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0); 3597226Sgblack@eecs.umich.edu int32_t res; 3607232Sgblack@eecs.umich.edu if (satInt(res, operand, imm)) 3618302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3627226Sgblack@eecs.umich.edu Dest = res; 3637226Sgblack@eecs.umich.edu ''' 3647232Sgblack@eecs.umich.edu ssatIop = InstObjParams("ssat", "Ssat", "RegImmRegShiftOp", 3657226Sgblack@eecs.umich.edu { "code": ssatCode, 3668304SAli.Saidi@ARM.com "predicate_test": pickPredicate(ssatCode) }, []) 3677232Sgblack@eecs.umich.edu header_output += RegImmRegShiftOpDeclare.subst(ssatIop) 3687232Sgblack@eecs.umich.edu decoder_output += RegImmRegShiftOpConstructor.subst(ssatIop) 3697226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ssatIop) 3707226Sgblack@eecs.umich.edu 3717226Sgblack@eecs.umich.edu usatCode = ''' 3727226Sgblack@eecs.umich.edu int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0); 3737226Sgblack@eecs.umich.edu int32_t res; 3747232Sgblack@eecs.umich.edu if (uSatInt(res, operand, imm)) 3758302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3767226Sgblack@eecs.umich.edu Dest = res; 3777226Sgblack@eecs.umich.edu ''' 3787232Sgblack@eecs.umich.edu usatIop = InstObjParams("usat", "Usat", "RegImmRegShiftOp", 3797226Sgblack@eecs.umich.edu { "code": usatCode, 3808304SAli.Saidi@ARM.com "predicate_test": pickPredicate(usatCode) }, []) 3817232Sgblack@eecs.umich.edu header_output += RegImmRegShiftOpDeclare.subst(usatIop) 3827232Sgblack@eecs.umich.edu decoder_output += RegImmRegShiftOpConstructor.subst(usatIop) 3837226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usatIop) 3847226Sgblack@eecs.umich.edu 3857226Sgblack@eecs.umich.edu ssat16Code = ''' 3867226Sgblack@eecs.umich.edu int32_t res; 3877226Sgblack@eecs.umich.edu uint32_t resTemp = 0; 3887226Sgblack@eecs.umich.edu int32_t argLow = sext<16>(bits(Op1, 15, 0)); 3897226Sgblack@eecs.umich.edu int32_t argHigh = sext<16>(bits(Op1, 31, 16)); 3907232Sgblack@eecs.umich.edu if (satInt(res, argLow, imm)) 3918302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3927226Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, res); 3937232Sgblack@eecs.umich.edu if (satInt(res, argHigh, imm)) 3948302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 3957226Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, res); 3967226Sgblack@eecs.umich.edu Dest = resTemp; 3977226Sgblack@eecs.umich.edu ''' 3987232Sgblack@eecs.umich.edu ssat16Iop = InstObjParams("ssat16", "Ssat16", "RegImmRegOp", 3997226Sgblack@eecs.umich.edu { "code": ssat16Code, 4008304SAli.Saidi@ARM.com "predicate_test": pickPredicate(ssat16Code) }, []) 4017232Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(ssat16Iop) 4027232Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(ssat16Iop) 4037226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ssat16Iop) 4047226Sgblack@eecs.umich.edu 4057226Sgblack@eecs.umich.edu usat16Code = ''' 4067226Sgblack@eecs.umich.edu int32_t res; 4077226Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4087226Sgblack@eecs.umich.edu int32_t argLow = sext<16>(bits(Op1, 15, 0)); 4097226Sgblack@eecs.umich.edu int32_t argHigh = sext<16>(bits(Op1, 31, 16)); 4107232Sgblack@eecs.umich.edu if (uSatInt(res, argLow, imm)) 4118302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 4127226Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, res); 4137232Sgblack@eecs.umich.edu if (uSatInt(res, argHigh, imm)) 4148302SAli.Saidi@ARM.com CpsrQ = 1 << 27; 4157226Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, res); 4167226Sgblack@eecs.umich.edu Dest = resTemp; 4177226Sgblack@eecs.umich.edu ''' 4187232Sgblack@eecs.umich.edu usat16Iop = InstObjParams("usat16", "Usat16", "RegImmRegOp", 4197226Sgblack@eecs.umich.edu { "code": usat16Code, 4208304SAli.Saidi@ARM.com "predicate_test": pickPredicate(usat16Code) }, []) 4217232Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(usat16Iop) 4227232Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(usat16Iop) 4237226Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usat16Iop) 4247234Sgblack@eecs.umich.edu 4257234Sgblack@eecs.umich.edu sxtbIop = InstObjParams("sxtb", "Sxtb", "RegImmRegOp", 4267234Sgblack@eecs.umich.edu { "code": 4278588Sgblack@eecs.umich.edu "Dest = sext<8>((uint8_t)(Op1_ud >> imm));", 4287234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4297234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxtbIop) 4307234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxtbIop) 4317234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtbIop) 4327234Sgblack@eecs.umich.edu 4337234Sgblack@eecs.umich.edu sxtabIop = InstObjParams("sxtab", "Sxtab", "RegRegRegImmOp", 4347234Sgblack@eecs.umich.edu { "code": 4357234Sgblack@eecs.umich.edu ''' 4368588Sgblack@eecs.umich.edu Dest = sext<8>((uint8_t)(Op2_ud >> imm)) + 4377234Sgblack@eecs.umich.edu Op1; 4387234Sgblack@eecs.umich.edu ''', 4397234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4407234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtabIop) 4417234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtabIop) 4427234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtabIop) 4437234Sgblack@eecs.umich.edu 4447234Sgblack@eecs.umich.edu sxtb16Code = ''' 4457234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4467234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, sext<8>(bits(Op1, imm + 7, imm))); 4477234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 4487234Sgblack@eecs.umich.edu sext<8>(bits(Op1, (imm + 23) % 32, (imm + 16) % 32))); 4497234Sgblack@eecs.umich.edu Dest = resTemp; 4507234Sgblack@eecs.umich.edu ''' 4517234Sgblack@eecs.umich.edu sxtb16Iop = InstObjParams("sxtb16", "Sxtb16", "RegImmRegOp", 4527234Sgblack@eecs.umich.edu { "code": sxtb16Code, 4537234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4547234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxtb16Iop) 4557234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxtb16Iop) 4567234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtb16Iop) 4577234Sgblack@eecs.umich.edu 4587234Sgblack@eecs.umich.edu sxtab16Code = ''' 4597234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 4607234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, sext<8>(bits(Op2, imm + 7, imm)) + 4617234Sgblack@eecs.umich.edu bits(Op1, 15, 0)); 4627234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 4637234Sgblack@eecs.umich.edu sext<8>(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) + 4647234Sgblack@eecs.umich.edu bits(Op1, 31, 16)); 4657234Sgblack@eecs.umich.edu Dest = resTemp; 4667234Sgblack@eecs.umich.edu ''' 4677234Sgblack@eecs.umich.edu sxtab16Iop = InstObjParams("sxtab16", "Sxtab16", "RegRegRegImmOp", 4687234Sgblack@eecs.umich.edu { "code": sxtab16Code, 4697234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4707234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtab16Iop) 4717234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtab16Iop) 4727234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtab16Iop) 4737234Sgblack@eecs.umich.edu 4747234Sgblack@eecs.umich.edu sxthCode = ''' 4757234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op1; 4767234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 4777234Sgblack@eecs.umich.edu Dest = sext<16>((uint16_t)rotated); 4787234Sgblack@eecs.umich.edu ''' 4797234Sgblack@eecs.umich.edu sxthIop = InstObjParams("sxth", "Sxth", "RegImmRegOp", 4807234Sgblack@eecs.umich.edu { "code": sxthCode, 4817234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4827234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(sxthIop) 4837234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(sxthIop) 4847234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxthIop) 4857234Sgblack@eecs.umich.edu 4867234Sgblack@eecs.umich.edu sxtahCode = ''' 4877234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op2; 4887234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 4897234Sgblack@eecs.umich.edu Dest = sext<16>((uint16_t)rotated) + Op1; 4907234Sgblack@eecs.umich.edu ''' 4917234Sgblack@eecs.umich.edu sxtahIop = InstObjParams("sxtah", "Sxtah", "RegRegRegImmOp", 4927234Sgblack@eecs.umich.edu { "code": sxtahCode, 4937234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 4947234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(sxtahIop) 4957234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(sxtahIop) 4967234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sxtahIop) 4977234Sgblack@eecs.umich.edu 4987234Sgblack@eecs.umich.edu uxtbIop = InstObjParams("uxtb", "Uxtb", "RegImmRegOp", 4998588Sgblack@eecs.umich.edu { "code": "Dest = (uint8_t)(Op1_ud >> imm);", 5007234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5017234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxtbIop) 5027234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxtbIop) 5037234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtbIop) 5047234Sgblack@eecs.umich.edu 5057234Sgblack@eecs.umich.edu uxtabIop = InstObjParams("uxtab", "Uxtab", "RegRegRegImmOp", 5067234Sgblack@eecs.umich.edu { "code": 5078588Sgblack@eecs.umich.edu "Dest = (uint8_t)(Op2_ud >> imm) + Op1;", 5087234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5097234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtabIop) 5107234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtabIop) 5117234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtabIop) 5127234Sgblack@eecs.umich.edu 5137234Sgblack@eecs.umich.edu uxtb16Code = ''' 5147234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5157234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op1, imm + 7, imm))); 5167234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 5177234Sgblack@eecs.umich.edu (uint8_t)(bits(Op1, (imm + 23) % 32, (imm + 16) % 32))); 5187234Sgblack@eecs.umich.edu Dest = resTemp; 5197234Sgblack@eecs.umich.edu ''' 5207234Sgblack@eecs.umich.edu uxtb16Iop = InstObjParams("uxtb16", "Uxtb16", "RegImmRegOp", 5217234Sgblack@eecs.umich.edu { "code": uxtb16Code, 5227234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5237234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxtb16Iop) 5247234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxtb16Iop) 5257234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtb16Iop) 5267234Sgblack@eecs.umich.edu 5277234Sgblack@eecs.umich.edu uxtab16Code = ''' 5287234Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5297234Sgblack@eecs.umich.edu replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op2, imm + 7, imm)) + 5307234Sgblack@eecs.umich.edu bits(Op1, 15, 0)); 5317234Sgblack@eecs.umich.edu replaceBits(resTemp, 31, 16, 5327234Sgblack@eecs.umich.edu (uint8_t)(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) + 5337234Sgblack@eecs.umich.edu bits(Op1, 31, 16)); 5347234Sgblack@eecs.umich.edu Dest = resTemp; 5357234Sgblack@eecs.umich.edu ''' 5367234Sgblack@eecs.umich.edu uxtab16Iop = InstObjParams("uxtab16", "Uxtab16", "RegRegRegImmOp", 5377234Sgblack@eecs.umich.edu { "code": uxtab16Code, 5387234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5397234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtab16Iop) 5407234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtab16Iop) 5417234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtab16Iop) 5427234Sgblack@eecs.umich.edu 5437234Sgblack@eecs.umich.edu uxthCode = ''' 5447234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op1; 5457234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 5467234Sgblack@eecs.umich.edu Dest = (uint16_t)rotated; 5477234Sgblack@eecs.umich.edu ''' 5487234Sgblack@eecs.umich.edu uxthIop = InstObjParams("uxth", "Uxth", "RegImmRegOp", 5497234Sgblack@eecs.umich.edu { "code": uxthCode, 5507234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5517234Sgblack@eecs.umich.edu header_output += RegImmRegOpDeclare.subst(uxthIop) 5527234Sgblack@eecs.umich.edu decoder_output += RegImmRegOpConstructor.subst(uxthIop) 5537234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxthIop) 5547234Sgblack@eecs.umich.edu 5557234Sgblack@eecs.umich.edu uxtahCode = ''' 5567234Sgblack@eecs.umich.edu uint64_t rotated = (uint32_t)Op2; 5577234Sgblack@eecs.umich.edu rotated = (rotated | (rotated << 32)) >> imm; 5587234Sgblack@eecs.umich.edu Dest = (uint16_t)rotated + Op1; 5597234Sgblack@eecs.umich.edu ''' 5607234Sgblack@eecs.umich.edu uxtahIop = InstObjParams("uxtah", "Uxtah", "RegRegRegImmOp", 5617234Sgblack@eecs.umich.edu { "code": uxtahCode, 5627234Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5637234Sgblack@eecs.umich.edu header_output += RegRegRegImmOpDeclare.subst(uxtahIop) 5647234Sgblack@eecs.umich.edu decoder_output += RegRegRegImmOpConstructor.subst(uxtahIop) 5657234Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(uxtahIop) 5667239Sgblack@eecs.umich.edu 5677239Sgblack@eecs.umich.edu selCode = ''' 5687239Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5697239Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 5707239Sgblack@eecs.umich.edu int low = i * 8; 5717239Sgblack@eecs.umich.edu int high = low + 7; 5727239Sgblack@eecs.umich.edu replaceBits(resTemp, high, low, 5738303SAli.Saidi@ARM.com bits(CondCodesGE, i) ? 5747239Sgblack@eecs.umich.edu bits(Op1, high, low) : bits(Op2, high, low)); 5757239Sgblack@eecs.umich.edu } 5767239Sgblack@eecs.umich.edu Dest = resTemp; 5777239Sgblack@eecs.umich.edu ''' 5787239Sgblack@eecs.umich.edu selIop = InstObjParams("sel", "Sel", "RegRegRegOp", 5797239Sgblack@eecs.umich.edu { "code": selCode, 5808303SAli.Saidi@ARM.com "predicate_test": predicateTest }, []) 5817239Sgblack@eecs.umich.edu header_output += RegRegRegOpDeclare.subst(selIop) 5827239Sgblack@eecs.umich.edu decoder_output += RegRegRegOpConstructor.subst(selIop) 5837239Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(selIop) 5847242Sgblack@eecs.umich.edu 5857242Sgblack@eecs.umich.edu usad8Code = ''' 5867242Sgblack@eecs.umich.edu uint32_t resTemp = 0; 5877242Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 5887242Sgblack@eecs.umich.edu int low = i * 8; 5897242Sgblack@eecs.umich.edu int high = low + 7; 5907242Sgblack@eecs.umich.edu int32_t diff = bits(Op1, high, low) - 5917242Sgblack@eecs.umich.edu bits(Op2, high, low); 5927242Sgblack@eecs.umich.edu resTemp += ((diff < 0) ? -diff : diff); 5937242Sgblack@eecs.umich.edu } 5947242Sgblack@eecs.umich.edu Dest = resTemp; 5957242Sgblack@eecs.umich.edu ''' 5967242Sgblack@eecs.umich.edu usad8Iop = InstObjParams("usad8", "Usad8", "RegRegRegOp", 5977242Sgblack@eecs.umich.edu { "code": usad8Code, 5987242Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 5997242Sgblack@eecs.umich.edu header_output += RegRegRegOpDeclare.subst(usad8Iop) 6007242Sgblack@eecs.umich.edu decoder_output += RegRegRegOpConstructor.subst(usad8Iop) 6017242Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usad8Iop) 6027242Sgblack@eecs.umich.edu 6037242Sgblack@eecs.umich.edu usada8Code = ''' 6047242Sgblack@eecs.umich.edu uint32_t resTemp = 0; 6057242Sgblack@eecs.umich.edu for (unsigned i = 0; i < 4; i++) { 6067242Sgblack@eecs.umich.edu int low = i * 8; 6077242Sgblack@eecs.umich.edu int high = low + 7; 6087242Sgblack@eecs.umich.edu int32_t diff = bits(Op1, high, low) - 6097242Sgblack@eecs.umich.edu bits(Op2, high, low); 6107242Sgblack@eecs.umich.edu resTemp += ((diff < 0) ? -diff : diff); 6117242Sgblack@eecs.umich.edu } 6127242Sgblack@eecs.umich.edu Dest = Op3 + resTemp; 6137242Sgblack@eecs.umich.edu ''' 6147242Sgblack@eecs.umich.edu usada8Iop = InstObjParams("usada8", "Usada8", "RegRegRegRegOp", 6157242Sgblack@eecs.umich.edu { "code": usada8Code, 6167242Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 6177242Sgblack@eecs.umich.edu header_output += RegRegRegRegOpDeclare.subst(usada8Iop) 6187242Sgblack@eecs.umich.edu decoder_output += RegRegRegRegOpConstructor.subst(usada8Iop) 6197242Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(usada8Iop) 6207247Sgblack@eecs.umich.edu 6217797Sgblack@eecs.umich.edu bkptCode = 'return new PrefetchAbort(PC, ArmFault::DebugEvent);\n' 6227848SAli.Saidi@ARM.com bkptIop = InstObjParams("bkpt", "BkptInst", "PredOp", bkptCode) 6237410Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(bkptIop) 6247410Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(bkptIop) 6257410Sgblack@eecs.umich.edu exec_output += BasicExecute.subst(bkptIop) 6267410Sgblack@eecs.umich.edu 62710037SARM gem5 Developers nopIop = InstObjParams("nop", "NopInst", "ArmStaticInst", "", ['IsNop']) 6287247Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(nopIop) 62910037SARM gem5 Developers decoder_output += BasicConstructor64.subst(nopIop) 63010037SARM gem5 Developers exec_output += BasicExecute.subst(nopIop) 6317408Sgblack@eecs.umich.edu 6327418Sgblack@eecs.umich.edu yieldIop = InstObjParams("yield", "YieldInst", "PredOp", \ 6337418Sgblack@eecs.umich.edu { "code" : "", "predicate_test" : predicateTest }) 6347418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(yieldIop) 6357418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(yieldIop) 6367418Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(yieldIop) 6377418Sgblack@eecs.umich.edu 6387418Sgblack@eecs.umich.edu wfeCode = ''' 63910037SARM gem5 Developers HCR hcr = Hcr; 64010037SARM gem5 Developers CPSR cpsr = Cpsr; 64110037SARM gem5 Developers SCR scr = Scr64; 64210037SARM gem5 Developers SCTLR sctlr = Sctlr; 64310037SARM gem5 Developers 64410037SARM gem5 Developers // WFE Sleeps if SevMailbox==0 and no unmasked interrupts are pending, 64510037SARM gem5 Developers ThreadContext *tc = xc->tcBase(); 6468285SPrakash.Ramrakhyani@arm.com if (SevMailbox == 1) { 6477418Sgblack@eecs.umich.edu SevMailbox = 0; 64810037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 64910037SARM gem5 Developers } else if (tc->getCpuPtr()->getInterruptController()->checkInterrupts(tc)) { 65010037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65110037SARM gem5 Developers } else if (cpsr.el == EL0 && !sctlr.ntwe) { 65210037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65310037SARM gem5 Developers fault = new SupervisorTrap(machInst, 0x1E00001, EC_TRAPPED_WFI_WFE); 65410037SARM gem5 Developers } else if (ArmSystem::haveVirtualization(tc) && 65510037SARM gem5 Developers !inSecureState(scr, cpsr) && (cpsr.mode != MODE_HYP) && 65610037SARM gem5 Developers hcr.twe) { 65710037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 65810037SARM gem5 Developers fault = new HypervisorTrap(machInst, 0x1E00001, EC_TRAPPED_WFI_WFE); 65910037SARM gem5 Developers } else if (ArmSystem::haveSecurity(tc) && cpsr.el != EL3 && scr.twe) { 66010037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 66110037SARM gem5 Developers fault = new SecureMonitorTrap(machInst, 0x1E00001, EC_TRAPPED_WFI_WFE); 6628285SPrakash.Ramrakhyani@arm.com } else { 66310037SARM gem5 Developers PseudoInst::quiesce(tc); 6648142SAli.Saidi@ARM.com } 6657418Sgblack@eecs.umich.edu ''' 6668518Sgeoffrey.blake@arm.com wfePredFixUpCode = ''' 6678518Sgeoffrey.blake@arm.com // WFE is predicated false, reset SevMailbox to reduce spurious sleeps 6688518Sgeoffrey.blake@arm.com // and SEV interrupts 6698518Sgeoffrey.blake@arm.com SevMailbox = 1; 6708518Sgeoffrey.blake@arm.com ''' 6717418Sgblack@eecs.umich.edu wfeIop = InstObjParams("wfe", "WfeInst", "PredOp", \ 6728518Sgeoffrey.blake@arm.com { "code" : wfeCode, 6738518Sgeoffrey.blake@arm.com "pred_fixup" : wfePredFixUpCode, 6748518Sgeoffrey.blake@arm.com "predicate_test" : predicateTest }, 6758733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsQuiesce", 6768733Sgeoffrey.blake@arm.com "IsSerializeAfter", "IsUnverifiable"]) 6777418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(wfeIop) 6787418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(wfeIop) 6798518Sgeoffrey.blake@arm.com exec_output += QuiescePredOpExecuteWithFixup.subst(wfeIop) 6807418Sgblack@eecs.umich.edu 6817418Sgblack@eecs.umich.edu wfiCode = ''' 68210037SARM gem5 Developers HCR hcr = Hcr; 68310037SARM gem5 Developers CPSR cpsr = Cpsr; 68410037SARM gem5 Developers SCR scr = Scr64; 68510037SARM gem5 Developers SCTLR sctlr = Sctlr; 68610037SARM gem5 Developers 6878285SPrakash.Ramrakhyani@arm.com // WFI doesn't sleep if interrupts are pending (masked or not) 68810037SARM gem5 Developers ThreadContext *tc = xc->tcBase(); 68910037SARM gem5 Developers if (tc->getCpuPtr()->getInterruptController()->checkWfiWake(hcr, cpsr, 69010037SARM gem5 Developers scr)) { 69110037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 69210037SARM gem5 Developers } else if (cpsr.el == EL0 && !sctlr.ntwi) { 69310037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 69410037SARM gem5 Developers fault = new SupervisorTrap(machInst, 0x1E00000, EC_TRAPPED_WFI_WFE); 69510037SARM gem5 Developers } else if (ArmSystem::haveVirtualization(tc) && hcr.twi && 69610037SARM gem5 Developers (cpsr.mode != MODE_HYP) && !inSecureState(scr, cpsr)) { 69710037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 69810037SARM gem5 Developers fault = new HypervisorTrap(machInst, 0x1E00000, EC_TRAPPED_WFI_WFE); 69910037SARM gem5 Developers } else if (ArmSystem::haveSecurity(tc) && cpsr.el != EL3 && scr.twi) { 70010037SARM gem5 Developers PseudoInst::quiesceSkip(tc); 70110037SARM gem5 Developers fault = new SecureMonitorTrap(machInst, 0x1E00000, EC_TRAPPED_WFI_WFE); 7028285SPrakash.Ramrakhyani@arm.com } else { 70310037SARM gem5 Developers PseudoInst::quiesce(tc); 7048285SPrakash.Ramrakhyani@arm.com } 70510037SARM gem5 Developers tc->getCpuPtr()->clearInterrupt(INT_ABT, 0); 7067418Sgblack@eecs.umich.edu ''' 7077418Sgblack@eecs.umich.edu wfiIop = InstObjParams("wfi", "WfiInst", "PredOp", \ 7087418Sgblack@eecs.umich.edu { "code" : wfiCode, "predicate_test" : predicateTest }, 7098733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsQuiesce", 7108733Sgeoffrey.blake@arm.com "IsSerializeAfter", "IsUnverifiable"]) 7117418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(wfiIop) 7127418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(wfiIop) 7138142SAli.Saidi@ARM.com exec_output += QuiescePredOpExecute.subst(wfiIop) 7147418Sgblack@eecs.umich.edu 7157418Sgblack@eecs.umich.edu sevCode = ''' 7168142SAli.Saidi@ARM.com SevMailbox = 1; 7177418Sgblack@eecs.umich.edu System *sys = xc->tcBase()->getSystemPtr(); 7187418Sgblack@eecs.umich.edu for (int x = 0; x < sys->numContexts(); x++) { 7197418Sgblack@eecs.umich.edu ThreadContext *oc = sys->getThreadContext(x); 7208285SPrakash.Ramrakhyani@arm.com if (oc == xc->tcBase()) 7218285SPrakash.Ramrakhyani@arm.com continue; 7228518Sgeoffrey.blake@arm.com // Wake CPU with interrupt if they were sleeping 7238285SPrakash.Ramrakhyani@arm.com if (oc->readMiscReg(MISCREG_SEV_MAILBOX) == 0) { 7248518Sgeoffrey.blake@arm.com // Post Interrupt and wake cpu if needed 7258518Sgeoffrey.blake@arm.com oc->getCpuPtr()->postInterrupt(INT_SEV, 0); 7268142SAli.Saidi@ARM.com } 7277418Sgblack@eecs.umich.edu } 7287418Sgblack@eecs.umich.edu ''' 7297418Sgblack@eecs.umich.edu sevIop = InstObjParams("sev", "SevInst", "PredOp", \ 7307418Sgblack@eecs.umich.edu { "code" : sevCode, "predicate_test" : predicateTest }, 7318733Sgeoffrey.blake@arm.com ["IsNonSpeculative", "IsSquashAfter", "IsUnverifiable"]) 7327418Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(sevIop) 7337418Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(sevIop) 7347418Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sevIop) 7357418Sgblack@eecs.umich.edu 73610037SARM gem5 Developers sevlCode = ''' 73710037SARM gem5 Developers SevMailbox = 1; 73810037SARM gem5 Developers ''' 73910037SARM gem5 Developers sevlIop = InstObjParams("sevl", "SevlInst", "PredOp", \ 74010037SARM gem5 Developers { "code" : sevlCode, "predicate_test" : predicateTest }, 74110037SARM gem5 Developers ["IsNonSpeculative", "IsSquashAfter", "IsUnverifiable"]) 74210037SARM gem5 Developers header_output += BasicDeclare.subst(sevlIop) 74310037SARM gem5 Developers decoder_output += BasicConstructor.subst(sevlIop) 74410037SARM gem5 Developers exec_output += BasicExecute.subst(sevlIop) 74510037SARM gem5 Developers 7467408Sgblack@eecs.umich.edu itIop = InstObjParams("it", "ItInst", "PredOp", \ 7478205SAli.Saidi@ARM.com { "code" : ";", 7488908Sgeoffrey.blake@arm.com "predicate_test" : predicateTest }, []) 7497408Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(itIop) 7507408Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(itIop) 7517408Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(itIop) 7527409Sgblack@eecs.umich.edu unknownCode = ''' 75310037SARM gem5 Developers return new UndefinedInstruction(machInst, true); 7547409Sgblack@eecs.umich.edu ''' 7557409Sgblack@eecs.umich.edu unknownIop = InstObjParams("unknown", "Unknown", "UnknownOp", \ 7567409Sgblack@eecs.umich.edu { "code": unknownCode, 7577409Sgblack@eecs.umich.edu "predicate_test": predicateTest }) 7587409Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(unknownIop) 7597409Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(unknownIop) 7607409Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(unknownIop) 7617254Sgblack@eecs.umich.edu 7627254Sgblack@eecs.umich.edu ubfxCode = ''' 7637254Sgblack@eecs.umich.edu Dest = bits(Op1, imm2, imm1); 7647254Sgblack@eecs.umich.edu ''' 7657254Sgblack@eecs.umich.edu ubfxIop = InstObjParams("ubfx", "Ubfx", "RegRegImmImmOp", 7667254Sgblack@eecs.umich.edu { "code": ubfxCode, 7677254Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7687254Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(ubfxIop) 7697254Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(ubfxIop) 7707254Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(ubfxIop) 7717254Sgblack@eecs.umich.edu 7727254Sgblack@eecs.umich.edu sbfxCode = ''' 7737254Sgblack@eecs.umich.edu int32_t resTemp = bits(Op1, imm2, imm1); 7747254Sgblack@eecs.umich.edu Dest = resTemp | -(resTemp & (1 << (imm2 - imm1))); 7757254Sgblack@eecs.umich.edu ''' 7767254Sgblack@eecs.umich.edu sbfxIop = InstObjParams("sbfx", "Sbfx", "RegRegImmImmOp", 7777254Sgblack@eecs.umich.edu { "code": sbfxCode, 7787254Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7797254Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(sbfxIop) 7807254Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(sbfxIop) 7817254Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(sbfxIop) 7827257Sgblack@eecs.umich.edu 7837257Sgblack@eecs.umich.edu bfcCode = ''' 7847257Sgblack@eecs.umich.edu Dest = Op1 & ~(mask(imm2 - imm1 + 1) << imm1); 7857257Sgblack@eecs.umich.edu ''' 7867257Sgblack@eecs.umich.edu bfcIop = InstObjParams("bfc", "Bfc", "RegRegImmImmOp", 7877257Sgblack@eecs.umich.edu { "code": bfcCode, 7887257Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 7897257Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(bfcIop) 7907257Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(bfcIop) 7917257Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(bfcIop) 7927257Sgblack@eecs.umich.edu 7937257Sgblack@eecs.umich.edu bfiCode = ''' 7947257Sgblack@eecs.umich.edu uint32_t bitMask = (mask(imm2 - imm1 + 1) << imm1); 7957257Sgblack@eecs.umich.edu Dest = ((Op1 << imm1) & bitMask) | (Dest & ~bitMask); 7967257Sgblack@eecs.umich.edu ''' 7977257Sgblack@eecs.umich.edu bfiIop = InstObjParams("bfi", "Bfi", "RegRegImmImmOp", 7987257Sgblack@eecs.umich.edu { "code": bfiCode, 7997257Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 8007257Sgblack@eecs.umich.edu header_output += RegRegImmImmOpDeclare.subst(bfiIop) 8017257Sgblack@eecs.umich.edu decoder_output += RegRegImmImmOpConstructor.subst(bfiIop) 8027257Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(bfiIop) 8037262Sgblack@eecs.umich.edu 8048868SMatt.Horsnell@arm.com mrc14code = ''' 80510037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) xc->tcBase()->flattenMiscIndex(op1); 80610037SARM gem5 Developers if (!canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase())) { 80710037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 80810037SARM gem5 Developers } 80910037SARM gem5 Developers if (mcrMrc14TrapToHyp((const MiscRegIndex) op1, Hcr, Cpsr, Scr, Hdcr, 81010037SARM gem5 Developers Hstr, Hcptr, imm)) { 81110037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP14_MCR_MRC); 8128868SMatt.Horsnell@arm.com } 8138868SMatt.Horsnell@arm.com Dest = MiscOp1; 8148868SMatt.Horsnell@arm.com ''' 8158868SMatt.Horsnell@arm.com 81610037SARM gem5 Developers mrc14Iop = InstObjParams("mrc", "Mrc14", "RegRegImmOp", 8178868SMatt.Horsnell@arm.com { "code": mrc14code, 8188868SMatt.Horsnell@arm.com "predicate_test": predicateTest }, []) 81910037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mrc14Iop) 82010037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mrc14Iop) 8218868SMatt.Horsnell@arm.com exec_output += PredOpExecute.subst(mrc14Iop) 8228868SMatt.Horsnell@arm.com 8238868SMatt.Horsnell@arm.com 8248868SMatt.Horsnell@arm.com mcr14code = ''' 82510037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest); 82610037SARM gem5 Developers if (!canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase())) { 82710037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 82810037SARM gem5 Developers } 82910037SARM gem5 Developers if (mcrMrc14TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, 83010037SARM gem5 Developers Hstr, Hcptr, imm)) { 83110037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP14_MCR_MRC); 8328868SMatt.Horsnell@arm.com } 8338868SMatt.Horsnell@arm.com MiscDest = Op1; 8348868SMatt.Horsnell@arm.com ''' 83510037SARM gem5 Developers mcr14Iop = InstObjParams("mcr", "Mcr14", "RegRegImmOp", 8368868SMatt.Horsnell@arm.com { "code": mcr14code, 8378868SMatt.Horsnell@arm.com "predicate_test": predicateTest }, 8388868SMatt.Horsnell@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 83910037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mcr14Iop) 84010037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mcr14Iop) 8418868SMatt.Horsnell@arm.com exec_output += PredOpExecute.subst(mcr14Iop) 8428868SMatt.Horsnell@arm.com 84310037SARM gem5 Developers mrc15code = ''' 84410037SARM gem5 Developers int preFlatOp1 = flattenMiscRegNsBanked(op1, xc->tcBase()); 84510037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 84610037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatOp1); 84710037SARM gem5 Developers bool hypTrap = mcrMrc15TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, Hstr, 84810037SARM gem5 Developers Hcptr, imm); 84910037SARM gem5 Developers bool canRead = canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 8508868SMatt.Horsnell@arm.com 85110037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 85210037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 85310037SARM gem5 Developers // IS accessable. 85410037SARM gem5 Developers if (!canRead & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 85510037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 8568782Sgblack@eecs.umich.edu } 85710037SARM gem5 Developers if (hypTrap) { 85810037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP15_MCR_MRC); 85910037SARM gem5 Developers } 86010037SARM gem5 Developers Dest = MiscNsBankedOp1; 8617347SAli.Saidi@ARM.com ''' 8627347SAli.Saidi@ARM.com 86310037SARM gem5 Developers mrc15Iop = InstObjParams("mrc", "Mrc15", "RegRegImmOp", 8647347SAli.Saidi@ARM.com { "code": mrc15code, 8657262Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 86610037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mrc15Iop) 86710037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mrc15Iop) 8687262Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mrc15Iop) 8697262Sgblack@eecs.umich.edu 8707347SAli.Saidi@ARM.com 8717347SAli.Saidi@ARM.com mcr15code = ''' 87210037SARM gem5 Developers int preFlatDest = flattenMiscRegNsBanked(dest, xc->tcBase()); 87310037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 87410037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatDest); 87510037SARM gem5 Developers bool hypTrap = mcrMrc15TrapToHyp(miscReg, Hcr, Cpsr, Scr, Hdcr, Hstr, 87610037SARM gem5 Developers Hcptr, imm); 87710037SARM gem5 Developers bool canWrite = canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 87810037SARM gem5 Developers 87910037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 88010037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 88110037SARM gem5 Developers // IS accessable. 88210037SARM gem5 Developers if (!canWrite & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 88310037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 8848782Sgblack@eecs.umich.edu } 88510037SARM gem5 Developers if (hypTrap) { 88610037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP15_MCR_MRC); 88710037SARM gem5 Developers } 88810037SARM gem5 Developers MiscNsBankedDest = Op1; 8897347SAli.Saidi@ARM.com ''' 89010037SARM gem5 Developers mcr15Iop = InstObjParams("mcr", "Mcr15", "RegRegImmOp", 8917347SAli.Saidi@ARM.com { "code": mcr15code, 8927599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 8937599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 89410037SARM gem5 Developers header_output += RegRegImmOpDeclare.subst(mcr15Iop) 89510037SARM gem5 Developers decoder_output += RegRegImmOpConstructor.subst(mcr15Iop) 8967262Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(mcr15Iop) 8977283Sgblack@eecs.umich.edu 8987420Sgblack@eecs.umich.edu 89910037SARM gem5 Developers mrrc15code = ''' 90010037SARM gem5 Developers int preFlatOp1 = flattenMiscRegNsBanked(op1, xc->tcBase()); 90110037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 90210037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatOp1); 90310037SARM gem5 Developers bool hypTrap = mcrrMrrc15TrapToHyp(miscReg, Cpsr, Scr, Hstr, Hcr, imm); 90410037SARM gem5 Developers bool canRead = canReadCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 90510037SARM gem5 Developers 90610037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 90710037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 90810037SARM gem5 Developers // IS accessable. 90910037SARM gem5 Developers if (!canRead & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 91010037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 91110037SARM gem5 Developers } 91210037SARM gem5 Developers if (hypTrap) { 91310037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP15_MCRR_MRRC); 91410037SARM gem5 Developers } 91510037SARM gem5 Developers Dest = bits(MiscNsBankedOp164, 63, 32); 91610037SARM gem5 Developers Dest2 = bits(MiscNsBankedOp164, 31, 0); 91710037SARM gem5 Developers ''' 91810037SARM gem5 Developers mrrc15Iop = InstObjParams("mrrc", "Mrrc15", "MrrcOp", 91910037SARM gem5 Developers { "code": mrrc15code, 92010037SARM gem5 Developers "predicate_test": predicateTest }, []) 92110037SARM gem5 Developers header_output += MrrcOpDeclare.subst(mrrc15Iop) 92210037SARM gem5 Developers decoder_output += MrrcOpConstructor.subst(mrrc15Iop) 92310037SARM gem5 Developers exec_output += PredOpExecute.subst(mrrc15Iop) 92410037SARM gem5 Developers 92510037SARM gem5 Developers 92610037SARM gem5 Developers mcrr15code = ''' 92710037SARM gem5 Developers int preFlatDest = flattenMiscRegNsBanked(dest, xc->tcBase()); 92810037SARM gem5 Developers MiscRegIndex miscReg = (MiscRegIndex) 92910037SARM gem5 Developers xc->tcBase()->flattenMiscIndex(preFlatDest); 93010037SARM gem5 Developers bool hypTrap = mcrrMrrc15TrapToHyp(miscReg, Cpsr, Scr, Hstr, Hcr, imm); 93110037SARM gem5 Developers bool canWrite = canWriteCoprocReg(miscReg, Scr, Cpsr, xc->tcBase()); 93210037SARM gem5 Developers 93310037SARM gem5 Developers // if we're in non secure PL1 mode then we can trap regargless of whether 93410037SARM gem5 Developers // the register is accessable, in other modes we trap if only if the register 93510037SARM gem5 Developers // IS accessable. 93610037SARM gem5 Developers if (!canWrite & !(hypTrap & !inUserMode(Cpsr) & !inSecureState(Scr, Cpsr))) { 93710037SARM gem5 Developers return new UndefinedInstruction(machInst, false, mnemonic); 93810037SARM gem5 Developers } 93910037SARM gem5 Developers if (hypTrap) { 94010037SARM gem5 Developers return new HypervisorTrap(machInst, imm, EC_TRAPPED_CP15_MCRR_MRRC); 94110037SARM gem5 Developers } 94210037SARM gem5 Developers MiscNsBankedDest64 = ((uint64_t) Op1 << 32) | Op2; 94310037SARM gem5 Developers ''' 94410037SARM gem5 Developers mcrr15Iop = InstObjParams("mcrr", "Mcrr15", "McrrOp", 94510037SARM gem5 Developers { "code": mcrr15code, 94610037SARM gem5 Developers "predicate_test": predicateTest }, []) 94710037SARM gem5 Developers header_output += McrrOpDeclare.subst(mcrr15Iop) 94810037SARM gem5 Developers decoder_output += McrrOpConstructor.subst(mcrr15Iop) 94910037SARM gem5 Developers exec_output += PredOpExecute.subst(mcrr15Iop) 95010037SARM gem5 Developers 9517420Sgblack@eecs.umich.edu 9527283Sgblack@eecs.umich.edu enterxCode = ''' 9537797Sgblack@eecs.umich.edu NextThumb = true; 9547797Sgblack@eecs.umich.edu NextJazelle = true; 9557283Sgblack@eecs.umich.edu ''' 9567283Sgblack@eecs.umich.edu enterxIop = InstObjParams("enterx", "Enterx", "PredOp", 9577283Sgblack@eecs.umich.edu { "code": enterxCode, 9587283Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 9597283Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(enterxIop) 9607283Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(enterxIop) 9617283Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(enterxIop) 9627283Sgblack@eecs.umich.edu 9637283Sgblack@eecs.umich.edu leavexCode = ''' 9647797Sgblack@eecs.umich.edu NextThumb = true; 9657797Sgblack@eecs.umich.edu NextJazelle = false; 9667283Sgblack@eecs.umich.edu ''' 9677283Sgblack@eecs.umich.edu leavexIop = InstObjParams("leavex", "Leavex", "PredOp", 9687283Sgblack@eecs.umich.edu { "code": leavexCode, 9697283Sgblack@eecs.umich.edu "predicate_test": predicateTest }, []) 9707283Sgblack@eecs.umich.edu header_output += BasicDeclare.subst(leavexIop) 9717283Sgblack@eecs.umich.edu decoder_output += BasicConstructor.subst(leavexIop) 9727283Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(leavexIop) 9737307Sgblack@eecs.umich.edu 9747307Sgblack@eecs.umich.edu setendCode = ''' 9757307Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 9767307Sgblack@eecs.umich.edu cpsr.e = imm; 9777307Sgblack@eecs.umich.edu Cpsr = cpsr; 9787307Sgblack@eecs.umich.edu ''' 9797307Sgblack@eecs.umich.edu setendIop = InstObjParams("setend", "Setend", "ImmOp", 9807307Sgblack@eecs.umich.edu { "code": setendCode, 9817648SAli.Saidi@ARM.com "predicate_test": predicateTest }, 9827648SAli.Saidi@ARM.com ["IsSerializeAfter","IsNonSpeculative"]) 9837307Sgblack@eecs.umich.edu header_output += ImmOpDeclare.subst(setendIop) 9847307Sgblack@eecs.umich.edu decoder_output += ImmOpConstructor.subst(setendIop) 9857307Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(setendIop) 9867315Sgblack@eecs.umich.edu 9877603SGene.Wu@arm.com clrexCode = ''' 9888209SAli.Saidi@ARM.com LLSCLock = 0; 9897603SGene.Wu@arm.com ''' 9907603SGene.Wu@arm.com clrexIop = InstObjParams("clrex", "Clrex","PredOp", 9917603SGene.Wu@arm.com { "code": clrexCode, 9927603SGene.Wu@arm.com "predicate_test": predicateTest },[]) 9938209SAli.Saidi@ARM.com header_output += BasicDeclare.subst(clrexIop) 9947603SGene.Wu@arm.com decoder_output += BasicConstructor.subst(clrexIop) 9957603SGene.Wu@arm.com exec_output += PredOpExecute.subst(clrexIop) 9967603SGene.Wu@arm.com 9977605SGene.Wu@arm.com isbCode = ''' 99810037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 99910037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15ISB, Hcr, Cpsr, Scr, 100010037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 100110037SARM gem5 Developers return new HypervisorTrap(machInst, imm, 100210037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 100310037SARM gem5 Developers } 10048068SAli.Saidi@ARM.com fault = new FlushPipe; 10057605SGene.Wu@arm.com ''' 100610037SARM gem5 Developers isbIop = InstObjParams("isb", "Isb", "ImmOp", 10077605SGene.Wu@arm.com {"code": isbCode, 10088068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10098068SAli.Saidi@ARM.com ['IsSerializeAfter']) 101010037SARM gem5 Developers header_output += ImmOpDeclare.subst(isbIop) 101110037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(isbIop) 10127605SGene.Wu@arm.com exec_output += PredOpExecute.subst(isbIop) 10137605SGene.Wu@arm.com 10147605SGene.Wu@arm.com dsbCode = ''' 101510037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 101610037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15DSB, Hcr, Cpsr, Scr, 101710037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 101810037SARM gem5 Developers return new HypervisorTrap(machInst, imm, 101910037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 102010037SARM gem5 Developers } 10218068SAli.Saidi@ARM.com fault = new FlushPipe; 10227605SGene.Wu@arm.com ''' 102310037SARM gem5 Developers dsbIop = InstObjParams("dsb", "Dsb", "ImmOp", 10247605SGene.Wu@arm.com {"code": dsbCode, 10258068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10268068SAli.Saidi@ARM.com ['IsMemBarrier', 'IsSerializeAfter']) 102710037SARM gem5 Developers header_output += ImmOpDeclare.subst(dsbIop) 102810037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(dsbIop) 10297605SGene.Wu@arm.com exec_output += PredOpExecute.subst(dsbIop) 10307605SGene.Wu@arm.com 10317605SGene.Wu@arm.com dmbCode = ''' 103210037SARM gem5 Developers // If the barrier is due to a CP15 access check for hyp traps 103310037SARM gem5 Developers if ((imm != 0) && mcrMrc15TrapToHyp(MISCREG_CP15DMB, Hcr, Cpsr, Scr, 103410037SARM gem5 Developers Hdcr, Hstr, Hcptr, imm)) { 103510037SARM gem5 Developers return new HypervisorTrap(machInst, imm, 103610037SARM gem5 Developers EC_TRAPPED_CP15_MCR_MRC); 103710037SARM gem5 Developers } 10387605SGene.Wu@arm.com ''' 103910037SARM gem5 Developers dmbIop = InstObjParams("dmb", "Dmb", "ImmOp", 10407605SGene.Wu@arm.com {"code": dmbCode, 10418068SAli.Saidi@ARM.com "predicate_test": predicateTest}, 10428068SAli.Saidi@ARM.com ['IsMemBarrier']) 104310037SARM gem5 Developers header_output += ImmOpDeclare.subst(dmbIop) 104410037SARM gem5 Developers decoder_output += ImmOpConstructor.subst(dmbIop) 10457605SGene.Wu@arm.com exec_output += PredOpExecute.subst(dmbIop) 10467605SGene.Wu@arm.com 10477613SGene.Wu@arm.com dbgCode = ''' 10487613SGene.Wu@arm.com ''' 10497613SGene.Wu@arm.com dbgIop = InstObjParams("dbg", "Dbg", "PredOp", 10507613SGene.Wu@arm.com {"code": dbgCode, 10517613SGene.Wu@arm.com "predicate_test": predicateTest}) 10527613SGene.Wu@arm.com header_output += BasicDeclare.subst(dbgIop) 10537613SGene.Wu@arm.com decoder_output += BasicConstructor.subst(dbgIop) 10547613SGene.Wu@arm.com exec_output += PredOpExecute.subst(dbgIop) 10557613SGene.Wu@arm.com 10567315Sgblack@eecs.umich.edu cpsCode = ''' 10577315Sgblack@eecs.umich.edu uint32_t mode = bits(imm, 4, 0); 10587315Sgblack@eecs.umich.edu uint32_t f = bits(imm, 5); 10597315Sgblack@eecs.umich.edu uint32_t i = bits(imm, 6); 10607315Sgblack@eecs.umich.edu uint32_t a = bits(imm, 7); 10617315Sgblack@eecs.umich.edu bool setMode = bits(imm, 8); 10627315Sgblack@eecs.umich.edu bool enable = bits(imm, 9); 10637315Sgblack@eecs.umich.edu CPSR cpsr = Cpsr; 10647400SAli.Saidi@ARM.com SCTLR sctlr = Sctlr; 10657315Sgblack@eecs.umich.edu if (cpsr.mode != MODE_USER) { 10667315Sgblack@eecs.umich.edu if (enable) { 10677315Sgblack@eecs.umich.edu if (f) cpsr.f = 0; 10687315Sgblack@eecs.umich.edu if (i) cpsr.i = 0; 10697315Sgblack@eecs.umich.edu if (a) cpsr.a = 0; 10707315Sgblack@eecs.umich.edu } else { 10717400SAli.Saidi@ARM.com if (f && !sctlr.nmfi) cpsr.f = 1; 10727315Sgblack@eecs.umich.edu if (i) cpsr.i = 1; 10737315Sgblack@eecs.umich.edu if (a) cpsr.a = 1; 10747315Sgblack@eecs.umich.edu } 10757315Sgblack@eecs.umich.edu if (setMode) { 10767315Sgblack@eecs.umich.edu cpsr.mode = mode; 10777315Sgblack@eecs.umich.edu } 10787315Sgblack@eecs.umich.edu } 10797315Sgblack@eecs.umich.edu Cpsr = cpsr; 10807315Sgblack@eecs.umich.edu ''' 10817315Sgblack@eecs.umich.edu cpsIop = InstObjParams("cps", "Cps", "ImmOp", 10827315Sgblack@eecs.umich.edu { "code": cpsCode, 10837599Sminkyu.jeong@arm.com "predicate_test": predicateTest }, 10847599Sminkyu.jeong@arm.com ["IsSerializeAfter","IsNonSpeculative"]) 10857315Sgblack@eecs.umich.edu header_output += ImmOpDeclare.subst(cpsIop) 10867315Sgblack@eecs.umich.edu decoder_output += ImmOpConstructor.subst(cpsIop) 10877315Sgblack@eecs.umich.edu exec_output += PredOpExecute.subst(cpsIop) 10887202Sgblack@eecs.umich.edu}}; 1089