misc.isa revision 8065
12100SN/A// -*- mode:c++ -*-
22100SN/A
32706Sksewell@umich.edu// Copyright (c) 2010 ARM Limited
42706Sksewell@umich.edu// All rights reserved
52706Sksewell@umich.edu//
62706Sksewell@umich.edu// The license below extends only to copyright in the software and shall
72706Sksewell@umich.edu// not be construed as granting a license to any other intellectual
82706Sksewell@umich.edu// property including but not limited to intellectual property relating
92706Sksewell@umich.edu// to a hardware implementation of the functionality of the software
102706Sksewell@umich.edu// licensed hereunder.  You may use the software subject to the license
112706Sksewell@umich.edu// terms below provided that you ensure that this notice is replicated
122706Sksewell@umich.edu// unmodified and in its entirety in all distributions of the software,
132706Sksewell@umich.edu// modified or unmodified, in source code or in binary form.
142706Sksewell@umich.edu//
152706Sksewell@umich.edu// Redistribution and use in source and binary forms, with or without
162706Sksewell@umich.edu// modification, are permitted provided that the following conditions are
172706Sksewell@umich.edu// met: redistributions of source code must retain the above copyright
182706Sksewell@umich.edu// notice, this list of conditions and the following disclaimer;
192706Sksewell@umich.edu// redistributions in binary form must reproduce the above copyright
202706Sksewell@umich.edu// notice, this list of conditions and the following disclaimer in the
212706Sksewell@umich.edu// documentation and/or other materials provided with the distribution;
222706Sksewell@umich.edu// neither the name of the copyright holders nor the names of its
232706Sksewell@umich.edu// contributors may be used to endorse or promote products derived from
242706Sksewell@umich.edu// this software without specific prior written permission.
252706Sksewell@umich.edu//
262706Sksewell@umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
272706Sksewell@umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
282706Sksewell@umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
292706Sksewell@umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
302706Sksewell@umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
312706Sksewell@umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
322100SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
332124SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
342124SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
352124SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
362124SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
372124SN/A//
382124SN/A// Authors: Gabe Black
392124SN/A
402124SN/Alet {{
412124SN/A
422124SN/A    svcCode = '''
432124SN/A#if FULL_SYSTEM
442124SN/A    fault = new SupervisorCall;
452124SN/A#else
462124SN/A    fault = new SupervisorCall(machInst);
472124SN/A#endif
482124SN/A    '''
492124SN/A
502124SN/A    svcIop = InstObjParams("svc", "Svc", "PredOp",
512124SN/A                           { "code": svcCode,
522124SN/A                             "predicate_test": predicateTest }, ["IsSyscall"])
532124SN/A    header_output = BasicDeclare.subst(svcIop)
542124SN/A    decoder_output = BasicConstructor.subst(svcIop)
552124SN/A    exec_output = PredOpExecute.subst(svcIop)
562124SN/A
572124SN/A}};
582124SN/A
592124SN/Alet {{
602124SN/A
612124SN/A    header_output = decoder_output = exec_output = ""
622124SN/A
632124SN/A    mrsCpsrCode = "Dest = (Cpsr | CondCodes) & 0xF8FF03DF"
642124SN/A    mrsCpsrIop = InstObjParams("mrs", "MrsCpsr", "MrsOp",
652124SN/A                               { "code": mrsCpsrCode,
662124SN/A                                 "predicate_test": condPredicateTest },
672124SN/A                               ["IsSerializeBefore"])
682124SN/A    header_output += MrsDeclare.subst(mrsCpsrIop)
692124SN/A    decoder_output += MrsConstructor.subst(mrsCpsrIop)
702124SN/A    exec_output += PredOpExecute.subst(mrsCpsrIop)
712124SN/A
722124SN/A    mrsSpsrCode = "Dest = Spsr"
732124SN/A    mrsSpsrIop = InstObjParams("mrs", "MrsSpsr", "MrsOp",
742124SN/A                               { "code": mrsSpsrCode,
752124SN/A                                 "predicate_test": predicateTest },
762124SN/A                               ["IsSerializeBefore"])
772124SN/A    header_output += MrsDeclare.subst(mrsSpsrIop)
782124SN/A    decoder_output += MrsConstructor.subst(mrsSpsrIop)
792124SN/A    exec_output += PredOpExecute.subst(mrsSpsrIop)
802124SN/A
812124SN/A    msrCpsrRegCode = '''
822124SN/A        SCTLR sctlr = Sctlr;
832124SN/A        uint32_t newCpsr =
842124SN/A            cpsrWriteByInstr(Cpsr | CondCodes, Op1, byteMask, false, sctlr.nmfi);
852124SN/A        Cpsr = ~CondCodesMask & newCpsr;
862124SN/A        NextThumb = ((CPSR)newCpsr).t;
872124SN/A        NextJazelle = ((CPSR)newCpsr).j;
882124SN/A        ForcedItState = ((((CPSR)Op1).it2 << 2) & 0xFC)
892124SN/A                | (((CPSR)Op1).it1 & 0x3);
902124SN/A        CondCodes = CondCodesMask & newCpsr;
912124SN/A    '''
922124SN/A    msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp",
932124SN/A                                  { "code": msrCpsrRegCode,
942124SN/A                                    "predicate_test": condPredicateTest },
952124SN/A                                  ["IsSerializeAfter","IsNonSpeculative"])
962124SN/A    header_output += MsrRegDeclare.subst(msrCpsrRegIop)
972124SN/A    decoder_output += MsrRegConstructor.subst(msrCpsrRegIop)
982124SN/A    exec_output += PredOpExecute.subst(msrCpsrRegIop)
992124SN/A
1002124SN/A    msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);"
1012124SN/A    msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp",
1022124SN/A                                  { "code": msrSpsrRegCode,
1032124SN/A                                    "predicate_test": predicateTest },
1042124SN/A                                  ["IsSerializeAfter","IsNonSpeculative"])
1052124SN/A    header_output += MsrRegDeclare.subst(msrSpsrRegIop)
1062124SN/A    decoder_output += MsrRegConstructor.subst(msrSpsrRegIop)
1072124SN/A    exec_output += PredOpExecute.subst(msrSpsrRegIop)
1082124SN/A
1092124SN/A    msrCpsrImmCode = '''
1102124SN/A        SCTLR sctlr = Sctlr;
1112124SN/A        uint32_t newCpsr =
1122124SN/A            cpsrWriteByInstr(Cpsr | CondCodes, imm, byteMask, false, sctlr.nmfi);
1132124SN/A        Cpsr = ~CondCodesMask & newCpsr;
1142124SN/A        NextThumb = ((CPSR)newCpsr).t;
1152124SN/A        NextJazelle = ((CPSR)newCpsr).j;
1162124SN/A        ForcedItState = ((((CPSR)imm).it2 << 2) & 0xFC)
1172124SN/A            | (((CPSR)imm).it1 & 0x3);
1182124SN/A        CondCodes = CondCodesMask & newCpsr;
1192124SN/A    '''
1202100SN/A    msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp",
1212123SN/A                                  { "code": msrCpsrImmCode,
1222686Sksewell@umich.edu                                    "predicate_test": condPredicateTest },
1232686Sksewell@umich.edu                                  ["IsSerializeAfter","IsNonSpeculative"])
1242686Sksewell@umich.edu    header_output += MsrImmDeclare.subst(msrCpsrImmIop)
1252124SN/A    decoder_output += MsrImmConstructor.subst(msrCpsrImmIop)
1262686Sksewell@umich.edu    exec_output += PredOpExecute.subst(msrCpsrImmIop)
1272686Sksewell@umich.edu
1282686Sksewell@umich.edu    msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);"
1292686Sksewell@umich.edu    msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp",
1302686Sksewell@umich.edu                                  { "code": msrSpsrImmCode,
1312686Sksewell@umich.edu                                    "predicate_test": predicateTest },
1322686Sksewell@umich.edu                                  ["IsSerializeAfter","IsNonSpeculative"])
1332686Sksewell@umich.edu    header_output += MsrImmDeclare.subst(msrSpsrImmIop)
1342686Sksewell@umich.edu    decoder_output += MsrImmConstructor.subst(msrSpsrImmIop)
1352686Sksewell@umich.edu    exec_output += PredOpExecute.subst(msrSpsrImmIop)
1362686Sksewell@umich.edu
1372686Sksewell@umich.edu    revCode = '''
1382686Sksewell@umich.edu    uint32_t val = Op1;
1392686Sksewell@umich.edu    Dest = swap_byte(val);
1402686Sksewell@umich.edu    '''
1412686Sksewell@umich.edu    revIop = InstObjParams("rev", "Rev", "RegRegOp",
1422686Sksewell@umich.edu                           { "code": revCode,
1432686Sksewell@umich.edu                             "predicate_test": predicateTest }, [])
1442686Sksewell@umich.edu    header_output += RegRegOpDeclare.subst(revIop)
1452686Sksewell@umich.edu    decoder_output += RegRegOpConstructor.subst(revIop)
1462686Sksewell@umich.edu    exec_output += PredOpExecute.subst(revIop)
1472123SN/A
1482123SN/A    rev16Code = '''
1492550SN/A    uint32_t val = Op1;
1502550SN/A    Dest = (bits(val, 15, 8) << 0) |
1512123SN/A           (bits(val, 7, 0) << 8) |
1522123SN/A           (bits(val, 31, 24) << 16) |
1532123SN/A           (bits(val, 23, 16) << 24);
1542123SN/A    '''
1552123SN/A    rev16Iop = InstObjParams("rev16", "Rev16", "RegRegOp",
1562123SN/A                             { "code": rev16Code,
1572239SN/A                               "predicate_test": predicateTest }, [])
1582239SN/A    header_output += RegRegOpDeclare.subst(rev16Iop)
1592239SN/A    decoder_output += RegRegOpConstructor.subst(rev16Iop)
1602239SN/A    exec_output += PredOpExecute.subst(rev16Iop)
1612239SN/A
1622239SN/A    revshCode = '''
1632239SN/A    uint16_t val = Op1;
1642239SN/A    Dest = sext<16>(swap_byte(val));
1652239SN/A    '''
1662239SN/A    revshIop = InstObjParams("revsh", "Revsh", "RegRegOp",
1672239SN/A                             { "code": revshCode,
1682239SN/A                               "predicate_test": predicateTest }, [])
1692239SN/A    header_output += RegRegOpDeclare.subst(revshIop)
1702239SN/A    decoder_output += RegRegOpConstructor.subst(revshIop)
1712239SN/A    exec_output += PredOpExecute.subst(revshIop)
1722239SN/A
1732239SN/A    rbitCode = '''
1742239SN/A    uint8_t *opBytes = (uint8_t *)&Op1;
1752239SN/A    uint32_t resTemp;
1762239SN/A    uint8_t *destBytes = (uint8_t *)&resTemp;
1772239SN/A    // This reverses the bytes and bits of the input, or so says the
1782239SN/A    // internet.
1792239SN/A    for (int i = 0; i < 4; i++) {
1802686Sksewell@umich.edu        uint32_t temp = opBytes[i];
1812135SN/A        temp = (temp * 0x0802 & 0x22110) | (temp * 0x8020 & 0x88440);
1822239SN/A        destBytes[3 - i] = (temp * 0x10101) >> 16;
1832239SN/A    }
184    Dest = resTemp;
185    '''
186    rbitIop = InstObjParams("rbit", "Rbit", "RegRegOp",
187                            { "code": rbitCode,
188                              "predicate_test": predicateTest }, [])
189    header_output += RegRegOpDeclare.subst(rbitIop)
190    decoder_output += RegRegOpConstructor.subst(rbitIop)
191    exec_output += PredOpExecute.subst(rbitIop)
192
193    clzCode = '''
194        Dest = (Op1 == 0) ? 32 : (31 - findMsbSet(Op1));
195    '''
196    clzIop = InstObjParams("clz", "Clz", "RegRegOp",
197                           { "code": clzCode,
198                             "predicate_test": predicateTest }, [])
199    header_output += RegRegOpDeclare.subst(clzIop)
200    decoder_output += RegRegOpConstructor.subst(clzIop)
201    exec_output += PredOpExecute.subst(clzIop)
202
203    ssatCode = '''
204        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
205        int32_t res;
206        if (satInt(res, operand, imm))
207            CondCodes = CondCodes | (1 << 27);
208        else
209            CondCodes = CondCodes;
210        Dest = res;
211    '''
212    ssatIop = InstObjParams("ssat", "Ssat", "RegImmRegShiftOp",
213                            { "code": ssatCode,
214                              "predicate_test": condPredicateTest }, [])
215    header_output += RegImmRegShiftOpDeclare.subst(ssatIop)
216    decoder_output += RegImmRegShiftOpConstructor.subst(ssatIop)
217    exec_output += PredOpExecute.subst(ssatIop)
218
219    usatCode = '''
220        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
221        int32_t res;
222        if (uSatInt(res, operand, imm))
223            CondCodes = CondCodes | (1 << 27);
224        else
225            CondCodes = CondCodes;
226        Dest = res;
227    '''
228    usatIop = InstObjParams("usat", "Usat", "RegImmRegShiftOp",
229                            { "code": usatCode,
230                              "predicate_test": condPredicateTest }, [])
231    header_output += RegImmRegShiftOpDeclare.subst(usatIop)
232    decoder_output += RegImmRegShiftOpConstructor.subst(usatIop)
233    exec_output += PredOpExecute.subst(usatIop)
234
235    ssat16Code = '''
236        int32_t res;
237        uint32_t resTemp = 0;
238        CondCodes = CondCodes;
239        int32_t argLow = sext<16>(bits(Op1, 15, 0));
240        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
241        if (satInt(res, argLow, imm))
242            CondCodes = CondCodes | (1 << 27);
243        replaceBits(resTemp, 15, 0, res);
244        if (satInt(res, argHigh, imm))
245            CondCodes = CondCodes | (1 << 27);
246        replaceBits(resTemp, 31, 16, res);
247        Dest = resTemp;
248    '''
249    ssat16Iop = InstObjParams("ssat16", "Ssat16", "RegImmRegOp",
250                              { "code": ssat16Code,
251                                "predicate_test": condPredicateTest }, [])
252    header_output += RegImmRegOpDeclare.subst(ssat16Iop)
253    decoder_output += RegImmRegOpConstructor.subst(ssat16Iop)
254    exec_output += PredOpExecute.subst(ssat16Iop)
255
256    usat16Code = '''
257        int32_t res;
258        uint32_t resTemp = 0;
259        CondCodes = CondCodes;
260        int32_t argLow = sext<16>(bits(Op1, 15, 0));
261        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
262        if (uSatInt(res, argLow, imm))
263            CondCodes = CondCodes | (1 << 27);
264        replaceBits(resTemp, 15, 0, res);
265        if (uSatInt(res, argHigh, imm))
266            CondCodes = CondCodes | (1 << 27);
267        replaceBits(resTemp, 31, 16, res);
268        Dest = resTemp;
269    '''
270    usat16Iop = InstObjParams("usat16", "Usat16", "RegImmRegOp",
271                              { "code": usat16Code,
272                                "predicate_test": condPredicateTest }, [])
273    header_output += RegImmRegOpDeclare.subst(usat16Iop)
274    decoder_output += RegImmRegOpConstructor.subst(usat16Iop)
275    exec_output += PredOpExecute.subst(usat16Iop)
276
277    sxtbIop = InstObjParams("sxtb", "Sxtb", "RegImmRegOp",
278                            { "code":
279                              "Dest = sext<8>((uint8_t)(Op1.ud >> imm));",
280                              "predicate_test": predicateTest }, [])
281    header_output += RegImmRegOpDeclare.subst(sxtbIop)
282    decoder_output += RegImmRegOpConstructor.subst(sxtbIop)
283    exec_output += PredOpExecute.subst(sxtbIop)
284
285    sxtabIop = InstObjParams("sxtab", "Sxtab", "RegRegRegImmOp",
286                             { "code":
287                               '''
288                                   Dest = sext<8>((uint8_t)(Op2.ud >> imm)) +
289                                          Op1;
290                               ''',
291                               "predicate_test": predicateTest }, [])
292    header_output += RegRegRegImmOpDeclare.subst(sxtabIop)
293    decoder_output += RegRegRegImmOpConstructor.subst(sxtabIop)
294    exec_output += PredOpExecute.subst(sxtabIop)
295
296    sxtb16Code = '''
297    uint32_t resTemp = 0;
298    replaceBits(resTemp, 15, 0, sext<8>(bits(Op1, imm + 7, imm)));
299    replaceBits(resTemp, 31, 16,
300                sext<8>(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
301    Dest = resTemp;
302    '''
303    sxtb16Iop = InstObjParams("sxtb16", "Sxtb16", "RegImmRegOp",
304                              { "code": sxtb16Code,
305                                "predicate_test": predicateTest }, [])
306    header_output += RegImmRegOpDeclare.subst(sxtb16Iop)
307    decoder_output += RegImmRegOpConstructor.subst(sxtb16Iop)
308    exec_output += PredOpExecute.subst(sxtb16Iop)
309
310    sxtab16Code = '''
311    uint32_t resTemp = 0;
312    replaceBits(resTemp, 15, 0, sext<8>(bits(Op2, imm + 7, imm)) +
313                                        bits(Op1, 15, 0));
314    replaceBits(resTemp, 31, 16,
315                sext<8>(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
316                bits(Op1, 31, 16));
317    Dest = resTemp;
318    '''
319    sxtab16Iop = InstObjParams("sxtab16", "Sxtab16", "RegRegRegImmOp",
320                               { "code": sxtab16Code,
321                                 "predicate_test": predicateTest }, [])
322    header_output += RegRegRegImmOpDeclare.subst(sxtab16Iop)
323    decoder_output += RegRegRegImmOpConstructor.subst(sxtab16Iop)
324    exec_output += PredOpExecute.subst(sxtab16Iop)
325
326    sxthCode = '''
327    uint64_t rotated = (uint32_t)Op1;
328    rotated = (rotated | (rotated << 32)) >> imm;
329    Dest = sext<16>((uint16_t)rotated);
330    '''
331    sxthIop = InstObjParams("sxth", "Sxth", "RegImmRegOp",
332                              { "code": sxthCode,
333                                "predicate_test": predicateTest }, [])
334    header_output += RegImmRegOpDeclare.subst(sxthIop)
335    decoder_output += RegImmRegOpConstructor.subst(sxthIop)
336    exec_output += PredOpExecute.subst(sxthIop)
337
338    sxtahCode = '''
339    uint64_t rotated = (uint32_t)Op2;
340    rotated = (rotated | (rotated << 32)) >> imm;
341    Dest = sext<16>((uint16_t)rotated) + Op1;
342    '''
343    sxtahIop = InstObjParams("sxtah", "Sxtah", "RegRegRegImmOp",
344                             { "code": sxtahCode,
345                               "predicate_test": predicateTest }, [])
346    header_output += RegRegRegImmOpDeclare.subst(sxtahIop)
347    decoder_output += RegRegRegImmOpConstructor.subst(sxtahIop)
348    exec_output += PredOpExecute.subst(sxtahIop)
349
350    uxtbIop = InstObjParams("uxtb", "Uxtb", "RegImmRegOp",
351                            { "code": "Dest = (uint8_t)(Op1.ud >> imm);",
352                              "predicate_test": predicateTest }, [])
353    header_output += RegImmRegOpDeclare.subst(uxtbIop)
354    decoder_output += RegImmRegOpConstructor.subst(uxtbIop)
355    exec_output += PredOpExecute.subst(uxtbIop)
356
357    uxtabIop = InstObjParams("uxtab", "Uxtab", "RegRegRegImmOp",
358                             { "code":
359                               "Dest = (uint8_t)(Op2.ud >> imm) + Op1;",
360                               "predicate_test": predicateTest }, [])
361    header_output += RegRegRegImmOpDeclare.subst(uxtabIop)
362    decoder_output += RegRegRegImmOpConstructor.subst(uxtabIop)
363    exec_output += PredOpExecute.subst(uxtabIop)
364
365    uxtb16Code = '''
366    uint32_t resTemp = 0;
367    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op1, imm + 7, imm)));
368    replaceBits(resTemp, 31, 16,
369                (uint8_t)(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
370    Dest = resTemp;
371    '''
372    uxtb16Iop = InstObjParams("uxtb16", "Uxtb16", "RegImmRegOp",
373                              { "code": uxtb16Code,
374                                "predicate_test": predicateTest }, [])
375    header_output += RegImmRegOpDeclare.subst(uxtb16Iop)
376    decoder_output += RegImmRegOpConstructor.subst(uxtb16Iop)
377    exec_output += PredOpExecute.subst(uxtb16Iop)
378
379    uxtab16Code = '''
380    uint32_t resTemp = 0;
381    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op2, imm + 7, imm)) +
382                                        bits(Op1, 15, 0));
383    replaceBits(resTemp, 31, 16,
384                (uint8_t)(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
385                bits(Op1, 31, 16));
386    Dest = resTemp;
387    '''
388    uxtab16Iop = InstObjParams("uxtab16", "Uxtab16", "RegRegRegImmOp",
389                               { "code": uxtab16Code,
390                                 "predicate_test": predicateTest }, [])
391    header_output += RegRegRegImmOpDeclare.subst(uxtab16Iop)
392    decoder_output += RegRegRegImmOpConstructor.subst(uxtab16Iop)
393    exec_output += PredOpExecute.subst(uxtab16Iop)
394
395    uxthCode = '''
396    uint64_t rotated = (uint32_t)Op1;
397    rotated = (rotated | (rotated << 32)) >> imm;
398    Dest = (uint16_t)rotated;
399    '''
400    uxthIop = InstObjParams("uxth", "Uxth", "RegImmRegOp",
401                              { "code": uxthCode,
402                                "predicate_test": predicateTest }, [])
403    header_output += RegImmRegOpDeclare.subst(uxthIop)
404    decoder_output += RegImmRegOpConstructor.subst(uxthIop)
405    exec_output += PredOpExecute.subst(uxthIop)
406
407    uxtahCode = '''
408    uint64_t rotated = (uint32_t)Op2;
409    rotated = (rotated | (rotated << 32)) >> imm;
410    Dest = (uint16_t)rotated + Op1;
411    '''
412    uxtahIop = InstObjParams("uxtah", "Uxtah", "RegRegRegImmOp",
413                             { "code": uxtahCode,
414                               "predicate_test": predicateTest }, [])
415    header_output += RegRegRegImmOpDeclare.subst(uxtahIop)
416    decoder_output += RegRegRegImmOpConstructor.subst(uxtahIop)
417    exec_output += PredOpExecute.subst(uxtahIop)
418
419    selCode = '''
420        uint32_t resTemp = 0;
421        for (unsigned i = 0; i < 4; i++) {
422            int low = i * 8;
423            int high = low + 7;
424            replaceBits(resTemp, high, low,
425                        bits(CondCodes, 16 + i) ?
426                            bits(Op1, high, low) : bits(Op2, high, low));
427        }
428        Dest = resTemp;
429    '''
430    selIop = InstObjParams("sel", "Sel", "RegRegRegOp",
431                           { "code": selCode,
432                             "predicate_test": condPredicateTest }, [])
433    header_output += RegRegRegOpDeclare.subst(selIop)
434    decoder_output += RegRegRegOpConstructor.subst(selIop)
435    exec_output += PredOpExecute.subst(selIop)
436
437    usad8Code = '''
438        uint32_t resTemp = 0;
439        for (unsigned i = 0; i < 4; i++) {
440            int low = i * 8;
441            int high = low + 7;
442            int32_t diff = bits(Op1, high, low) -
443                           bits(Op2, high, low);
444            resTemp += ((diff < 0) ? -diff : diff);
445        }
446        Dest = resTemp;
447    '''
448    usad8Iop = InstObjParams("usad8", "Usad8", "RegRegRegOp",
449                             { "code": usad8Code,
450                               "predicate_test": predicateTest }, [])
451    header_output += RegRegRegOpDeclare.subst(usad8Iop)
452    decoder_output += RegRegRegOpConstructor.subst(usad8Iop)
453    exec_output += PredOpExecute.subst(usad8Iop)
454
455    usada8Code = '''
456        uint32_t resTemp = 0;
457        for (unsigned i = 0; i < 4; i++) {
458            int low = i * 8;
459            int high = low + 7;
460            int32_t diff = bits(Op1, high, low) -
461                           bits(Op2, high, low);
462            resTemp += ((diff < 0) ? -diff : diff);
463        }
464        Dest = Op3 + resTemp;
465    '''
466    usada8Iop = InstObjParams("usada8", "Usada8", "RegRegRegRegOp",
467                              { "code": usada8Code,
468                                "predicate_test": predicateTest }, [])
469    header_output += RegRegRegRegOpDeclare.subst(usada8Iop)
470    decoder_output += RegRegRegRegOpConstructor.subst(usada8Iop)
471    exec_output += PredOpExecute.subst(usada8Iop)
472
473    bkptCode = 'return new PrefetchAbort(PC, ArmFault::DebugEvent);\n'
474    bkptIop = InstObjParams("bkpt", "BkptInst", "PredOp", bkptCode)
475    header_output += BasicDeclare.subst(bkptIop)
476    decoder_output += BasicConstructor.subst(bkptIop)
477    exec_output += BasicExecute.subst(bkptIop)
478
479    nopIop = InstObjParams("nop", "NopInst", "PredOp", \
480            { "code" : "", "predicate_test" : predicateTest },
481            ['IsNop'])
482    header_output += BasicDeclare.subst(nopIop)
483    decoder_output += BasicConstructor.subst(nopIop)
484    exec_output += PredOpExecute.subst(nopIop)
485
486    yieldIop = InstObjParams("yield", "YieldInst", "PredOp", \
487            { "code" : "", "predicate_test" : predicateTest })
488    header_output += BasicDeclare.subst(yieldIop)
489    decoder_output += BasicConstructor.subst(yieldIop)
490    exec_output += PredOpExecute.subst(yieldIop)
491
492    wfeCode = '''
493#if FULL_SYSTEM
494    if (SevMailbox)
495        SevMailbox = 0;
496    else
497        PseudoInst::quiesce(xc->tcBase());
498#endif
499    '''
500    wfeIop = InstObjParams("wfe", "WfeInst", "PredOp", \
501            { "code" : wfeCode, "predicate_test" : predicateTest },
502            ["IsNonSpeculative", "IsQuiesce", "IsSerializeAfter"])
503    header_output += BasicDeclare.subst(wfeIop)
504    decoder_output += BasicConstructor.subst(wfeIop)
505    exec_output += PredOpExecute.subst(wfeIop)
506
507    wfiCode = '''
508#if FULL_SYSTEM
509    PseudoInst::quiesce(xc->tcBase());
510#endif
511    '''
512    wfiIop = InstObjParams("wfi", "WfiInst", "PredOp", \
513            { "code" : wfiCode, "predicate_test" : predicateTest },
514            ["IsNonSpeculative", "IsQuiesce"])
515    header_output += BasicDeclare.subst(wfiIop)
516    decoder_output += BasicConstructor.subst(wfiIop)
517    exec_output += PredOpExecute.subst(wfiIop)
518
519    sevCode = '''
520    // Need a way for O3 to not scoreboard these accesses as pipe flushes.
521    System *sys = xc->tcBase()->getSystemPtr();
522    for (int x = 0; x < sys->numContexts(); x++) {
523        ThreadContext *oc = sys->getThreadContext(x);
524        oc->setMiscReg(MISCREG_SEV_MAILBOX, 1);
525    }
526    '''
527    sevIop = InstObjParams("sev", "SevInst", "PredOp", \
528            { "code" : sevCode, "predicate_test" : predicateTest },
529            ["IsNonSpeculative", "IsQuiesce", "IsSerializeAfter"])
530    header_output += BasicDeclare.subst(sevIop)
531    decoder_output += BasicConstructor.subst(sevIop)
532    exec_output += PredOpExecute.subst(sevIop)
533
534    itIop = InstObjParams("it", "ItInst", "PredOp", \
535            { "code" : "Itstate = machInst.newItstate;",
536              "predicate_test" : predicateTest },
537            ["IsNonSpeculative", "IsSerializeAfter"])
538    header_output += BasicDeclare.subst(itIop)
539    decoder_output += BasicConstructor.subst(itIop)
540    exec_output += PredOpExecute.subst(itIop)
541    unknownCode = '''
542#if FULL_SYSTEM
543            return new UndefinedInstruction;
544#else
545            return new UndefinedInstruction(machInst, true);
546#endif
547    '''
548    unknownIop = InstObjParams("unknown", "Unknown", "UnknownOp", \
549                               { "code": unknownCode,
550                                 "predicate_test": predicateTest })
551    header_output += BasicDeclare.subst(unknownIop)
552    decoder_output += BasicConstructor.subst(unknownIop)
553    exec_output += PredOpExecute.subst(unknownIop)
554
555    ubfxCode = '''
556        Dest = bits(Op1, imm2, imm1);
557    '''
558    ubfxIop = InstObjParams("ubfx", "Ubfx", "RegRegImmImmOp",
559                            { "code": ubfxCode,
560                              "predicate_test": predicateTest }, [])
561    header_output += RegRegImmImmOpDeclare.subst(ubfxIop)
562    decoder_output += RegRegImmImmOpConstructor.subst(ubfxIop)
563    exec_output += PredOpExecute.subst(ubfxIop)
564
565    sbfxCode = '''
566        int32_t resTemp = bits(Op1, imm2, imm1);
567        Dest = resTemp | -(resTemp & (1 << (imm2 - imm1)));
568    '''
569    sbfxIop = InstObjParams("sbfx", "Sbfx", "RegRegImmImmOp",
570                            { "code": sbfxCode,
571                              "predicate_test": predicateTest }, [])
572    header_output += RegRegImmImmOpDeclare.subst(sbfxIop)
573    decoder_output += RegRegImmImmOpConstructor.subst(sbfxIop)
574    exec_output += PredOpExecute.subst(sbfxIop)
575
576    bfcCode = '''
577        Dest = Op1 & ~(mask(imm2 - imm1 + 1) << imm1);
578    '''
579    bfcIop = InstObjParams("bfc", "Bfc", "RegRegImmImmOp",
580                           { "code": bfcCode,
581                             "predicate_test": predicateTest }, [])
582    header_output += RegRegImmImmOpDeclare.subst(bfcIop)
583    decoder_output += RegRegImmImmOpConstructor.subst(bfcIop)
584    exec_output += PredOpExecute.subst(bfcIop)
585
586    bfiCode = '''
587        uint32_t bitMask = (mask(imm2 - imm1 + 1) << imm1);
588        Dest = ((Op1 << imm1) & bitMask) | (Dest & ~bitMask);
589    '''
590    bfiIop = InstObjParams("bfi", "Bfi", "RegRegImmImmOp",
591                           { "code": bfiCode,
592                             "predicate_test": predicateTest }, [])
593    header_output += RegRegImmImmOpDeclare.subst(bfiIop)
594    decoder_output += RegRegImmImmOpConstructor.subst(bfiIop)
595    exec_output += PredOpExecute.subst(bfiIop)
596
597    mrc15code = '''
598    CPSR cpsr = Cpsr;
599    if (cpsr.mode == MODE_USER)
600#if FULL_SYSTEM
601        return new UndefinedInstruction;
602#else
603        return new UndefinedInstruction(false, mnemonic);
604#endif
605    Dest = MiscOp1;
606    '''
607
608    mrc15Iop = InstObjParams("mrc", "Mrc15", "RegRegOp",
609                             { "code": mrc15code,
610                               "predicate_test": predicateTest }, [])
611    header_output += RegRegOpDeclare.subst(mrc15Iop)
612    decoder_output += RegRegOpConstructor.subst(mrc15Iop)
613    exec_output += PredOpExecute.subst(mrc15Iop)
614
615
616    mcr15code = '''
617    CPSR cpsr = Cpsr;
618    if (cpsr.mode == MODE_USER)
619#if FULL_SYSTEM
620        return new UndefinedInstruction;
621#else
622        return new UndefinedInstruction(false, mnemonic);
623#endif
624    MiscDest = Op1;
625    '''
626    mcr15Iop = InstObjParams("mcr", "Mcr15", "RegRegOp",
627                             { "code": mcr15code,
628                               "predicate_test": predicateTest },
629                               ["IsSerializeAfter","IsNonSpeculative"])
630    header_output += RegRegOpDeclare.subst(mcr15Iop)
631    decoder_output += RegRegOpConstructor.subst(mcr15Iop)
632    exec_output += PredOpExecute.subst(mcr15Iop)
633
634    mrc15UserIop = InstObjParams("mrc", "Mrc15User", "RegRegOp",
635                                 { "code": "Dest = MiscOp1;",
636                                   "predicate_test": predicateTest }, [])
637    header_output += RegRegOpDeclare.subst(mrc15UserIop)
638    decoder_output += RegRegOpConstructor.subst(mrc15UserIop)
639    exec_output += PredOpExecute.subst(mrc15UserIop)
640
641    mcr15UserIop = InstObjParams("mcr", "Mcr15User", "RegRegOp",
642                                 { "code": "MiscDest = Op1",
643                                   "predicate_test": predicateTest },
644                                   ["IsSerializeAfter","IsNonSpeculative"])
645    header_output += RegRegOpDeclare.subst(mcr15UserIop)
646    decoder_output += RegRegOpConstructor.subst(mcr15UserIop)
647    exec_output += PredOpExecute.subst(mcr15UserIop)
648
649    enterxCode = '''
650        NextThumb = true;
651        NextJazelle = true;
652    '''
653    enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
654                              { "code": enterxCode,
655                                "predicate_test": predicateTest }, [])
656    header_output += BasicDeclare.subst(enterxIop)
657    decoder_output += BasicConstructor.subst(enterxIop)
658    exec_output += PredOpExecute.subst(enterxIop)
659
660    leavexCode = '''
661        NextThumb = true;
662        NextJazelle = false;
663    '''
664    leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
665                              { "code": leavexCode,
666                                "predicate_test": predicateTest }, [])
667    header_output += BasicDeclare.subst(leavexIop)
668    decoder_output += BasicConstructor.subst(leavexIop)
669    exec_output += PredOpExecute.subst(leavexIop)
670
671    setendCode = '''
672        CPSR cpsr = Cpsr;
673        cpsr.e = imm;
674        Cpsr = cpsr;
675    '''
676    setendIop = InstObjParams("setend", "Setend", "ImmOp",
677                              { "code": setendCode,
678                                "predicate_test": predicateTest },
679                              ["IsSerializeAfter","IsNonSpeculative"])
680    header_output += ImmOpDeclare.subst(setendIop)
681    decoder_output += ImmOpConstructor.subst(setendIop)
682    exec_output += PredOpExecute.subst(setendIop)
683
684    clrexCode = '''
685        unsigned memAccessFlags = Request::CLEAR_LL |
686            ArmISA::TLB::AlignWord | Request::LLSC;
687        fault = xc->read(0, (uint32_t&)Mem, memAccessFlags);
688    '''
689    clrexIop = InstObjParams("clrex", "Clrex","PredOp",
690                             { "code": clrexCode,
691                               "predicate_test": predicateTest },[])
692    header_output += ClrexDeclare.subst(clrexIop)
693    decoder_output += BasicConstructor.subst(clrexIop)
694    exec_output += PredOpExecute.subst(clrexIop)
695    exec_output += ClrexInitiateAcc.subst(clrexIop)
696    exec_output += ClrexCompleteAcc.subst(clrexIop)
697
698    isbCode = '''
699    '''
700    isbIop = InstObjParams("isb", "Isb", "PredOp",
701                             {"code": isbCode,
702                               "predicate_test": predicateTest}, ['IsSerializing'])
703    header_output += BasicDeclare.subst(isbIop)
704    decoder_output += BasicConstructor.subst(isbIop)
705    exec_output += PredOpExecute.subst(isbIop)
706
707    dsbCode = '''
708    '''
709    dsbIop = InstObjParams("dsb", "Dsb", "PredOp",
710                             {"code": dsbCode,
711                               "predicate_test": predicateTest},['IsMemBarrier'])
712    header_output += BasicDeclare.subst(dsbIop)
713    decoder_output += BasicConstructor.subst(dsbIop)
714    exec_output += PredOpExecute.subst(dsbIop)
715
716    dmbCode = '''
717    '''
718    dmbIop = InstObjParams("dmb", "Dmb", "PredOp",
719                             {"code": dmbCode,
720                               "predicate_test": predicateTest},['IsMemBarrier'])
721    header_output += BasicDeclare.subst(dmbIop)
722    decoder_output += BasicConstructor.subst(dmbIop)
723    exec_output += PredOpExecute.subst(dmbIop)
724
725    dbgCode = '''
726    '''
727    dbgIop = InstObjParams("dbg", "Dbg", "PredOp",
728                             {"code": dbgCode,
729                               "predicate_test": predicateTest})
730    header_output += BasicDeclare.subst(dbgIop)
731    decoder_output += BasicConstructor.subst(dbgIop)
732    exec_output += PredOpExecute.subst(dbgIop)
733
734    cpsCode = '''
735    uint32_t mode = bits(imm, 4, 0);
736    uint32_t f = bits(imm, 5);
737    uint32_t i = bits(imm, 6);
738    uint32_t a = bits(imm, 7);
739    bool setMode = bits(imm, 8);
740    bool enable = bits(imm, 9);
741    CPSR cpsr = Cpsr;
742    SCTLR sctlr = Sctlr;
743    if (cpsr.mode != MODE_USER) {
744        if (enable) {
745            if (f) cpsr.f = 0;
746            if (i) cpsr.i = 0;
747            if (a) cpsr.a = 0;
748        } else {
749            if (f && !sctlr.nmfi) cpsr.f = 1;
750            if (i) cpsr.i = 1;
751            if (a) cpsr.a = 1;
752        }
753        if (setMode) {
754            cpsr.mode = mode;
755        }
756    }
757    Cpsr = cpsr;
758    '''
759    cpsIop = InstObjParams("cps", "Cps", "ImmOp",
760                           { "code": cpsCode,
761                             "predicate_test": predicateTest },
762                           ["IsSerializeAfter","IsNonSpeculative"])
763    header_output += ImmOpDeclare.subst(cpsIop)
764    decoder_output += ImmOpConstructor.subst(cpsIop)
765    exec_output += PredOpExecute.subst(cpsIop)
766}};
767