data64.isa revision 11862
110037SARM gem5 Developers// -*- mode:c++ -*- 210037SARM gem5 Developers 311582SDylan.Johnson@ARM.com// Copyright (c) 2011-2013, 2016 ARM Limited 410037SARM gem5 Developers// All rights reserved 510037SARM gem5 Developers// 610037SARM gem5 Developers// The license below extends only to copyright in the software and shall 710037SARM gem5 Developers// not be construed as granting a license to any other intellectual 810037SARM gem5 Developers// property including but not limited to intellectual property relating 910037SARM gem5 Developers// to a hardware implementation of the functionality of the software 1010037SARM gem5 Developers// licensed hereunder. You may use the software subject to the license 1110037SARM gem5 Developers// terms below provided that you ensure that this notice is replicated 1210037SARM gem5 Developers// unmodified and in its entirety in all distributions of the software, 1310037SARM gem5 Developers// modified or unmodified, in source code or in binary form. 1410037SARM gem5 Developers// 1510037SARM gem5 Developers// Redistribution and use in source and binary forms, with or without 1610037SARM gem5 Developers// modification, are permitted provided that the following conditions are 1710037SARM gem5 Developers// met: redistributions of source code must retain the above copyright 1810037SARM gem5 Developers// notice, this list of conditions and the following disclaimer; 1910037SARM gem5 Developers// redistributions in binary form must reproduce the above copyright 2010037SARM gem5 Developers// notice, this list of conditions and the following disclaimer in the 2110037SARM gem5 Developers// documentation and/or other materials provided with the distribution; 2210037SARM gem5 Developers// neither the name of the copyright holders nor the names of its 2310037SARM gem5 Developers// contributors may be used to endorse or promote products derived from 2410037SARM gem5 Developers// this software without specific prior written permission. 2510037SARM gem5 Developers// 2610037SARM gem5 Developers// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2710037SARM gem5 Developers// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2810037SARM gem5 Developers// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2910037SARM gem5 Developers// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3010037SARM gem5 Developers// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3110037SARM gem5 Developers// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3210037SARM gem5 Developers// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3310037SARM gem5 Developers// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3410037SARM gem5 Developers// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3510037SARM gem5 Developers// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3610037SARM gem5 Developers// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3710037SARM gem5 Developers// 3810037SARM gem5 Developers// Authors: Gabe Black 3910037SARM gem5 Developers 4010037SARM gem5 Developerslet {{ 4110037SARM gem5 Developers 4210037SARM gem5 Developers header_output = "" 4310037SARM gem5 Developers decoder_output = "" 4410037SARM gem5 Developers exec_output = "" 4510037SARM gem5 Developers 4610037SARM gem5 Developers def createCcCode64(carry, overflow): 4710037SARM gem5 Developers code = "" 4810037SARM gem5 Developers code += ''' 4910037SARM gem5 Developers uint16_t _iz, _in; 5010037SARM gem5 Developers _in = bits(resTemp, intWidth - 1); 5110037SARM gem5 Developers _iz = ((resTemp & mask(intWidth)) == 0); 5210037SARM gem5 Developers CondCodesNZ = (_in << 1) | _iz; 5311862Snikos.nikoleris@arm.com DPRINTF(Arm, "(in, iz) = (%d, %d)\\n", _in, _iz); 5410037SARM gem5 Developers ''' 5510037SARM gem5 Developers if overflow and overflow != "none": 5610037SARM gem5 Developers code += ''' 5710037SARM gem5 Developers uint16_t _iv; 5810037SARM gem5 Developers _iv = %s & 1; 5910037SARM gem5 Developers CondCodesV = _iv; 6010037SARM gem5 Developers DPRINTF(Arm, "(iv) = (%%d)\\n", _iv); 6110037SARM gem5 Developers ''' % overflow 6210037SARM gem5 Developers if carry and carry != "none": 6310037SARM gem5 Developers code += ''' 6410037SARM gem5 Developers uint16_t _ic; 6510037SARM gem5 Developers _ic = %s & 1; 6610037SARM gem5 Developers CondCodesC = _ic; 6710037SARM gem5 Developers DPRINTF(Arm, "(ic) = (%%d)\\n", _ic); 6810037SARM gem5 Developers ''' % carry 6910037SARM gem5 Developers return code 7010037SARM gem5 Developers 7110037SARM gem5 Developers oldC = 'CondCodesC' 7210037SARM gem5 Developers oldV = 'CondCodesV' 7310037SARM gem5 Developers # Dicts of ways to set the carry flag. 7410037SARM gem5 Developers carryCode64 = { 7510037SARM gem5 Developers "none": "none", 7610037SARM gem5 Developers "add": 'findCarry(intWidth, resTemp, Op164, secOp)', 7710037SARM gem5 Developers "sub": 'findCarry(intWidth, resTemp, Op164, ~secOp)', 7810037SARM gem5 Developers "logic": '0' 7910037SARM gem5 Developers } 8010037SARM gem5 Developers # Dict of ways to set the overflow flag. 8110037SARM gem5 Developers overflowCode64 = { 8210037SARM gem5 Developers "none": "none", 8310037SARM gem5 Developers "add": 'findOverflow(intWidth, resTemp, Op164, secOp)', 8410037SARM gem5 Developers "sub": 'findOverflow(intWidth, resTemp, Op164, ~secOp)', 8510037SARM gem5 Developers "logic": '0' 8610037SARM gem5 Developers } 8710037SARM gem5 Developers 8810037SARM gem5 Developers immOp2 = "uint64_t secOp M5_VAR_USED = imm;" 8910037SARM gem5 Developers sRegOp2 = "uint64_t secOp M5_VAR_USED = " + \ 9010037SARM gem5 Developers "shiftReg64(Op264, shiftAmt, shiftType, intWidth);" 9110037SARM gem5 Developers eRegOp2 = "uint64_t secOp M5_VAR_USED = " + \ 9210037SARM gem5 Developers "extendReg64(Op264, extendType, shiftAmt, intWidth);" 9310037SARM gem5 Developers 9410037SARM gem5 Developers def buildDataWork(mnem, code, flagType, suffix, buildCc, buildNonCc, 9510037SARM gem5 Developers base, templateBase): 9610037SARM gem5 Developers code = ''' 9710037SARM gem5 Developers uint64_t resTemp M5_VAR_USED = 0; 9810037SARM gem5 Developers ''' + code 9910037SARM gem5 Developers ccCode = createCcCode64(carryCode64[flagType], overflowCode64[flagType]) 10010037SARM gem5 Developers Name = mnem.capitalize() + suffix 10110037SARM gem5 Developers iop = InstObjParams(mnem, Name, base, code) 10210037SARM gem5 Developers iopCc = InstObjParams(mnem + "s", Name + "Cc", base, code + ccCode) 10310037SARM gem5 Developers 10410037SARM gem5 Developers def subst(iop): 10510037SARM gem5 Developers global header_output, decoder_output, exec_output 10610037SARM gem5 Developers header_output += eval(templateBase + "Declare").subst(iop) 10710037SARM gem5 Developers decoder_output += eval(templateBase + "Constructor").subst(iop) 10810037SARM gem5 Developers exec_output += BasicExecute.subst(iop) 10910037SARM gem5 Developers 11010037SARM gem5 Developers if buildNonCc: 11110037SARM gem5 Developers subst(iop) 11210037SARM gem5 Developers if buildCc: 11310037SARM gem5 Developers subst(iopCc) 11410037SARM gem5 Developers 11510037SARM gem5 Developers def buildXImmDataInst(mnem, code, flagType = "logic", \ 11610037SARM gem5 Developers buildCc = True, buildNonCc = True, \ 11710037SARM gem5 Developers suffix = "XImm"): 11810037SARM gem5 Developers buildDataWork(mnem, immOp2 + code, flagType, suffix, 11910037SARM gem5 Developers buildCc, buildNonCc, "DataXImmOp", "DataXImm") 12010037SARM gem5 Developers 12110037SARM gem5 Developers def buildXSRegDataInst(mnem, code, flagType = "logic", \ 12210037SARM gem5 Developers buildCc = True, buildNonCc = True, \ 12310037SARM gem5 Developers suffix = "XSReg"): 12410037SARM gem5 Developers buildDataWork(mnem, sRegOp2 + code, flagType, suffix, 12510037SARM gem5 Developers buildCc, buildNonCc, "DataXSRegOp", "DataXSReg") 12610037SARM gem5 Developers 12710037SARM gem5 Developers def buildXERegDataInst(mnem, code, flagType = "logic", \ 12810037SARM gem5 Developers buildCc = True, buildNonCc = True, \ 12910037SARM gem5 Developers suffix = "XEReg"): 13010037SARM gem5 Developers buildDataWork(mnem, eRegOp2 + code, flagType, suffix, 13110037SARM gem5 Developers buildCc, buildNonCc, "DataXERegOp", "DataXEReg") 13210037SARM gem5 Developers 13310037SARM gem5 Developers def buildDataInst(mnem, code, flagType = "logic", 13410037SARM gem5 Developers buildCc = True, buildNonCc = True): 13510037SARM gem5 Developers buildXImmDataInst(mnem, code, flagType, buildCc, buildNonCc) 13610037SARM gem5 Developers buildXSRegDataInst(mnem, code, flagType, buildCc, buildNonCc) 13710037SARM gem5 Developers buildXERegDataInst(mnem, code, flagType, buildCc, buildNonCc) 13810037SARM gem5 Developers 13910037SARM gem5 Developers buildXImmDataInst("adr", "Dest64 = RawPC + imm", buildCc = False); 14010037SARM gem5 Developers buildXImmDataInst("adrp", "Dest64 = (RawPC & ~mask(12)) + imm", 14110037SARM gem5 Developers buildCc = False); 14210037SARM gem5 Developers buildDataInst("and", "Dest64 = resTemp = Op164 & secOp;") 14310037SARM gem5 Developers buildDataInst("eor", "Dest64 = Op164 ^ secOp;", buildCc = False) 14410037SARM gem5 Developers buildXSRegDataInst("eon", "Dest64 = Op164 ^ ~secOp;", buildCc = False) 14510037SARM gem5 Developers buildDataInst("sub", "Dest64 = resTemp = Op164 - secOp;", "sub") 14610037SARM gem5 Developers buildDataInst("add", "Dest64 = resTemp = Op164 + secOp;", "add") 14710037SARM gem5 Developers buildXSRegDataInst("adc", 14810037SARM gem5 Developers "Dest64 = resTemp = Op164 + secOp + %s;" % oldC, "add") 14910037SARM gem5 Developers buildXSRegDataInst("sbc", 15010037SARM gem5 Developers "Dest64 = resTemp = Op164 - secOp - !%s;" % oldC, "sub") 15110037SARM gem5 Developers buildDataInst("orr", "Dest64 = Op164 | secOp;", buildCc = False) 15210037SARM gem5 Developers buildXSRegDataInst("orn", "Dest64 = Op164 | ~secOp;", buildCc = False) 15310037SARM gem5 Developers buildXSRegDataInst("bic", "Dest64 = resTemp = Op164 & ~secOp;") 15410037SARM gem5 Developers 15510037SARM gem5 Developers def buildDataXImmInst(mnem, code, optArgs = []): 15610037SARM gem5 Developers global header_output, decoder_output, exec_output 15710037SARM gem5 Developers classNamePrefix = mnem[0].upper() + mnem[1:] 15810037SARM gem5 Developers templateBase = "DataXImm" 15910037SARM gem5 Developers iop = InstObjParams(mnem, classNamePrefix + "64", 16010037SARM gem5 Developers templateBase + "Op", code, optArgs) 16110037SARM gem5 Developers header_output += eval(templateBase + "Declare").subst(iop) 16210037SARM gem5 Developers decoder_output += eval(templateBase + "Constructor").subst(iop) 16310037SARM gem5 Developers exec_output += BasicExecute.subst(iop) 16410037SARM gem5 Developers 16510037SARM gem5 Developers def buildDataXRegInst(mnem, regOps, code, optArgs = [], 16610037SARM gem5 Developers overrideOpClass=None): 16710037SARM gem5 Developers global header_output, decoder_output, exec_output 16810037SARM gem5 Developers templateBase = "DataX%dReg" % regOps 16910037SARM gem5 Developers classNamePrefix = mnem[0].upper() + mnem[1:] 17010037SARM gem5 Developers if overrideOpClass: 17110037SARM gem5 Developers iop = InstObjParams(mnem, classNamePrefix + "64", 17210037SARM gem5 Developers templateBase + "Op", 17310037SARM gem5 Developers { 'code': code, 'op_class': overrideOpClass}, 17410037SARM gem5 Developers optArgs) 17510037SARM gem5 Developers else: 17610037SARM gem5 Developers iop = InstObjParams(mnem, classNamePrefix + "64", 17710037SARM gem5 Developers templateBase + "Op", code, optArgs) 17810037SARM gem5 Developers header_output += eval(templateBase + "Declare").subst(iop) 17910037SARM gem5 Developers decoder_output += eval(templateBase + "Constructor").subst(iop) 18010037SARM gem5 Developers exec_output += BasicExecute.subst(iop) 18110037SARM gem5 Developers 18210037SARM gem5 Developers buildDataXRegInst("madd", 3, "Dest64 = Op164 + Op264 * Op364", 18310037SARM gem5 Developers overrideOpClass="IntMultOp") 18410037SARM gem5 Developers buildDataXRegInst("msub", 3, "Dest64 = Op164 - Op264 * Op364", 18510037SARM gem5 Developers overrideOpClass="IntMultOp") 18610037SARM gem5 Developers buildDataXRegInst("smaddl", 3, 18710037SARM gem5 Developers "XDest = XOp1 + sext<32>(WOp2) * sext<32>(WOp3)", 18810037SARM gem5 Developers overrideOpClass="IntMultOp") 18910037SARM gem5 Developers buildDataXRegInst("smsubl", 3, 19010037SARM gem5 Developers "XDest = XOp1 - sext<32>(WOp2) * sext<32>(WOp3)", 19110037SARM gem5 Developers overrideOpClass="IntMultOp") 19210037SARM gem5 Developers buildDataXRegInst("smulh", 2, ''' 19310037SARM gem5 Developers uint64_t op1H = (int32_t)(XOp1 >> 32); 19410037SARM gem5 Developers uint64_t op1L = (uint32_t)XOp1; 19510037SARM gem5 Developers uint64_t op2H = (int32_t)(XOp2 >> 32); 19610037SARM gem5 Developers uint64_t op2L = (uint32_t)XOp2; 19710037SARM gem5 Developers uint64_t mid1 = ((op1L * op2L) >> 32) + op1H * op2L; 19810037SARM gem5 Developers uint64_t mid2 = op1L * op2H; 19910037SARM gem5 Developers uint64_t result = ((uint64_t)(uint32_t)mid1 + (uint32_t)mid2) >> 32; 20010037SARM gem5 Developers result += shiftReg64(mid1, 32, ASR, intWidth); 20110037SARM gem5 Developers result += shiftReg64(mid2, 32, ASR, intWidth); 20210037SARM gem5 Developers XDest = result + op1H * op2H; 20310037SARM gem5 Developers ''', overrideOpClass="IntMultOp") 20410037SARM gem5 Developers buildDataXRegInst("umaddl", 3, "XDest = XOp1 + WOp2 * WOp3", 20510037SARM gem5 Developers overrideOpClass="IntMultOp") 20610037SARM gem5 Developers buildDataXRegInst("umsubl", 3, "XDest = XOp1 - WOp2 * WOp3", 20710037SARM gem5 Developers overrideOpClass="IntMultOp") 20810037SARM gem5 Developers buildDataXRegInst("umulh", 2, ''' 20910037SARM gem5 Developers uint64_t op1H = (uint32_t)(XOp1 >> 32); 21010037SARM gem5 Developers uint64_t op1L = (uint32_t)XOp1; 21110037SARM gem5 Developers uint64_t op2H = (uint32_t)(XOp2 >> 32); 21210037SARM gem5 Developers uint64_t op2L = (uint32_t)XOp2; 21310037SARM gem5 Developers uint64_t mid1 = ((op1L * op2L) >> 32) + op1H * op2L; 21410037SARM gem5 Developers uint64_t mid2 = op1L * op2H; 21510037SARM gem5 Developers uint64_t result = ((uint64_t)(uint32_t)mid1 + (uint32_t)mid2) >> 32; 21610037SARM gem5 Developers result += mid1 >> 32; 21710037SARM gem5 Developers result += mid2 >> 32; 21810037SARM gem5 Developers XDest = result + op1H * op2H; 21910037SARM gem5 Developers ''', overrideOpClass="IntMultOp") 22010037SARM gem5 Developers 22110037SARM gem5 Developers buildDataXRegInst("asrv", 2, 22210037SARM gem5 Developers "Dest64 = shiftReg64(Op164, Op264, ASR, intWidth)") 22310037SARM gem5 Developers buildDataXRegInst("lslv", 2, 22410037SARM gem5 Developers "Dest64 = shiftReg64(Op164, Op264, LSL, intWidth)") 22510037SARM gem5 Developers buildDataXRegInst("lsrv", 2, 22610037SARM gem5 Developers "Dest64 = shiftReg64(Op164, Op264, LSR, intWidth)") 22710037SARM gem5 Developers buildDataXRegInst("rorv", 2, 22810037SARM gem5 Developers "Dest64 = shiftReg64(Op164, Op264, ROR, intWidth)") 22910037SARM gem5 Developers buildDataXRegInst("sdiv", 2, ''' 23010037SARM gem5 Developers int64_t op1 = Op164; 23110037SARM gem5 Developers int64_t op2 = Op264; 23210037SARM gem5 Developers if (intWidth == 32) { 23310037SARM gem5 Developers op1 = sext<32>(op1); 23410037SARM gem5 Developers op2 = sext<32>(op2); 23510037SARM gem5 Developers } 23610037SARM gem5 Developers Dest64 = op2 == -1 ? -op1 : op2 ? op1 / op2 : 0; 23710037SARM gem5 Developers ''', overrideOpClass="IntDivOp") 23810037SARM gem5 Developers buildDataXRegInst("udiv", 2, "Dest64 = Op264 ? Op164 / Op264 : 0", 23910037SARM gem5 Developers overrideOpClass="IntDivOp") 24010037SARM gem5 Developers 24110037SARM gem5 Developers buildDataXRegInst("cls", 1, ''' 24210037SARM gem5 Developers uint64_t op1 = Op164; 24310037SARM gem5 Developers if (bits(op1, intWidth - 1)) 24410037SARM gem5 Developers op1 ^= mask(intWidth); 24510037SARM gem5 Developers Dest64 = (op1 == 0) ? intWidth - 1 : (intWidth - 2 - findMsbSet(op1)); 24610037SARM gem5 Developers ''') 24710037SARM gem5 Developers buildDataXRegInst("clz", 1, ''' 24810037SARM gem5 Developers Dest64 = (Op164 == 0) ? intWidth : (intWidth - 1 - findMsbSet(Op164)); 24910037SARM gem5 Developers ''') 25010037SARM gem5 Developers buildDataXRegInst("rbit", 1, ''' 25110037SARM gem5 Developers uint64_t result = Op164; 25210037SARM gem5 Developers uint64_t lBit = 1ULL << (intWidth - 1); 25310037SARM gem5 Developers uint64_t rBit = 1ULL; 25410037SARM gem5 Developers while (lBit > rBit) { 25510037SARM gem5 Developers uint64_t maskBits = lBit | rBit; 25610037SARM gem5 Developers uint64_t testBits = result & maskBits; 25710037SARM gem5 Developers // If these bits are different, swap them by toggling them. 25810037SARM gem5 Developers if (testBits && testBits != maskBits) 25910037SARM gem5 Developers result ^= maskBits; 26010037SARM gem5 Developers lBit >>= 1; rBit <<= 1; 26110037SARM gem5 Developers } 26210037SARM gem5 Developers Dest64 = result; 26310037SARM gem5 Developers ''') 26410037SARM gem5 Developers buildDataXRegInst("rev", 1, ''' 26510037SARM gem5 Developers if (intWidth == 32) 26610037SARM gem5 Developers Dest64 = betole<uint32_t>(Op164); 26710037SARM gem5 Developers else 26810037SARM gem5 Developers Dest64 = betole<uint64_t>(Op164); 26910037SARM gem5 Developers ''') 27010037SARM gem5 Developers buildDataXRegInst("rev16", 1, ''' 27110037SARM gem5 Developers int count = intWidth / 16; 27210037SARM gem5 Developers uint64_t result = 0; 27310037SARM gem5 Developers for (unsigned i = 0; i < count; i++) { 27410037SARM gem5 Developers uint16_t hw = Op164 >> (i * 16); 27510037SARM gem5 Developers result |= (uint64_t)betole<uint16_t>(hw) << (i * 16); 27610037SARM gem5 Developers } 27710037SARM gem5 Developers Dest64 = result; 27810037SARM gem5 Developers ''') 27910037SARM gem5 Developers buildDataXRegInst("rev32", 1, ''' 28010037SARM gem5 Developers int count = intWidth / 32; 28110037SARM gem5 Developers uint64_t result = 0; 28210037SARM gem5 Developers for (unsigned i = 0; i < count; i++) { 28310037SARM gem5 Developers uint32_t hw = Op164 >> (i * 32); 28410037SARM gem5 Developers result |= (uint64_t)betole<uint32_t>(hw) << (i * 32); 28510037SARM gem5 Developers } 28610037SARM gem5 Developers Dest64 = result; 28710037SARM gem5 Developers ''') 28810037SARM gem5 Developers 28910037SARM gem5 Developers msrMrs64EnabledCheckCode = ''' 29010037SARM gem5 Developers // Check for read/write access right 29110037SARM gem5 Developers if (!can%sAArch64SysReg(flat_idx, Scr64, cpsr, xc->tcBase())) { 29210037SARM gem5 Developers if (flat_idx == MISCREG_DAIF || 29310037SARM gem5 Developers flat_idx == MISCREG_DC_ZVA_Xt || 29410037SARM gem5 Developers flat_idx == MISCREG_DC_CVAC_Xt || 29510037SARM gem5 Developers flat_idx == MISCREG_DC_CIVAC_Xt 29610037SARM gem5 Developers ) 29710474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>( 29810474Sandreas.hansson@arm.com machInst, 0, EC_TRAPPED_MSR_MRS_64, 29910205SAli.Saidi@ARM.com mnemonic); 30010474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 30110474Sandreas.hansson@arm.com mnemonic); 30210037SARM gem5 Developers } 30310037SARM gem5 Developers 30410037SARM gem5 Developers // Check for traps to supervisor (FP/SIMD regs) 30510037SARM gem5 Developers if (el <= EL1 && msrMrs64TrapToSup(flat_idx, el, Cpacr64)) 30610474Sandreas.hansson@arm.com return std::make_shared<SupervisorTrap>(machInst, 0x1E00000, 30710474Sandreas.hansson@arm.com EC_TRAPPED_SIMD_FP); 30810037SARM gem5 Developers 30910037SARM gem5 Developers bool is_vfp_neon = false; 31010037SARM gem5 Developers 31110037SARM gem5 Developers // Check for traps to hypervisor 31210037SARM gem5 Developers if ((ArmSystem::haveVirtualization(xc->tcBase()) && el <= EL2) && 31311582SDylan.Johnson@ARM.com msrMrs64TrapToHyp(flat_idx, el, %s, CptrEl264, Hcr64, &is_vfp_neon)) { 31410474Sandreas.hansson@arm.com return std::make_shared<HypervisorTrap>( 31510474Sandreas.hansson@arm.com machInst, is_vfp_neon ? 0x1E00000 : imm, 31610037SARM gem5 Developers is_vfp_neon ? EC_TRAPPED_SIMD_FP : EC_TRAPPED_MSR_MRS_64); 31710037SARM gem5 Developers } 31810037SARM gem5 Developers 31910037SARM gem5 Developers // Check for traps to secure monitor 32010037SARM gem5 Developers if ((ArmSystem::haveSecurity(xc->tcBase()) && el <= EL3) && 32110037SARM gem5 Developers msrMrs64TrapToMon(flat_idx, CptrEl364, el, &is_vfp_neon)) { 32210474Sandreas.hansson@arm.com return std::make_shared<SecureMonitorTrap>( 32310474Sandreas.hansson@arm.com machInst, 32410037SARM gem5 Developers is_vfp_neon ? 0x1E00000 : imm, 32510037SARM gem5 Developers is_vfp_neon ? EC_TRAPPED_SIMD_FP : EC_TRAPPED_MSR_MRS_64); 32610037SARM gem5 Developers } 32710037SARM gem5 Developers ''' 32810037SARM gem5 Developers 32910037SARM gem5 Developers buildDataXImmInst("mrs", ''' 33010037SARM gem5 Developers MiscRegIndex flat_idx = (MiscRegIndex) xc->tcBase()-> 33110037SARM gem5 Developers flattenMiscIndex(op1); 33210037SARM gem5 Developers CPSR cpsr = Cpsr; 33310037SARM gem5 Developers ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsr.el; 33410037SARM gem5 Developers %s 33510037SARM gem5 Developers XDest = MiscOp1_ud; 33610037SARM gem5 Developers ''' % (msrMrs64EnabledCheckCode % ('Read', 'true'),), 33710037SARM gem5 Developers ["IsSerializeBefore"]) 33810037SARM gem5 Developers 33910037SARM gem5 Developers buildDataXRegInst("mrsNZCV", 1, ''' 34010037SARM gem5 Developers CPSR cpsr = 0; 34110037SARM gem5 Developers cpsr.nz = CondCodesNZ; 34210037SARM gem5 Developers cpsr.c = CondCodesC; 34310037SARM gem5 Developers cpsr.v = CondCodesV; 34410037SARM gem5 Developers XDest = cpsr; 34510037SARM gem5 Developers ''') 34610037SARM gem5 Developers 34710037SARM gem5 Developers buildDataXImmInst("msr", ''' 34810037SARM gem5 Developers MiscRegIndex flat_idx = (MiscRegIndex) xc->tcBase()-> 34910037SARM gem5 Developers flattenMiscIndex(dest); 35010037SARM gem5 Developers CPSR cpsr = Cpsr; 35110037SARM gem5 Developers ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsr.el; 35210037SARM gem5 Developers %s 35310037SARM gem5 Developers MiscDest_ud = XOp1; 35410037SARM gem5 Developers ''' % (msrMrs64EnabledCheckCode % ('Write', 'false'),), 35510037SARM gem5 Developers ["IsSerializeAfter", "IsNonSpeculative"]) 35610037SARM gem5 Developers 35710037SARM gem5 Developers buildDataXRegInst("msrNZCV", 1, ''' 35810037SARM gem5 Developers CPSR cpsr = XOp1; 35910037SARM gem5 Developers CondCodesNZ = cpsr.nz; 36010037SARM gem5 Developers CondCodesC = cpsr.c; 36110037SARM gem5 Developers CondCodesV = cpsr.v; 36210037SARM gem5 Developers ''') 36310037SARM gem5 Developers 36410037SARM gem5 Developers msrdczva_ea_code = ''' 36510037SARM gem5 Developers MiscRegIndex flat_idx = (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest); 36610037SARM gem5 Developers CPSR cpsr = Cpsr; 36710037SARM gem5 Developers ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsr.el; 36810037SARM gem5 Developers ''' 36910037SARM gem5 Developers 37010037SARM gem5 Developers msrdczva_ea_code += msrMrs64EnabledCheckCode % ('Write', 'false') 37110037SARM gem5 Developers msrdczva_ea_code += ''' 37210037SARM gem5 Developers Request::Flags memAccessFlags = Request::CACHE_BLOCK_ZERO|ArmISA::TLB::MustBeOne; 37310037SARM gem5 Developers EA = XBase; 37410037SARM gem5 Developers assert(!(Dczid & 0x10)); 37510037SARM gem5 Developers uint64_t op_size = power(2, Dczid + 2); 37610037SARM gem5 Developers EA &= ~(op_size - 1); 37710037SARM gem5 Developers 37810037SARM gem5 Developers ''' 37910037SARM gem5 Developers 38010037SARM gem5 Developers msrDCZVAIop = InstObjParams("dczva", "Dczva", "SysDC64", 38110037SARM gem5 Developers { "ea_code" : msrdczva_ea_code, 38210037SARM gem5 Developers "memacc_code" : ";", "use_uops" : 0, 38310037SARM gem5 Developers "op_wb" : ";", "fa_code" : ";"}, ['IsStore', 'IsMemRef']); 38410037SARM gem5 Developers header_output += DCStore64Declare.subst(msrDCZVAIop); 38510037SARM gem5 Developers decoder_output += DCStore64Constructor.subst(msrDCZVAIop); 38610037SARM gem5 Developers exec_output += DCStore64Execute.subst(msrDCZVAIop); 38710037SARM gem5 Developers exec_output += DCStore64InitiateAcc.subst(msrDCZVAIop); 38810037SARM gem5 Developers exec_output += Store64CompleteAcc.subst(msrDCZVAIop); 38910037SARM gem5 Developers 39010037SARM gem5 Developers 39110037SARM gem5 Developers 39210037SARM gem5 Developers buildDataXImmInst("msrSP", ''' 39310037SARM gem5 Developers if (!canWriteAArch64SysReg( 39410037SARM gem5 Developers (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest), 39510037SARM gem5 Developers Scr64, Cpsr, xc->tcBase())) { 39610474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>(machInst, false, 39710474Sandreas.hansson@arm.com mnemonic); 39810037SARM gem5 Developers } 39910037SARM gem5 Developers MiscDest_ud = imm; 40010037SARM gem5 Developers ''', optArgs = ["IsSerializeAfter", "IsNonSpeculative"]) 40110037SARM gem5 Developers 40210037SARM gem5 Developers buildDataXImmInst("msrDAIFSet", ''' 40310037SARM gem5 Developers if (!canWriteAArch64SysReg( 40410037SARM gem5 Developers (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest), 40510037SARM gem5 Developers Scr64, Cpsr, xc->tcBase())) { 40610474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>( 40710474Sandreas.hansson@arm.com machInst, 0, EC_TRAPPED_MSR_MRS_64, 40810205SAli.Saidi@ARM.com mnemonic); 40910037SARM gem5 Developers } 41010037SARM gem5 Developers CPSR cpsr = Cpsr; 41110037SARM gem5 Developers cpsr.daif = cpsr.daif | imm; 41210037SARM gem5 Developers Cpsr = cpsr; 41310037SARM gem5 Developers ''', optArgs = ["IsSerializeAfter", "IsNonSpeculative"]) 41410037SARM gem5 Developers 41510037SARM gem5 Developers buildDataXImmInst("msrDAIFClr", ''' 41610037SARM gem5 Developers if (!canWriteAArch64SysReg( 41710037SARM gem5 Developers (MiscRegIndex) xc->tcBase()->flattenMiscIndex(dest), 41810037SARM gem5 Developers Scr64, Cpsr, xc->tcBase())) { 41910474Sandreas.hansson@arm.com return std::make_shared<UndefinedInstruction>( 42010474Sandreas.hansson@arm.com machInst, 0, EC_TRAPPED_MSR_MRS_64, 42110205SAli.Saidi@ARM.com mnemonic); 42210037SARM gem5 Developers } 42310037SARM gem5 Developers CPSR cpsr = Cpsr; 42410037SARM gem5 Developers cpsr.daif = cpsr.daif & ~imm; 42510037SARM gem5 Developers Cpsr = cpsr; 42610037SARM gem5 Developers ''', optArgs = ["IsSerializeAfter", "IsNonSpeculative"]) 42710037SARM gem5 Developers 42810037SARM gem5 Developers def buildDataXCompInst(mnem, instType, suffix, code): 42910037SARM gem5 Developers global header_output, decoder_output, exec_output 43010037SARM gem5 Developers templateBase = "DataXCond%s" % instType 43110037SARM gem5 Developers iop = InstObjParams(mnem, mnem.capitalize() + suffix + "64", 43210037SARM gem5 Developers templateBase + "Op", code) 43310037SARM gem5 Developers header_output += eval(templateBase + "Declare").subst(iop) 43410037SARM gem5 Developers decoder_output += eval(templateBase + "Constructor").subst(iop) 43510037SARM gem5 Developers exec_output += BasicExecute.subst(iop) 43610037SARM gem5 Developers 43710037SARM gem5 Developers def buildDataXCondImmInst(mnem, code): 43810037SARM gem5 Developers buildDataXCompInst(mnem, "CompImm", "Imm", code) 43910037SARM gem5 Developers def buildDataXCondRegInst(mnem, code): 44010037SARM gem5 Developers buildDataXCompInst(mnem, "CompReg", "Reg", code) 44110037SARM gem5 Developers def buildDataXCondSelInst(mnem, code): 44210037SARM gem5 Developers buildDataXCompInst(mnem, "Sel", "", code) 44310037SARM gem5 Developers 44410037SARM gem5 Developers def condCompCode(flagType, op, imm): 44510037SARM gem5 Developers ccCode = createCcCode64(carryCode64[flagType], overflowCode64[flagType]) 44610037SARM gem5 Developers opDecl = "uint64_t secOp M5_VAR_USED = imm;" 44710037SARM gem5 Developers if not imm: 44810037SARM gem5 Developers opDecl = "uint64_t secOp M5_VAR_USED = Op264;" 44910037SARM gem5 Developers return opDecl + ''' 45010037SARM gem5 Developers if (testPredicate(CondCodesNZ, CondCodesC, CondCodesV, condCode)) { 45110037SARM gem5 Developers uint64_t resTemp = Op164 ''' + op + ''' secOp; 45210037SARM gem5 Developers ''' + ccCode + ''' 45310037SARM gem5 Developers } else { 45410037SARM gem5 Developers CondCodesNZ = (defCc >> 2) & 0x3; 45510037SARM gem5 Developers CondCodesC = (defCc >> 1) & 0x1; 45610037SARM gem5 Developers CondCodesV = defCc & 0x1; 45710037SARM gem5 Developers } 45810037SARM gem5 Developers ''' 45910037SARM gem5 Developers 46010037SARM gem5 Developers buildDataXCondImmInst("ccmn", condCompCode("add", "+", True)) 46110037SARM gem5 Developers buildDataXCondImmInst("ccmp", condCompCode("sub", "-", True)) 46210037SARM gem5 Developers buildDataXCondRegInst("ccmn", condCompCode("add", "+", False)) 46310037SARM gem5 Developers buildDataXCondRegInst("ccmp", condCompCode("sub", "-", False)) 46410037SARM gem5 Developers 46510037SARM gem5 Developers condSelCode = ''' 46610037SARM gem5 Developers if (testPredicate(CondCodesNZ, CondCodesC, CondCodesV, condCode)) { 46710037SARM gem5 Developers Dest64 = Op164; 46810037SARM gem5 Developers } else { 46910037SARM gem5 Developers Dest64 = %(altVal)s; 47010037SARM gem5 Developers } 47110037SARM gem5 Developers ''' 47210037SARM gem5 Developers buildDataXCondSelInst("csel", condSelCode % {"altVal" : "Op264"}) 47310037SARM gem5 Developers buildDataXCondSelInst("csinc", condSelCode % {"altVal" : "Op264 + 1"}) 47410037SARM gem5 Developers buildDataXCondSelInst("csinv", condSelCode % {"altVal" : "~Op264"}) 47510037SARM gem5 Developers buildDataXCondSelInst("csneg", condSelCode % {"altVal" : "-Op264"}) 47610037SARM gem5 Developers}}; 477