misc.cc (7409:1ff897327905) misc.cc (7426:5da64155a605)
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Gabe Black
38 */
39
40#include "arch/arm/insts/misc.hh"
41
42std::string
43MrsOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
44{
45 std::stringstream ss;
46 printMnemonic(ss);
47 printReg(ss, dest);
48 ss << ", ";
49 bool foundPsr = false;
50 for (unsigned i = 0; i < numSrcRegs(); i++) {
51 int idx = srcRegIdx(i);
52 if (idx < Ctrl_Base_DepTag) {
53 continue;
54 }
55 idx -= Ctrl_Base_DepTag;
56 if (idx == MISCREG_CPSR) {
57 ss << "cpsr";
58 foundPsr = true;
59 break;
60 }
61 if (idx == MISCREG_SPSR) {
62 ss << "spsr";
63 foundPsr = true;
64 break;
65 }
66 }
67 if (!foundPsr) {
68 ss << "????";
69 }
70 return ss.str();
71}
72
73void
74MsrBase::printMsrBase(std::ostream &os) const
75{
76 printMnemonic(os);
77 bool apsr = false;
78 bool foundPsr = false;
79 for (unsigned i = 0; i < numDestRegs(); i++) {
80 int idx = destRegIdx(i);
81 if (idx < Ctrl_Base_DepTag) {
82 continue;
83 }
84 idx -= Ctrl_Base_DepTag;
85 if (idx == MISCREG_CPSR) {
86 os << "cpsr_";
87 foundPsr = true;
88 break;
89 }
90 if (idx == MISCREG_SPSR) {
91 if (bits(byteMask, 1, 0)) {
92 os << "spsr_";
93 } else {
94 os << "apsr_";
95 apsr = true;
96 }
97 foundPsr = true;
98 break;
99 }
100 }
101 if (!foundPsr) {
102 os << "????";
103 return;
104 }
105 if (bits(byteMask, 3)) {
106 if (apsr) {
107 os << "nzcvq";
108 } else {
109 os << "f";
110 }
111 }
112 if (bits(byteMask, 2)) {
113 if (apsr) {
114 os << "g";
115 } else {
116 os << "s";
117 }
118 }
119 if (bits(byteMask, 1)) {
120 os << "x";
121 }
122 if (bits(byteMask, 0)) {
123 os << "c";
124 }
125}
126
127std::string
128MsrImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
129{
130 std::stringstream ss;
131 printMsrBase(ss);
132 ccprintf(ss, ", #%#x", imm);
133 return ss.str();
134}
135
136std::string
137MsrRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
138{
139 std::stringstream ss;
140 printMsrBase(ss);
141 ss << ", ";
142 printReg(ss, op1);
143 return ss.str();
144}
145
146std::string
147ImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
148{
149 std::stringstream ss;
150 printMnemonic(ss);
151 ccprintf(ss, "#%d", imm);
152 return ss.str();
153}
154
155std::string
156RegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
157{
158 std::stringstream ss;
159 printMnemonic(ss);
160 printReg(ss, dest);
161 ccprintf(ss, ", #%d", imm);
162 return ss.str();
163}
164
165std::string
166RegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
167{
168 std::stringstream ss;
169 printMnemonic(ss);
170 printReg(ss, dest);
171 ss << ", ";
172 printReg(ss, op1);
173 return ss.str();
174}
175
176std::string
177RegRegRegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
178{
179 std::stringstream ss;
180 printMnemonic(ss);
181 printReg(ss, dest);
182 ss << ", ";
183 printReg(ss, op1);
184 ss << ", ";
185 printReg(ss, op2);
186 ccprintf(ss, ", #%d", imm);
187 return ss.str();
188}
189
190std::string
191RegRegRegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
192{
193 std::stringstream ss;
194 printMnemonic(ss);
195 printReg(ss, dest);
196 ss << ", ";
197 printReg(ss, op1);
198 ss << ", ";
199 printReg(ss, op2);
200 ss << ", ";
201 printReg(ss, op3);
202 return ss.str();
203}
204
205std::string
206RegRegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
207{
208 std::stringstream ss;
209 printMnemonic(ss);
210 printReg(ss, dest);
211 ss << ", ";
212 printReg(ss, op1);
213 ss << ", ";
214 printReg(ss, op2);
215 return ss.str();
216}
217
218std::string
219RegRegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
220{
221 std::stringstream ss;
222 printMnemonic(ss);
223 printReg(ss, dest);
224 ss << ", ";
225 printReg(ss, op1);
226 ccprintf(ss, ", #%d", imm);
227 return ss.str();
228}
229
230std::string
231RegRegImmImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
232{
233 std::stringstream ss;
234 printMnemonic(ss);
235 printReg(ss, dest);
236 ss << ", ";
237 printReg(ss, op1);
238 ccprintf(ss, ", #%d, #%d", imm1, imm2);
239 return ss.str();
240}
241
242std::string
243RegImmRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
244{
245 std::stringstream ss;
246 printMnemonic(ss);
247 printReg(ss, dest);
248 ccprintf(ss, ", #%d, ", imm);
249 printReg(ss, op1);
250 return ss.str();
251}
252
253std::string
254RegImmRegShiftOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
255{
256 std::stringstream ss;
257 printMnemonic(ss);
258 printReg(ss, dest);
259 ccprintf(ss, ", #%d, ", imm);
260 printShiftOperand(ss, op1, true, shiftAmt, INTREG_ZERO, shiftType);
261 printReg(ss, op1);
262 return ss.str();
263}
264
265std::string
266UnknownOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
267{
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Gabe Black
38 */
39
40#include "arch/arm/insts/misc.hh"
41
42std::string
43MrsOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
44{
45 std::stringstream ss;
46 printMnemonic(ss);
47 printReg(ss, dest);
48 ss << ", ";
49 bool foundPsr = false;
50 for (unsigned i = 0; i < numSrcRegs(); i++) {
51 int idx = srcRegIdx(i);
52 if (idx < Ctrl_Base_DepTag) {
53 continue;
54 }
55 idx -= Ctrl_Base_DepTag;
56 if (idx == MISCREG_CPSR) {
57 ss << "cpsr";
58 foundPsr = true;
59 break;
60 }
61 if (idx == MISCREG_SPSR) {
62 ss << "spsr";
63 foundPsr = true;
64 break;
65 }
66 }
67 if (!foundPsr) {
68 ss << "????";
69 }
70 return ss.str();
71}
72
73void
74MsrBase::printMsrBase(std::ostream &os) const
75{
76 printMnemonic(os);
77 bool apsr = false;
78 bool foundPsr = false;
79 for (unsigned i = 0; i < numDestRegs(); i++) {
80 int idx = destRegIdx(i);
81 if (idx < Ctrl_Base_DepTag) {
82 continue;
83 }
84 idx -= Ctrl_Base_DepTag;
85 if (idx == MISCREG_CPSR) {
86 os << "cpsr_";
87 foundPsr = true;
88 break;
89 }
90 if (idx == MISCREG_SPSR) {
91 if (bits(byteMask, 1, 0)) {
92 os << "spsr_";
93 } else {
94 os << "apsr_";
95 apsr = true;
96 }
97 foundPsr = true;
98 break;
99 }
100 }
101 if (!foundPsr) {
102 os << "????";
103 return;
104 }
105 if (bits(byteMask, 3)) {
106 if (apsr) {
107 os << "nzcvq";
108 } else {
109 os << "f";
110 }
111 }
112 if (bits(byteMask, 2)) {
113 if (apsr) {
114 os << "g";
115 } else {
116 os << "s";
117 }
118 }
119 if (bits(byteMask, 1)) {
120 os << "x";
121 }
122 if (bits(byteMask, 0)) {
123 os << "c";
124 }
125}
126
127std::string
128MsrImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
129{
130 std::stringstream ss;
131 printMsrBase(ss);
132 ccprintf(ss, ", #%#x", imm);
133 return ss.str();
134}
135
136std::string
137MsrRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
138{
139 std::stringstream ss;
140 printMsrBase(ss);
141 ss << ", ";
142 printReg(ss, op1);
143 return ss.str();
144}
145
146std::string
147ImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
148{
149 std::stringstream ss;
150 printMnemonic(ss);
151 ccprintf(ss, "#%d", imm);
152 return ss.str();
153}
154
155std::string
156RegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
157{
158 std::stringstream ss;
159 printMnemonic(ss);
160 printReg(ss, dest);
161 ccprintf(ss, ", #%d", imm);
162 return ss.str();
163}
164
165std::string
166RegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
167{
168 std::stringstream ss;
169 printMnemonic(ss);
170 printReg(ss, dest);
171 ss << ", ";
172 printReg(ss, op1);
173 return ss.str();
174}
175
176std::string
177RegRegRegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
178{
179 std::stringstream ss;
180 printMnemonic(ss);
181 printReg(ss, dest);
182 ss << ", ";
183 printReg(ss, op1);
184 ss << ", ";
185 printReg(ss, op2);
186 ccprintf(ss, ", #%d", imm);
187 return ss.str();
188}
189
190std::string
191RegRegRegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
192{
193 std::stringstream ss;
194 printMnemonic(ss);
195 printReg(ss, dest);
196 ss << ", ";
197 printReg(ss, op1);
198 ss << ", ";
199 printReg(ss, op2);
200 ss << ", ";
201 printReg(ss, op3);
202 return ss.str();
203}
204
205std::string
206RegRegRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
207{
208 std::stringstream ss;
209 printMnemonic(ss);
210 printReg(ss, dest);
211 ss << ", ";
212 printReg(ss, op1);
213 ss << ", ";
214 printReg(ss, op2);
215 return ss.str();
216}
217
218std::string
219RegRegImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
220{
221 std::stringstream ss;
222 printMnemonic(ss);
223 printReg(ss, dest);
224 ss << ", ";
225 printReg(ss, op1);
226 ccprintf(ss, ", #%d", imm);
227 return ss.str();
228}
229
230std::string
231RegRegImmImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
232{
233 std::stringstream ss;
234 printMnemonic(ss);
235 printReg(ss, dest);
236 ss << ", ";
237 printReg(ss, op1);
238 ccprintf(ss, ", #%d, #%d", imm1, imm2);
239 return ss.str();
240}
241
242std::string
243RegImmRegOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
244{
245 std::stringstream ss;
246 printMnemonic(ss);
247 printReg(ss, dest);
248 ccprintf(ss, ", #%d, ", imm);
249 printReg(ss, op1);
250 return ss.str();
251}
252
253std::string
254RegImmRegShiftOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
255{
256 std::stringstream ss;
257 printMnemonic(ss);
258 printReg(ss, dest);
259 ccprintf(ss, ", #%d, ", imm);
260 printShiftOperand(ss, op1, true, shiftAmt, INTREG_ZERO, shiftType);
261 printReg(ss, op1);
262 return ss.str();
263}
264
265std::string
266UnknownOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
267{
268 return csprintf("%-10s (inst 0x%x, opcode 0x%x, binary:%s)",
269 "unknown", machInst, machInst.opcode,
270 inst2string(machInst));
268 return csprintf("%-10s (inst %#08x)", "unknown", machInst);
271}
269}