misc.isa revision 7408
1// -*- mode:c++ -*-
2
3// Copyright (c) 2010 ARM Limited
4// All rights reserved
5//
6// The license below extends only to copyright in the software and shall
7// not be construed as granting a license to any other intellectual
8// property including but not limited to intellectual property relating
9// to a hardware implementation of the functionality of the software
10// licensed hereunder.  You may use the software subject to the license
11// terms below provided that you ensure that this notice is replicated
12// unmodified and in its entirety in all distributions of the software,
13// modified or unmodified, in source code or in binary form.
14//
15// Redistribution and use in source and binary forms, with or without
16// modification, are permitted provided that the following conditions are
17// met: redistributions of source code must retain the above copyright
18// notice, this list of conditions and the following disclaimer;
19// redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution;
22// neither the name of the copyright holders nor the names of its
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Authors: Gabe Black
39
40let {{
41
42    svcCode = '''
43#if FULL_SYSTEM
44    fault = new SupervisorCall;
45#else
46    fault = new SupervisorCall(machInst);
47#endif
48    '''
49
50    svcIop = InstObjParams("svc", "Svc", "PredOp",
51                           { "code": svcCode,
52                             "predicate_test": predicateTest }, ["IsSyscall"])
53    header_output = BasicDeclare.subst(svcIop)
54    decoder_output = BasicConstructor.subst(svcIop)
55    exec_output = PredOpExecute.subst(svcIop)
56
57}};
58
59let {{
60
61    header_output = decoder_output = exec_output = ""
62
63    mrsCpsrCode = "Dest = (Cpsr | CondCodes) & 0xF8FF03DF"
64    mrsCpsrIop = InstObjParams("mrs", "MrsCpsr", "MrsOp",
65                               { "code": mrsCpsrCode,
66                                 "predicate_test": predicateTest }, [])
67    header_output += MrsDeclare.subst(mrsCpsrIop)
68    decoder_output += MrsConstructor.subst(mrsCpsrIop)
69    exec_output += PredOpExecute.subst(mrsCpsrIop)
70
71    mrsSpsrCode = "Dest = Spsr"
72    mrsSpsrIop = InstObjParams("mrs", "MrsSpsr", "MrsOp",
73                               { "code": mrsSpsrCode,
74                                 "predicate_test": predicateTest }, [])
75    header_output += MrsDeclare.subst(mrsSpsrIop)
76    decoder_output += MrsConstructor.subst(mrsSpsrIop)
77    exec_output += PredOpExecute.subst(mrsSpsrIop)
78
79    msrCpsrRegCode = '''
80        SCTLR sctlr = Sctlr;
81        uint32_t newCpsr =
82            cpsrWriteByInstr(Cpsr | CondCodes, Op1, byteMask, false, sctlr.nmfi);
83        Cpsr = ~CondCodesMask & newCpsr;
84        CondCodes = CondCodesMask & newCpsr;
85    '''
86    msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp",
87                                  { "code": msrCpsrRegCode,
88                                    "predicate_test": predicateTest }, [])
89    header_output += MsrRegDeclare.subst(msrCpsrRegIop)
90    decoder_output += MsrRegConstructor.subst(msrCpsrRegIop)
91    exec_output += PredOpExecute.subst(msrCpsrRegIop)
92
93    msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);"
94    msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp",
95                                  { "code": msrSpsrRegCode,
96                                    "predicate_test": predicateTest }, [])
97    header_output += MsrRegDeclare.subst(msrSpsrRegIop)
98    decoder_output += MsrRegConstructor.subst(msrSpsrRegIop)
99    exec_output += PredOpExecute.subst(msrSpsrRegIop)
100
101    msrCpsrImmCode = '''
102        SCTLR sctlr = Sctlr;
103        uint32_t newCpsr =
104            cpsrWriteByInstr(Cpsr | CondCodes, imm, byteMask, false, sctlr.nmfi);
105        Cpsr = ~CondCodesMask & newCpsr;
106        CondCodes = CondCodesMask & newCpsr;
107    '''
108    msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp",
109                                  { "code": msrCpsrImmCode,
110                                    "predicate_test": predicateTest }, [])
111    header_output += MsrImmDeclare.subst(msrCpsrImmIop)
112    decoder_output += MsrImmConstructor.subst(msrCpsrImmIop)
113    exec_output += PredOpExecute.subst(msrCpsrImmIop)
114
115    msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);"
116    msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp",
117                                  { "code": msrSpsrImmCode,
118                                    "predicate_test": predicateTest }, [])
119    header_output += MsrImmDeclare.subst(msrSpsrImmIop)
120    decoder_output += MsrImmConstructor.subst(msrSpsrImmIop)
121    exec_output += PredOpExecute.subst(msrSpsrImmIop)
122
123    revCode = '''
124    uint32_t val = Op1;
125    Dest = swap_byte(val);
126    '''
127    revIop = InstObjParams("rev", "Rev", "RegRegOp",
128                           { "code": revCode,
129                             "predicate_test": predicateTest }, [])
130    header_output += RegRegOpDeclare.subst(revIop)
131    decoder_output += RegRegOpConstructor.subst(revIop)
132    exec_output += PredOpExecute.subst(revIop)
133
134    rev16Code = '''
135    uint32_t val = Op1;
136    Dest = (bits(val, 15, 8) << 0) |
137           (bits(val, 7, 0) << 8) |
138           (bits(val, 31, 24) << 16) |
139           (bits(val, 23, 16) << 24);
140    '''
141    rev16Iop = InstObjParams("rev16", "Rev16", "RegRegOp",
142                             { "code": rev16Code,
143                               "predicate_test": predicateTest }, [])
144    header_output += RegRegOpDeclare.subst(rev16Iop)
145    decoder_output += RegRegOpConstructor.subst(rev16Iop)
146    exec_output += PredOpExecute.subst(rev16Iop)
147
148    revshCode = '''
149    uint16_t val = Op1;
150    Dest = sext<16>(swap_byte(val));
151    '''
152    revshIop = InstObjParams("revsh", "Revsh", "RegRegOp",
153                             { "code": revshCode,
154                               "predicate_test": predicateTest }, [])
155    header_output += RegRegOpDeclare.subst(revshIop)
156    decoder_output += RegRegOpConstructor.subst(revshIop)
157    exec_output += PredOpExecute.subst(revshIop)
158
159    rbitCode = '''
160    uint8_t *opBytes = (uint8_t *)&Op1;
161    uint32_t resTemp;
162    uint8_t *destBytes = (uint8_t *)&resTemp;
163    // This reverses the bytes and bits of the input, or so says the
164    // internet.
165    for (int i = 0; i < 4; i++) {
166        uint32_t temp = opBytes[i];
167        temp = (temp * 0x0802 & 0x22110) | (temp * 0x8020 & 0x88440);
168        destBytes[3 - i] = (temp * 0x10101) >> 16;
169    }
170    Dest = resTemp;
171    '''
172    rbitIop = InstObjParams("rbit", "Rbit", "RegRegOp",
173                            { "code": rbitCode,
174                              "predicate_test": predicateTest }, [])
175    header_output += RegRegOpDeclare.subst(rbitIop)
176    decoder_output += RegRegOpConstructor.subst(rbitIop)
177    exec_output += PredOpExecute.subst(rbitIop)
178
179    clzCode = '''
180        Dest = (Op1 == 0) ? 32 : (31 - findMsbSet(Op1));
181    '''
182    clzIop = InstObjParams("clz", "Clz", "RegRegOp",
183                           { "code": clzCode,
184                             "predicate_test": predicateTest }, [])
185    header_output += RegRegOpDeclare.subst(clzIop)
186    decoder_output += RegRegOpConstructor.subst(clzIop)
187    exec_output += PredOpExecute.subst(clzIop)
188
189    ssatCode = '''
190        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
191        int32_t res;
192        if (satInt(res, operand, imm))
193            CondCodes = CondCodes | (1 << 27);
194        else
195            CondCodes = CondCodes;
196        Dest = res;
197    '''
198    ssatIop = InstObjParams("ssat", "Ssat", "RegImmRegShiftOp",
199                            { "code": ssatCode,
200                              "predicate_test": predicateTest }, [])
201    header_output += RegImmRegShiftOpDeclare.subst(ssatIop)
202    decoder_output += RegImmRegShiftOpConstructor.subst(ssatIop)
203    exec_output += PredOpExecute.subst(ssatIop)
204
205    usatCode = '''
206        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
207        int32_t res;
208        if (uSatInt(res, operand, imm))
209            CondCodes = CondCodes | (1 << 27);
210        else
211            CondCodes = CondCodes;
212        Dest = res;
213    '''
214    usatIop = InstObjParams("usat", "Usat", "RegImmRegShiftOp",
215                            { "code": usatCode,
216                              "predicate_test": predicateTest }, [])
217    header_output += RegImmRegShiftOpDeclare.subst(usatIop)
218    decoder_output += RegImmRegShiftOpConstructor.subst(usatIop)
219    exec_output += PredOpExecute.subst(usatIop)
220
221    ssat16Code = '''
222        int32_t res;
223        uint32_t resTemp = 0;
224        CondCodes = CondCodes;
225        int32_t argLow = sext<16>(bits(Op1, 15, 0));
226        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
227        if (satInt(res, argLow, imm))
228            CondCodes = CondCodes | (1 << 27);
229        replaceBits(resTemp, 15, 0, res);
230        if (satInt(res, argHigh, imm))
231            CondCodes = CondCodes | (1 << 27);
232        replaceBits(resTemp, 31, 16, res);
233        Dest = resTemp;
234    '''
235    ssat16Iop = InstObjParams("ssat16", "Ssat16", "RegImmRegOp",
236                              { "code": ssat16Code,
237                                "predicate_test": predicateTest }, [])
238    header_output += RegImmRegOpDeclare.subst(ssat16Iop)
239    decoder_output += RegImmRegOpConstructor.subst(ssat16Iop)
240    exec_output += PredOpExecute.subst(ssat16Iop)
241
242    usat16Code = '''
243        int32_t res;
244        uint32_t resTemp = 0;
245        CondCodes = CondCodes;
246        int32_t argLow = sext<16>(bits(Op1, 15, 0));
247        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
248        if (uSatInt(res, argLow, imm))
249            CondCodes = CondCodes | (1 << 27);
250        replaceBits(resTemp, 15, 0, res);
251        if (uSatInt(res, argHigh, imm))
252            CondCodes = CondCodes | (1 << 27);
253        replaceBits(resTemp, 31, 16, res);
254        Dest = resTemp;
255    '''
256    usat16Iop = InstObjParams("usat16", "Usat16", "RegImmRegOp",
257                              { "code": usat16Code,
258                                "predicate_test": predicateTest }, [])
259    header_output += RegImmRegOpDeclare.subst(usat16Iop)
260    decoder_output += RegImmRegOpConstructor.subst(usat16Iop)
261    exec_output += PredOpExecute.subst(usat16Iop)
262
263    sxtbIop = InstObjParams("sxtb", "Sxtb", "RegImmRegOp",
264                            { "code":
265                              "Dest = sext<8>((uint8_t)(Op1.ud >> imm));",
266                              "predicate_test": predicateTest }, [])
267    header_output += RegImmRegOpDeclare.subst(sxtbIop)
268    decoder_output += RegImmRegOpConstructor.subst(sxtbIop)
269    exec_output += PredOpExecute.subst(sxtbIop)
270
271    sxtabIop = InstObjParams("sxtab", "Sxtab", "RegRegRegImmOp",
272                             { "code":
273                               '''
274                                   Dest = sext<8>((uint8_t)(Op2.ud >> imm)) +
275                                          Op1;
276                               ''',
277                               "predicate_test": predicateTest }, [])
278    header_output += RegRegRegImmOpDeclare.subst(sxtabIop)
279    decoder_output += RegRegRegImmOpConstructor.subst(sxtabIop)
280    exec_output += PredOpExecute.subst(sxtabIop)
281
282    sxtb16Code = '''
283    uint32_t resTemp = 0;
284    replaceBits(resTemp, 15, 0, sext<8>(bits(Op1, imm + 7, imm)));
285    replaceBits(resTemp, 31, 16,
286                sext<8>(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
287    Dest = resTemp;
288    '''
289    sxtb16Iop = InstObjParams("sxtb16", "Sxtb16", "RegImmRegOp",
290                              { "code": sxtb16Code,
291                                "predicate_test": predicateTest }, [])
292    header_output += RegImmRegOpDeclare.subst(sxtb16Iop)
293    decoder_output += RegImmRegOpConstructor.subst(sxtb16Iop)
294    exec_output += PredOpExecute.subst(sxtb16Iop)
295
296    sxtab16Code = '''
297    uint32_t resTemp = 0;
298    replaceBits(resTemp, 15, 0, sext<8>(bits(Op2, imm + 7, imm)) +
299                                        bits(Op1, 15, 0));
300    replaceBits(resTemp, 31, 16,
301                sext<8>(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
302                bits(Op1, 31, 16));
303    Dest = resTemp;
304    '''
305    sxtab16Iop = InstObjParams("sxtab16", "Sxtab16", "RegRegRegImmOp",
306                               { "code": sxtab16Code,
307                                 "predicate_test": predicateTest }, [])
308    header_output += RegRegRegImmOpDeclare.subst(sxtab16Iop)
309    decoder_output += RegRegRegImmOpConstructor.subst(sxtab16Iop)
310    exec_output += PredOpExecute.subst(sxtab16Iop)
311
312    sxthCode = '''
313    uint64_t rotated = (uint32_t)Op1;
314    rotated = (rotated | (rotated << 32)) >> imm;
315    Dest = sext<16>((uint16_t)rotated);
316    '''
317    sxthIop = InstObjParams("sxth", "Sxth", "RegImmRegOp",
318                              { "code": sxthCode,
319                                "predicate_test": predicateTest }, [])
320    header_output += RegImmRegOpDeclare.subst(sxthIop)
321    decoder_output += RegImmRegOpConstructor.subst(sxthIop)
322    exec_output += PredOpExecute.subst(sxthIop)
323
324    sxtahCode = '''
325    uint64_t rotated = (uint32_t)Op2;
326    rotated = (rotated | (rotated << 32)) >> imm;
327    Dest = sext<16>((uint16_t)rotated) + Op1;
328    '''
329    sxtahIop = InstObjParams("sxtah", "Sxtah", "RegRegRegImmOp",
330                             { "code": sxtahCode,
331                               "predicate_test": predicateTest }, [])
332    header_output += RegRegRegImmOpDeclare.subst(sxtahIop)
333    decoder_output += RegRegRegImmOpConstructor.subst(sxtahIop)
334    exec_output += PredOpExecute.subst(sxtahIop)
335
336    uxtbIop = InstObjParams("uxtb", "Uxtb", "RegImmRegOp",
337                            { "code": "Dest = (uint8_t)(Op1.ud >> imm);",
338                              "predicate_test": predicateTest }, [])
339    header_output += RegImmRegOpDeclare.subst(uxtbIop)
340    decoder_output += RegImmRegOpConstructor.subst(uxtbIop)
341    exec_output += PredOpExecute.subst(uxtbIop)
342
343    uxtabIop = InstObjParams("uxtab", "Uxtab", "RegRegRegImmOp",
344                             { "code":
345                               "Dest = (uint8_t)(Op2.ud >> imm) + Op1;",
346                               "predicate_test": predicateTest }, [])
347    header_output += RegRegRegImmOpDeclare.subst(uxtabIop)
348    decoder_output += RegRegRegImmOpConstructor.subst(uxtabIop)
349    exec_output += PredOpExecute.subst(uxtabIop)
350
351    uxtb16Code = '''
352    uint32_t resTemp = 0;
353    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op1, imm + 7, imm)));
354    replaceBits(resTemp, 31, 16,
355                (uint8_t)(bits(Op1, (imm + 23) % 32, (imm + 16) % 32)));
356    Dest = resTemp;
357    '''
358    uxtb16Iop = InstObjParams("uxtb16", "Uxtb16", "RegImmRegOp",
359                              { "code": uxtb16Code,
360                                "predicate_test": predicateTest }, [])
361    header_output += RegImmRegOpDeclare.subst(uxtb16Iop)
362    decoder_output += RegImmRegOpConstructor.subst(uxtb16Iop)
363    exec_output += PredOpExecute.subst(uxtb16Iop)
364
365    uxtab16Code = '''
366    uint32_t resTemp = 0;
367    replaceBits(resTemp, 15, 0, (uint8_t)(bits(Op2, imm + 7, imm)) +
368                                        bits(Op1, 15, 0));
369    replaceBits(resTemp, 31, 16,
370                (uint8_t)(bits(Op2, (imm + 23) % 32, (imm + 16) % 32)) +
371                bits(Op1, 31, 16));
372    Dest = resTemp;
373    '''
374    uxtab16Iop = InstObjParams("uxtab16", "Uxtab16", "RegRegRegImmOp",
375                               { "code": uxtab16Code,
376                                 "predicate_test": predicateTest }, [])
377    header_output += RegRegRegImmOpDeclare.subst(uxtab16Iop)
378    decoder_output += RegRegRegImmOpConstructor.subst(uxtab16Iop)
379    exec_output += PredOpExecute.subst(uxtab16Iop)
380
381    uxthCode = '''
382    uint64_t rotated = (uint32_t)Op1;
383    rotated = (rotated | (rotated << 32)) >> imm;
384    Dest = (uint16_t)rotated;
385    '''
386    uxthIop = InstObjParams("uxth", "Uxth", "RegImmRegOp",
387                              { "code": uxthCode,
388                                "predicate_test": predicateTest }, [])
389    header_output += RegImmRegOpDeclare.subst(uxthIop)
390    decoder_output += RegImmRegOpConstructor.subst(uxthIop)
391    exec_output += PredOpExecute.subst(uxthIop)
392
393    uxtahCode = '''
394    uint64_t rotated = (uint32_t)Op2;
395    rotated = (rotated | (rotated << 32)) >> imm;
396    Dest = (uint16_t)rotated + Op1;
397    '''
398    uxtahIop = InstObjParams("uxtah", "Uxtah", "RegRegRegImmOp",
399                             { "code": uxtahCode,
400                               "predicate_test": predicateTest }, [])
401    header_output += RegRegRegImmOpDeclare.subst(uxtahIop)
402    decoder_output += RegRegRegImmOpConstructor.subst(uxtahIop)
403    exec_output += PredOpExecute.subst(uxtahIop)
404
405    selCode = '''
406        uint32_t resTemp = 0;
407        for (unsigned i = 0; i < 4; i++) {
408            int low = i * 8;
409            int high = low + 7;
410            replaceBits(resTemp, high, low,
411                        bits(CondCodes, 16 + i) ?
412                            bits(Op1, high, low) : bits(Op2, high, low));
413        }
414        Dest = resTemp;
415    '''
416    selIop = InstObjParams("sel", "Sel", "RegRegRegOp",
417                           { "code": selCode,
418                             "predicate_test": predicateTest }, [])
419    header_output += RegRegRegOpDeclare.subst(selIop)
420    decoder_output += RegRegRegOpConstructor.subst(selIop)
421    exec_output += PredOpExecute.subst(selIop)
422
423    usad8Code = '''
424        uint32_t resTemp = 0;
425        for (unsigned i = 0; i < 4; i++) {
426            int low = i * 8;
427            int high = low + 7;
428            int32_t diff = bits(Op1, high, low) -
429                           bits(Op2, high, low);
430            resTemp += ((diff < 0) ? -diff : diff);
431        }
432        Dest = resTemp;
433    '''
434    usad8Iop = InstObjParams("usad8", "Usad8", "RegRegRegOp",
435                             { "code": usad8Code,
436                               "predicate_test": predicateTest }, [])
437    header_output += RegRegRegOpDeclare.subst(usad8Iop)
438    decoder_output += RegRegRegOpConstructor.subst(usad8Iop)
439    exec_output += PredOpExecute.subst(usad8Iop)
440
441    usada8Code = '''
442        uint32_t resTemp = 0;
443        for (unsigned i = 0; i < 4; i++) {
444            int low = i * 8;
445            int high = low + 7;
446            int32_t diff = bits(Op1, high, low) -
447                           bits(Op2, high, low);
448            resTemp += ((diff < 0) ? -diff : diff);
449        }
450        Dest = Op3 + resTemp;
451    '''
452    usada8Iop = InstObjParams("usada8", "Usada8", "RegRegRegRegOp",
453                              { "code": usada8Code,
454                                "predicate_test": predicateTest }, [])
455    header_output += RegRegRegRegOpDeclare.subst(usada8Iop)
456    decoder_output += RegRegRegRegOpConstructor.subst(usada8Iop)
457    exec_output += PredOpExecute.subst(usada8Iop)
458
459    nopIop = InstObjParams("nop", "NopInst", "PredOp", \
460            { "code" : "", "predicate_test" : predicateTest })
461    header_output += BasicDeclare.subst(nopIop)
462    decoder_output += BasicConstructor.subst(nopIop)
463    exec_output += PredOpExecute.subst(nopIop)
464
465    itIop = InstObjParams("it", "ItInst", "PredOp", \
466            { "code" : "Itstate = machInst.newItstate;",
467              "predicate_test" : predicateTest })
468    header_output += BasicDeclare.subst(itIop)
469    decoder_output += BasicConstructor.subst(itIop)
470    exec_output += PredOpExecute.subst(itIop)
471
472    ubfxCode = '''
473        Dest = bits(Op1, imm2, imm1);
474    '''
475    ubfxIop = InstObjParams("ubfx", "Ubfx", "RegRegImmImmOp",
476                            { "code": ubfxCode,
477                              "predicate_test": predicateTest }, [])
478    header_output += RegRegImmImmOpDeclare.subst(ubfxIop)
479    decoder_output += RegRegImmImmOpConstructor.subst(ubfxIop)
480    exec_output += PredOpExecute.subst(ubfxIop)
481
482    sbfxCode = '''
483        int32_t resTemp = bits(Op1, imm2, imm1);
484        Dest = resTemp | -(resTemp & (1 << (imm2 - imm1)));
485    '''
486    sbfxIop = InstObjParams("sbfx", "Sbfx", "RegRegImmImmOp",
487                            { "code": sbfxCode,
488                              "predicate_test": predicateTest }, [])
489    header_output += RegRegImmImmOpDeclare.subst(sbfxIop)
490    decoder_output += RegRegImmImmOpConstructor.subst(sbfxIop)
491    exec_output += PredOpExecute.subst(sbfxIop)
492
493    bfcCode = '''
494        Dest = Op1 & ~(mask(imm2 - imm1 + 1) << imm1);
495    '''
496    bfcIop = InstObjParams("bfc", "Bfc", "RegRegImmImmOp",
497                           { "code": bfcCode,
498                             "predicate_test": predicateTest }, [])
499    header_output += RegRegImmImmOpDeclare.subst(bfcIop)
500    decoder_output += RegRegImmImmOpConstructor.subst(bfcIop)
501    exec_output += PredOpExecute.subst(bfcIop)
502
503    bfiCode = '''
504        uint32_t bitMask = (mask(imm2 - imm1 + 1) << imm1);
505        Dest = ((Op1 << imm1) & bitMask) | (Dest & ~bitMask);
506    '''
507    bfiIop = InstObjParams("bfi", "Bfi", "RegRegImmImmOp",
508                           { "code": bfiCode,
509                             "predicate_test": predicateTest }, [])
510    header_output += RegRegImmImmOpDeclare.subst(bfiIop)
511    decoder_output += RegRegImmImmOpConstructor.subst(bfiIop)
512    exec_output += PredOpExecute.subst(bfiIop)
513
514    mrc15code = '''
515    CPSR cpsr = Cpsr;
516    if (cpsr.mode == MODE_USER)
517#if FULL_SYSTEM
518        return new UndefinedInstruction;
519#else
520        return new UndefinedInstruction(false, mnemonic);
521#endif
522    Dest = MiscOp1;
523    '''
524
525    mrc15Iop = InstObjParams("mrc", "Mrc15", "RegRegOp",
526                             { "code": mrc15code,
527                               "predicate_test": predicateTest }, [])
528    header_output += RegRegOpDeclare.subst(mrc15Iop)
529    decoder_output += RegRegOpConstructor.subst(mrc15Iop)
530    exec_output += PredOpExecute.subst(mrc15Iop)
531
532
533    mcr15code = '''
534    CPSR cpsr = Cpsr;
535    if (cpsr.mode == MODE_USER)
536#if FULL_SYSTEM
537        return new UndefinedInstruction;
538#else
539        return new UndefinedInstruction(false, mnemonic);
540#endif
541    MiscDest = Op1;
542    '''
543    mcr15Iop = InstObjParams("mcr", "Mcr15", "RegRegOp",
544                             { "code": mcr15code,
545                               "predicate_test": predicateTest }, [])
546    header_output += RegRegOpDeclare.subst(mcr15Iop)
547    decoder_output += RegRegOpConstructor.subst(mcr15Iop)
548    exec_output += PredOpExecute.subst(mcr15Iop)
549
550    enterxCode = '''
551        FNPC = NPC | (1ULL << PcJBitShift) | (1ULL << PcTBitShift);
552    '''
553    enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
554                              { "code": enterxCode,
555                                "predicate_test": predicateTest }, [])
556    header_output += BasicDeclare.subst(enterxIop)
557    decoder_output += BasicConstructor.subst(enterxIop)
558    exec_output += PredOpExecute.subst(enterxIop)
559
560    leavexCode = '''
561        FNPC = (NPC & ~(1ULL << PcJBitShift)) | (1ULL << PcTBitShift);
562    '''
563    leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
564                              { "code": leavexCode,
565                                "predicate_test": predicateTest }, [])
566    header_output += BasicDeclare.subst(leavexIop)
567    decoder_output += BasicConstructor.subst(leavexIop)
568    exec_output += PredOpExecute.subst(leavexIop)
569
570    setendCode = '''
571        CPSR cpsr = Cpsr;
572        cpsr.e = imm;
573        Cpsr = cpsr;
574    '''
575    setendIop = InstObjParams("setend", "Setend", "ImmOp",
576                              { "code": setendCode,
577                                "predicate_test": predicateTest }, [])
578    header_output += ImmOpDeclare.subst(setendIop)
579    decoder_output += ImmOpConstructor.subst(setendIop)
580    exec_output += PredOpExecute.subst(setendIop)
581
582    cpsCode = '''
583    uint32_t mode = bits(imm, 4, 0);
584    uint32_t f = bits(imm, 5);
585    uint32_t i = bits(imm, 6);
586    uint32_t a = bits(imm, 7);
587    bool setMode = bits(imm, 8);
588    bool enable = bits(imm, 9);
589    CPSR cpsr = Cpsr;
590    SCTLR sctlr = Sctlr;
591    if (cpsr.mode != MODE_USER) {
592        if (enable) {
593            if (f) cpsr.f = 0;
594            if (i) cpsr.i = 0;
595            if (a) cpsr.a = 0;
596        } else {
597            if (f && !sctlr.nmfi) cpsr.f = 1;
598            if (i) cpsr.i = 1;
599            if (a) cpsr.a = 1;
600        }
601        if (setMode) {
602            cpsr.mode = mode;
603        }
604    }
605    Cpsr = cpsr;
606    '''
607    cpsIop = InstObjParams("cps", "Cps", "ImmOp",
608                           { "code": cpsCode,
609                             "predicate_test": predicateTest }, [])
610    header_output += ImmOpDeclare.subst(cpsIop)
611    decoder_output += ImmOpConstructor.subst(cpsIop)
612    exec_output += PredOpExecute.subst(cpsIop)
613}};
614