blob: 8d4f3ce263035857a2cf8e6ce4bb3eb6f3196dfb [file] [log] [blame]
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "disassembler_arm.h"
18
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080019#include <iostream>
20
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
Elliott Hughese222ee02012-12-13 14:41:43 -080022#include "base/stringprintf.h"
Elliott Hughes28fa76d2012-04-09 17:31:46 -070023#include "thread.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070024
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080025namespace art {
26namespace arm {
27
28DisassemblerArm::DisassemblerArm() {
29}
30
Ian Rogersb23a7722012-10-09 16:54:26 -070031size_t DisassemblerArm::Dump(std::ostream& os, const uint8_t* begin) {
32 if ((reinterpret_cast<intptr_t>(begin) & 1) == 0) {
33 DumpArm(os, begin);
34 return 4;
35 } else {
36 // remove thumb specifier bits
37 begin = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(begin) & ~1);
38 return DumpThumb16(os, begin);
39 }
40}
41
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080042void DisassemblerArm::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) {
43 if ((reinterpret_cast<intptr_t>(begin) & 1) == 0) {
44 for (const uint8_t* cur = begin; cur < end; cur += 4) {
45 DumpArm(os, cur);
46 }
47 } else {
48 // remove thumb specifier bits
49 begin = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(begin) & ~1);
50 end = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(end) & ~1);
51 for (const uint8_t* cur = begin; cur < end;) {
52 cur += DumpThumb16(os, cur);
53 }
54 }
55}
56
Elliott Hughes77405792012-03-15 15:22:12 -070057static const char* kConditionCodeNames[] = {
Elliott Hughescbf0b612012-03-15 16:23:47 -070058 "eq", // 0000 - equal
59 "ne", // 0001 - not-equal
60 "cs", // 0010 - carry-set, greater than, equal or unordered
61 "cc", // 0011 - carry-clear, less than
62 "mi", // 0100 - minus, negative
63 "pl", // 0101 - plus, positive or zero
64 "vs", // 0110 - overflow
65 "vc", // 0111 - no overflow
66 "hi", // 1000 - unsigned higher
67 "ls", // 1001 - unsigned lower or same
68 "ge", // 1010 - signed greater than or equal
69 "lt", // 1011 - signed less than
70 "gt", // 1100 - signed greater than
71 "le", // 1101 - signed less than or equal
72 "", // 1110 - always
73 "nv", // 1111 - never (mostly obsolete, but might be a clue that we're mistranslating)
Ian Rogers40627db2012-03-04 17:31:09 -080074};
75
76void DisassemblerArm::DumpCond(std::ostream& os, uint32_t cond) {
77 if (cond < 15) {
Elliott Hughes77405792012-03-15 15:22:12 -070078 os << kConditionCodeNames[cond];
Ian Rogers40627db2012-03-04 17:31:09 -080079 } else {
80 os << "Unexpected condition: " << cond;
81 }
82}
83
Ian Rogers40627db2012-03-04 17:31:09 -080084void DisassemblerArm::DumpBranchTarget(std::ostream& os, const uint8_t* instr_ptr, int32_t imm32) {
Elliott Hughes1ca98492012-04-12 17:21:02 -070085 os << StringPrintf("%+d (%p)", imm32, instr_ptr + imm32);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080086}
87
88static uint32_t ReadU16(const uint8_t* ptr) {
89 return ptr[0] | (ptr[1] << 8);
90}
91
92static uint32_t ReadU32(const uint8_t* ptr) {
93 return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
94}
95
Elliott Hughes77405792012-03-15 15:22:12 -070096static const char* kDataProcessingOperations[] = {
Elliott Hughescbf0b612012-03-15 16:23:47 -070097 "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc",
98 "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn",
Elliott Hughes77405792012-03-15 15:22:12 -070099};
100
Ian Rogersad03ef52012-03-18 19:34:47 -0700101static const char* kThumbDataProcessingOperations[] = {
102 "and", "eor", "lsl", "lsr", "asr", "adc", "sbc", "ror",
103 "tst", "rsb", "cmp", "cmn", "orr", "mul", "bic", "mvn",
104};
105
Vladimir Markoa8b4caf2013-10-24 15:08:57 +0100106static const char* kThumbReverseOperations[] = {
107 "rev", "rev16", "rbit", "revsh"
108};
109
Elliott Hughes77405792012-03-15 15:22:12 -0700110struct ArmRegister {
Elliott Hughes74847412012-06-20 18:10:21 -0700111 explicit ArmRegister(uint32_t r) : r(r) { CHECK_LE(r, 15U); }
Elliott Hughes630e77d2012-03-22 19:20:56 -0700112 ArmRegister(uint32_t instruction, uint32_t at_bit) : r((instruction >> at_bit) & 0xf) { CHECK_LE(r, 15U); }
Elliott Hughes77405792012-03-15 15:22:12 -0700113 uint32_t r;
114};
115std::ostream& operator<<(std::ostream& os, const ArmRegister& r) {
116 if (r.r == 13) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700117 os << "sp";
Elliott Hughes77405792012-03-15 15:22:12 -0700118 } else if (r.r == 14) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700119 os << "lr";
Elliott Hughes77405792012-03-15 15:22:12 -0700120 } else if (r.r == 15) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700121 os << "pc";
Elliott Hughes77405792012-03-15 15:22:12 -0700122 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700123 os << "r" << r.r;
Elliott Hughes77405792012-03-15 15:22:12 -0700124 }
125 return os;
126}
127
Elliott Hughes630e77d2012-03-22 19:20:56 -0700128struct ThumbRegister : ArmRegister {
129 ThumbRegister(uint16_t instruction, uint16_t at_bit) : ArmRegister((instruction >> at_bit) & 0x7) {}
Elliott Hughes77405792012-03-15 15:22:12 -0700130};
131
132struct Rm {
Elliott Hughes74847412012-06-20 18:10:21 -0700133 explicit Rm(uint32_t instruction) : shift((instruction >> 4) & 0xff), rm(instruction & 0xf) {}
Elliott Hughes77405792012-03-15 15:22:12 -0700134 uint32_t shift;
135 ArmRegister rm;
136};
137std::ostream& operator<<(std::ostream& os, const Rm& r) {
138 os << r.rm;
139 if (r.shift != 0) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700140 os << "-shift-" << r.shift; // TODO
Elliott Hughes77405792012-03-15 15:22:12 -0700141 }
142 return os;
143}
144
Elliott Hughes1ca98492012-04-12 17:21:02 -0700145struct ShiftedImmediate {
Elliott Hughes74847412012-06-20 18:10:21 -0700146 explicit ShiftedImmediate(uint32_t instruction) {
Elliott Hughes3d71d072012-04-10 18:28:35 -0700147 uint32_t rotate = ((instruction >> 8) & 0xf);
148 uint32_t imm = (instruction & 0xff);
149 value = (imm >> (2 * rotate)) | (imm << (32 - (2 * rotate)));
150 }
151 uint32_t value;
Elliott Hughes77405792012-03-15 15:22:12 -0700152};
Elliott Hughes1ca98492012-04-12 17:21:02 -0700153std::ostream& operator<<(std::ostream& os, const ShiftedImmediate& rhs) {
Elliott Hughes3d71d072012-04-10 18:28:35 -0700154 os << "#" << rhs.value;
Elliott Hughes77405792012-03-15 15:22:12 -0700155 return os;
156}
157
158struct RegisterList {
Elliott Hughes74847412012-06-20 18:10:21 -0700159 explicit RegisterList(uint32_t instruction) : register_list(instruction & 0xffff) {}
Elliott Hughes77405792012-03-15 15:22:12 -0700160 uint32_t register_list;
161};
162std::ostream& operator<<(std::ostream& os, const RegisterList& rhs) {
163 if (rhs.register_list == 0) {
164 os << "<no register list?>";
165 return os;
166 }
Elliott Hughes630e77d2012-03-22 19:20:56 -0700167 os << "{";
Elliott Hughes77405792012-03-15 15:22:12 -0700168 bool first = true;
169 for (size_t i = 0; i < 16; i++) {
170 if ((rhs.register_list & (1 << i)) != 0) {
171 if (first) {
Elliott Hughes77405792012-03-15 15:22:12 -0700172 first = false;
173 } else {
174 os << ", ";
175 }
176 os << ArmRegister(i);
177 }
178 }
179 os << "}";
180 return os;
181}
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800182
183void DisassemblerArm::DumpArm(std::ostream& os, const uint8_t* instr_ptr) {
Elliott Hughes77405792012-03-15 15:22:12 -0700184 uint32_t instruction = ReadU32(instr_ptr);
185 uint32_t cond = (instruction >> 28) & 0xf;
186 uint32_t op1 = (instruction >> 25) & 0x7;
Elliott Hughes3d71d072012-04-10 18:28:35 -0700187 std::string opcode;
188 std::string suffixes;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700189 std::ostringstream args;
Elliott Hughes77405792012-03-15 15:22:12 -0700190 switch (op1) {
191 case 0:
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700192 case 1: // Data processing instructions.
Elliott Hughes77405792012-03-15 15:22:12 -0700193 {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700194 if ((instruction & 0x0ff000f0) == 0x01200070) { // BKPT
Elliott Hughes3d71d072012-04-10 18:28:35 -0700195 opcode = "bkpt";
196 uint32_t imm12 = (instruction >> 8) & 0xfff;
197 uint32_t imm4 = (instruction & 0xf);
198 args << '#' << ((imm12 << 4) | imm4);
199 break;
200 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700201 if ((instruction & 0x0fffffd0) == 0x012fff10) { // BX and BLX (register)
Elliott Hughes3d71d072012-04-10 18:28:35 -0700202 opcode = (((instruction >> 5) & 1) ? "blx" : "bx");
Elliott Hughescbf0b612012-03-15 16:23:47 -0700203 args << ArmRegister(instruction & 0xf);
Elliott Hughes77405792012-03-15 15:22:12 -0700204 break;
205 }
206 bool i = (instruction & (1 << 25)) != 0;
207 bool s = (instruction & (1 << 20)) != 0;
Elliott Hughes3d71d072012-04-10 18:28:35 -0700208 uint32_t op = (instruction >> 21) & 0xf;
209 opcode = kDataProcessingOperations[op];
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700210 bool implicit_s = ((op & ~3) == 8); // TST, TEQ, CMP, and CMN.
Elliott Hughes3d71d072012-04-10 18:28:35 -0700211 if (implicit_s) {
212 // Rd is unused (and not shown), and we don't show the 's' suffix either.
213 } else {
214 if (s) {
215 suffixes += 's';
216 }
217 args << ArmRegister(instruction, 12) << ", ";
218 }
Elliott Hughes77405792012-03-15 15:22:12 -0700219 if (i) {
Elliott Hughes1ca98492012-04-12 17:21:02 -0700220 args << ArmRegister(instruction, 16) << ", " << ShiftedImmediate(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700221 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700222 args << Rm(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700223 }
224 }
225 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700226 case 2: // Load/store word and unsigned byte.
Elliott Hughes77405792012-03-15 15:22:12 -0700227 {
228 bool p = (instruction & (1 << 24)) != 0;
229 bool b = (instruction & (1 << 22)) != 0;
230 bool w = (instruction & (1 << 21)) != 0;
231 bool l = (instruction & (1 << 20)) != 0;
Elliott Hughes3d71d072012-04-10 18:28:35 -0700232 opcode = StringPrintf("%s%s", (l ? "ldr" : "str"), (b ? "b" : ""));
Elliott Hughes630e77d2012-03-22 19:20:56 -0700233 args << ArmRegister(instruction, 12) << ", ";
234 ArmRegister rn(instruction, 16);
235 if (rn.r == 0xf) {
Elliott Hughes77405792012-03-15 15:22:12 -0700236 UNIMPLEMENTED(FATAL) << "literals";
237 } else {
238 bool wback = !p || w;
Elliott Hughes1ca98492012-04-12 17:21:02 -0700239 uint32_t offset = (instruction & 0xfff);
Elliott Hughes77405792012-03-15 15:22:12 -0700240 if (p && !wback) {
Elliott Hughes1ca98492012-04-12 17:21:02 -0700241 args << "[" << rn << ", #" << offset << "]";
Elliott Hughes77405792012-03-15 15:22:12 -0700242 } else if (p && wback) {
Elliott Hughes1ca98492012-04-12 17:21:02 -0700243 args << "[" << rn << ", #" << offset << "]!";
Elliott Hughes77405792012-03-15 15:22:12 -0700244 } else if (!p && wback) {
Elliott Hughes1ca98492012-04-12 17:21:02 -0700245 args << "[" << rn << "], #" << offset;
Elliott Hughes77405792012-03-15 15:22:12 -0700246 } else {
247 LOG(FATAL) << p << " " << w;
248 }
Elliott Hughes3d71d072012-04-10 18:28:35 -0700249 if (rn.r == 9) {
250 args << " ; ";
Elliott Hughes1ca98492012-04-12 17:21:02 -0700251 Thread::DumpThreadOffset(args, offset, 4);
Elliott Hughes3d71d072012-04-10 18:28:35 -0700252 }
Elliott Hughes77405792012-03-15 15:22:12 -0700253 }
254 }
255 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700256 case 4: // Load/store multiple.
Elliott Hughes77405792012-03-15 15:22:12 -0700257 {
258 bool p = (instruction & (1 << 24)) != 0;
259 bool u = (instruction & (1 << 23)) != 0;
260 bool w = (instruction & (1 << 21)) != 0;
261 bool l = (instruction & (1 << 20)) != 0;
Elliott Hughes3d71d072012-04-10 18:28:35 -0700262 opcode = StringPrintf("%s%c%c", (l ? "ldm" : "stm"), (u ? 'i' : 'd'), (p ? 'b' : 'a'));
Elliott Hughes630e77d2012-03-22 19:20:56 -0700263 args << ArmRegister(instruction, 16) << (w ? "!" : "") << ", " << RegisterList(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700264 }
265 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700266 case 5: // Branch/branch with link.
Elliott Hughes3d71d072012-04-10 18:28:35 -0700267 {
268 bool bl = (instruction & (1 << 24)) != 0;
269 opcode = (bl ? "bl" : "b");
Elliott Hughesd86261e2012-04-11 11:23:23 -0700270 int32_t imm26 = (instruction & 0xffffff) << 2;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700271 int32_t imm32 = (imm26 << 6) >> 6; // Sign extend.
Elliott Hughes3d71d072012-04-10 18:28:35 -0700272 DumpBranchTarget(args, instr_ptr + 8, imm32);
273 }
274 break;
Elliott Hughes77405792012-03-15 15:22:12 -0700275 default:
Elliott Hughes3d71d072012-04-10 18:28:35 -0700276 opcode = "???";
Elliott Hughes77405792012-03-15 15:22:12 -0700277 break;
278 }
Elliott Hughes3d71d072012-04-10 18:28:35 -0700279 opcode += kConditionCodeNames[cond];
280 opcode += suffixes;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700281 // TODO: a more complete ARM disassembler could generate wider opcodes.
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800282 os << StringPrintf("%p: %08x\t%-7s ", instr_ptr, instruction, opcode.c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800283}
284
Ian Rogersa9650dd2013-10-04 08:23:32 -0700285int32_t ThumbExpand(int32_t imm12) {
286 if ((imm12 & 0xC00) == 0) {
287 switch ((imm12 >> 8) & 3) {
288 case 0:
289 return imm12 & 0xFF;
290 case 1:
291 return ((imm12 & 0xFF) << 16) | (imm12 & 0xFF);
292 case 2:
293 return ((imm12 & 0xFF) << 24) | ((imm12 & 0xFF) << 8);
294 default: // 3
295 return ((imm12 & 0xFF) << 24) | ((imm12 & 0xFF) << 16) | ((imm12 & 0xFF) << 8) |
296 (imm12 & 0xFF);
297 }
298 } else {
299 uint32_t val = 0x80 | (imm12 & 0x7F);
300 int32_t rotate = (imm12 >> 7) & 0x1F;
301 return (val >> rotate) | (val << (32 - rotate));
302 }
303}
304
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800305size_t DisassemblerArm::DumpThumb32(std::ostream& os, const uint8_t* instr_ptr) {
306 uint32_t instr = (ReadU16(instr_ptr) << 16) | ReadU16(instr_ptr + 2);
307 // |111|1 1|1000000|0000|1111110000000000|
308 // |5 3|2 1|0987654|3 0|5 0 5 0|
309 // |---|---|-------|----|----------------|
310 // |332|2 2|2222222|1111|1111110000000000|
311 // |1 9|8 7|6543210|9 6|5 0 5 0|
312 // |---|---|-------|----|----------------|
313 // |111|op1| op2 | | |
314 uint32_t op1 = (instr >> 27) & 3;
Elliott Hughes77405792012-03-15 15:22:12 -0700315 if (op1 == 0) {
316 return DumpThumb16(os, instr_ptr);
317 }
318
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800319 uint32_t op2 = (instr >> 20) & 0x7F;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700320 std::ostringstream opcode;
321 std::ostringstream args;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800322 switch (op1) {
323 case 0:
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800324 break;
325 case 1:
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700326 if ((op2 & 0x64) == 0) { // 00x x0xx
327 // |111|11|10|00|0|00|0000|1111110000000000|
328 // |5 3|21|09|87|6|54|3 0|5 0 5 0|
329 // |---|--|--|--|-|--|----|----------------|
330 // |332|22|22|22|2|22|1111|1111110000000000|
331 // |1 9|87|65|43|2|10|9 6|5 0 5 0|
332 // |---|--|--|--|-|--|----|----------------|
333 // |111|01|00|op|0|WL| Rn | |
334 // |111|01| op2 | | |
335 // STM - 111 01 00-01-0-W0 nnnn rrrrrrrrrrrrrrrr
336 // LDM - 111 01 00-01-0-W1 nnnn rrrrrrrrrrrrrrrr
337 // PUSH- 111 01 00-01-0-10 1101 0M0rrrrrrrrrrrrr
338 // POP - 111 01 00-01-0-11 1101 PM0rrrrrrrrrrrrr
339 uint32_t op = (instr >> 23) & 3;
340 uint32_t W = (instr >> 21) & 1;
341 uint32_t L = (instr >> 20) & 1;
342 ArmRegister Rn(instr, 16);
343 if (op == 1 || op == 2) {
344 if (op == 1) {
345 if (L == 0) {
346 opcode << "stm";
347 args << Rn << (W == 0 ? "" : "!") << ", ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800348 } else {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700349 if (Rn.r != 13) {
350 opcode << "ldm";
Elliott Hughes630e77d2012-03-22 19:20:56 -0700351 args << Rn << (W == 0 ? "" : "!") << ", ";
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700352 } else {
353 opcode << "pop";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800354 }
355 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700356 } else {
357 if (L == 0) {
358 if (Rn.r != 13) {
359 opcode << "stmdb";
360 args << Rn << (W == 0 ? "" : "!") << ", ";
361 } else {
362 opcode << "push";
363 }
364 } else {
365 opcode << "ldmdb";
366 args << Rn << (W == 0 ? "" : "!") << ", ";
367 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800368 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700369 args << RegisterList(instr);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800370 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700371 } else if ((op2 & 0x64) == 4) { // 00x x1xx
Ian Rogers9af89402012-09-07 11:29:35 -0700372 uint32_t op3 = (instr >> 23) & 3;
373 uint32_t op4 = (instr >> 20) & 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700374 // uint32_t op5 = (instr >> 4) & 0xF;
Ian Rogers9af89402012-09-07 11:29:35 -0700375 ArmRegister Rn(instr, 16);
376 ArmRegister Rt(instr, 12);
Dave Allison70202782013-10-22 17:52:19 -0700377 ArmRegister Rd(instr, 8);
Ian Rogers9af89402012-09-07 11:29:35 -0700378 uint32_t imm8 = instr & 0xFF;
Dave Allison70202782013-10-22 17:52:19 -0700379 if ((op3 & 2) == 2) { // 1x
380 int W = (instr >> 21) & 1;
381 int U = (instr >> 23) & 1;
382 int P = (instr >> 24) & 1;
383
384 if ((op4 & 1) == 1) {
385 opcode << "ldrd";
386 } else {
387 opcode << "strd";
388 }
389 args << Rt << "," << Rd << ", [" << Rn;
390 const char *sign = U ? "+" : "-";
391 if (P == 0 && W == 1) {
392 args << "], #" << sign << imm8;
393 } else {
394 args << ", #" << sign << imm8 << "]";
395 if (W == 1) {
396 args << "!";
397 }
398 }
399 } else { // 0x
400 switch (op4) {
401 case 0:
402 if (op3 == 0) { // op3 is 00, op4 is 00
403 opcode << "strex";
404 args << Rd << ", " << Rt << ", [" << Rn << ", #" << (imm8 << 2) << "]";
405 } else { // op3 is 01, op4 is 00
406 // this is one of strexb, strexh or strexd
407 int op5 = (instr >> 4) & 0xf;
408 switch (op5) {
409 case 4:
410 opcode << "strexb";
411 break;
412 case 5:
413 opcode << "strexh";
414 break;
415 case 7:
416 opcode << "strexd";
417 break;
418 }
419 }
420 break;
421 case 1:
422 if (op3 == 0) { // op3 is 00, op4 is 01
423 opcode << "ldrex";
424 args << Rt << ", [" << Rn << ", #" << (imm8 << 2) << "]";
425 } else { // op3 is 01, op4 is 01
426 // this is one of strexb, strexh or strexd
427 int op5 = (instr >> 4) & 0xf;
428 switch (op5) {
429 case 0:
430 opcode << "tbb";
431 break;
432 case 1:
433 opcode << "tbh";
434 break;
435 case 4:
436 opcode << "ldrexb";
437 break;
438 case 5:
439 opcode << "ldrexh";
440 break;
441 case 7:
442 opcode << "ldrexd";
443 break;
444 }
445 }
446 break;
447 case 2: // op3 is 0x, op4 is 10
448 case 3: // op3 is 0x, op4 is 11
449 if (op4 == 2) {
450 opcode << "strd";
451 } else {
452 opcode << "ldrd";
453 }
454 int W = (instr >> 21) & 1;
455 int U = (instr >> 23) & 1;
456 int P = (instr >> 24) & 1;
457
458 args << Rt << "," << Rd << ", [" << Rn;
459 const char *sign = U ? "+" : "-";
460 if (P == 0 && W == 1) {
461 args << "], #" << sign << imm8;
462 } else {
463 args << ", #" << sign << imm8 << "]";
464 if (W == 1) {
465 args << "!";
466 }
467 }
468 break;
469 }
470 }
471
472
Ian Rogers9af89402012-09-07 11:29:35 -0700473 if (op3 == 0 && op4 == 0) { // STREX
474 ArmRegister Rd(instr, 8);
475 opcode << "strex";
476 args << Rd << ", " << Rt << ", [" << Rn << ", #" << (imm8 << 2) << "]";
477 } else if (op3 == 0 && op4 == 1) { // LDREX
478 opcode << "ldrex";
479 args << Rt << ", [" << Rn << ", #" << (imm8 << 2) << "]";
480 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700481 } else if ((op2 & 0x60) == 0x20) { // 01x xxxx
482 // Data-processing (shifted register)
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100483 // |111|1110|0000|0|0000|1111|1100|00|00|0000|
484 // |5 3|2109|8765|4|3 0|5 |10 8|7 |5 |3 0|
485 // |---|----|----|-|----|----|----|--|--|----|
486 // |332|2222|2222|2|1111|1111|1100|00|00|0000|
487 // |1 9|8765|4321|0|9 6|5 |10 8|7 |5 |3 0|
488 // |---|----|----|-|----|----|----|--|--|----|
489 // |111|0101| op3|S| Rn |imm3| Rd |i2|ty| Rm |
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700490 uint32_t op3 = (instr >> 21) & 0xF;
491 uint32_t S = (instr >> 20) & 1;
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100492 uint32_t imm3 = ((instr >> 12) & 0x7);
493 uint32_t imm2 = ((instr >> 6) & 0x3);
494 uint32_t imm5 = ((imm3 << 3) | imm2) & 0x1F;
495 uint32_t shift_type = ((instr >> 4) & 0x2);
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700496 ArmRegister Rd(instr, 8);
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100497 ArmRegister Rn(instr, 16);
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700498 ArmRegister Rm(instr, 0);
499 switch (op3) {
500 case 0x0:
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100501 if (Rd.r != 0xF) {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700502 opcode << "and";
503 } else {
Brian Carlstrom4a999e22013-03-11 16:57:09 -0700504 if (S != 1U) {
505 opcode << "UNKNOWN TST-" << S;
506 break;
507 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700508 opcode << "tst";
509 S = 0; // don't print 's'
510 }
511 break;
512 case 0x1: opcode << "bic"; break;
513 case 0x2:
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100514 if (Rn.r != 0xF) {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700515 opcode << "orr";
516 } else {
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100517 // TODO: use canonical form if there is a shift (lsl, ...).
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700518 opcode << "mov";
519 }
520 break;
521 case 0x3:
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100522 if (Rn.r != 0xF) {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700523 opcode << "orn";
524 } else {
525 opcode << "mvn";
526 }
527 break;
528 case 0x4:
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100529 if (Rd.r != 0xF) {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700530 opcode << "eor";
531 } else {
Brian Carlstrom4a999e22013-03-11 16:57:09 -0700532 if (S != 1U) {
533 opcode << "UNKNOWN TEQ-" << S;
534 break;
535 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700536 opcode << "teq";
537 S = 0; // don't print 's'
538 }
539 break;
540 case 0x6: opcode << "pkh"; break;
541 case 0x8:
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100542 if (Rd.r != 0xF) {
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700543 opcode << "add";
544 } else {
Brian Carlstrom4a999e22013-03-11 16:57:09 -0700545 if (S != 1U) {
546 opcode << "UNKNOWN CMN-" << S;
547 break;
548 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700549 opcode << "cmn";
550 S = 0; // don't print 's'
551 }
552 break;
553 case 0xA: opcode << "adc"; break;
554 case 0xB: opcode << "sbc"; break;
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100555 case 0xD:
556 if (Rd.r != 0xF) {
557 opcode << "sub";
558 } else {
Brian Carlstrom4a999e22013-03-11 16:57:09 -0700559 if (S != 1U) {
560 opcode << "UNKNOWN CMP-" << S;
561 break;
562 }
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100563 opcode << "cmp";
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100564 S = 0; // don't print 's'
565 }
566 break;
567 case 0xE: opcode << "rsb"; break;
568 default: opcode << "UNKNOWN DPSR-" << op3; break;
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700569 }
Ian Rogers087b2412012-03-21 01:30:32 -0700570
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700571 if (S == 1) {
572 opcode << "s";
Ian Rogers087b2412012-03-21 01:30:32 -0700573 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700574 opcode << ".w";
Sebastien Hertzd9e63c02013-02-22 15:19:55 +0100575
576 if (Rd.r != 0xF) {
577 args << Rd << ", ";
578 }
579 if (Rn.r != 0xF) {
580 args << Rn << ", ";
581 }
582 args << Rm;
583
584 // Shift operand.
585 bool noShift = (imm5 == 0 && shift_type != 0x3);
586 if (!noShift) {
587 args << ", ";
588 switch (shift_type) {
589 case 0x0: args << "lsl"; break;
590 case 0x1: args << "lsr"; break;
591 case 0x2: args << "asr"; break;
592 case 0x3:
593 if (imm5 == 0) {
594 args << "rrx";
595 } else {
596 args << "ror";
597 }
598 break;
599 }
600 if (shift_type != 0x3 /* rrx */) {
601 args << StringPrintf(" #%d", imm5);
602 }
603 }
604
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700605 } else if ((op2 & 0x40) == 0x40) { // 1xx xxxx
606 // Co-processor instructions
607 // |111|1|11|000000|0000|1111|1100|000|0 |0000|
608 // |5 3|2|10|987654|3 0|54 2|10 8|7 5|4 | 0|
609 // |---|-|--|------|----|----|----|---|---|----|
610 // |332|2|22|222222|1111|1111|1100|000|0 |0000|
611 // |1 9|8|76|543210|9 6|54 2|10 8|7 5|4 | 0|
612 // |---|-|--|------|----|----|----|---|---|----|
613 // |111| |11| op3 | Rn | |copr| |op4| |
614 uint32_t op3 = (instr >> 20) & 0x3F;
615 uint32_t coproc = (instr >> 8) & 0xF;
616 uint32_t op4 = (instr >> 4) & 0x1;
Dave Allison70202782013-10-22 17:52:19 -0700617
618 if (coproc == 10 || coproc == 11) { // 101x
619 if (op3 < 0x20 && (op3 >> 1) != 2) { // 0xxxxx and not 00010x
620 // extension load/store instructions
621 int op = op3 & 0x1f;
Ian Rogers9af89402012-09-07 11:29:35 -0700622 uint32_t P = (instr >> 24) & 1;
623 uint32_t U = (instr >> 23) & 1;
624 uint32_t D = (instr >> 22) & 1;
625 uint32_t W = (instr >> 21) & 1;
626 uint32_t S = (instr >> 8) & 1;
627 ArmRegister Rn(instr, 16);
628 uint32_t Vd = (instr >> 12) & 0xF;
629 uint32_t imm8 = instr & 0xFF;
630 uint32_t d = (S == 0 ? ((Vd << 1) | D) : (Vd | (D << 4)));
Dave Allison70202782013-10-22 17:52:19 -0700631 ArmRegister Rd(d, 0);
632
633 if (op == 8 || op == 12 || op == 10 || op == 14 ||
634 op == 18 || op == 22) { // 01x00 or 01x10
635 // vector store multiple or vpush
636 if (P == 1 && U == 0 && W == 1 && Rn.r == 13) {
637 opcode << "vpush" << (S == 0 ? ".f64" : ".f32");
638 args << Rd << " .. " << (Rd.r + imm8);
639 } else {
640 opcode << "vstm" << (S == 0 ? ".f64" : ".f32");
641 args << Rn << ", " << Rd << " .. " << (Rd.r + imm8);
642 }
643 } else if (op == 16 || op == 20 || op == 24 || op == 28) {
644 // 1xx00
645 // vector store register
646 opcode << "vstr" << (S == 0 ? ".f64" : ".f32");
647 args << Rd << ", [" << Rn << ", #" << imm8 << "]";
648 } else if (op == 17 || op == 21 || op == 25 || op == 29) {
649 // 1xx01
650 // vector load register
651 opcode << "vldr" << (S == 0 ? ".f64" : ".f32");
652 args << Rd << ", [" << Rn << ", #" << imm8 << "]";
653 } else if (op == 9 || op == 13 || op == 11 || op == 15 ||
654 op == 19 || op == 23 ) { // 01x11 10x11
655 // vldm or vpop
656 if (P == 1 && U == 0 && W == 1 && Rn.r == 13) {
657 opcode << "vpop" << (S == 0 ? ".f64" : ".f32");
658 args << Rd << " .. " << (Rd.r + imm8);
659 } else {
660 opcode << "vldm" << (S == 0 ? ".f64" : ".f32");
661 args << Rn << ", " << Rd << " .. " << (Rd.r + imm8);
662 }
Ian Rogers9af89402012-09-07 11:29:35 -0700663 }
Dave Allison70202782013-10-22 17:52:19 -0700664 } else if ((op3 >> 1) == 2) { // 00010x
665 // 64 bit transfers
666 } else if ((op3 >> 4) == 2 && op4 == 0) { // 10xxxx, op = 0
667 // fp data processing
668 } else if ((op3 >> 4) == 2 && op4 == 1) { // 10xxxx, op = 1
669 // 8,16,32 bit transfers
Ian Rogers9af89402012-09-07 11:29:35 -0700670 }
Dave Allison70202782013-10-22 17:52:19 -0700671 }
672
673 if ((op3 & 0x30) == 0x20 && op4 == 0) { // 10 xxxx ... 0
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700674 if ((coproc & 0xE) == 0xA) {
675 // VFP data-processing instructions
676 // |111|1|1100|0000|0000|1111|110|0|00 |0|0|0000|
677 // |5 3|2|1098|7654|3 0|54 2|10 |8|76 |5|4|3 0|
678 // |---|-|----|----|----|----|---|-|----|-|-|----|
679 // |332|2|2222|2222|1111|1111|110|0|00 |0|0|0000|
680 // |1 9|8|7654|3210|9 6|54 2|109|8|76 |5|4|3 0|
681 // |---|-|----|----|----|----|---|-|----|-|-|----|
682 // |111|T|1110|opc1|opc2| |101| |opc3| | | |
683 // 111 0 1110|1111 0100 1110 101 0 01 1 0 1001 - eef4ea69
684 uint32_t opc1 = (instr >> 20) & 0xF;
685 uint32_t opc2 = (instr >> 16) & 0xF;
Ian Rogers0183dd72012-09-17 23:06:51 -0700686 uint32_t opc3 = (instr >> 6) & 0x3;
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700687 if ((opc1 & 0xB) == 0xB) { // 1x11
688 // Other VFP data-processing instructions.
Ian Rogers0183dd72012-09-17 23:06:51 -0700689 uint32_t D = (instr >> 22) & 0x1;
690 uint32_t Vd = (instr >> 12) & 0xF;
691 uint32_t sz = (instr >> 8) & 1;
692 uint32_t M = (instr >> 5) & 1;
693 uint32_t Vm = instr & 0xF;
694 bool dp_operation = sz == 1;
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700695 switch (opc2) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700696 case 0x1: // Vneg/Vsqrt
Ian Rogers0183dd72012-09-17 23:06:51 -0700697 // 1110 11101 D 11 0001 dddd 101s o1M0 mmmm
698 opcode << (opc3 == 1 ? "vneg" : "vsqrt") << (dp_operation ? ".f64" : ".f32");
699 if (dp_operation) {
700 args << "f" << ((D << 4) | Vd) << ", " << "f" << ((M << 4) | Vm);
701 } else {
702 args << "f" << ((Vd << 1) | D) << ", " << "f" << ((Vm << 1) | M);
703 }
704 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700705 case 0x4: case 0x5: { // Vector compare
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700706 // 1110 11101 D 11 0100 dddd 101 sE1M0 mmmm
Ian Rogers0183dd72012-09-17 23:06:51 -0700707 opcode << (opc3 == 1 ? "vcmp" : "vcmpe") << (dp_operation ? ".f64" : ".f32");
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700708 if (dp_operation) {
709 args << "f" << ((D << 4) | Vd) << ", " << "f" << ((M << 4) | Vm);
710 } else {
711 args << "f" << ((Vd << 1) | D) << ", " << "f" << ((Vm << 1) | M);
712 }
713 break;
714 }
715 }
716 }
717 }
Ian Rogers0183dd72012-09-17 23:06:51 -0700718 } else if ((op3 & 0x30) == 0x30) { // 11 xxxx
719 // Advanced SIMD
720 if ((instr & 0xFFBF0ED0) == 0xeeb10ac0) { // Vsqrt
721 // 1110 11101 D 11 0001 dddd 101S 11M0 mmmm
722 // 1110 11101 0 11 0001 1101 1011 1100 1000 - eeb1dbc8
723 uint32_t D = (instr >> 22) & 1;
724 uint32_t Vd = (instr >> 12) & 0xF;
725 uint32_t sz = (instr >> 8) & 1;
726 uint32_t M = (instr >> 5) & 1;
727 uint32_t Vm = instr & 0xF;
728 bool dp_operation = sz == 1;
729 opcode << "vsqrt" << (dp_operation ? ".f64" : ".f32");
730 if (dp_operation) {
731 args << "f" << ((D << 4) | Vd) << ", " << "f" << ((M << 4) | Vm);
732 } else {
733 args << "f" << ((Vd << 1) | D) << ", " << "f" << ((Vm << 1) | M);
734 }
735 }
Ian Rogersc7fe4e02012-03-29 21:36:21 -0700736 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800737 }
738 break;
Ian Rogers40627db2012-03-04 17:31:09 -0800739 case 2:
740 if ((instr & 0x8000) == 0 && (op2 & 0x20) == 0) {
741 // Data-processing (modified immediate)
742 // |111|11|10|0000|0|0000|1|111|1100|00000000|
743 // |5 3|21|09|8765|4|3 0|5|4 2|10 8|7 5 0|
744 // |---|--|--|----|-|----|-|---|----|--------|
745 // |332|22|22|2222|2|1111|1|111|1100|00000000|
746 // |1 9|87|65|4321|0|9 6|5|4 2|10 8|7 5 0|
747 // |---|--|--|----|-|----|-|---|----|--------|
748 // |111|10|i0| op3|S| Rn |0|iii| Rd |iiiiiiii|
749 // 111 10 x0 xxxx x xxxx opxxx xxxx xxxxxxxx
Ian Rogers40627db2012-03-04 17:31:09 -0800750 uint32_t i = (instr >> 26) & 1;
751 uint32_t op3 = (instr >> 21) & 0xF;
752 uint32_t S = (instr >> 20) & 1;
Elliott Hughes630e77d2012-03-22 19:20:56 -0700753 ArmRegister Rn(instr, 16);
Ian Rogers40627db2012-03-04 17:31:09 -0800754 uint32_t imm3 = (instr >> 12) & 7;
Elliott Hughes630e77d2012-03-22 19:20:56 -0700755 ArmRegister Rd(instr, 8);
Ian Rogers40627db2012-03-04 17:31:09 -0800756 uint32_t imm8 = instr & 0xFF;
Jeff Hao7cb0f9c2013-02-04 16:15:27 -0800757 int32_t imm32 = (i << 11) | (imm3 << 8) | imm8;
758 if (Rn.r == 0xF && (op3 == 0x2 || op3 == 0x3)) {
759 if (op3 == 0x2) {
760 opcode << "mov";
761 if (S == 1) {
762 opcode << "s";
763 }
764 opcode << ".w";
765 } else {
766 opcode << "mvn";
767 if (S == 1) {
768 opcode << "s";
769 }
770 }
Ian Rogersa9650dd2013-10-04 08:23:32 -0700771 args << Rd << ", #" << ThumbExpand(imm32);
Jeff Hao7cb0f9c2013-02-04 16:15:27 -0800772 } else if (Rd.r == 0xF && S == 1 &&
773 (op3 == 0x0 || op3 == 0x4 || op3 == 0x8 || op3 == 0xD)) {
774 if (op3 == 0x0) {
775 opcode << "tst";
776 } else if (op3 == 0x4) {
777 opcode << "teq";
778 } else if (op3 == 0x8) {
779 opcode << "cmw";
780 } else {
781 opcode << "cmp.w";
782 }
Ian Rogersa9650dd2013-10-04 08:23:32 -0700783 args << Rn << ", #" << ThumbExpand(imm32);
Jeff Hao7cb0f9c2013-02-04 16:15:27 -0800784 } else {
785 switch (op3) {
786 case 0x0: opcode << "and"; break;
787 case 0x1: opcode << "bic"; break;
788 case 0x2: opcode << "orr"; break;
789 case 0x3: opcode << "orn"; break;
790 case 0x4: opcode << "eor"; break;
791 case 0x8: opcode << "add"; break;
792 case 0xA: opcode << "adc"; break;
793 case 0xB: opcode << "sbc"; break;
794 case 0xD: opcode << "sub"; break;
795 case 0xE: opcode << "rsb"; break;
796 default: opcode << "UNKNOWN DPMI-" << op3; break;
797 }
798 if (S == 1) {
799 opcode << "s";
800 }
Ian Rogersa9650dd2013-10-04 08:23:32 -0700801 args << Rd << ", " << Rn << ", #" << ThumbExpand(imm32);
Ian Rogers40627db2012-03-04 17:31:09 -0800802 }
Ian Rogers40627db2012-03-04 17:31:09 -0800803 } else if ((instr & 0x8000) == 0 && (op2 & 0x20) != 0) {
804 // Data-processing (plain binary immediate)
805 // |111|11|10|00000|0000|1|111110000000000|
806 // |5 3|21|09|87654|3 0|5|4 0 5 0|
807 // |---|--|--|-----|----|-|---------------|
808 // |332|22|22|22222|1111|1|111110000000000|
809 // |1 9|87|65|43210|9 6|5|4 0 5 0|
810 // |---|--|--|-----|----|-|---------------|
811 // |111|10|x1| op3 | Rn |0|xxxxxxxxxxxxxxx|
812 uint32_t op3 = (instr >> 20) & 0x1F;
Ian Rogers40627db2012-03-04 17:31:09 -0800813 switch (op3) {
Ian Rogers55019132013-02-08 01:05:23 -0800814 case 0x00: case 0x0A: {
815 // ADD/SUB.W Rd, Rn #imm12 - 111 10 i1 0101 0 nnnn 0 iii dddd iiiiiiii
Ian Rogers66a3fca2012-04-09 19:51:34 -0700816 ArmRegister Rd(instr, 8);
817 ArmRegister Rn(instr, 16);
818 uint32_t i = (instr >> 26) & 1;
819 uint32_t imm3 = (instr >> 12) & 0x7;
820 uint32_t imm8 = instr & 0xFF;
821 uint32_t imm12 = (i << 11) | (imm3 << 8) | imm8;
822 if (Rn.r != 0xF) {
Ian Rogers55019132013-02-08 01:05:23 -0800823 opcode << (op3 == 0 ? "addw" : "subw");
Ian Rogers66a3fca2012-04-09 19:51:34 -0700824 args << Rd << ", " << Rn << ", #" << imm12;
825 } else {
826 opcode << "adr";
827 args << Rd << ", ";
Ian Rogers55019132013-02-08 01:05:23 -0800828 DumpBranchTarget(args, instr_ptr + 4, (op3 == 0) ? imm12 : -imm12);
Ian Rogers66a3fca2012-04-09 19:51:34 -0700829 }
830 break;
831 }
Ian Rogers55019132013-02-08 01:05:23 -0800832 case 0x04: case 0x0C: {
833 // MOVW/T Rd, #imm16 - 111 10 i0 0010 0 iiii 0 iii dddd iiiiiiii
Elliott Hughes630e77d2012-03-22 19:20:56 -0700834 ArmRegister Rd(instr, 8);
Ian Rogers40627db2012-03-04 17:31:09 -0800835 uint32_t i = (instr >> 26) & 1;
836 uint32_t imm3 = (instr >> 12) & 0x7;
837 uint32_t imm8 = instr & 0xFF;
Elliott Hughes630e77d2012-03-22 19:20:56 -0700838 uint32_t Rn = (instr >> 16) & 0xF;
Ian Rogers40627db2012-03-04 17:31:09 -0800839 uint32_t imm16 = (Rn << 12) | (i << 11) | (imm3 << 8) | imm8;
Ian Rogers55019132013-02-08 01:05:23 -0800840 opcode << (op3 == 0x04 ? "movw" : "movt");
Elliott Hughes630e77d2012-03-22 19:20:56 -0700841 args << Rd << ", #" << imm16;
Ian Rogers40627db2012-03-04 17:31:09 -0800842 break;
843 }
jeffhaoeae26912013-01-28 16:29:54 -0800844 case 0x16: {
845 // BFI Rd, Rn, #lsb, #width - 111 10 0 11 011 0 nnnn 0 iii dddd ii 0 iiiii
846 ArmRegister Rd(instr, 8);
847 ArmRegister Rn(instr, 16);
848 uint32_t msb = instr & 0x1F;
849 uint32_t imm2 = (instr >> 6) & 0x3;
850 uint32_t imm3 = (instr >> 12) & 0x7;
851 uint32_t lsb = (imm3 << 2) | imm2;
852 uint32_t width = msb - lsb + 1;
853 if (Rn.r != 0xF) {
854 opcode << "bfi";
855 args << Rd << ", " << Rn << ", #" << lsb << ", #" << width;
856 } else {
857 opcode << "bfc";
858 args << Rd << ", #" << lsb << ", #" << width;
859 }
860 break;
861 }
Ian Rogers40627db2012-03-04 17:31:09 -0800862 default:
863 break;
864 }
865 } else {
866 // Branches and miscellaneous control
867 // |111|11|1000000|0000|1|111|1100|00000000|
868 // |5 3|21|0987654|3 0|5|4 2|10 8|7 5 0|
869 // |---|--|-------|----|-|---|----|--------|
870 // |332|22|2222222|1111|1|111|1100|00000000|
871 // |1 9|87|6543210|9 6|5|4 2|10 8|7 5 0|
872 // |---|--|-------|----|-|---|----|--------|
873 // |111|10| op2 | |1|op3|op4 | |
874
875 uint32_t op3 = (instr >> 12) & 7;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700876 // uint32_t op4 = (instr >> 8) & 0xF;
Ian Rogers40627db2012-03-04 17:31:09 -0800877 switch (op3) {
878 case 0:
879 if ((op2 & 0x38) != 0x38) {
880 // Conditional branch
881 // |111|11|1|0000|000000|1|1|1 |1|1 |10000000000|
882 // |5 3|21|0|9876|543 0|5|4|3 |2|1 |0 5 0|
883 // |---|--|-|----|------|-|-|--|-|--|-----------|
884 // |332|22|2|2222|221111|1|1|1 |1|1 |10000000000|
885 // |1 9|87|6|5432|109 6|5|4|3 |2|1 |0 5 0|
886 // |---|--|-|----|------|-|-|--|-|--|-----------|
887 // |111|10|S|cond| imm6 |1|0|J1|0|J2| imm11 |
888 uint32_t S = (instr >> 26) & 1;
889 uint32_t J2 = (instr >> 11) & 1;
890 uint32_t J1 = (instr >> 13) & 1;
891 uint32_t imm6 = (instr >> 16) & 0x3F;
892 uint32_t imm11 = instr & 0x7FF;
893 uint32_t cond = (instr >> 22) & 0xF;
894 int32_t imm32 = (S << 20) | (J2 << 19) | (J1 << 18) | (imm6 << 12) | (imm11 << 1);
895 imm32 = (imm32 << 11) >> 11; // sign extend 21bit immediate
Elliott Hughescbf0b612012-03-15 16:23:47 -0700896 opcode << "b";
897 DumpCond(opcode, cond);
898 opcode << ".w";
899 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers9af89402012-09-07 11:29:35 -0700900 } else if (op2 == 0x3B) {
901 // Miscellaneous control instructions
902 uint32_t op5 = (instr >> 4) & 0xF;
903 switch (op5) {
904 case 4: opcode << "dsb"; break;
905 case 5: opcode << "dmb"; break;
906 case 6: opcode << "isb"; break;
907 }
Ian Rogers40627db2012-03-04 17:31:09 -0800908 }
909 break;
910 case 2:
Ian Rogersd0876a92013-02-08 11:30:38 -0800911 if ((op2 & 0x38) == 0x38) {
912 if (op2 == 0x7F) {
913 opcode << "udf";
914 }
915 break;
916 }
917 // Else deliberate fall-through to B.
918 case 1: case 3: {
919 // B
920 // |111|11|1|0000|000000|11|1 |1|1 |10000000000|
921 // |5 3|21|0|9876|543 0|54|3 |2|1 |0 5 0|
922 // |---|--|-|----|------|--|--|-|--|-----------|
923 // |332|22|2|2222|221111|11|1 |1|1 |10000000000|
924 // |1 9|87|6|5 2|10 6|54|3 |2|1 |0 5 0|
925 // |---|--|-|----|------|--|--|-|--|-----------|
926 // |111|10|S|cond| imm6 |10|J1|0|J2| imm11 |
927 // |111|10|S| imm10 |10|J1|1|J2| imm11 |
928 uint32_t S = (instr >> 26) & 1;
929 uint32_t cond = (instr >> 22) & 0xF;
930 uint32_t J2 = (instr >> 11) & 1;
931 uint32_t form = (instr >> 12) & 1;
932 uint32_t J1 = (instr >> 13) & 1;
933 uint32_t imm10 = (instr >> 16) & 0x3FF;
934 uint32_t imm6 = (instr >> 16) & 0x3F;
935 uint32_t imm11 = instr & 0x7FF;
936 opcode << "b";
937 int32_t imm32;
938 if (form == 0) {
939 DumpCond(opcode, cond);
940 imm32 = (S << 20) | (J2 << 19) | (J1 << 18) | (imm6 << 12) | (imm11 << 1);
941 imm32 = (imm32 << 11) >> 11; // sign extend 21 bit immediate.
942 } else {
943 uint32_t I1 = ~(J1 ^ S);
944 uint32_t I2 = ~(J2 ^ S);
945 imm32 = (S << 24) | (I1 << 23) | (I2 << 22) | (imm10 << 12) | (imm11 << 1);
946 imm32 = (imm32 << 8) >> 8; // sign extend 24 bit immediate.
947 }
948 opcode << ".w";
949 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers40627db2012-03-04 17:31:09 -0800950 break;
Ian Rogersd0876a92013-02-08 11:30:38 -0800951 }
Ian Rogers40627db2012-03-04 17:31:09 -0800952 case 4: case 6: case 5: case 7: {
953 // BL, BLX (immediate)
954 // |111|11|1|0000000000|11|1 |1|1 |10000000000|
955 // |5 3|21|0|9876543 0|54|3 |2|1 |0 5 0|
956 // |---|--|-|----------|--|--|-|--|-----------|
957 // |332|22|2|2222221111|11|1 |1|1 |10000000000|
958 // |1 9|87|6|5 0 6|54|3 |2|1 |0 5 0|
959 // |---|--|-|----------|--|--|-|--|-----------|
960 // |111|10|S| imm10 |11|J1|L|J2| imm11 |
961 uint32_t S = (instr >> 26) & 1;
962 uint32_t J2 = (instr >> 11) & 1;
963 uint32_t L = (instr >> 12) & 1;
964 uint32_t J1 = (instr >> 13) & 1;
965 uint32_t imm10 = (instr >> 16) & 0x3FF;
966 uint32_t imm11 = instr & 0x7FF;
967 if (L == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700968 opcode << "bx";
Ian Rogers40627db2012-03-04 17:31:09 -0800969 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700970 opcode << "blx";
Ian Rogers40627db2012-03-04 17:31:09 -0800971 }
972 uint32_t I1 = ~(J1 ^ S);
973 uint32_t I2 = ~(J2 ^ S);
974 int32_t imm32 = (S << 24) | (I1 << 23) | (I2 << 22) | (imm10 << 12) | (imm11 << 1);
975 imm32 = (imm32 << 8) >> 8; // sign extend 24 bit immediate.
Elliott Hughescbf0b612012-03-15 16:23:47 -0700976 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers40627db2012-03-04 17:31:09 -0800977 break;
978 }
979 }
980 }
981 break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800982 case 3:
983 switch (op2) {
984 case 0x00: case 0x02: case 0x04: case 0x06: // 000xxx0
985 case 0x08: case 0x0A: case 0x0C: case 0x0E: {
986 // Store single data item
Ian Rogers40627db2012-03-04 17:31:09 -0800987 // |111|11|100|000|0|0000|1111|110000|000000|
988 // |5 3|21|098|765|4|3 0|5 2|10 6|5 0|
989 // |---|--|---|---|-|----|----|------|------|
990 // |332|22|222|222|2|1111|1111|110000|000000|
991 // |1 9|87|654|321|0|9 6|5 2|10 6|5 0|
992 // |---|--|---|---|-|----|----|------|------|
993 // |111|11|000|op3|0| | | op4 | |
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800994 uint32_t op3 = (instr >> 21) & 7;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700995 // uint32_t op4 = (instr >> 6) & 0x3F;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800996 switch (op3) {
Ian Rogers087b2412012-03-21 01:30:32 -0700997 case 0x0: case 0x4: {
998 // STRB Rt,[Rn,#+/-imm8] - 111 11 00 0 0 00 0 nnnn tttt 1 PUWii ii iiii
999 // STRB Rt,[Rn,Rm,lsl #imm2] - 111 11 00 0 0 00 0 nnnn tttt 0 00000 ii mmmm
Elliott Hughes630e77d2012-03-22 19:20:56 -07001000 ArmRegister Rn(instr, 16);
1001 ArmRegister Rt(instr, 12);
Ian Rogers087b2412012-03-21 01:30:32 -07001002 opcode << "strb";
1003 if ((instr & 0x800) != 0) {
1004 uint32_t imm8 = instr & 0xFF;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001005 args << Rt << ", [" << Rn << ",#" << imm8 << "]";
Ian Rogers087b2412012-03-21 01:30:32 -07001006 } else {
1007 uint32_t imm2 = (instr >> 4) & 3;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001008 ArmRegister Rm(instr, 0);
1009 args << Rt << ", [" << Rn << ", " << Rm;
Ian Rogers087b2412012-03-21 01:30:32 -07001010 if (imm2 != 0) {
1011 args << ", " << "lsl #" << imm2;
1012 }
1013 args << "]";
1014 }
1015 break;
1016 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001017 case 0x2: case 0x6: {
Elliott Hughes630e77d2012-03-22 19:20:56 -07001018 ArmRegister Rn(instr, 16);
1019 ArmRegister Rt(instr, 12);
Ian Rogers40627db2012-03-04 17:31:09 -08001020 if (op3 == 2) {
Ian Rogers66a3fca2012-04-09 19:51:34 -07001021 if ((instr & 0x800) != 0) {
1022 // STR Rt, [Rn, #imm8] - 111 11 000 010 0 nnnn tttt 1PUWiiiiiiii
1023 uint32_t P = (instr >> 10) & 1;
1024 uint32_t U = (instr >> 9) & 1;
1025 uint32_t W = (instr >> 8) & 1;
1026 uint32_t imm8 = instr & 0xFF;
1027 int32_t imm32 = (imm8 << 24) >> 24; // sign-extend imm8
1028 if (Rn.r == 13 && P == 1 && U == 0 && W == 1 && imm32 == 4) {
1029 opcode << "push";
1030 args << Rt;
1031 } else if (Rn.r == 15 || (P == 0 && W == 0)) {
1032 opcode << "UNDEFINED";
Ian Rogers40627db2012-03-04 17:31:09 -08001033 } else {
Ian Rogers66a3fca2012-04-09 19:51:34 -07001034 if (P == 1 && U == 1 && W == 0) {
1035 opcode << "strt";
1036 } else {
1037 opcode << "str";
1038 }
1039 args << Rt << ", [" << Rn;
1040 if (P == 0 && W == 1) {
1041 args << "], #" << imm32;
1042 } else {
1043 args << ", #" << imm32 << "]";
1044 if (W == 1) {
1045 args << "!";
1046 }
Ian Rogers40627db2012-03-04 17:31:09 -08001047 }
1048 }
Ian Rogers66a3fca2012-04-09 19:51:34 -07001049 } else {
1050 // STR Rt, [Rn, Rm, LSL #imm2] - 111 11 000 010 0 nnnn tttt 000000iimmmm
1051 ArmRegister Rn(instr, 16);
1052 ArmRegister Rt(instr, 12);
1053 ArmRegister Rm(instr, 0);
1054 uint32_t imm2 = (instr >> 4) & 3;
1055 opcode << "str.w";
1056 args << Rt << ", [" << Rn << ", " << Rm;
1057 if (imm2 != 0) {
1058 args << ", lsl #" << imm2;
1059 }
1060 args << "]";
Ian Rogers40627db2012-03-04 17:31:09 -08001061 }
1062 } else if (op3 == 6) {
Ian Rogers66a3fca2012-04-09 19:51:34 -07001063 // STR.W Rt, [Rn, #imm12] - 111 11 000 110 0 nnnn tttt iiiiiiiiiiii
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001064 uint32_t imm12 = instr & 0xFFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -07001065 opcode << "str.w";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001066 args << Rt << ", [" << Rn << ", #" << imm12 << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001067 }
Ian Rogers40627db2012-03-04 17:31:09 -08001068 break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001069 }
1070 }
1071
1072 break;
1073 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001074 case 0x03: case 0x0B: case 0x13: case 0x1B: { // 00xx011
jeffhaoeae26912013-01-28 16:29:54 -08001075 // Load halfword
1076 // |111|11|10|0 0|00|0|0000|1111|110000|000000|
1077 // |5 3|21|09|8 7|65|4|3 0|5 2|10 6|5 0|
1078 // |---|--|--|---|--|-|----|----|------|------|
1079 // |332|22|22|2 2|22|2|1111|1111|110000|000000|
1080 // |1 9|87|65|4 3|21|0|9 6|5 2|10 6|5 0|
1081 // |---|--|--|---|--|-|----|----|------|------|
1082 // |111|11|00|op3|01|1| Rn | Rt | op4 | |
1083 // |111|11| op2 | | | imm12 |
1084 uint32_t op3 = (instr >> 23) & 3;
1085 ArmRegister Rn(instr, 16);
1086 ArmRegister Rt(instr, 12);
1087 if (Rt.r != 15) {
1088 if (op3 == 1) {
1089 // LDRH.W Rt, [Rn, #imm12] - 111 11 00 01 011 nnnn tttt iiiiiiiiiiii
1090 uint32_t imm12 = instr & 0xFFF;
1091 opcode << "ldrh.w";
1092 args << Rt << ", [" << Rn << ", #" << imm12 << "]";
1093 if (Rn.r == 9) {
1094 args << " ; ";
1095 Thread::DumpThreadOffset(args, imm12, 4);
1096 } else if (Rn.r == 15) {
1097 intptr_t lit_adr = reinterpret_cast<intptr_t>(instr_ptr);
1098 lit_adr = RoundDown(lit_adr, 4) + 4 + imm12;
1099 args << " ; " << reinterpret_cast<void*>(*reinterpret_cast<int32_t*>(lit_adr));
1100 }
1101 } else if (op3 == 3) {
1102 // LDRSH.W Rt, [Rn, #imm12] - 111 11 00 11 011 nnnn tttt iiiiiiiiiiii
1103 uint32_t imm12 = instr & 0xFFF;
1104 opcode << "ldrsh.w";
1105 args << Rt << ", [" << Rn << ", #" << imm12 << "]";
1106 if (Rn.r == 9) {
1107 args << " ; ";
1108 Thread::DumpThreadOffset(args, imm12, 4);
1109 } else if (Rn.r == 15) {
1110 intptr_t lit_adr = reinterpret_cast<intptr_t>(instr_ptr);
1111 lit_adr = RoundDown(lit_adr, 4) + 4 + imm12;
1112 args << " ; " << reinterpret_cast<void*>(*reinterpret_cast<int32_t*>(lit_adr));
1113 }
1114 }
1115 }
1116 break;
1117 }
Vladimir Markoa8b4caf2013-10-24 15:08:57 +01001118 case 0x29: { // 0101001
1119 // |111|11|1000000|0000|1111|1100|00|0 0|0000|
1120 // |5 3|21|0 4|3 0|5 2|1 8|76|5 4|3 0|
1121 // |---|--|-------|----|----|----|--|---|----|
1122 // |332|22|2222222|1111|1111|1100|00|0 0|0000|
1123 // |1 9|87|6 0|9 6|5 2|1 8|76|5 4|3 0|
1124 // |---|--|-------|----|----|----|--|---|----|
1125 // |111|11|0101001| Rm |1111| Rd |11|op3| Rm |
1126 // REV - 111 11 0101001 mmmm 1111 dddd 1000 mmmm
1127 // REV16 - 111 11 0101001 mmmm 1111 dddd 1001 mmmm
1128 // RBIT - 111 11 0101001 mmmm 1111 dddd 1010 mmmm
1129 // REVSH - 111 11 0101001 mmmm 1111 dddd 1011 mmmm
1130 if ((instr & 0xf0c0) == 0xf080) {
1131 uint32_t op3 = (instr >> 4) & 3;
1132 opcode << kThumbReverseOperations[op3];
1133 ArmRegister Rm(instr, 0);
1134 ArmRegister Rd(instr, 8);
1135 args << Rd << ", " << Rm;
1136 ArmRegister Rm2(instr, 16);
1137 if (Rm.r != Rm2.r || Rm.r == 13 || Rm.r == 15 || Rd.r == 13 || Rd.r == 15) {
1138 args << " (UNPREDICTABLE)";
1139 }
Vladimir Marko1f6754d2013-10-28 20:27:17 +00001140 } // else unknown instruction
Vladimir Markoa8b4caf2013-10-24 15:08:57 +01001141 break;
1142 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001143 case 0x05: case 0x0D: case 0x15: case 0x1D: { // 00xx101
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001144 // Load word
1145 // |111|11|10|0 0|00|0|0000|1111|110000|000000|
1146 // |5 3|21|09|8 7|65|4|3 0|5 2|10 6|5 0|
1147 // |---|--|--|---|--|-|----|----|------|------|
1148 // |332|22|22|2 2|22|2|1111|1111|110000|000000|
1149 // |1 9|87|65|4 3|21|0|9 6|5 2|10 6|5 0|
1150 // |---|--|--|---|--|-|----|----|------|------|
1151 // |111|11|00|op3|10|1| Rn | Rt | op4 | |
1152 // |111|11| op2 | | | imm12 |
1153 uint32_t op3 = (instr >> 23) & 3;
1154 uint32_t op4 = (instr >> 6) & 0x3F;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001155 ArmRegister Rn(instr, 16);
1156 ArmRegister Rt(instr, 12);
1157 if (op3 == 1 || Rn.r == 15) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001158 // LDR.W Rt, [Rn, #imm12] - 111 11 00 00 101 nnnn tttt iiiiiiiiiiii
1159 // LDR.W Rt, [PC, #imm12] - 111 11 00 0x 101 1111 tttt iiiiiiiiiiii
1160 uint32_t imm12 = instr & 0xFFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -07001161 opcode << "ldr.w";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001162 args << Rt << ", [" << Rn << ", #" << imm12 << "]";
Elliott Hughes28fa76d2012-04-09 17:31:46 -07001163 if (Rn.r == 9) {
1164 args << " ; ";
1165 Thread::DumpThreadOffset(args, imm12, 4);
Ian Rogers5b9b1bc2012-04-09 22:51:43 -07001166 } else if (Rn.r == 15) {
1167 intptr_t lit_adr = reinterpret_cast<intptr_t>(instr_ptr);
1168 lit_adr = RoundDown(lit_adr, 4) + 4 + imm12;
1169 args << " ; " << reinterpret_cast<void*>(*reinterpret_cast<int32_t*>(lit_adr));
Elliott Hughes28fa76d2012-04-09 17:31:46 -07001170 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001171 } else if (op4 == 0) {
1172 // LDR.W Rt, [Rn, Rm{, LSL #imm2}] - 111 11 00 00 101 nnnn tttt 000000iimmmm
1173 uint32_t imm2 = (instr >> 4) & 0xF;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001174 ArmRegister rm(instr, 0);
Elliott Hughescbf0b612012-03-15 16:23:47 -07001175 opcode << "ldr.w";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001176 args << Rt << ", [" << Rn << ", " << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001177 if (imm2 != 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001178 args << ", lsl #" << imm2;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001179 }
Elliott Hughescbf0b612012-03-15 16:23:47 -07001180 args << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001181 } else {
1182 // LDRT Rt, [Rn, #imm8] - 111 11 00 00 101 nnnn tttt 1110iiiiiiii
1183 uint32_t imm8 = instr & 0xFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -07001184 opcode << "ldrt";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001185 args << Rt << ", [" << Rn << ", #" << imm8 << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001186 }
1187 break;
1188 }
Dave Allison70202782013-10-22 17:52:19 -07001189 default: // more formats
1190 if ((op2 >> 4) == 2) { // 010xxxx
1191 // data processing (register)
1192 } else if ((op2 >> 3) == 6) { // 0110xxx
1193 // Multiply, multiply accumulate, and absolute difference
1194 op1 = (instr >> 20) & 0x7;
1195 op2 = (instr >> 4) & 0x2;
1196 ArmRegister Ra(instr, 12);
1197 ArmRegister Rn(instr, 16);
1198 ArmRegister Rm(instr, 0);
1199 ArmRegister Rd(instr, 8);
1200 switch (op1) {
1201 case 0:
1202 if (op2 == 0) {
1203 if (Ra.r == 0xf) {
1204 opcode << "mul";
1205 args << Rd << ", " << Rn << ", " << Rm;
1206 } else {
1207 opcode << "mla";
1208 args << Rd << ", " << Rn << ", " << Rm << ", " << Ra;
1209 }
1210 } else {
1211 opcode << "mls";
1212 args << Rd << ", " << Rn << ", " << Rm << ", " << Ra;
1213 }
1214 break;
1215 case 1:
1216 case 2:
1217 case 3:
1218 case 4:
1219 case 5:
1220 case 6:
1221 break; // do these sometime
1222 }
1223 } else if ((op2 >> 3) == 7) { // 0111xxx
1224 // Long multiply, long multiply accumulate, and divide
1225 op1 = (instr >> 20) & 0x7;
1226 op2 = (instr >> 4) & 0xf;
1227 ArmRegister Rn(instr, 16);
1228 ArmRegister Rm(instr, 0);
1229 ArmRegister Rd(instr, 8);
1230 ArmRegister RdHi(instr, 8);
1231 ArmRegister RdLo(instr, 12);
1232 switch (op1) {
1233 case 0:
1234 opcode << "smull";
1235 args << RdLo << ", " << RdHi << ", " << Rn << ", " << Rm;
1236 break;
1237 case 1:
1238 opcode << "sdiv";
1239 args << Rd << ", " << Rn << ", " << Rm;
1240 break;
1241 case 2:
1242 opcode << "umull";
1243 args << RdLo << ", " << RdHi << ", " << Rn << ", " << Rm;
1244 break;
1245 case 3:
1246 opcode << "udiv";
1247 args << Rd << ", " << Rn << ", " << Rm;
1248 break;
1249 case 4:
1250 case 5:
1251 case 6:
1252 break; // TODO: when we generate these...
1253 }
1254 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001255 }
1256 default:
1257 break;
1258 }
Ian Rogers9af89402012-09-07 11:29:35 -07001259
1260 // Apply any IT-block conditions to the opcode if necessary.
1261 if (!it_conditions_.empty()) {
1262 opcode << it_conditions_.back();
1263 it_conditions_.pop_back();
1264 }
1265
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001266 os << StringPrintf("%p: %08x\t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001267 return 4;
Brian Carlstrom1895ea32013-07-18 13:28:37 -07001268} // NOLINT(readability/fn_size)
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001269
1270size_t DisassemblerArm::DumpThumb16(std::ostream& os, const uint8_t* instr_ptr) {
1271 uint16_t instr = ReadU16(instr_ptr);
1272 bool is_32bit = ((instr & 0xF000) == 0xF000) || ((instr & 0xF800) == 0xE800);
1273 if (is_32bit) {
1274 return DumpThumb32(os, instr_ptr);
1275 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001276 std::ostringstream opcode;
1277 std::ostringstream args;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001278 uint16_t opcode1 = instr >> 10;
1279 if (opcode1 < 0x10) {
1280 // shift (immediate), add, subtract, move, and compare
1281 uint16_t opcode2 = instr >> 9;
1282 switch (opcode2) {
1283 case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
1284 case 0x8: case 0x9: case 0xA: case 0xB: {
Sebastien Hertze78500c2013-02-19 14:29:52 +01001285 // Logical shift left - 00 000xx iii mmm ddd
1286 // Logical shift right - 00 001xx iii mmm ddd
1287 // Arithmetic shift right - 00 010xx iii mmm ddd
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001288 uint16_t imm5 = (instr >> 6) & 0x1F;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001289 ThumbRegister rm(instr, 3);
Sebastien Hertze78500c2013-02-19 14:29:52 +01001290 ThumbRegister Rd(instr, 0);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001291 if (opcode2 <= 3) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001292 opcode << "lsls";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001293 } else if (opcode2 <= 7) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001294 opcode << "lsrs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001295 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001296 opcode << "asrs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001297 }
Elliott Hughes630e77d2012-03-22 19:20:56 -07001298 args << Rd << ", " << rm << ", #" << imm5;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001299 break;
1300 }
1301 case 0xC: case 0xD: case 0xE: case 0xF: {
1302 // Add register - 00 01100 mmm nnn ddd
1303 // Sub register - 00 01101 mmm nnn ddd
1304 // Add 3-bit immediate - 00 01110 iii nnn ddd
1305 // Sub 3-bit immediate - 00 01111 iii nnn ddd
1306 uint16_t imm3_or_Rm = (instr >> 6) & 7;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001307 ThumbRegister Rn(instr, 3);
1308 ThumbRegister Rd(instr, 0);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001309 if ((opcode2 & 2) != 0 && imm3_or_Rm == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001310 opcode << "mov";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001311 } else {
1312 if ((opcode2 & 1) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001313 opcode << "adds";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001314 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001315 opcode << "subs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001316 }
1317 }
Elliott Hughes630e77d2012-03-22 19:20:56 -07001318 args << Rd << ", " << Rn;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001319 if ((opcode2 & 2) == 0) {
Elliott Hughes630e77d2012-03-22 19:20:56 -07001320 ArmRegister Rm(imm3_or_Rm);
1321 args << ", " << Rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001322 } else if (imm3_or_Rm != 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001323 args << ", #" << imm3_or_Rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001324 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001325 break;
1326 }
1327 case 0x10: case 0x11: case 0x12: case 0x13:
1328 case 0x14: case 0x15: case 0x16: case 0x17:
1329 case 0x18: case 0x19: case 0x1A: case 0x1B:
1330 case 0x1C: case 0x1D: case 0x1E: case 0x1F: {
1331 // MOVS Rd, #imm8 - 00100 ddd iiiiiiii
1332 // CMP Rn, #imm8 - 00101 nnn iiiiiiii
1333 // ADDS Rn, #imm8 - 00110 nnn iiiiiiii
1334 // SUBS Rn, #imm8 - 00111 nnn iiiiiiii
Elliott Hughes630e77d2012-03-22 19:20:56 -07001335 ThumbRegister Rn(instr, 8);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001336 uint16_t imm8 = instr & 0xFF;
1337 switch (opcode2 >> 2) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001338 case 4: opcode << "movs"; break;
1339 case 5: opcode << "cmp"; break;
1340 case 6: opcode << "adds"; break;
1341 case 7: opcode << "subs"; break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001342 }
Elliott Hughes630e77d2012-03-22 19:20:56 -07001343 args << Rn << ", #" << imm8;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001344 break;
1345 }
1346 default:
1347 break;
1348 }
Ian Rogersad03ef52012-03-18 19:34:47 -07001349 } else if (opcode1 == 0x10) {
1350 // Data-processing
1351 uint16_t opcode2 = (instr >> 6) & 0xF;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001352 ThumbRegister rm(instr, 3);
1353 ThumbRegister rdn(instr, 0);
Ian Rogersad03ef52012-03-18 19:34:47 -07001354 opcode << kThumbDataProcessingOperations[opcode2];
Elliott Hughes630e77d2012-03-22 19:20:56 -07001355 args << rdn << ", " << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001356 } else if (opcode1 == 0x11) {
1357 // Special data instructions and branch and exchange
1358 uint16_t opcode2 = (instr >> 6) & 0x0F;
1359 switch (opcode2) {
1360 case 0x0: case 0x1: case 0x2: case 0x3: {
1361 // Add low registers - 010001 0000 xxxxxx
1362 // Add high registers - 010001 0001/001x xxxxxx
1363 uint16_t DN = (instr >> 7) & 1;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001364 ArmRegister rm(instr, 3);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001365 uint16_t Rdn = instr & 7;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001366 ArmRegister DN_Rdn((DN << 3) | Rdn);
Elliott Hughescbf0b612012-03-15 16:23:47 -07001367 opcode << "add";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001368 args << DN_Rdn << ", " << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001369 break;
1370 }
1371 case 0x8: case 0x9: case 0xA: case 0xB: {
1372 // Move low registers - 010001 1000 xxxxxx
1373 // Move high registers - 010001 1001/101x xxxxxx
1374 uint16_t DN = (instr >> 7) & 1;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001375 ArmRegister rm(instr, 3);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001376 uint16_t Rdn = instr & 7;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001377 ArmRegister DN_Rdn((DN << 3) | Rdn);
Elliott Hughescbf0b612012-03-15 16:23:47 -07001378 opcode << "mov";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001379 args << DN_Rdn << ", " << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001380 break;
1381 }
1382 case 0x5: case 0x6: case 0x7: {
1383 // Compare high registers - 010001 0101/011x xxxxxx
1384 uint16_t N = (instr >> 7) & 1;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001385 ArmRegister rm(instr, 3);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001386 uint16_t Rn = instr & 7;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001387 ArmRegister N_Rn((N << 3) | Rn);
Elliott Hughescbf0b612012-03-15 16:23:47 -07001388 opcode << "cmp";
Elliott Hughes630e77d2012-03-22 19:20:56 -07001389 args << N_Rn << ", " << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001390 break;
1391 }
1392 case 0xC: case 0xD: case 0xE: case 0xF: {
1393 // Branch and exchange - 010001 110x xxxxxx
1394 // Branch with link and exchange - 010001 111x xxxxxx
Elliott Hughes630e77d2012-03-22 19:20:56 -07001395 ArmRegister rm(instr, 3);
1396 opcode << ((opcode2 & 0x2) == 0 ? "bx" : "blx");
1397 args << rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001398 break;
1399 }
1400 default:
1401 break;
1402 }
jeffhaoeae26912013-01-28 16:29:54 -08001403 } else if (opcode1 == 0x12 || opcode1 == 0x13) { // 01001x
1404 ThumbRegister Rt(instr, 8);
1405 uint16_t imm8 = instr & 0xFF;
1406 opcode << "ldr";
1407 args << Rt << ", [pc, #" << (imm8 << 2) << "]";
Ian Rogersd83bc362012-09-07 17:43:13 -07001408 } else if ((opcode1 >= 0x14 && opcode1 <= 0x17) || // 0101xx
1409 (opcode1 >= 0x18 && opcode1 <= 0x1f) || // 011xxx
1410 (opcode1 >= 0x20 && opcode1 <= 0x27)) { // 100xxx
1411 // Load/store single data item
1412 uint16_t opA = (instr >> 12) & 0xF;
1413 if (opA == 0x5) {
1414 uint16_t opB = (instr >> 9) & 0x7;
1415 ThumbRegister Rm(instr, 6);
1416 ThumbRegister Rn(instr, 3);
1417 ThumbRegister Rt(instr, 0);
Brian Carlstromdf629502013-07-17 22:39:56 -07001418 switch (opB) {
Ian Rogersd83bc362012-09-07 17:43:13 -07001419 case 0: opcode << "str"; break;
1420 case 1: opcode << "strh"; break;
1421 case 2: opcode << "strb"; break;
1422 case 3: opcode << "ldrsb"; break;
1423 case 4: opcode << "ldr"; break;
1424 case 5: opcode << "ldrh"; break;
1425 case 6: opcode << "ldrb"; break;
1426 case 7: opcode << "ldrsh"; break;
1427 }
1428 args << Rt << ", [" << Rn << ", " << Rm << "]";
1429 } else if (opA == 9) {
1430 uint16_t opB = (instr >> 11) & 1;
1431 ThumbRegister Rt(instr, 8);
1432 uint16_t imm8 = instr & 0xFF;
1433 opcode << (opB == 0 ? "str" : "ldr");
Ian Rogers137e88f2012-10-08 17:46:47 -07001434 args << Rt << ", [sp, #" << (imm8 << 2) << "]";
Ian Rogersd83bc362012-09-07 17:43:13 -07001435 } else {
1436 uint16_t imm5 = (instr >> 6) & 0x1F;
1437 uint16_t opB = (instr >> 11) & 1;
1438 ThumbRegister Rn(instr, 3);
1439 ThumbRegister Rt(instr, 0);
Brian Carlstromdf629502013-07-17 22:39:56 -07001440 switch (opA) {
Ian Rogersd83bc362012-09-07 17:43:13 -07001441 case 6:
1442 imm5 <<= 2;
1443 opcode << (opB == 0 ? "str" : "ldr");
1444 break;
1445 case 7:
1446 imm5 <<= 0;
1447 opcode << (opB == 0 ? "strb" : "ldrb");
1448 break;
1449 case 8:
1450 imm5 <<= 1;
1451 opcode << (opB == 0 ? "strh" : "ldrh");
1452 break;
1453 }
1454 args << Rt << ", [" << Rn << ", #" << imm5 << "]";
1455 }
jeffhaoeae26912013-01-28 16:29:54 -08001456 } else if (opcode1 >= 0x34 && opcode1 <= 0x37) { // 1101xx
Ian Rogers7761cb62013-06-17 14:10:46 -07001457 int8_t imm8 = instr & 0xFF;
jeffhaoeae26912013-01-28 16:29:54 -08001458 uint32_t cond = (instr >> 8) & 0xF;
1459 opcode << "b";
1460 DumpCond(opcode, cond);
1461 DumpBranchTarget(args, instr_ptr + 4, (imm8 << 1));
Ian Rogers9af89402012-09-07 11:29:35 -07001462 } else if ((instr & 0xF800) == 0xA800) {
1463 // Generate SP-relative address
1464 ThumbRegister rd(instr, 8);
1465 int imm8 = instr & 0xFF;
1466 opcode << "add";
1467 args << rd << ", sp, #" << (imm8 << 2);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001468 } else if ((instr & 0xF000) == 0xB000) {
1469 // Miscellaneous 16-bit instructions
1470 uint16_t opcode2 = (instr >> 5) & 0x7F;
1471 switch (opcode2) {
1472 case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: {
1473 // Add immediate to SP - 1011 00000 ii iiiii
1474 // Subtract immediate from SP - 1011 00001 ii iiiii
1475 int imm7 = instr & 0x7F;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001476 opcode << ((opcode2 & 4) == 0 ? "add" : "sub");
Elliott Hughescbf0b612012-03-15 16:23:47 -07001477 args << "sp, sp, #" << (imm7 << 2);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001478 break;
1479 }
Ian Rogers087b2412012-03-21 01:30:32 -07001480 case 0x08: case 0x09: case 0x0A: case 0x0B: // 0001xxx
Ian Rogersebbc5772012-04-11 17:00:08 -07001481 case 0x0C: case 0x0D: case 0x0E: case 0x0F:
Ian Rogers55019132013-02-08 01:05:23 -08001482 case 0x18: case 0x19: case 0x1A: case 0x1B: // 0011xxx
1483 case 0x1C: case 0x1D: case 0x1E: case 0x1F:
Ian Rogersebbc5772012-04-11 17:00:08 -07001484 case 0x48: case 0x49: case 0x4A: case 0x4B: // 1001xxx
Ian Rogers55019132013-02-08 01:05:23 -08001485 case 0x4C: case 0x4D: case 0x4E: case 0x4F:
1486 case 0x58: case 0x59: case 0x5A: case 0x5B: // 1011xxx
1487 case 0x5C: case 0x5D: case 0x5E: case 0x5F: {
Ian Rogers087b2412012-03-21 01:30:32 -07001488 // CBNZ, CBZ
1489 uint16_t op = (instr >> 11) & 1;
1490 uint16_t i = (instr >> 9) & 1;
1491 uint16_t imm5 = (instr >> 3) & 0x1F;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001492 ThumbRegister Rn(instr, 0);
Ian Rogers087b2412012-03-21 01:30:32 -07001493 opcode << (op != 0 ? "cbnz" : "cbz");
Ian Rogers828a07f2013-06-18 22:27:34 -07001494 uint32_t imm32 = (i << 6) | (imm5 << 1);
Elliott Hughes630e77d2012-03-22 19:20:56 -07001495 args << Rn << ", ";
Ian Rogers087b2412012-03-21 01:30:32 -07001496 DumpBranchTarget(args, instr_ptr + 4, imm32);
1497 break;
1498 }
Vladimir Markoa8b4caf2013-10-24 15:08:57 +01001499 case 0x50: case 0x51: // 101000x
1500 case 0x52: case 0x53: // 101001x
1501 case 0x56: case 0x57: { // 101011x
1502 uint16_t op = (instr >> 6) & 3;
1503 opcode << kThumbReverseOperations[op];
1504 ThumbRegister Rm(instr, 3);
1505 ThumbRegister Rd(instr, 0);
1506 args << Rd << ", " << Rm;
1507 break;
1508 }
Ian Rogers40627db2012-03-04 17:31:09 -08001509 case 0x78: case 0x79: case 0x7A: case 0x7B: // 1111xxx
1510 case 0x7C: case 0x7D: case 0x7E: case 0x7F: {
1511 // If-Then, and hints
1512 uint16_t opA = (instr >> 4) & 0xF;
1513 uint16_t opB = instr & 0xF;
1514 if (opB == 0) {
1515 switch (opA) {
Elliott Hughescbf0b612012-03-15 16:23:47 -07001516 case 0: opcode << "nop"; break;
1517 case 1: opcode << "yield"; break;
1518 case 2: opcode << "wfe"; break;
1519 case 3: opcode << "sev"; break;
Ian Rogers40627db2012-03-04 17:31:09 -08001520 default: break;
1521 }
1522 } else {
Elliott Hughes105afd22012-04-10 15:04:25 -07001523 uint32_t first_cond = opA;
1524 uint32_t mask = opB;
Elliott Hughescbf0b612012-03-15 16:23:47 -07001525 opcode << "it";
Elliott Hughes105afd22012-04-10 15:04:25 -07001526
1527 // Flesh out the base "it" opcode with the specific collection of 't's and 'e's,
1528 // and store up the actual condition codes we'll want to add to the next few opcodes.
1529 size_t count = 3 - CTZ(mask);
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001530 it_conditions_.resize(count + 2); // Plus the implicit 't', plus the "" for the IT itself.
Elliott Hughes105afd22012-04-10 15:04:25 -07001531 for (size_t i = 0; i < count; ++i) {
1532 bool positive_cond = ((first_cond & 1) != 0);
1533 bool positive_mask = ((mask & (1 << (3 - i))) != 0);
1534 if (positive_mask == positive_cond) {
1535 opcode << 't';
1536 it_conditions_[i] = kConditionCodeNames[first_cond];
1537 } else {
1538 opcode << 'e';
1539 it_conditions_[i] = kConditionCodeNames[first_cond ^ 1];
1540 }
1541 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001542 it_conditions_[count] = kConditionCodeNames[first_cond]; // The implicit 't'.
Elliott Hughes105afd22012-04-10 15:04:25 -07001543
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001544 it_conditions_[count + 1] = ""; // No condition code for the IT itself...
1545 DumpCond(args, first_cond); // ...because it's considered an argument.
Ian Rogers40627db2012-03-04 17:31:09 -08001546 }
1547 break;
1548 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001549 default:
1550 break;
1551 }
1552 } else if (((instr & 0xF000) == 0x5000) || ((instr & 0xE000) == 0x6000) ||
1553 ((instr & 0xE000) == 0x8000)) {
1554 // Load/store single data item
1555 uint16_t opA = instr >> 12;
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001556 // uint16_t opB = (instr >> 9) & 7;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001557 switch (opA) {
1558 case 0x6: {
Elliott Hughes28fa76d2012-04-09 17:31:46 -07001559 // STR Rt, [Rn, #imm] - 01100 iiiii nnn ttt
1560 // LDR Rt, [Rn, #imm] - 01101 iiiii nnn ttt
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001561 uint16_t imm5 = (instr >> 6) & 0x1F;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001562 ThumbRegister Rn(instr, 3);
Elliott Hughes28fa76d2012-04-09 17:31:46 -07001563 ThumbRegister Rt(instr, 0);
Elliott Hughes630e77d2012-03-22 19:20:56 -07001564 opcode << ((instr & 0x800) == 0 ? "str" : "ldr");
1565 args << Rt << ", [" << Rn << ", #" << (imm5 << 2) << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001566 break;
1567 }
1568 case 0x9: {
1569 // STR Rt, [SP, #imm] - 01100 ttt iiiiiiii
1570 // LDR Rt, [SP, #imm] - 01101 ttt iiiiiiii
1571 uint16_t imm8 = instr & 0xFF;
Elliott Hughes630e77d2012-03-22 19:20:56 -07001572 ThumbRegister Rt(instr, 8);
1573 opcode << ((instr & 0x800) == 0 ? "str" : "ldr");
1574 args << Rt << ", [sp, #" << (imm8 << 2) << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001575 break;
1576 }
1577 default:
1578 break;
1579 }
Ian Rogers40627db2012-03-04 17:31:09 -08001580 } else if (opcode1 == 0x38 || opcode1 == 0x39) {
1581 uint16_t imm11 = instr & 0x7FFF;
1582 int32_t imm32 = imm11 << 1;
1583 imm32 = (imm32 << 20) >> 20; // sign extend 12 bit immediate
Elliott Hughescbf0b612012-03-15 16:23:47 -07001584 opcode << "b";
1585 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001586 }
Elliott Hughes105afd22012-04-10 15:04:25 -07001587
1588 // Apply any IT-block conditions to the opcode if necessary.
1589 if (!it_conditions_.empty()) {
1590 opcode << it_conditions_.back();
1591 it_conditions_.pop_back();
1592 }
1593
Ian Rogers2bcb4a42012-11-08 10:39:18 -08001594 os << StringPrintf("%p: %04x \t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001595 }
1596 return 2;
1597}
1598
1599} // namespace arm
1600} // namespace art