misc.isa revision 8782
17199Sgblack@eecs.umich.edu// -*- mode:c++ -*-
27199Sgblack@eecs.umich.edu
37199Sgblack@eecs.umich.edu// Copyright (c) 2010 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 = '''
438782Sgblack@eecs.umich.edu    if (FullSystem) {
448782Sgblack@eecs.umich.edu        fault = new SupervisorCall;
458782Sgblack@eecs.umich.edu    } else {
468782Sgblack@eecs.umich.edu        fault = new SupervisorCall(machInst);
478782Sgblack@eecs.umich.edu    }
487199Sgblack@eecs.umich.edu    '''
497199Sgblack@eecs.umich.edu
507199Sgblack@eecs.umich.edu    svcIop = InstObjParams("svc", "Svc", "PredOp",
517199Sgblack@eecs.umich.edu                           { "code": svcCode,
527199Sgblack@eecs.umich.edu                             "predicate_test": predicateTest }, ["IsSyscall"])
537199Sgblack@eecs.umich.edu    header_output = BasicDeclare.subst(svcIop)
547199Sgblack@eecs.umich.edu    decoder_output = BasicConstructor.subst(svcIop)
557199Sgblack@eecs.umich.edu    exec_output = PredOpExecute.subst(svcIop)
567199Sgblack@eecs.umich.edu
577199Sgblack@eecs.umich.edu}};
587202Sgblack@eecs.umich.edu
597202Sgblack@eecs.umich.edulet {{
607202Sgblack@eecs.umich.edu
617202Sgblack@eecs.umich.edu    header_output = decoder_output = exec_output = ""
627202Sgblack@eecs.umich.edu
638301SAli.Saidi@ARM.com    mrsCpsrCode = '''
648303SAli.Saidi@ARM.com        CPSR cpsr = Cpsr;
658303SAli.Saidi@ARM.com        cpsr.nz = CondCodesNZ;
668303SAli.Saidi@ARM.com        cpsr.c = CondCodesC;
678303SAli.Saidi@ARM.com        cpsr.v = CondCodesV;
688303SAli.Saidi@ARM.com        cpsr.ge = CondCodesGE;
698303SAli.Saidi@ARM.com        Dest = cpsr & 0xF8FF03DF
708301SAli.Saidi@ARM.com    '''
718301SAli.Saidi@ARM.com
727202Sgblack@eecs.umich.edu    mrsCpsrIop = InstObjParams("mrs", "MrsCpsr", "MrsOp",
737202Sgblack@eecs.umich.edu                               { "code": mrsCpsrCode,
747599Sminkyu.jeong@arm.com                                 "predicate_test": condPredicateTest },
757783SGiacomo.Gabrielli@arm.com                               ["IsSerializeBefore"])
767202Sgblack@eecs.umich.edu    header_output += MrsDeclare.subst(mrsCpsrIop)
777202Sgblack@eecs.umich.edu    decoder_output += MrsConstructor.subst(mrsCpsrIop)
787202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mrsCpsrIop)
797202Sgblack@eecs.umich.edu
807202Sgblack@eecs.umich.edu    mrsSpsrCode = "Dest = Spsr"
817202Sgblack@eecs.umich.edu    mrsSpsrIop = InstObjParams("mrs", "MrsSpsr", "MrsOp",
827202Sgblack@eecs.umich.edu                               { "code": mrsSpsrCode,
837599Sminkyu.jeong@arm.com                                 "predicate_test": predicateTest },
847783SGiacomo.Gabrielli@arm.com                               ["IsSerializeBefore"])
857202Sgblack@eecs.umich.edu    header_output += MrsDeclare.subst(mrsSpsrIop)
867202Sgblack@eecs.umich.edu    decoder_output += MrsConstructor.subst(mrsSpsrIop)
877202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mrsSpsrIop)
887202Sgblack@eecs.umich.edu
897202Sgblack@eecs.umich.edu    msrCpsrRegCode = '''
907400SAli.Saidi@ARM.com        SCTLR sctlr = Sctlr;
918303SAli.Saidi@ARM.com        CPSR old_cpsr = Cpsr;
928303SAli.Saidi@ARM.com        old_cpsr.nz = CondCodesNZ;
938303SAli.Saidi@ARM.com        old_cpsr.c = CondCodesC;
948303SAli.Saidi@ARM.com        old_cpsr.v = CondCodesV;
958303SAli.Saidi@ARM.com        old_cpsr.ge = CondCodesGE;
968303SAli.Saidi@ARM.com
978303SAli.Saidi@ARM.com        CPSR new_cpsr =
988303SAli.Saidi@ARM.com            cpsrWriteByInstr(old_cpsr, Op1, byteMask, false, sctlr.nmfi);
998303SAli.Saidi@ARM.com        Cpsr = ~CondCodesMask & new_cpsr;
1008303SAli.Saidi@ARM.com        CondCodesNZ = new_cpsr.nz;
1018303SAli.Saidi@ARM.com        CondCodesC = new_cpsr.c;
1028303SAli.Saidi@ARM.com        CondCodesV = new_cpsr.v;
1038303SAli.Saidi@ARM.com        CondCodesGE = new_cpsr.ge;
1047202Sgblack@eecs.umich.edu    '''
1057202Sgblack@eecs.umich.edu    msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp",
1067202Sgblack@eecs.umich.edu                                  { "code": msrCpsrRegCode,
1077599Sminkyu.jeong@arm.com                                    "predicate_test": condPredicateTest },
1087599Sminkyu.jeong@arm.com                                  ["IsSerializeAfter","IsNonSpeculative"])
1097202Sgblack@eecs.umich.edu    header_output += MsrRegDeclare.subst(msrCpsrRegIop)
1107202Sgblack@eecs.umich.edu    decoder_output += MsrRegConstructor.subst(msrCpsrRegIop)
1117202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(msrCpsrRegIop)
1127202Sgblack@eecs.umich.edu
1137202Sgblack@eecs.umich.edu    msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);"
1147202Sgblack@eecs.umich.edu    msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp",
1157202Sgblack@eecs.umich.edu                                  { "code": msrSpsrRegCode,
1167599Sminkyu.jeong@arm.com                                    "predicate_test": predicateTest },
1177599Sminkyu.jeong@arm.com                                  ["IsSerializeAfter","IsNonSpeculative"])
1187202Sgblack@eecs.umich.edu    header_output += MsrRegDeclare.subst(msrSpsrRegIop)
1197202Sgblack@eecs.umich.edu    decoder_output += MsrRegConstructor.subst(msrSpsrRegIop)
1207202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(msrSpsrRegIop)
1217202Sgblack@eecs.umich.edu
1227202Sgblack@eecs.umich.edu    msrCpsrImmCode = '''
1237400SAli.Saidi@ARM.com        SCTLR sctlr = Sctlr;
1248303SAli.Saidi@ARM.com        CPSR old_cpsr = Cpsr;
1258303SAli.Saidi@ARM.com        old_cpsr.nz = CondCodesNZ;
1268303SAli.Saidi@ARM.com        old_cpsr.c = CondCodesC;
1278303SAli.Saidi@ARM.com        old_cpsr.v = CondCodesV;
1288303SAli.Saidi@ARM.com        old_cpsr.ge = CondCodesGE;
1298303SAli.Saidi@ARM.com        CPSR new_cpsr =
1308303SAli.Saidi@ARM.com            cpsrWriteByInstr(old_cpsr, imm, byteMask, false, sctlr.nmfi);
1318303SAli.Saidi@ARM.com        Cpsr = ~CondCodesMask & new_cpsr;
1328303SAli.Saidi@ARM.com        CondCodesNZ = new_cpsr.nz;
1338303SAli.Saidi@ARM.com        CondCodesC = new_cpsr.c;
1348303SAli.Saidi@ARM.com        CondCodesV = new_cpsr.v;
1358303SAli.Saidi@ARM.com        CondCodesGE = new_cpsr.ge;
1367202Sgblack@eecs.umich.edu    '''
1377202Sgblack@eecs.umich.edu    msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp",
1387202Sgblack@eecs.umich.edu                                  { "code": msrCpsrImmCode,
1397599Sminkyu.jeong@arm.com                                    "predicate_test": condPredicateTest },
1407599Sminkyu.jeong@arm.com                                  ["IsSerializeAfter","IsNonSpeculative"])
1417202Sgblack@eecs.umich.edu    header_output += MsrImmDeclare.subst(msrCpsrImmIop)
1427202Sgblack@eecs.umich.edu    decoder_output += MsrImmConstructor.subst(msrCpsrImmIop)
1437202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(msrCpsrImmIop)
1447202Sgblack@eecs.umich.edu
1457202Sgblack@eecs.umich.edu    msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);"
1467202Sgblack@eecs.umich.edu    msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp",
1477202Sgblack@eecs.umich.edu                                  { "code": msrSpsrImmCode,
1487599Sminkyu.jeong@arm.com                                    "predicate_test": predicateTest },
1497599Sminkyu.jeong@arm.com                                  ["IsSerializeAfter","IsNonSpeculative"])
1507202Sgblack@eecs.umich.edu    header_output += MsrImmDeclare.subst(msrSpsrImmIop)
1517202Sgblack@eecs.umich.edu    decoder_output += MsrImmConstructor.subst(msrSpsrImmIop)
1527202Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(msrSpsrImmIop)
1537209Sgblack@eecs.umich.edu
1547209Sgblack@eecs.umich.edu    revCode = '''
1557209Sgblack@eecs.umich.edu    uint32_t val = Op1;
1567209Sgblack@eecs.umich.edu    Dest = swap_byte(val);
1577209Sgblack@eecs.umich.edu    '''
1587261Sgblack@eecs.umich.edu    revIop = InstObjParams("rev", "Rev", "RegRegOp",
1597209Sgblack@eecs.umich.edu                           { "code": revCode,
1607209Sgblack@eecs.umich.edu                             "predicate_test": predicateTest }, [])
1617261Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(revIop)
1627261Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(revIop)
1637209Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(revIop)
1647209Sgblack@eecs.umich.edu
1657209Sgblack@eecs.umich.edu    rev16Code = '''
1667209Sgblack@eecs.umich.edu    uint32_t val = Op1;
1677209Sgblack@eecs.umich.edu    Dest = (bits(val, 15, 8) << 0) |
1687209Sgblack@eecs.umich.edu           (bits(val, 7, 0) << 8) |
1697209Sgblack@eecs.umich.edu           (bits(val, 31, 24) << 16) |
1707209Sgblack@eecs.umich.edu           (bits(val, 23, 16) << 24);
1717209Sgblack@eecs.umich.edu    '''
1727261Sgblack@eecs.umich.edu    rev16Iop = InstObjParams("rev16", "Rev16", "RegRegOp",
1737209Sgblack@eecs.umich.edu                             { "code": rev16Code,
1747209Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
1757261Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(rev16Iop)
1767261Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(rev16Iop)
1777209Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(rev16Iop)
1787209Sgblack@eecs.umich.edu
1797209Sgblack@eecs.umich.edu    revshCode = '''
1807209Sgblack@eecs.umich.edu    uint16_t val = Op1;
1817209Sgblack@eecs.umich.edu    Dest = sext<16>(swap_byte(val));
1827209Sgblack@eecs.umich.edu    '''
1837261Sgblack@eecs.umich.edu    revshIop = InstObjParams("revsh", "Revsh", "RegRegOp",
1847209Sgblack@eecs.umich.edu                             { "code": revshCode,
1857209Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
1867261Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(revshIop)
1877261Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(revshIop)
1887209Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(revshIop)
1897226Sgblack@eecs.umich.edu
1907249Sgblack@eecs.umich.edu    rbitCode = '''
1917249Sgblack@eecs.umich.edu    uint8_t *opBytes = (uint8_t *)&Op1;
1927249Sgblack@eecs.umich.edu    uint32_t resTemp;
1937249Sgblack@eecs.umich.edu    uint8_t *destBytes = (uint8_t *)&resTemp;
1947249Sgblack@eecs.umich.edu    // This reverses the bytes and bits of the input, or so says the
1957249Sgblack@eecs.umich.edu    // internet.
1967249Sgblack@eecs.umich.edu    for (int i = 0; i < 4; i++) {
1977249Sgblack@eecs.umich.edu        uint32_t temp = opBytes[i];
1987249Sgblack@eecs.umich.edu        temp = (temp * 0x0802 & 0x22110) | (temp * 0x8020 & 0x88440);
1997249Sgblack@eecs.umich.edu        destBytes[3 - i] = (temp * 0x10101) >> 16;
2007249Sgblack@eecs.umich.edu    }
2017249Sgblack@eecs.umich.edu    Dest = resTemp;
2027249Sgblack@eecs.umich.edu    '''
2037261Sgblack@eecs.umich.edu    rbitIop = InstObjParams("rbit", "Rbit", "RegRegOp",
2047249Sgblack@eecs.umich.edu                            { "code": rbitCode,
2057249Sgblack@eecs.umich.edu                              "predicate_test": predicateTest }, [])
2067261Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(rbitIop)
2077261Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(rbitIop)
2087249Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(rbitIop)
2097249Sgblack@eecs.umich.edu
2107251Sgblack@eecs.umich.edu    clzCode = '''
2117251Sgblack@eecs.umich.edu        Dest = (Op1 == 0) ? 32 : (31 - findMsbSet(Op1));
2127251Sgblack@eecs.umich.edu    '''
2137261Sgblack@eecs.umich.edu    clzIop = InstObjParams("clz", "Clz", "RegRegOp",
2147251Sgblack@eecs.umich.edu                           { "code": clzCode,
2157251Sgblack@eecs.umich.edu                             "predicate_test": predicateTest }, [])
2167261Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(clzIop)
2177261Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(clzIop)
2187251Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(clzIop)
2197251Sgblack@eecs.umich.edu
2207226Sgblack@eecs.umich.edu    ssatCode = '''
2217226Sgblack@eecs.umich.edu        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
2227226Sgblack@eecs.umich.edu        int32_t res;
2237232Sgblack@eecs.umich.edu        if (satInt(res, operand, imm))
2248302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2257226Sgblack@eecs.umich.edu        Dest = res;
2267226Sgblack@eecs.umich.edu    '''
2277232Sgblack@eecs.umich.edu    ssatIop = InstObjParams("ssat", "Ssat", "RegImmRegShiftOp",
2287226Sgblack@eecs.umich.edu                            { "code": ssatCode,
2298304SAli.Saidi@ARM.com                              "predicate_test": pickPredicate(ssatCode) }, [])
2307232Sgblack@eecs.umich.edu    header_output += RegImmRegShiftOpDeclare.subst(ssatIop)
2317232Sgblack@eecs.umich.edu    decoder_output += RegImmRegShiftOpConstructor.subst(ssatIop)
2327226Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(ssatIop)
2337226Sgblack@eecs.umich.edu
2347226Sgblack@eecs.umich.edu    usatCode = '''
2357226Sgblack@eecs.umich.edu        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
2367226Sgblack@eecs.umich.edu        int32_t res;
2377232Sgblack@eecs.umich.edu        if (uSatInt(res, operand, imm))
2388302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2397226Sgblack@eecs.umich.edu        Dest = res;
2407226Sgblack@eecs.umich.edu    '''
2417232Sgblack@eecs.umich.edu    usatIop = InstObjParams("usat", "Usat", "RegImmRegShiftOp",
2427226Sgblack@eecs.umich.edu                            { "code": usatCode,
2438304SAli.Saidi@ARM.com                              "predicate_test": pickPredicate(usatCode) }, [])
2447232Sgblack@eecs.umich.edu    header_output += RegImmRegShiftOpDeclare.subst(usatIop)
2457232Sgblack@eecs.umich.edu    decoder_output += RegImmRegShiftOpConstructor.subst(usatIop)
2467226Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(usatIop)
2477226Sgblack@eecs.umich.edu
2487226Sgblack@eecs.umich.edu    ssat16Code = '''
2497226Sgblack@eecs.umich.edu        int32_t res;
2507226Sgblack@eecs.umich.edu        uint32_t resTemp = 0;
2517226Sgblack@eecs.umich.edu        int32_t argLow = sext<16>(bits(Op1, 15, 0));
2527226Sgblack@eecs.umich.edu        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
2537232Sgblack@eecs.umich.edu        if (satInt(res, argLow, imm))
2548302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2557226Sgblack@eecs.umich.edu        replaceBits(resTemp, 15, 0, res);
2567232Sgblack@eecs.umich.edu        if (satInt(res, argHigh, imm))
2578302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2587226Sgblack@eecs.umich.edu        replaceBits(resTemp, 31, 16, res);
2597226Sgblack@eecs.umich.edu        Dest = resTemp;
2607226Sgblack@eecs.umich.edu    '''
2617232Sgblack@eecs.umich.edu    ssat16Iop = InstObjParams("ssat16", "Ssat16", "RegImmRegOp",
2627226Sgblack@eecs.umich.edu                              { "code": ssat16Code,
2638304SAli.Saidi@ARM.com                                "predicate_test": pickPredicate(ssat16Code) }, [])
2647232Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(ssat16Iop)
2657232Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(ssat16Iop)
2667226Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(ssat16Iop)
2677226Sgblack@eecs.umich.edu
2687226Sgblack@eecs.umich.edu    usat16Code = '''
2697226Sgblack@eecs.umich.edu        int32_t res;
2707226Sgblack@eecs.umich.edu        uint32_t resTemp = 0;
2717226Sgblack@eecs.umich.edu        int32_t argLow = sext<16>(bits(Op1, 15, 0));
2727226Sgblack@eecs.umich.edu        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
2737232Sgblack@eecs.umich.edu        if (uSatInt(res, argLow, imm))
2748302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2757226Sgblack@eecs.umich.edu        replaceBits(resTemp, 15, 0, res);
2767232Sgblack@eecs.umich.edu        if (uSatInt(res, argHigh, imm))
2778302SAli.Saidi@ARM.com            CpsrQ = 1 << 27;
2787226Sgblack@eecs.umich.edu        replaceBits(resTemp, 31, 16, res);
2797226Sgblack@eecs.umich.edu        Dest = resTemp;
2807226Sgblack@eecs.umich.edu    '''
2817232Sgblack@eecs.umich.edu    usat16Iop = InstObjParams("usat16", "Usat16", "RegImmRegOp",
2827226Sgblack@eecs.umich.edu                              { "code": usat16Code,
2838304SAli.Saidi@ARM.com                                "predicate_test": pickPredicate(usat16Code) }, [])
2847232Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(usat16Iop)
2857232Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(usat16Iop)
2867226Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(usat16Iop)
2877234Sgblack@eecs.umich.edu
2887234Sgblack@eecs.umich.edu    sxtbIop = InstObjParams("sxtb", "Sxtb", "RegImmRegOp",
2897234Sgblack@eecs.umich.edu                            { "code":
2908588Sgblack@eecs.umich.edu                              "Dest = sext<8>((uint8_t)(Op1_ud >> imm));",
2917234Sgblack@eecs.umich.edu                              "predicate_test": predicateTest }, [])
2927234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(sxtbIop)
2937234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(sxtbIop)
2947234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxtbIop)
2957234Sgblack@eecs.umich.edu
2967234Sgblack@eecs.umich.edu    sxtabIop = InstObjParams("sxtab", "Sxtab", "RegRegRegImmOp",
2977234Sgblack@eecs.umich.edu                             { "code":
2987234Sgblack@eecs.umich.edu                               '''
2998588Sgblack@eecs.umich.edu                                   Dest = sext<8>((uint8_t)(Op2_ud >> imm)) +
3007234Sgblack@eecs.umich.edu                                          Op1;
3017234Sgblack@eecs.umich.edu                               ''',
3027234Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
3037234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(sxtabIop)
3047234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(sxtabIop)
3057234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxtabIop)
3067234Sgblack@eecs.umich.edu
3077234Sgblack@eecs.umich.edu    sxtb16Code = '''
3087234Sgblack@eecs.umich.edu    uint32_t resTemp = 0;
3097234Sgblack@eecs.umich.edu    replaceBits(resTemp, 15, 0, sext<8>(bits(Op1, imm + 7, imm)));
3107234Sgblack@eecs.umich.edu    replaceBits(resTemp, 31, 16,
3117234Sgblack@eecs.umich.edu                sext<8>(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
3127234Sgblack@eecs.umich.edu    Dest = resTemp;
3137234Sgblack@eecs.umich.edu    '''
3147234Sgblack@eecs.umich.edu    sxtb16Iop = InstObjParams("sxtb16", "Sxtb16", "RegImmRegOp",
3157234Sgblack@eecs.umich.edu                              { "code": sxtb16Code,
3167234Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
3177234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(sxtb16Iop)
3187234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(sxtb16Iop)
3197234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxtb16Iop)
3207234Sgblack@eecs.umich.edu
3217234Sgblack@eecs.umich.edu    sxtab16Code = '''
3227234Sgblack@eecs.umich.edu    uint32_t resTemp = 0;
3237234Sgblack@eecs.umich.edu    replaceBits(resTemp, 15, 0, sext<8>(bits(Op2, imm + 7, imm)) +
3247234Sgblack@eecs.umich.edu                                        bits(Op1, 15, 0));
3257234Sgblack@eecs.umich.edu    replaceBits(resTemp, 31, 16,
3267234Sgblack@eecs.umich.edu                sext<8>(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
3277234Sgblack@eecs.umich.edu                bits(Op1, 31, 16));
3287234Sgblack@eecs.umich.edu    Dest = resTemp;
3297234Sgblack@eecs.umich.edu    '''
3307234Sgblack@eecs.umich.edu    sxtab16Iop = InstObjParams("sxtab16", "Sxtab16", "RegRegRegImmOp",
3317234Sgblack@eecs.umich.edu                               { "code": sxtab16Code,
3327234Sgblack@eecs.umich.edu                                 "predicate_test": predicateTest }, [])
3337234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(sxtab16Iop)
3347234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(sxtab16Iop)
3357234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxtab16Iop)
3367234Sgblack@eecs.umich.edu
3377234Sgblack@eecs.umich.edu    sxthCode = '''
3387234Sgblack@eecs.umich.edu    uint64_t rotated = (uint32_t)Op1;
3397234Sgblack@eecs.umich.edu    rotated = (rotated | (rotated << 32)) >> imm;
3407234Sgblack@eecs.umich.edu    Dest = sext<16>((uint16_t)rotated);
3417234Sgblack@eecs.umich.edu    '''
3427234Sgblack@eecs.umich.edu    sxthIop = InstObjParams("sxth", "Sxth", "RegImmRegOp",
3437234Sgblack@eecs.umich.edu                              { "code": sxthCode,
3447234Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
3457234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(sxthIop)
3467234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(sxthIop)
3477234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxthIop)
3487234Sgblack@eecs.umich.edu
3497234Sgblack@eecs.umich.edu    sxtahCode = '''
3507234Sgblack@eecs.umich.edu    uint64_t rotated = (uint32_t)Op2;
3517234Sgblack@eecs.umich.edu    rotated = (rotated | (rotated << 32)) >> imm;
3527234Sgblack@eecs.umich.edu    Dest = sext<16>((uint16_t)rotated) + Op1;
3537234Sgblack@eecs.umich.edu    '''
3547234Sgblack@eecs.umich.edu    sxtahIop = InstObjParams("sxtah", "Sxtah", "RegRegRegImmOp",
3557234Sgblack@eecs.umich.edu                             { "code": sxtahCode,
3567234Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
3577234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(sxtahIop)
3587234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(sxtahIop)
3597234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sxtahIop)
3607234Sgblack@eecs.umich.edu
3617234Sgblack@eecs.umich.edu    uxtbIop = InstObjParams("uxtb", "Uxtb", "RegImmRegOp",
3628588Sgblack@eecs.umich.edu                            { "code": "Dest = (uint8_t)(Op1_ud >> imm);",
3637234Sgblack@eecs.umich.edu                              "predicate_test": predicateTest }, [])
3647234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(uxtbIop)
3657234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(uxtbIop)
3667234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxtbIop)
3677234Sgblack@eecs.umich.edu
3687234Sgblack@eecs.umich.edu    uxtabIop = InstObjParams("uxtab", "Uxtab", "RegRegRegImmOp",
3697234Sgblack@eecs.umich.edu                             { "code":
3708588Sgblack@eecs.umich.edu                               "Dest = (uint8_t)(Op2_ud >> imm) + Op1;",
3717234Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
3727234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(uxtabIop)
3737234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(uxtabIop)
3747234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxtabIop)
3757234Sgblack@eecs.umich.edu
3767234Sgblack@eecs.umich.edu    uxtb16Code = '''
3777234Sgblack@eecs.umich.edu    uint32_t resTemp = 0;
3787234Sgblack@eecs.umich.edu    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op1, imm + 7, imm)));
3797234Sgblack@eecs.umich.edu    replaceBits(resTemp, 31, 16,
3807234Sgblack@eecs.umich.edu                (uint8_t)(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
3817234Sgblack@eecs.umich.edu    Dest = resTemp;
3827234Sgblack@eecs.umich.edu    '''
3837234Sgblack@eecs.umich.edu    uxtb16Iop = InstObjParams("uxtb16", "Uxtb16", "RegImmRegOp",
3847234Sgblack@eecs.umich.edu                              { "code": uxtb16Code,
3857234Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
3867234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(uxtb16Iop)
3877234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(uxtb16Iop)
3887234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxtb16Iop)
3897234Sgblack@eecs.umich.edu
3907234Sgblack@eecs.umich.edu    uxtab16Code = '''
3917234Sgblack@eecs.umich.edu    uint32_t resTemp = 0;
3927234Sgblack@eecs.umich.edu    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op2, imm + 7, imm)) +
3937234Sgblack@eecs.umich.edu                                        bits(Op1, 15, 0));
3947234Sgblack@eecs.umich.edu    replaceBits(resTemp, 31, 16,
3957234Sgblack@eecs.umich.edu                (uint8_t)(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
3967234Sgblack@eecs.umich.edu                bits(Op1, 31, 16));
3977234Sgblack@eecs.umich.edu    Dest = resTemp;
3987234Sgblack@eecs.umich.edu    '''
3997234Sgblack@eecs.umich.edu    uxtab16Iop = InstObjParams("uxtab16", "Uxtab16", "RegRegRegImmOp",
4007234Sgblack@eecs.umich.edu                               { "code": uxtab16Code,
4017234Sgblack@eecs.umich.edu                                 "predicate_test": predicateTest }, [])
4027234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(uxtab16Iop)
4037234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(uxtab16Iop)
4047234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxtab16Iop)
4057234Sgblack@eecs.umich.edu
4067234Sgblack@eecs.umich.edu    uxthCode = '''
4077234Sgblack@eecs.umich.edu    uint64_t rotated = (uint32_t)Op1;
4087234Sgblack@eecs.umich.edu    rotated = (rotated | (rotated << 32)) >> imm;
4097234Sgblack@eecs.umich.edu    Dest = (uint16_t)rotated;
4107234Sgblack@eecs.umich.edu    '''
4117234Sgblack@eecs.umich.edu    uxthIop = InstObjParams("uxth", "Uxth", "RegImmRegOp",
4127234Sgblack@eecs.umich.edu                              { "code": uxthCode,
4137234Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
4147234Sgblack@eecs.umich.edu    header_output += RegImmRegOpDeclare.subst(uxthIop)
4157234Sgblack@eecs.umich.edu    decoder_output += RegImmRegOpConstructor.subst(uxthIop)
4167234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxthIop)
4177234Sgblack@eecs.umich.edu
4187234Sgblack@eecs.umich.edu    uxtahCode = '''
4197234Sgblack@eecs.umich.edu    uint64_t rotated = (uint32_t)Op2;
4207234Sgblack@eecs.umich.edu    rotated = (rotated | (rotated << 32)) >> imm;
4217234Sgblack@eecs.umich.edu    Dest = (uint16_t)rotated + Op1;
4227234Sgblack@eecs.umich.edu    '''
4237234Sgblack@eecs.umich.edu    uxtahIop = InstObjParams("uxtah", "Uxtah", "RegRegRegImmOp",
4247234Sgblack@eecs.umich.edu                             { "code": uxtahCode,
4257234Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
4267234Sgblack@eecs.umich.edu    header_output += RegRegRegImmOpDeclare.subst(uxtahIop)
4277234Sgblack@eecs.umich.edu    decoder_output += RegRegRegImmOpConstructor.subst(uxtahIop)
4287234Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(uxtahIop)
4297239Sgblack@eecs.umich.edu
4307239Sgblack@eecs.umich.edu    selCode = '''
4317239Sgblack@eecs.umich.edu        uint32_t resTemp = 0;
4327239Sgblack@eecs.umich.edu        for (unsigned i = 0; i < 4; i++) {
4337239Sgblack@eecs.umich.edu            int low = i * 8;
4347239Sgblack@eecs.umich.edu            int high = low + 7;
4357239Sgblack@eecs.umich.edu            replaceBits(resTemp, high, low,
4368303SAli.Saidi@ARM.com                        bits(CondCodesGE, i) ?
4377239Sgblack@eecs.umich.edu                            bits(Op1, high, low) : bits(Op2, high, low));
4387239Sgblack@eecs.umich.edu        }
4397239Sgblack@eecs.umich.edu        Dest = resTemp;
4407239Sgblack@eecs.umich.edu    '''
4417239Sgblack@eecs.umich.edu    selIop = InstObjParams("sel", "Sel", "RegRegRegOp",
4427239Sgblack@eecs.umich.edu                           { "code": selCode,
4438303SAli.Saidi@ARM.com                             "predicate_test": predicateTest }, [])
4447239Sgblack@eecs.umich.edu    header_output += RegRegRegOpDeclare.subst(selIop)
4457239Sgblack@eecs.umich.edu    decoder_output += RegRegRegOpConstructor.subst(selIop)
4467239Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(selIop)
4477242Sgblack@eecs.umich.edu
4487242Sgblack@eecs.umich.edu    usad8Code = '''
4497242Sgblack@eecs.umich.edu        uint32_t resTemp = 0;
4507242Sgblack@eecs.umich.edu        for (unsigned i = 0; i < 4; i++) {
4517242Sgblack@eecs.umich.edu            int low = i * 8;
4527242Sgblack@eecs.umich.edu            int high = low + 7;
4537242Sgblack@eecs.umich.edu            int32_t diff = bits(Op1, high, low) -
4547242Sgblack@eecs.umich.edu                           bits(Op2, high, low);
4557242Sgblack@eecs.umich.edu            resTemp += ((diff < 0) ? -diff : diff);
4567242Sgblack@eecs.umich.edu        }
4577242Sgblack@eecs.umich.edu        Dest = resTemp;
4587242Sgblack@eecs.umich.edu    '''
4597242Sgblack@eecs.umich.edu    usad8Iop = InstObjParams("usad8", "Usad8", "RegRegRegOp",
4607242Sgblack@eecs.umich.edu                             { "code": usad8Code,
4617242Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
4627242Sgblack@eecs.umich.edu    header_output += RegRegRegOpDeclare.subst(usad8Iop)
4637242Sgblack@eecs.umich.edu    decoder_output += RegRegRegOpConstructor.subst(usad8Iop)
4647242Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(usad8Iop)
4657242Sgblack@eecs.umich.edu
4667242Sgblack@eecs.umich.edu    usada8Code = '''
4677242Sgblack@eecs.umich.edu        uint32_t resTemp = 0;
4687242Sgblack@eecs.umich.edu        for (unsigned i = 0; i < 4; i++) {
4697242Sgblack@eecs.umich.edu            int low = i * 8;
4707242Sgblack@eecs.umich.edu            int high = low + 7;
4717242Sgblack@eecs.umich.edu            int32_t diff = bits(Op1, high, low) -
4727242Sgblack@eecs.umich.edu                           bits(Op2, high, low);
4737242Sgblack@eecs.umich.edu            resTemp += ((diff < 0) ? -diff : diff);
4747242Sgblack@eecs.umich.edu        }
4757242Sgblack@eecs.umich.edu        Dest = Op3 + resTemp;
4767242Sgblack@eecs.umich.edu    '''
4777242Sgblack@eecs.umich.edu    usada8Iop = InstObjParams("usada8", "Usada8", "RegRegRegRegOp",
4787242Sgblack@eecs.umich.edu                              { "code": usada8Code,
4797242Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
4807242Sgblack@eecs.umich.edu    header_output += RegRegRegRegOpDeclare.subst(usada8Iop)
4817242Sgblack@eecs.umich.edu    decoder_output += RegRegRegRegOpConstructor.subst(usada8Iop)
4827242Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(usada8Iop)
4837247Sgblack@eecs.umich.edu
4847797Sgblack@eecs.umich.edu    bkptCode = 'return new PrefetchAbort(PC, ArmFault::DebugEvent);\n'
4857848SAli.Saidi@ARM.com    bkptIop = InstObjParams("bkpt", "BkptInst", "PredOp", bkptCode)
4867410Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(bkptIop)
4877410Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(bkptIop)
4887410Sgblack@eecs.umich.edu    exec_output += BasicExecute.subst(bkptIop)
4897410Sgblack@eecs.umich.edu
4907408Sgblack@eecs.umich.edu    nopIop = InstObjParams("nop", "NopInst", "PredOp", \
4918065SAli.Saidi@ARM.com            { "code" : "", "predicate_test" : predicateTest },
4928065SAli.Saidi@ARM.com            ['IsNop'])
4937247Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(nopIop)
4947247Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(nopIop)
4957408Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(nopIop)
4967408Sgblack@eecs.umich.edu
4977418Sgblack@eecs.umich.edu    yieldIop = InstObjParams("yield", "YieldInst", "PredOp", \
4987418Sgblack@eecs.umich.edu            { "code" : "", "predicate_test" : predicateTest })
4997418Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(yieldIop)
5007418Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(yieldIop)
5017418Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(yieldIop)
5027418Sgblack@eecs.umich.edu
5037418Sgblack@eecs.umich.edu    wfeCode = '''
5048518Sgeoffrey.blake@arm.com    // WFE Sleeps if SevMailbox==0 and no unmasked interrupts are pending
5058285SPrakash.Ramrakhyani@arm.com    if (SevMailbox == 1) {
5067418Sgblack@eecs.umich.edu        SevMailbox = 0;
5078142SAli.Saidi@ARM.com        PseudoInst::quiesceSkip(xc->tcBase());
5088518Sgeoffrey.blake@arm.com    } else if (xc->tcBase()->getCpuPtr()->getInterruptController()->checkInterrupts(xc->tcBase())) {
5098518Sgeoffrey.blake@arm.com        PseudoInst::quiesceSkip(xc->tcBase());
5108285SPrakash.Ramrakhyani@arm.com    } else {
5117418Sgblack@eecs.umich.edu        PseudoInst::quiesce(xc->tcBase());
5128142SAli.Saidi@ARM.com    }
5137418Sgblack@eecs.umich.edu    '''
5148518Sgeoffrey.blake@arm.com    wfePredFixUpCode = '''
5158518Sgeoffrey.blake@arm.com    // WFE is predicated false, reset SevMailbox to reduce spurious sleeps
5168518Sgeoffrey.blake@arm.com    // and SEV interrupts
5178518Sgeoffrey.blake@arm.com    SevMailbox = 1;
5188518Sgeoffrey.blake@arm.com    '''
5197418Sgblack@eecs.umich.edu    wfeIop = InstObjParams("wfe", "WfeInst", "PredOp", \
5208518Sgeoffrey.blake@arm.com            { "code" : wfeCode,
5218518Sgeoffrey.blake@arm.com              "pred_fixup" : wfePredFixUpCode,
5228518Sgeoffrey.blake@arm.com              "predicate_test" : predicateTest },
5237648SAli.Saidi@ARM.com            ["IsNonSpeculative", "IsQuiesce", "IsSerializeAfter"])
5247418Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(wfeIop)
5257418Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(wfeIop)
5268518Sgeoffrey.blake@arm.com    exec_output += QuiescePredOpExecuteWithFixup.subst(wfeIop)
5277418Sgblack@eecs.umich.edu
5287418Sgblack@eecs.umich.edu    wfiCode = '''
5298285SPrakash.Ramrakhyani@arm.com    // WFI doesn't sleep if interrupts are pending (masked or not)
5308285SPrakash.Ramrakhyani@arm.com    if (xc->tcBase()->getCpuPtr()->getInterruptController()->checkRaw()) {
5318285SPrakash.Ramrakhyani@arm.com        PseudoInst::quiesceSkip(xc->tcBase());
5328285SPrakash.Ramrakhyani@arm.com    } else {
5338285SPrakash.Ramrakhyani@arm.com        PseudoInst::quiesce(xc->tcBase());
5348285SPrakash.Ramrakhyani@arm.com    }
5357418Sgblack@eecs.umich.edu    '''
5367418Sgblack@eecs.umich.edu    wfiIop = InstObjParams("wfi", "WfiInst", "PredOp", \
5377418Sgblack@eecs.umich.edu            { "code" : wfiCode, "predicate_test" : predicateTest },
5388142SAli.Saidi@ARM.com            ["IsNonSpeculative", "IsQuiesce", "IsSerializeAfter"])
5397418Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(wfiIop)
5407418Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(wfiIop)
5418142SAli.Saidi@ARM.com    exec_output += QuiescePredOpExecute.subst(wfiIop)
5427418Sgblack@eecs.umich.edu
5437418Sgblack@eecs.umich.edu    sevCode = '''
5448142SAli.Saidi@ARM.com    SevMailbox = 1;
5457418Sgblack@eecs.umich.edu    System *sys = xc->tcBase()->getSystemPtr();
5467418Sgblack@eecs.umich.edu    for (int x = 0; x < sys->numContexts(); x++) {
5477418Sgblack@eecs.umich.edu        ThreadContext *oc = sys->getThreadContext(x);
5488285SPrakash.Ramrakhyani@arm.com        if (oc == xc->tcBase())
5498285SPrakash.Ramrakhyani@arm.com            continue;
5508518Sgeoffrey.blake@arm.com        // Wake CPU with interrupt if they were sleeping
5518285SPrakash.Ramrakhyani@arm.com        if (oc->readMiscReg(MISCREG_SEV_MAILBOX) == 0) {
5528518Sgeoffrey.blake@arm.com            // Post Interrupt and wake cpu if needed
5538518Sgeoffrey.blake@arm.com            oc->getCpuPtr()->postInterrupt(INT_SEV, 0);
5548142SAli.Saidi@ARM.com        }
5557418Sgblack@eecs.umich.edu    }
5567418Sgblack@eecs.umich.edu    '''
5577418Sgblack@eecs.umich.edu    sevIop = InstObjParams("sev", "SevInst", "PredOp", \
5587418Sgblack@eecs.umich.edu            { "code" : sevCode, "predicate_test" : predicateTest },
5598142SAli.Saidi@ARM.com            ["IsNonSpeculative", "IsSquashAfter"])
5607418Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(sevIop)
5617418Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(sevIop)
5627418Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sevIop)
5637418Sgblack@eecs.umich.edu
5647408Sgblack@eecs.umich.edu    itIop = InstObjParams("it", "ItInst", "PredOp", \
5658205SAli.Saidi@ARM.com            { "code" : ";",
5667648SAli.Saidi@ARM.com              "predicate_test" : predicateTest },
5677648SAli.Saidi@ARM.com            ["IsNonSpeculative", "IsSerializeAfter"])
5687408Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(itIop)
5697408Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(itIop)
5707408Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(itIop)
5717409Sgblack@eecs.umich.edu    unknownCode = '''
5728782Sgblack@eecs.umich.edu    if (FullSystem)
5738782Sgblack@eecs.umich.edu        return new UndefinedInstruction;
5748782Sgblack@eecs.umich.edu    else
5758782Sgblack@eecs.umich.edu        return new UndefinedInstruction(machInst, true);
5767409Sgblack@eecs.umich.edu    '''
5777409Sgblack@eecs.umich.edu    unknownIop = InstObjParams("unknown", "Unknown", "UnknownOp", \
5787409Sgblack@eecs.umich.edu                               { "code": unknownCode,
5797409Sgblack@eecs.umich.edu                                 "predicate_test": predicateTest })
5807409Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(unknownIop)
5817409Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(unknownIop)
5827409Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(unknownIop)
5837254Sgblack@eecs.umich.edu
5847254Sgblack@eecs.umich.edu    ubfxCode = '''
5857254Sgblack@eecs.umich.edu        Dest = bits(Op1, imm2, imm1);
5867254Sgblack@eecs.umich.edu    '''
5877254Sgblack@eecs.umich.edu    ubfxIop = InstObjParams("ubfx", "Ubfx", "RegRegImmImmOp",
5887254Sgblack@eecs.umich.edu                            { "code": ubfxCode,
5897254Sgblack@eecs.umich.edu                              "predicate_test": predicateTest }, [])
5907254Sgblack@eecs.umich.edu    header_output += RegRegImmImmOpDeclare.subst(ubfxIop)
5917254Sgblack@eecs.umich.edu    decoder_output += RegRegImmImmOpConstructor.subst(ubfxIop)
5927254Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(ubfxIop)
5937254Sgblack@eecs.umich.edu
5947254Sgblack@eecs.umich.edu    sbfxCode = '''
5957254Sgblack@eecs.umich.edu        int32_t resTemp = bits(Op1, imm2, imm1);
5967254Sgblack@eecs.umich.edu        Dest = resTemp | -(resTemp & (1 << (imm2 - imm1)));
5977254Sgblack@eecs.umich.edu    '''
5987254Sgblack@eecs.umich.edu    sbfxIop = InstObjParams("sbfx", "Sbfx", "RegRegImmImmOp",
5997254Sgblack@eecs.umich.edu                            { "code": sbfxCode,
6007254Sgblack@eecs.umich.edu                              "predicate_test": predicateTest }, [])
6017254Sgblack@eecs.umich.edu    header_output += RegRegImmImmOpDeclare.subst(sbfxIop)
6027254Sgblack@eecs.umich.edu    decoder_output += RegRegImmImmOpConstructor.subst(sbfxIop)
6037254Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(sbfxIop)
6047257Sgblack@eecs.umich.edu
6057257Sgblack@eecs.umich.edu    bfcCode = '''
6067257Sgblack@eecs.umich.edu        Dest = Op1 & ~(mask(imm2 - imm1 + 1) << imm1);
6077257Sgblack@eecs.umich.edu    '''
6087257Sgblack@eecs.umich.edu    bfcIop = InstObjParams("bfc", "Bfc", "RegRegImmImmOp",
6097257Sgblack@eecs.umich.edu                           { "code": bfcCode,
6107257Sgblack@eecs.umich.edu                             "predicate_test": predicateTest }, [])
6117257Sgblack@eecs.umich.edu    header_output += RegRegImmImmOpDeclare.subst(bfcIop)
6127257Sgblack@eecs.umich.edu    decoder_output += RegRegImmImmOpConstructor.subst(bfcIop)
6137257Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(bfcIop)
6147257Sgblack@eecs.umich.edu
6157257Sgblack@eecs.umich.edu    bfiCode = '''
6167257Sgblack@eecs.umich.edu        uint32_t bitMask = (mask(imm2 - imm1 + 1) << imm1);
6177257Sgblack@eecs.umich.edu        Dest = ((Op1 << imm1) & bitMask) | (Dest & ~bitMask);
6187257Sgblack@eecs.umich.edu    '''
6197257Sgblack@eecs.umich.edu    bfiIop = InstObjParams("bfi", "Bfi", "RegRegImmImmOp",
6207257Sgblack@eecs.umich.edu                           { "code": bfiCode,
6217257Sgblack@eecs.umich.edu                             "predicate_test": predicateTest }, [])
6227257Sgblack@eecs.umich.edu    header_output += RegRegImmImmOpDeclare.subst(bfiIop)
6237257Sgblack@eecs.umich.edu    decoder_output += RegRegImmImmOpConstructor.subst(bfiIop)
6247257Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(bfiIop)
6257262Sgblack@eecs.umich.edu
6267347SAli.Saidi@ARM.com    mrc15code = '''
6277347SAli.Saidi@ARM.com    CPSR cpsr = Cpsr;
6288782Sgblack@eecs.umich.edu    if (cpsr.mode == MODE_USER) {
6298782Sgblack@eecs.umich.edu        if (FullSystem)
6308782Sgblack@eecs.umich.edu            return new UndefinedInstruction;
6318782Sgblack@eecs.umich.edu        else
6328782Sgblack@eecs.umich.edu            return new UndefinedInstruction(false, mnemonic);
6338782Sgblack@eecs.umich.edu    }
6347347SAli.Saidi@ARM.com    Dest = MiscOp1;
6357347SAli.Saidi@ARM.com    '''
6367347SAli.Saidi@ARM.com
6377262Sgblack@eecs.umich.edu    mrc15Iop = InstObjParams("mrc", "Mrc15", "RegRegOp",
6387347SAli.Saidi@ARM.com                             { "code": mrc15code,
6397262Sgblack@eecs.umich.edu                               "predicate_test": predicateTest }, [])
6407262Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(mrc15Iop)
6417262Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(mrc15Iop)
6427262Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mrc15Iop)
6437262Sgblack@eecs.umich.edu
6447347SAli.Saidi@ARM.com
6457347SAli.Saidi@ARM.com    mcr15code = '''
6467347SAli.Saidi@ARM.com    CPSR cpsr = Cpsr;
6478782Sgblack@eecs.umich.edu    if (cpsr.mode == MODE_USER) {
6488782Sgblack@eecs.umich.edu        if (FullSystem)
6498782Sgblack@eecs.umich.edu            return new UndefinedInstruction;
6508782Sgblack@eecs.umich.edu        else
6518782Sgblack@eecs.umich.edu            return new UndefinedInstruction(false, mnemonic);
6528782Sgblack@eecs.umich.edu    }
6537347SAli.Saidi@ARM.com    MiscDest = Op1;
6547347SAli.Saidi@ARM.com    '''
6557262Sgblack@eecs.umich.edu    mcr15Iop = InstObjParams("mcr", "Mcr15", "RegRegOp",
6567347SAli.Saidi@ARM.com                             { "code": mcr15code,
6577599Sminkyu.jeong@arm.com                               "predicate_test": predicateTest },
6587599Sminkyu.jeong@arm.com                               ["IsSerializeAfter","IsNonSpeculative"])
6597262Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(mcr15Iop)
6607262Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(mcr15Iop)
6617262Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mcr15Iop)
6627283Sgblack@eecs.umich.edu
6637420Sgblack@eecs.umich.edu    mrc15UserIop = InstObjParams("mrc", "Mrc15User", "RegRegOp",
6647420Sgblack@eecs.umich.edu                                 { "code": "Dest = MiscOp1;",
6657420Sgblack@eecs.umich.edu                                   "predicate_test": predicateTest }, [])
6667420Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(mrc15UserIop)
6677420Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(mrc15UserIop)
6687420Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mrc15UserIop)
6697420Sgblack@eecs.umich.edu
6707420Sgblack@eecs.umich.edu    mcr15UserIop = InstObjParams("mcr", "Mcr15User", "RegRegOp",
6717420Sgblack@eecs.umich.edu                                 { "code": "MiscDest = Op1",
6727599Sminkyu.jeong@arm.com                                   "predicate_test": predicateTest },
6737599Sminkyu.jeong@arm.com                                   ["IsSerializeAfter","IsNonSpeculative"])
6747420Sgblack@eecs.umich.edu    header_output += RegRegOpDeclare.subst(mcr15UserIop)
6757420Sgblack@eecs.umich.edu    decoder_output += RegRegOpConstructor.subst(mcr15UserIop)
6767420Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(mcr15UserIop)
6777420Sgblack@eecs.umich.edu
6787283Sgblack@eecs.umich.edu    enterxCode = '''
6797797Sgblack@eecs.umich.edu        NextThumb = true;
6807797Sgblack@eecs.umich.edu        NextJazelle = true;
6817283Sgblack@eecs.umich.edu    '''
6827283Sgblack@eecs.umich.edu    enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
6837283Sgblack@eecs.umich.edu                              { "code": enterxCode,
6847283Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
6857283Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(enterxIop)
6867283Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(enterxIop)
6877283Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(enterxIop)
6887283Sgblack@eecs.umich.edu
6897283Sgblack@eecs.umich.edu    leavexCode = '''
6907797Sgblack@eecs.umich.edu        NextThumb = true;
6917797Sgblack@eecs.umich.edu        NextJazelle = false;
6927283Sgblack@eecs.umich.edu    '''
6937283Sgblack@eecs.umich.edu    leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
6947283Sgblack@eecs.umich.edu                              { "code": leavexCode,
6957283Sgblack@eecs.umich.edu                                "predicate_test": predicateTest }, [])
6967283Sgblack@eecs.umich.edu    header_output += BasicDeclare.subst(leavexIop)
6977283Sgblack@eecs.umich.edu    decoder_output += BasicConstructor.subst(leavexIop)
6987283Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(leavexIop)
6997307Sgblack@eecs.umich.edu
7007307Sgblack@eecs.umich.edu    setendCode = '''
7017307Sgblack@eecs.umich.edu        CPSR cpsr = Cpsr;
7027307Sgblack@eecs.umich.edu        cpsr.e = imm;
7037307Sgblack@eecs.umich.edu        Cpsr = cpsr;
7047307Sgblack@eecs.umich.edu    '''
7057307Sgblack@eecs.umich.edu    setendIop = InstObjParams("setend", "Setend", "ImmOp",
7067307Sgblack@eecs.umich.edu                              { "code": setendCode,
7077648SAli.Saidi@ARM.com                                "predicate_test": predicateTest },
7087648SAli.Saidi@ARM.com                              ["IsSerializeAfter","IsNonSpeculative"])
7097307Sgblack@eecs.umich.edu    header_output += ImmOpDeclare.subst(setendIop)
7107307Sgblack@eecs.umich.edu    decoder_output += ImmOpConstructor.subst(setendIop)
7117307Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(setendIop)
7127315Sgblack@eecs.umich.edu
7137603SGene.Wu@arm.com    clrexCode = '''
7148209SAli.Saidi@ARM.com        LLSCLock = 0;
7157603SGene.Wu@arm.com    '''
7167603SGene.Wu@arm.com    clrexIop = InstObjParams("clrex", "Clrex","PredOp",
7177603SGene.Wu@arm.com                             { "code": clrexCode,
7187603SGene.Wu@arm.com                               "predicate_test": predicateTest },[])
7198209SAli.Saidi@ARM.com    header_output += BasicDeclare.subst(clrexIop)
7207603SGene.Wu@arm.com    decoder_output += BasicConstructor.subst(clrexIop)
7217603SGene.Wu@arm.com    exec_output += PredOpExecute.subst(clrexIop)
7227603SGene.Wu@arm.com
7237605SGene.Wu@arm.com    isbCode = '''
7248068SAli.Saidi@ARM.com        fault = new FlushPipe;
7257605SGene.Wu@arm.com    '''
7267605SGene.Wu@arm.com    isbIop = InstObjParams("isb", "Isb", "PredOp",
7277605SGene.Wu@arm.com                             {"code": isbCode,
7288068SAli.Saidi@ARM.com                               "predicate_test": predicateTest},
7298068SAli.Saidi@ARM.com                                ['IsSerializeAfter'])
7307605SGene.Wu@arm.com    header_output += BasicDeclare.subst(isbIop)
7317605SGene.Wu@arm.com    decoder_output += BasicConstructor.subst(isbIop)
7327605SGene.Wu@arm.com    exec_output += PredOpExecute.subst(isbIop)
7337605SGene.Wu@arm.com
7347605SGene.Wu@arm.com    dsbCode = '''
7358068SAli.Saidi@ARM.com        fault = new FlushPipe;
7367605SGene.Wu@arm.com    '''
7377605SGene.Wu@arm.com    dsbIop = InstObjParams("dsb", "Dsb", "PredOp",
7387605SGene.Wu@arm.com                             {"code": dsbCode,
7398068SAli.Saidi@ARM.com                               "predicate_test": predicateTest},
7408068SAli.Saidi@ARM.com                              ['IsMemBarrier', 'IsSerializeAfter'])
7417605SGene.Wu@arm.com    header_output += BasicDeclare.subst(dsbIop)
7427605SGene.Wu@arm.com    decoder_output += BasicConstructor.subst(dsbIop)
7437605SGene.Wu@arm.com    exec_output += PredOpExecute.subst(dsbIop)
7447605SGene.Wu@arm.com
7457605SGene.Wu@arm.com    dmbCode = '''
7467605SGene.Wu@arm.com    '''
7477605SGene.Wu@arm.com    dmbIop = InstObjParams("dmb", "Dmb", "PredOp",
7487605SGene.Wu@arm.com                             {"code": dmbCode,
7498068SAli.Saidi@ARM.com                               "predicate_test": predicateTest},
7508068SAli.Saidi@ARM.com                               ['IsMemBarrier'])
7517605SGene.Wu@arm.com    header_output += BasicDeclare.subst(dmbIop)
7527605SGene.Wu@arm.com    decoder_output += BasicConstructor.subst(dmbIop)
7537605SGene.Wu@arm.com    exec_output += PredOpExecute.subst(dmbIop)
7547605SGene.Wu@arm.com
7557613SGene.Wu@arm.com    dbgCode = '''
7567613SGene.Wu@arm.com    '''
7577613SGene.Wu@arm.com    dbgIop = InstObjParams("dbg", "Dbg", "PredOp",
7587613SGene.Wu@arm.com                             {"code": dbgCode,
7597613SGene.Wu@arm.com                               "predicate_test": predicateTest})
7607613SGene.Wu@arm.com    header_output += BasicDeclare.subst(dbgIop)
7617613SGene.Wu@arm.com    decoder_output += BasicConstructor.subst(dbgIop)
7627613SGene.Wu@arm.com    exec_output += PredOpExecute.subst(dbgIop)
7637613SGene.Wu@arm.com
7647315Sgblack@eecs.umich.edu    cpsCode = '''
7657315Sgblack@eecs.umich.edu    uint32_t mode = bits(imm, 4, 0);
7667315Sgblack@eecs.umich.edu    uint32_t f = bits(imm, 5);
7677315Sgblack@eecs.umich.edu    uint32_t i = bits(imm, 6);
7687315Sgblack@eecs.umich.edu    uint32_t a = bits(imm, 7);
7697315Sgblack@eecs.umich.edu    bool setMode = bits(imm, 8);
7707315Sgblack@eecs.umich.edu    bool enable = bits(imm, 9);
7717315Sgblack@eecs.umich.edu    CPSR cpsr = Cpsr;
7727400SAli.Saidi@ARM.com    SCTLR sctlr = Sctlr;
7737315Sgblack@eecs.umich.edu    if (cpsr.mode != MODE_USER) {
7747315Sgblack@eecs.umich.edu        if (enable) {
7757315Sgblack@eecs.umich.edu            if (f) cpsr.f = 0;
7767315Sgblack@eecs.umich.edu            if (i) cpsr.i = 0;
7777315Sgblack@eecs.umich.edu            if (a) cpsr.a = 0;
7787315Sgblack@eecs.umich.edu        } else {
7797400SAli.Saidi@ARM.com            if (f && !sctlr.nmfi) cpsr.f = 1;
7807315Sgblack@eecs.umich.edu            if (i) cpsr.i = 1;
7817315Sgblack@eecs.umich.edu            if (a) cpsr.a = 1;
7827315Sgblack@eecs.umich.edu        }
7837315Sgblack@eecs.umich.edu        if (setMode) {
7847315Sgblack@eecs.umich.edu            cpsr.mode = mode;
7857315Sgblack@eecs.umich.edu        }
7867315Sgblack@eecs.umich.edu    }
7877315Sgblack@eecs.umich.edu    Cpsr = cpsr;
7887315Sgblack@eecs.umich.edu    '''
7897315Sgblack@eecs.umich.edu    cpsIop = InstObjParams("cps", "Cps", "ImmOp",
7907315Sgblack@eecs.umich.edu                           { "code": cpsCode,
7917599Sminkyu.jeong@arm.com                             "predicate_test": predicateTest },
7927599Sminkyu.jeong@arm.com                           ["IsSerializeAfter","IsNonSpeculative"])
7937315Sgblack@eecs.umich.edu    header_output += ImmOpDeclare.subst(cpsIop)
7947315Sgblack@eecs.umich.edu    decoder_output += ImmOpConstructor.subst(cpsIop)
7957315Sgblack@eecs.umich.edu    exec_output += PredOpExecute.subst(cpsIop)
7967202Sgblack@eecs.umich.edu}};
797