misc.isa revision 7226
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        uint32_t newCpsr =
81            cpsrWriteByInstr(Cpsr | CondCodes, Op1, byteMask, false);
82        Cpsr = ~CondCodesMask & newCpsr;
83        CondCodes = CondCodesMask & newCpsr;
84    '''
85    msrCpsrRegIop = InstObjParams("msr", "MsrCpsrReg", "MsrRegOp",
86                                  { "code": msrCpsrRegCode,
87                                    "predicate_test": predicateTest }, [])
88    header_output += MsrRegDeclare.subst(msrCpsrRegIop)
89    decoder_output += MsrRegConstructor.subst(msrCpsrRegIop)
90    exec_output += PredOpExecute.subst(msrCpsrRegIop)
91
92    msrSpsrRegCode = "Spsr = spsrWriteByInstr(Spsr, Op1, byteMask, false);"
93    msrSpsrRegIop = InstObjParams("msr", "MsrSpsrReg", "MsrRegOp",
94                                  { "code": msrSpsrRegCode,
95                                    "predicate_test": predicateTest }, [])
96    header_output += MsrRegDeclare.subst(msrSpsrRegIop)
97    decoder_output += MsrRegConstructor.subst(msrSpsrRegIop)
98    exec_output += PredOpExecute.subst(msrSpsrRegIop)
99
100    msrCpsrImmCode = '''
101        uint32_t newCpsr =
102            cpsrWriteByInstr(Cpsr | CondCodes, imm, byteMask, false);
103        Cpsr = ~CondCodesMask & newCpsr;
104        CondCodes = CondCodesMask & newCpsr;
105    '''
106    msrCpsrImmIop = InstObjParams("msr", "MsrCpsrImm", "MsrImmOp",
107                                  { "code": msrCpsrImmCode,
108                                    "predicate_test": predicateTest }, [])
109    header_output += MsrImmDeclare.subst(msrCpsrImmIop)
110    decoder_output += MsrImmConstructor.subst(msrCpsrImmIop)
111    exec_output += PredOpExecute.subst(msrCpsrImmIop)
112
113    msrSpsrImmCode = "Spsr = spsrWriteByInstr(Spsr, imm, byteMask, false);"
114    msrSpsrImmIop = InstObjParams("msr", "MsrSpsrImm", "MsrImmOp",
115                                  { "code": msrSpsrImmCode,
116                                    "predicate_test": predicateTest }, [])
117    header_output += MsrImmDeclare.subst(msrSpsrImmIop)
118    decoder_output += MsrImmConstructor.subst(msrSpsrImmIop)
119    exec_output += PredOpExecute.subst(msrSpsrImmIop)
120
121    revCode = '''
122    uint32_t val = Op1;
123    Dest = swap_byte(val);
124    '''
125    revIop = InstObjParams("rev", "Rev", "RevOp",
126                           { "code": revCode,
127                             "predicate_test": predicateTest }, [])
128    header_output += RevOpDeclare.subst(revIop)
129    decoder_output += RevOpConstructor.subst(revIop)
130    exec_output += PredOpExecute.subst(revIop)
131
132    rev16Code = '''
133    uint32_t val = Op1;
134    Dest = (bits(val, 15, 8) << 0) |
135           (bits(val, 7, 0) << 8) |
136           (bits(val, 31, 24) << 16) |
137           (bits(val, 23, 16) << 24);
138    '''
139    rev16Iop = InstObjParams("rev16", "Rev16", "RevOp",
140                             { "code": rev16Code,
141                               "predicate_test": predicateTest }, [])
142    header_output += RevOpDeclare.subst(rev16Iop)
143    decoder_output += RevOpConstructor.subst(rev16Iop)
144    exec_output += PredOpExecute.subst(rev16Iop)
145
146    revshCode = '''
147    uint16_t val = Op1;
148    Dest = sext<16>(swap_byte(val));
149    '''
150    revshIop = InstObjParams("revsh", "Revsh", "RevOp",
151                             { "code": revshCode,
152                               "predicate_test": predicateTest }, [])
153    header_output += RevOpDeclare.subst(revshIop)
154    decoder_output += RevOpConstructor.subst(revshIop)
155    exec_output += PredOpExecute.subst(revshIop)
156
157    ssatCode = '''
158        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
159        int32_t res;
160        if (satInt(res, operand, satImm))
161            CondCodes = CondCodes | (1 << 27);
162        else
163            CondCodes = CondCodes;
164        Dest = res;
165    '''
166    ssatIop = InstObjParams("ssat", "Ssat", "SatShiftOp",
167                            { "code": ssatCode,
168                              "predicate_test": predicateTest }, [])
169    header_output += SatShiftOpDeclare.subst(ssatIop)
170    decoder_output += SatShiftOpConstructor.subst(ssatIop)
171    exec_output += PredOpExecute.subst(ssatIop)
172
173    usatCode = '''
174        int32_t operand = shift_rm_imm(Op1, shiftAmt, shiftType, 0);
175        int32_t res;
176        if (uSatInt(res, operand, satImm))
177            CondCodes = CondCodes | (1 << 27);
178        else
179            CondCodes = CondCodes;
180        Dest = res;
181    '''
182    usatIop = InstObjParams("usat", "Usat", "SatShiftOp",
183                            { "code": usatCode,
184                              "predicate_test": predicateTest }, [])
185    header_output += SatShiftOpDeclare.subst(usatIop)
186    decoder_output += SatShiftOpConstructor.subst(usatIop)
187    exec_output += PredOpExecute.subst(usatIop)
188
189    ssat16Code = '''
190        int32_t res;
191        uint32_t resTemp = 0;
192        CondCodes = CondCodes;
193        int32_t argLow = sext<16>(bits(Op1, 15, 0));
194        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
195        if (satInt(res, argLow, satImm))
196            CondCodes = CondCodes | (1 << 27);
197        replaceBits(resTemp, 15, 0, res);
198        if (satInt(res, argHigh, satImm))
199            CondCodes = CondCodes | (1 << 27);
200        replaceBits(resTemp, 31, 16, res);
201        Dest = resTemp;
202    '''
203    ssat16Iop = InstObjParams("ssat16", "Ssat16", "SatOp",
204                              { "code": ssat16Code,
205                                "predicate_test": predicateTest }, [])
206    header_output += SatOpDeclare.subst(ssat16Iop)
207    decoder_output += SatOpConstructor.subst(ssat16Iop)
208    exec_output += PredOpExecute.subst(ssat16Iop)
209
210    usat16Code = '''
211        int32_t res;
212        uint32_t resTemp = 0;
213        CondCodes = CondCodes;
214        int32_t argLow = sext<16>(bits(Op1, 15, 0));
215        int32_t argHigh = sext<16>(bits(Op1, 31, 16));
216        if (uSatInt(res, argLow, satImm))
217            CondCodes = CondCodes | (1 << 27);
218        replaceBits(resTemp, 15, 0, res);
219        if (uSatInt(res, argHigh, satImm))
220            CondCodes = CondCodes | (1 << 27);
221        replaceBits(resTemp, 31, 16, res);
222        Dest = resTemp;
223    '''
224    usat16Iop = InstObjParams("usat16", "Usat16", "SatOp",
225                              { "code": usat16Code,
226                                "predicate_test": predicateTest }, [])
227    header_output += SatOpDeclare.subst(usat16Iop)
228    decoder_output += SatOpConstructor.subst(usat16Iop)
229    exec_output += PredOpExecute.subst(usat16Iop)
230}};
231