blob: e147c813a6f0eb4043470907c25a5e2bb8ea69c5 [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
19#include "stringprintf.h"
20
21#include <iostream>
22
23namespace art {
24namespace arm {
25
26DisassemblerArm::DisassemblerArm() {
27}
28
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080029void DisassemblerArm::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) {
30 if ((reinterpret_cast<intptr_t>(begin) & 1) == 0) {
31 for (const uint8_t* cur = begin; cur < end; cur += 4) {
32 DumpArm(os, cur);
33 }
34 } else {
35 // remove thumb specifier bits
36 begin = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(begin) & ~1);
37 end = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(end) & ~1);
38 for (const uint8_t* cur = begin; cur < end;) {
39 cur += DumpThumb16(os, cur);
40 }
41 }
42}
43
Elliott Hughes77405792012-03-15 15:22:12 -070044static const char* kConditionCodeNames[] = {
Elliott Hughescbf0b612012-03-15 16:23:47 -070045 "eq", // 0000 - equal
46 "ne", // 0001 - not-equal
47 "cs", // 0010 - carry-set, greater than, equal or unordered
48 "cc", // 0011 - carry-clear, less than
49 "mi", // 0100 - minus, negative
50 "pl", // 0101 - plus, positive or zero
51 "vs", // 0110 - overflow
52 "vc", // 0111 - no overflow
53 "hi", // 1000 - unsigned higher
54 "ls", // 1001 - unsigned lower or same
55 "ge", // 1010 - signed greater than or equal
56 "lt", // 1011 - signed less than
57 "gt", // 1100 - signed greater than
58 "le", // 1101 - signed less than or equal
59 "", // 1110 - always
60 "nv", // 1111 - never (mostly obsolete, but might be a clue that we're mistranslating)
Ian Rogers40627db2012-03-04 17:31:09 -080061};
62
63void DisassemblerArm::DumpCond(std::ostream& os, uint32_t cond) {
64 if (cond < 15) {
Elliott Hughes77405792012-03-15 15:22:12 -070065 os << kConditionCodeNames[cond];
Ian Rogers40627db2012-03-04 17:31:09 -080066 } else {
67 os << "Unexpected condition: " << cond;
68 }
69}
70
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080071void DisassemblerArm::DumpReg(std::ostream& os, uint32_t reg) {
72 switch (reg) {
Elliott Hughescbf0b612012-03-15 16:23:47 -070073 case 13: os << "sp"; break;
74 case 14: os << "lr"; break;
75 case 15: os << "pc"; break;
76 default: os << "r" << reg; break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080077 }
78}
79
Ian Rogers40627db2012-03-04 17:31:09 -080080void DisassemblerArm::DumpBranchTarget(std::ostream& os, const uint8_t* instr_ptr, int32_t imm32) {
81 os << imm32 << " (" << reinterpret_cast<const void*>(instr_ptr + imm32) << ")";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080082}
83
84static uint32_t ReadU16(const uint8_t* ptr) {
85 return ptr[0] | (ptr[1] << 8);
86}
87
88static uint32_t ReadU32(const uint8_t* ptr) {
89 return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
90}
91
Elliott Hughes77405792012-03-15 15:22:12 -070092static const char* kDataProcessingOperations[] = {
Elliott Hughescbf0b612012-03-15 16:23:47 -070093 "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc",
94 "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn",
Elliott Hughes77405792012-03-15 15:22:12 -070095};
96
97struct ArmRegister {
98 ArmRegister(uint32_t r) : r(r) { CHECK_LE(r, 15U); }
99 uint32_t r;
100};
101std::ostream& operator<<(std::ostream& os, const ArmRegister& r) {
102 if (r.r == 13) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700103 os << "sp";
Elliott Hughes77405792012-03-15 15:22:12 -0700104 } else if (r.r == 14) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700105 os << "lr";
Elliott Hughes77405792012-03-15 15:22:12 -0700106 } else if (r.r == 15) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700107 os << "pc";
Elliott Hughes77405792012-03-15 15:22:12 -0700108 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700109 os << "r" << r.r;
Elliott Hughes77405792012-03-15 15:22:12 -0700110 }
111 return os;
112}
113
114struct Rd : ArmRegister {
115 Rd(uint32_t instruction) : ArmRegister((instruction >> 12) & 0xf) {}
116};
117typedef Rd Rt;
118struct Rn : ArmRegister {
119 Rn(uint32_t instruction) : ArmRegister((instruction >> 16) & 0xf) {}
120};
121
122struct Rm {
123 Rm(uint32_t instruction) : shift((instruction >> 4) & 0xff), rm(instruction & 0xf) {}
124 uint32_t shift;
125 ArmRegister rm;
126};
127std::ostream& operator<<(std::ostream& os, const Rm& r) {
128 os << r.rm;
129 if (r.shift != 0) {
130 os << "-shift-" << r.shift; // TODO
131 }
132 return os;
133}
134
135struct Imm12 {
136 Imm12(uint32_t instruction) : rotate((instruction >> 8) & 0xf), imm(instruction & 0xff) {}
137 uint32_t rotate;
138 uint32_t imm;
139};
140std::ostream& operator<<(std::ostream& os, const Imm12& rhs) {
141 uint32_t imm = (rhs.imm >> (2 * rhs.rotate)) | (rhs.imm << (32 - (2 * rhs.rotate)));
142 os << "#" << imm;
143 return os;
144}
145
146struct RegisterList {
147 RegisterList(uint32_t instruction) : register_list(instruction & 0xffff) {}
148 uint32_t register_list;
149};
150std::ostream& operator<<(std::ostream& os, const RegisterList& rhs) {
151 if (rhs.register_list == 0) {
152 os << "<no register list?>";
153 return os;
154 }
155 bool first = true;
156 for (size_t i = 0; i < 16; i++) {
157 if ((rhs.register_list & (1 << i)) != 0) {
158 if (first) {
159 os << "{";
160 first = false;
161 } else {
162 os << ", ";
163 }
164 os << ArmRegister(i);
165 }
166 }
167 os << "}";
168 return os;
169}
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800170
171void DisassemblerArm::DumpArm(std::ostream& os, const uint8_t* instr_ptr) {
Elliott Hughes77405792012-03-15 15:22:12 -0700172 uint32_t instruction = ReadU32(instr_ptr);
173 uint32_t cond = (instruction >> 28) & 0xf;
174 uint32_t op1 = (instruction >> 25) & 0x7;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700175 std::ostringstream opcode;
176 std::ostringstream args;
Elliott Hughes77405792012-03-15 15:22:12 -0700177 switch (op1) {
178 case 0:
179 case 1: // Data processing instructions.
180 {
181 if ((instruction & 0x0fffffd0) == 0x012fff10) { // BX and BLX (register)
Elliott Hughescbf0b612012-03-15 16:23:47 -0700182 opcode << (((instruction >> 5) & 1) ? "blx" : "bx");
183 args << ArmRegister(instruction & 0xf);
Elliott Hughes77405792012-03-15 15:22:12 -0700184 break;
185 }
186 bool i = (instruction & (1 << 25)) != 0;
187 bool s = (instruction & (1 << 20)) != 0;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700188 opcode << kDataProcessingOperations[(instruction >> 21) & 0xf]
189 << kConditionCodeNames[cond]
190 << (s ? "s" : "");
191 args << Rd(instruction) << ", ";
Elliott Hughes77405792012-03-15 15:22:12 -0700192 if (i) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700193 args << Rn(instruction) << ", " << Imm12(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700194 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700195 args << Rm(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700196 }
197 }
198 break;
199 case 2: // Load/store word and unsigned byte.
200 {
201 bool p = (instruction & (1 << 24)) != 0;
202 bool b = (instruction & (1 << 22)) != 0;
203 bool w = (instruction & (1 << 21)) != 0;
204 bool l = (instruction & (1 << 20)) != 0;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700205 opcode << (l ? "ldr" : "str") << (b ? "b" : "") << kConditionCodeNames[cond];
206 args << Rt(instruction) << ", ";
Elliott Hughes77405792012-03-15 15:22:12 -0700207 if (Rn(instruction).r == 0xf) {
208 UNIMPLEMENTED(FATAL) << "literals";
209 } else {
210 bool wback = !p || w;
211 if (p && !wback) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700212 args << "[" << Rn(instruction) << ", " << Imm12(instruction) << "]";
Elliott Hughes77405792012-03-15 15:22:12 -0700213 } else if (p && wback) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700214 args << "[" << Rn(instruction) << ", " << Imm12(instruction) << "]!";
Elliott Hughes77405792012-03-15 15:22:12 -0700215 } else if (!p && wback) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700216 args << "[" << Rn(instruction) << "], " << Imm12(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700217 } else {
218 LOG(FATAL) << p << " " << w;
219 }
220 }
221 }
222 break;
223 case 4: // Load/store multiple.
224 {
225 bool p = (instruction & (1 << 24)) != 0;
226 bool u = (instruction & (1 << 23)) != 0;
227 bool w = (instruction & (1 << 21)) != 0;
228 bool l = (instruction & (1 << 20)) != 0;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700229 opcode << (l ? "ldm" : "stm")
230 << (u ? 'i' : 'd')
231 << (p ? 'b' : 'a')
232 << kConditionCodeNames[cond];
233 args << Rn(instruction) << (w ? "!" : "") << ", " << RegisterList(instruction);
Elliott Hughes77405792012-03-15 15:22:12 -0700234 }
235 break;
236 default:
Elliott Hughescbf0b612012-03-15 16:23:47 -0700237 opcode << "???";
Elliott Hughes77405792012-03-15 15:22:12 -0700238 break;
239 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700240 // TODO: a more complete ARM disassembler could generate wider opcodes.
241 os << StringPrintf("\t\t\t%p: %08x\t%-7s ", instr_ptr, instruction, opcode.str().c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800242}
243
244size_t DisassemblerArm::DumpThumb32(std::ostream& os, const uint8_t* instr_ptr) {
245 uint32_t instr = (ReadU16(instr_ptr) << 16) | ReadU16(instr_ptr + 2);
246 // |111|1 1|1000000|0000|1111110000000000|
247 // |5 3|2 1|0987654|3 0|5 0 5 0|
248 // |---|---|-------|----|----------------|
249 // |332|2 2|2222222|1111|1111110000000000|
250 // |1 9|8 7|6543210|9 6|5 0 5 0|
251 // |---|---|-------|----|----------------|
252 // |111|op1| op2 | | |
253 uint32_t op1 = (instr >> 27) & 3;
Elliott Hughes77405792012-03-15 15:22:12 -0700254 if (op1 == 0) {
255 return DumpThumb16(os, instr_ptr);
256 }
257
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800258 uint32_t op2 = (instr >> 20) & 0x7F;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700259 std::ostringstream opcode;
260 std::ostringstream args;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800261 switch (op1) {
262 case 0:
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800263 break;
264 case 1:
265 switch (op2) {
266 case 0x00: case 0x01: case 0x02: case 0x03: case 0x08: case 0x09: case 0x0A: case 0x0B:
267 case 0x10: case 0x11: case 0x12: case 0x13: case 0x18: case 0x19: case 0x1A: case 0x1B: {
268 // |111|11|10|00|0|00|0000|1111110000000000|
269 // |5 3|21|09|87|6|54|3 0|5 0 5 0|
270 // |---|--|--|--|-|--|----|----------------|
271 // |332|22|22|22|2|22|1111|1111110000000000|
272 // |1 9|87|65|43|2|10|9 6|5 0 5 0|
273 // |---|--|--|--|-|--|----|----------------|
274 // |111|01|00|op|0|WL| Rn | |
275 // |111|01| op2 | | |
276 // STM - 111 01 00-01-0-W0 nnnn rrrrrrrrrrrrrrrr
277 // LDM - 111 01 00-01-0-W1 nnnn rrrrrrrrrrrrrrrr
278 // PUSH- 111 01 00-01-0-10 1101 0M0rrrrrrrrrrrrr
279 // POP - 111 01 00-01-0-11 1101 PM0rrrrrrrrrrrrr
280 uint32_t op = (instr >> 23) & 3;
281 uint32_t W = (instr >> 21) & 1;
282 uint32_t L = (instr >> 20) & 1;
283 uint32_t Rn = (instr >> 16) & 0xF;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800284 if (op == 1 || op == 2) {
285 if (op == 1) {
286 if (L == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700287 opcode << "stm";
288 DumpReg(args, Rn);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800289 if (W == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700290 args << ", ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800291 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700292 args << "!, ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800293 }
294 } else {
295 if (Rn != 13) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700296 opcode << "ldm";
297 DumpReg(args, Rn);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800298 if (W == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700299 args << ", ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800300 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700301 args << "!, ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800302 }
303 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700304 opcode << "pop";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800305 }
306 }
307 } else {
308 if (L == 0) {
309 if (Rn != 13) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700310 opcode << "stmdb";
311 DumpReg(args, Rn);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800312 if (W == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700313 args << ", ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800314 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700315 args << "!, ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800316 }
317 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700318 opcode << "push";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800319 }
320 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700321 opcode << "ldmdb";
322 DumpReg(args, Rn);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800323 if (W == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700324 args << ", ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800325 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700326 args << "!, ";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800327 }
328 }
329 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700330 args << RegisterList(instr);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800331 }
332 break;
333 }
334 default:
335 break;
336 }
337 break;
Ian Rogers40627db2012-03-04 17:31:09 -0800338 case 2:
339 if ((instr & 0x8000) == 0 && (op2 & 0x20) == 0) {
340 // Data-processing (modified immediate)
341 // |111|11|10|0000|0|0000|1|111|1100|00000000|
342 // |5 3|21|09|8765|4|3 0|5|4 2|10 8|7 5 0|
343 // |---|--|--|----|-|----|-|---|----|--------|
344 // |332|22|22|2222|2|1111|1|111|1100|00000000|
345 // |1 9|87|65|4321|0|9 6|5|4 2|10 8|7 5 0|
346 // |---|--|--|----|-|----|-|---|----|--------|
347 // |111|10|i0| op3|S| Rn |0|iii| Rd |iiiiiiii|
348 // 111 10 x0 xxxx x xxxx opxxx xxxx xxxxxxxx
349 // 111 10 00 0110 0 0000 1 000 0000 10101101 - f0c080ad
350 uint32_t i = (instr >> 26) & 1;
351 uint32_t op3 = (instr >> 21) & 0xF;
352 uint32_t S = (instr >> 20) & 1;
353 uint32_t Rn = (instr >> 16) & 0xF;
354 uint32_t imm3 = (instr >> 12) & 7;
355 uint32_t Rd = (instr >> 8) & 0xF;
356 uint32_t imm8 = instr & 0xFF;
357 int32_t imm32 = (i << 12) | (imm3 << 8) | imm8;
358 switch (op3) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700359 case 0x0: opcode << "and"; break;
360 case 0x1: opcode << "bic"; break;
361 case 0x2: opcode << "orr"; break;
362 case 0x3: opcode << "orn"; break;
363 case 0x4: opcode << "eor"; break;
364 case 0x8: opcode << "add"; break;
365 case 0xA: opcode << "adc"; break;
366 case 0xB: opcode << "sbc"; break;
367 case 0xD: opcode << "sub"; break;
368 case 0xE: opcode << "rsb"; break;
369 default: opcode << "UNKNOWN DPMI-" << op3; break;
Ian Rogers40627db2012-03-04 17:31:09 -0800370 }
371 if (S == 1) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700372 opcode << "s";
Ian Rogers40627db2012-03-04 17:31:09 -0800373 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700374 DumpReg(args, Rd);
375 args << ", ";
376 DumpReg(args, Rn);
377 args << ", ThumbExpand(" << imm32 << ")";
Ian Rogers40627db2012-03-04 17:31:09 -0800378 } else if ((instr & 0x8000) == 0 && (op2 & 0x20) != 0) {
379 // Data-processing (plain binary immediate)
380 // |111|11|10|00000|0000|1|111110000000000|
381 // |5 3|21|09|87654|3 0|5|4 0 5 0|
382 // |---|--|--|-----|----|-|---------------|
383 // |332|22|22|22222|1111|1|111110000000000|
384 // |1 9|87|65|43210|9 6|5|4 0 5 0|
385 // |---|--|--|-----|----|-|---------------|
386 // |111|10|x1| op3 | Rn |0|xxxxxxxxxxxxxxx|
387 uint32_t op3 = (instr >> 20) & 0x1F;
388 uint32_t Rn = (instr >> 16) & 0xF;
389 switch (op3) {
390 case 0x04: {
391 // MOVW Rd, #imm16 - 111 10 i0 0010 0 iiii 0 iii dddd iiiiiiii
392 uint32_t Rd = (instr >> 8) & 0xF;
393 uint32_t i = (instr >> 26) & 1;
394 uint32_t imm3 = (instr >> 12) & 0x7;
395 uint32_t imm8 = instr & 0xFF;
396 uint32_t imm16 = (Rn << 12) | (i << 11) | (imm3 << 8) | imm8;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700397 opcode << "movw";
398 DumpReg(args, Rd);
399 args << ", #" << imm16;
Ian Rogers40627db2012-03-04 17:31:09 -0800400 break;
401 }
402 case 0x0A: {
403 // SUB.W Rd, Rn #imm12 - 111 10 i1 0101 0 nnnn 0 iii dddd iiiiiiii
404 uint32_t Rd = (instr >> 8) & 0xF;
405 uint32_t i = (instr >> 26) & 1;
406 uint32_t imm3 = (instr >> 12) & 0x7;
407 uint32_t imm8 = instr & 0xFF;
408 uint32_t imm12 = (i << 11) | (imm3 << 8) | imm8;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700409 opcode << "sub.w";
410 DumpReg(args, Rd);
411 args << ", ";
412 DumpReg(args, Rn);
413 args << ", #" << imm12;
Ian Rogers40627db2012-03-04 17:31:09 -0800414 break;
415 }
416 default:
417 break;
418 }
419 } else {
420 // Branches and miscellaneous control
421 // |111|11|1000000|0000|1|111|1100|00000000|
422 // |5 3|21|0987654|3 0|5|4 2|10 8|7 5 0|
423 // |---|--|-------|----|-|---|----|--------|
424 // |332|22|2222222|1111|1|111|1100|00000000|
425 // |1 9|87|6543210|9 6|5|4 2|10 8|7 5 0|
426 // |---|--|-------|----|-|---|----|--------|
427 // |111|10| op2 | |1|op3|op4 | |
428
429 uint32_t op3 = (instr >> 12) & 7;
430 //uint32_t op4 = (instr >> 8) & 0xF;
431 switch (op3) {
432 case 0:
433 if ((op2 & 0x38) != 0x38) {
434 // Conditional branch
435 // |111|11|1|0000|000000|1|1|1 |1|1 |10000000000|
436 // |5 3|21|0|9876|543 0|5|4|3 |2|1 |0 5 0|
437 // |---|--|-|----|------|-|-|--|-|--|-----------|
438 // |332|22|2|2222|221111|1|1|1 |1|1 |10000000000|
439 // |1 9|87|6|5432|109 6|5|4|3 |2|1 |0 5 0|
440 // |---|--|-|----|------|-|-|--|-|--|-----------|
441 // |111|10|S|cond| imm6 |1|0|J1|0|J2| imm11 |
442 uint32_t S = (instr >> 26) & 1;
443 uint32_t J2 = (instr >> 11) & 1;
444 uint32_t J1 = (instr >> 13) & 1;
445 uint32_t imm6 = (instr >> 16) & 0x3F;
446 uint32_t imm11 = instr & 0x7FF;
447 uint32_t cond = (instr >> 22) & 0xF;
448 int32_t imm32 = (S << 20) | (J2 << 19) | (J1 << 18) | (imm6 << 12) | (imm11 << 1);
449 imm32 = (imm32 << 11) >> 11; // sign extend 21bit immediate
Elliott Hughescbf0b612012-03-15 16:23:47 -0700450 opcode << "b";
451 DumpCond(opcode, cond);
452 opcode << ".w";
453 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers40627db2012-03-04 17:31:09 -0800454 }
455 break;
456 case 2:
457 case 1: case 3:
458 break;
459 case 4: case 6: case 5: case 7: {
460 // BL, BLX (immediate)
461 // |111|11|1|0000000000|11|1 |1|1 |10000000000|
462 // |5 3|21|0|9876543 0|54|3 |2|1 |0 5 0|
463 // |---|--|-|----------|--|--|-|--|-----------|
464 // |332|22|2|2222221111|11|1 |1|1 |10000000000|
465 // |1 9|87|6|5 0 6|54|3 |2|1 |0 5 0|
466 // |---|--|-|----------|--|--|-|--|-----------|
467 // |111|10|S| imm10 |11|J1|L|J2| imm11 |
468 uint32_t S = (instr >> 26) & 1;
469 uint32_t J2 = (instr >> 11) & 1;
470 uint32_t L = (instr >> 12) & 1;
471 uint32_t J1 = (instr >> 13) & 1;
472 uint32_t imm10 = (instr >> 16) & 0x3FF;
473 uint32_t imm11 = instr & 0x7FF;
474 if (L == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700475 opcode << "bx";
Ian Rogers40627db2012-03-04 17:31:09 -0800476 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700477 opcode << "blx";
Ian Rogers40627db2012-03-04 17:31:09 -0800478 }
479 uint32_t I1 = ~(J1 ^ S);
480 uint32_t I2 = ~(J2 ^ S);
481 int32_t imm32 = (S << 24) | (I1 << 23) | (I2 << 22) | (imm10 << 12) | (imm11 << 1);
482 imm32 = (imm32 << 8) >> 8; // sign extend 24 bit immediate.
Elliott Hughescbf0b612012-03-15 16:23:47 -0700483 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers40627db2012-03-04 17:31:09 -0800484 break;
485 }
486 }
487 }
488 break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800489 case 3:
490 switch (op2) {
491 case 0x00: case 0x02: case 0x04: case 0x06: // 000xxx0
492 case 0x08: case 0x0A: case 0x0C: case 0x0E: {
493 // Store single data item
Ian Rogers40627db2012-03-04 17:31:09 -0800494 // |111|11|100|000|0|0000|1111|110000|000000|
495 // |5 3|21|098|765|4|3 0|5 2|10 6|5 0|
496 // |---|--|---|---|-|----|----|------|------|
497 // |332|22|222|222|2|1111|1111|110000|000000|
498 // |1 9|87|654|321|0|9 6|5 2|10 6|5 0|
499 // |---|--|---|---|-|----|----|------|------|
500 // |111|11|000|op3|0| | | op4 | |
501
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800502 uint32_t op3 = (instr >> 21) & 7;
503 //uint32_t op4 = (instr >> 6) & 0x3F;
504 switch (op3) {
505 case 0x2: case 0x6: {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800506 // STR.W Rt, [Rn, #imm12] - 111 11 000 110 0 nnnn tttt iiiiiiiiiiii
507 // STR Rt, [Rn, #imm8] - 111 11 000 010 0 nnnn tttt 1PUWiiiiiiii
508 uint32_t Rn = (instr >> 16) & 0xF;
509 uint32_t Rt = (instr >> 12) & 0xF;
Ian Rogers40627db2012-03-04 17:31:09 -0800510 if (op3 == 2) {
511 uint32_t P = (instr >> 10) & 1;
512 uint32_t U = (instr >> 9) & 1;
513 uint32_t W = (instr >> 8) & 1;
514 uint32_t imm8 = instr & 0xFF;
515 int32_t imm32 = (imm8 << 24) >> 24; // sign-extend imm8
516 if (Rn == 13 && P == 1 && U == 0 && W == 1) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700517 opcode << "push";
518 DumpReg(args, Rt);
Ian Rogers40627db2012-03-04 17:31:09 -0800519 } else if (Rn == 15 || (P == 0 && W == 0)) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700520 opcode << "UNDEFINED";
Ian Rogers40627db2012-03-04 17:31:09 -0800521 } else {
522 if (P == 1 && U == 1 && W == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700523 opcode << "strt";
Ian Rogers40627db2012-03-04 17:31:09 -0800524 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700525 opcode << "str";
Ian Rogers40627db2012-03-04 17:31:09 -0800526 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700527 DumpReg(args, Rt);
528 args << ", [";
529 DumpReg(args, Rn);
Ian Rogers40627db2012-03-04 17:31:09 -0800530 if (P == 0 && W == 1) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700531 args << "], #" << imm32;
Ian Rogers40627db2012-03-04 17:31:09 -0800532 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700533 args << ", #" << imm32 << "]";
Ian Rogers40627db2012-03-04 17:31:09 -0800534 if (W == 1) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700535 args << "!";
Ian Rogers40627db2012-03-04 17:31:09 -0800536 }
537 }
Ian Rogers40627db2012-03-04 17:31:09 -0800538 }
539 } else if (op3 == 6) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800540 uint32_t imm12 = instr & 0xFFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700541 opcode << "str.w";
542 DumpReg(args, Rt);
543 args << ", [";
544 DumpReg(args, Rn);
545 args << ", #" << imm12 << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800546 }
Ian Rogers40627db2012-03-04 17:31:09 -0800547 break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800548 }
549 }
550
551 break;
552 }
553 case 0x05: case 0x0D: case 0x15: case 0x1D: { // 00xx101
554 // Load word
555 // |111|11|10|0 0|00|0|0000|1111|110000|000000|
556 // |5 3|21|09|8 7|65|4|3 0|5 2|10 6|5 0|
557 // |---|--|--|---|--|-|----|----|------|------|
558 // |332|22|22|2 2|22|2|1111|1111|110000|000000|
559 // |1 9|87|65|4 3|21|0|9 6|5 2|10 6|5 0|
560 // |---|--|--|---|--|-|----|----|------|------|
561 // |111|11|00|op3|10|1| Rn | Rt | op4 | |
562 // |111|11| op2 | | | imm12 |
563 uint32_t op3 = (instr >> 23) & 3;
564 uint32_t op4 = (instr >> 6) & 0x3F;
565 uint32_t Rn = (instr >> 16) & 0xF;
566 uint32_t Rt = (instr >> 12) & 0xF;
567 if (op3 == 1 || Rn == 15) {
568 // LDR.W Rt, [Rn, #imm12] - 111 11 00 00 101 nnnn tttt iiiiiiiiiiii
569 // LDR.W Rt, [PC, #imm12] - 111 11 00 0x 101 1111 tttt iiiiiiiiiiii
570 uint32_t imm12 = instr & 0xFFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700571 opcode << "ldr.w";
572 DumpReg(args, Rt);
573 args << ", [";
574 DumpReg(args, Rn);
575 args << ", #" << imm12 << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800576 } else if (op4 == 0) {
577 // LDR.W Rt, [Rn, Rm{, LSL #imm2}] - 111 11 00 00 101 nnnn tttt 000000iimmmm
578 uint32_t imm2 = (instr >> 4) & 0xF;
Elliott Hughes77405792012-03-15 15:22:12 -0700579 uint32_t rm = instr & 0xF;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700580 opcode << "ldr.w";
581 DumpReg(args, Rt);
582 args << ", [";
583 DumpReg(args, Rn);
584 args << ", ";
585 DumpReg(args, rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800586 if (imm2 != 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700587 args << ", lsl #" << imm2;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800588 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700589 args << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800590 } else {
591 // LDRT Rt, [Rn, #imm8] - 111 11 00 00 101 nnnn tttt 1110iiiiiiii
592 uint32_t imm8 = instr & 0xFF;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700593 opcode << "ldrt";
594 DumpReg(args, Rt);
595 args << ", [";
596 DumpReg(args, Rn);
597 args << ", #" << imm8 << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800598 }
599 break;
600 }
601 }
602 default:
603 break;
604 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700605 os << StringPrintf("\t\t\t%p: %08x\t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800606 return 4;
607}
608
609size_t DisassemblerArm::DumpThumb16(std::ostream& os, const uint8_t* instr_ptr) {
610 uint16_t instr = ReadU16(instr_ptr);
611 bool is_32bit = ((instr & 0xF000) == 0xF000) || ((instr & 0xF800) == 0xE800);
612 if (is_32bit) {
613 return DumpThumb32(os, instr_ptr);
614 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700615 std::ostringstream opcode;
616 std::ostringstream args;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800617 uint16_t opcode1 = instr >> 10;
618 if (opcode1 < 0x10) {
619 // shift (immediate), add, subtract, move, and compare
620 uint16_t opcode2 = instr >> 9;
621 switch (opcode2) {
622 case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7:
623 case 0x8: case 0x9: case 0xA: case 0xB: {
624 // Logical shift left - 00 000xx xxxxxxxxx
625 // Logical shift right - 00 001xx xxxxxxxxx
626 // Arithmetic shift right - 00 010xx xxxxxxxxx
627 uint16_t imm5 = (instr >> 6) & 0x1F;
Elliott Hughes77405792012-03-15 15:22:12 -0700628 uint16_t rm = (instr >> 3) & 7;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800629 uint16_t Rd = instr & 7;
630 if (opcode2 <= 3) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700631 opcode << "lsls";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800632 } else if (opcode2 <= 7) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700633 opcode << "lsrs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800634 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700635 opcode << "asrs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800636 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700637 DumpReg(args, Rd);
638 args << ", ";
639 DumpReg(args, rm);
640 args << ", #" << imm5;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800641 break;
642 }
643 case 0xC: case 0xD: case 0xE: case 0xF: {
644 // Add register - 00 01100 mmm nnn ddd
645 // Sub register - 00 01101 mmm nnn ddd
646 // Add 3-bit immediate - 00 01110 iii nnn ddd
647 // Sub 3-bit immediate - 00 01111 iii nnn ddd
648 uint16_t imm3_or_Rm = (instr >> 6) & 7;
649 uint16_t Rn = (instr >> 3) & 7;
650 uint16_t Rd = instr & 7;
651 if ((opcode2 & 2) != 0 && imm3_or_Rm == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700652 opcode << "mov";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800653 } else {
654 if ((opcode2 & 1) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700655 opcode << "adds";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800656 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700657 opcode << "subs";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800658 }
659 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700660 DumpReg(args, Rd);
661 args << ", ";
662 DumpReg(args, Rn);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800663 if ((opcode2 & 2) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700664 args << ", ";
665 DumpReg(args, imm3_or_Rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800666 } else if (imm3_or_Rm != 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700667 args << ", #" << imm3_or_Rm;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800668 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800669 break;
670 }
671 case 0x10: case 0x11: case 0x12: case 0x13:
672 case 0x14: case 0x15: case 0x16: case 0x17:
673 case 0x18: case 0x19: case 0x1A: case 0x1B:
674 case 0x1C: case 0x1D: case 0x1E: case 0x1F: {
675 // MOVS Rd, #imm8 - 00100 ddd iiiiiiii
676 // CMP Rn, #imm8 - 00101 nnn iiiiiiii
677 // ADDS Rn, #imm8 - 00110 nnn iiiiiiii
678 // SUBS Rn, #imm8 - 00111 nnn iiiiiiii
679 uint16_t Rn = (instr >> 8) & 7;
680 uint16_t imm8 = instr & 0xFF;
681 switch (opcode2 >> 2) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700682 case 4: opcode << "movs"; break;
683 case 5: opcode << "cmp"; break;
684 case 6: opcode << "adds"; break;
685 case 7: opcode << "subs"; break;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800686 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700687 DumpReg(args, Rn);
688 args << ", #" << imm8;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800689 break;
690 }
691 default:
692 break;
693 }
694 } else if (opcode1 == 0x11) {
695 // Special data instructions and branch and exchange
696 uint16_t opcode2 = (instr >> 6) & 0x0F;
697 switch (opcode2) {
698 case 0x0: case 0x1: case 0x2: case 0x3: {
699 // Add low registers - 010001 0000 xxxxxx
700 // Add high registers - 010001 0001/001x xxxxxx
701 uint16_t DN = (instr >> 7) & 1;
Elliott Hughes77405792012-03-15 15:22:12 -0700702 uint16_t rm = (instr >> 3) & 0xF;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800703 uint16_t Rdn = instr & 7;
704 uint16_t DN_Rdn = (DN << 3) | Rdn;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700705 opcode << "add";
706 DumpReg(args, DN_Rdn);
707 args << ", ";
708 DumpReg(args, rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800709 break;
710 }
711 case 0x8: case 0x9: case 0xA: case 0xB: {
712 // Move low registers - 010001 1000 xxxxxx
713 // Move high registers - 010001 1001/101x xxxxxx
714 uint16_t DN = (instr >> 7) & 1;
Elliott Hughes77405792012-03-15 15:22:12 -0700715 uint16_t rm = (instr >> 3) & 0xF;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800716 uint16_t Rdn = instr & 7;
717 uint16_t DN_Rdn = (DN << 3) | Rdn;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700718 opcode << "mov";
719 DumpReg(args, DN_Rdn);
720 args << ", ";
721 DumpReg(args, rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800722 break;
723 }
724 case 0x5: case 0x6: case 0x7: {
725 // Compare high registers - 010001 0101/011x xxxxxx
726 uint16_t N = (instr >> 7) & 1;
Elliott Hughes77405792012-03-15 15:22:12 -0700727 uint16_t rm = (instr >> 3) & 0xF;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800728 uint16_t Rn = instr & 7;
729 uint16_t N_Rn = (N << 3) | Rn;
Elliott Hughescbf0b612012-03-15 16:23:47 -0700730 opcode << "cmp";
731 DumpReg(args, N_Rn);
732 args << ", ";
733 DumpReg(args, rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800734 break;
735 }
736 case 0xC: case 0xD: case 0xE: case 0xF: {
737 // Branch and exchange - 010001 110x xxxxxx
738 // Branch with link and exchange - 010001 111x xxxxxx
Elliott Hughes77405792012-03-15 15:22:12 -0700739 uint16_t rm = instr >> 3 & 0xF;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800740 if ((opcode2 & 0x2) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700741 opcode << "bx";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800742 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700743 opcode << "blx";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800744 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700745 DumpReg(args, rm);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800746 break;
747 }
748 default:
749 break;
750 }
751 } else if ((instr & 0xF000) == 0xB000) {
752 // Miscellaneous 16-bit instructions
753 uint16_t opcode2 = (instr >> 5) & 0x7F;
754 switch (opcode2) {
755 case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: {
756 // Add immediate to SP - 1011 00000 ii iiiii
757 // Subtract immediate from SP - 1011 00001 ii iiiii
758 int imm7 = instr & 0x7F;
759 if ((opcode2 & 4) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700760 opcode << "add";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800761 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700762 opcode << "sub";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800763 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700764 args << "sp, sp, #" << (imm7 << 2);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800765 break;
766 }
Ian Rogers40627db2012-03-04 17:31:09 -0800767 case 0x78: case 0x79: case 0x7A: case 0x7B: // 1111xxx
768 case 0x7C: case 0x7D: case 0x7E: case 0x7F: {
769 // If-Then, and hints
770 uint16_t opA = (instr >> 4) & 0xF;
771 uint16_t opB = instr & 0xF;
772 if (opB == 0) {
773 switch (opA) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700774 case 0: opcode << "nop"; break;
775 case 1: opcode << "yield"; break;
776 case 2: opcode << "wfe"; break;
777 case 3: opcode << "sev"; break;
Ian Rogers40627db2012-03-04 17:31:09 -0800778 default: break;
779 }
780 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700781 opcode << "it";
782 args << reinterpret_cast<void*>(opB) << " ";
783 DumpCond(args, opA);
Ian Rogers40627db2012-03-04 17:31:09 -0800784 }
785 break;
786 }
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800787 default:
788 break;
789 }
790 } else if (((instr & 0xF000) == 0x5000) || ((instr & 0xE000) == 0x6000) ||
791 ((instr & 0xE000) == 0x8000)) {
792 // Load/store single data item
793 uint16_t opA = instr >> 12;
794 //uint16_t opB = (instr >> 9) & 7;
795 switch (opA) {
796 case 0x6: {
797 // STR Rt, Rn, #imm - 01100 iiiii nnn ttt
798 // LDR Rt, Rn, #imm - 01101 iiiii nnn ttt
799 uint16_t imm5 = (instr >> 6) & 0x1F;
800 uint16_t Rn = (instr >> 3) & 7;
801 uint16_t Rt = instr & 7;
802 if ((instr & 0x800) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700803 opcode << "str";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800804 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700805 opcode << "ldr";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800806 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700807 DumpReg(args, Rt);
808 args << ", [";
809 DumpReg(args, Rn);
810 args << ", #" << (imm5 << 2) << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800811 break;
812 }
813 case 0x9: {
814 // STR Rt, [SP, #imm] - 01100 ttt iiiiiiii
815 // LDR Rt, [SP, #imm] - 01101 ttt iiiiiiii
816 uint16_t imm8 = instr & 0xFF;
817 uint16_t Rt = (instr >> 8) & 7;
818 if ((instr & 0x800) == 0) {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700819 opcode << "str";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800820 } else {
Elliott Hughescbf0b612012-03-15 16:23:47 -0700821 opcode << "ldr";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800822 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700823 DumpReg(args, Rt);
824 args << ", [sp, #" << (imm8 << 2) << "]";
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800825 break;
826 }
827 default:
828 break;
829 }
Ian Rogers40627db2012-03-04 17:31:09 -0800830 } else if (opcode1 == 0x38 || opcode1 == 0x39) {
831 uint16_t imm11 = instr & 0x7FFF;
832 int32_t imm32 = imm11 << 1;
833 imm32 = (imm32 << 20) >> 20; // sign extend 12 bit immediate
Elliott Hughescbf0b612012-03-15 16:23:47 -0700834 opcode << "b";
835 DumpBranchTarget(args, instr_ptr + 4, imm32);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800836 }
Elliott Hughescbf0b612012-03-15 16:23:47 -0700837 os << StringPrintf("\t\t\t%p: %04x \t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n';
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800838 }
839 return 2;
840}
841
842} // namespace arm
843} // namespace art