Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 19 | #include <iostream> |
| 20 | |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 21 | #include "logging.h" |
| 22 | #include "stringprintf.h" |
| 23 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 24 | namespace art { |
| 25 | namespace arm { |
| 26 | |
| 27 | DisassemblerArm::DisassemblerArm() { |
| 28 | } |
| 29 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 30 | void DisassemblerArm::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) { |
| 31 | if ((reinterpret_cast<intptr_t>(begin) & 1) == 0) { |
| 32 | for (const uint8_t* cur = begin; cur < end; cur += 4) { |
| 33 | DumpArm(os, cur); |
| 34 | } |
| 35 | } else { |
| 36 | // remove thumb specifier bits |
| 37 | begin = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(begin) & ~1); |
| 38 | end = reinterpret_cast<const uint8_t*>(reinterpret_cast<uintptr_t>(end) & ~1); |
| 39 | for (const uint8_t* cur = begin; cur < end;) { |
| 40 | cur += DumpThumb16(os, cur); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 45 | static const char* kConditionCodeNames[] = { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 46 | "eq", // 0000 - equal |
| 47 | "ne", // 0001 - not-equal |
| 48 | "cs", // 0010 - carry-set, greater than, equal or unordered |
| 49 | "cc", // 0011 - carry-clear, less than |
| 50 | "mi", // 0100 - minus, negative |
| 51 | "pl", // 0101 - plus, positive or zero |
| 52 | "vs", // 0110 - overflow |
| 53 | "vc", // 0111 - no overflow |
| 54 | "hi", // 1000 - unsigned higher |
| 55 | "ls", // 1001 - unsigned lower or same |
| 56 | "ge", // 1010 - signed greater than or equal |
| 57 | "lt", // 1011 - signed less than |
| 58 | "gt", // 1100 - signed greater than |
| 59 | "le", // 1101 - signed less than or equal |
| 60 | "", // 1110 - always |
| 61 | "nv", // 1111 - never (mostly obsolete, but might be a clue that we're mistranslating) |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | void DisassemblerArm::DumpCond(std::ostream& os, uint32_t cond) { |
| 65 | if (cond < 15) { |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 66 | os << kConditionCodeNames[cond]; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 67 | } else { |
| 68 | os << "Unexpected condition: " << cond; |
| 69 | } |
| 70 | } |
| 71 | |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 72 | void DisassemblerArm::DumpBranchTarget(std::ostream& os, const uint8_t* instr_ptr, int32_t imm32) { |
| 73 | os << imm32 << " (" << reinterpret_cast<const void*>(instr_ptr + imm32) << ")"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static uint32_t ReadU16(const uint8_t* ptr) { |
| 77 | return ptr[0] | (ptr[1] << 8); |
| 78 | } |
| 79 | |
| 80 | static uint32_t ReadU32(const uint8_t* ptr) { |
| 81 | return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24); |
| 82 | } |
| 83 | |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 84 | static const char* kDataProcessingOperations[] = { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 85 | "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc", |
| 86 | "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn", |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Ian Rogers | ad03ef5 | 2012-03-18 19:34:47 -0700 | [diff] [blame] | 89 | static const char* kThumbDataProcessingOperations[] = { |
| 90 | "and", "eor", "lsl", "lsr", "asr", "adc", "sbc", "ror", |
| 91 | "tst", "rsb", "cmp", "cmn", "orr", "mul", "bic", "mvn", |
| 92 | }; |
| 93 | |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 94 | struct ArmRegister { |
| 95 | ArmRegister(uint32_t r) : r(r) { CHECK_LE(r, 15U); } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 96 | ArmRegister(uint32_t instruction, uint32_t at_bit) : r((instruction >> at_bit) & 0xf) { CHECK_LE(r, 15U); } |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 97 | uint32_t r; |
| 98 | }; |
| 99 | std::ostream& operator<<(std::ostream& os, const ArmRegister& r) { |
| 100 | if (r.r == 13) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 101 | os << "sp"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 102 | } else if (r.r == 14) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 103 | os << "lr"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 104 | } else if (r.r == 15) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 105 | os << "pc"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 106 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 107 | os << "r" << r.r; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 108 | } |
| 109 | return os; |
| 110 | } |
| 111 | |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 112 | struct ThumbRegister : ArmRegister { |
| 113 | ThumbRegister(uint16_t instruction, uint16_t at_bit) : ArmRegister((instruction >> at_bit) & 0x7) {} |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | struct Rm { |
| 117 | Rm(uint32_t instruction) : shift((instruction >> 4) & 0xff), rm(instruction & 0xf) {} |
| 118 | uint32_t shift; |
| 119 | ArmRegister rm; |
| 120 | }; |
| 121 | std::ostream& operator<<(std::ostream& os, const Rm& r) { |
| 122 | os << r.rm; |
| 123 | if (r.shift != 0) { |
| 124 | os << "-shift-" << r.shift; // TODO |
| 125 | } |
| 126 | return os; |
| 127 | } |
| 128 | |
| 129 | struct Imm12 { |
| 130 | Imm12(uint32_t instruction) : rotate((instruction >> 8) & 0xf), imm(instruction & 0xff) {} |
| 131 | uint32_t rotate; |
| 132 | uint32_t imm; |
| 133 | }; |
| 134 | std::ostream& operator<<(std::ostream& os, const Imm12& rhs) { |
| 135 | uint32_t imm = (rhs.imm >> (2 * rhs.rotate)) | (rhs.imm << (32 - (2 * rhs.rotate))); |
| 136 | os << "#" << imm; |
| 137 | return os; |
| 138 | } |
| 139 | |
| 140 | struct RegisterList { |
| 141 | RegisterList(uint32_t instruction) : register_list(instruction & 0xffff) {} |
| 142 | uint32_t register_list; |
| 143 | }; |
| 144 | std::ostream& operator<<(std::ostream& os, const RegisterList& rhs) { |
| 145 | if (rhs.register_list == 0) { |
| 146 | os << "<no register list?>"; |
| 147 | return os; |
| 148 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 149 | os << "{"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 150 | bool first = true; |
| 151 | for (size_t i = 0; i < 16; i++) { |
| 152 | if ((rhs.register_list & (1 << i)) != 0) { |
| 153 | if (first) { |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 154 | first = false; |
| 155 | } else { |
| 156 | os << ", "; |
| 157 | } |
| 158 | os << ArmRegister(i); |
| 159 | } |
| 160 | } |
| 161 | os << "}"; |
| 162 | return os; |
| 163 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 164 | |
| 165 | void DisassemblerArm::DumpArm(std::ostream& os, const uint8_t* instr_ptr) { |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 166 | uint32_t instruction = ReadU32(instr_ptr); |
| 167 | uint32_t cond = (instruction >> 28) & 0xf; |
| 168 | uint32_t op1 = (instruction >> 25) & 0x7; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 169 | std::ostringstream opcode; |
| 170 | std::ostringstream args; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 171 | switch (op1) { |
| 172 | case 0: |
| 173 | case 1: // Data processing instructions. |
| 174 | { |
| 175 | if ((instruction & 0x0fffffd0) == 0x012fff10) { // BX and BLX (register) |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 176 | opcode << (((instruction >> 5) & 1) ? "blx" : "bx"); |
| 177 | args << ArmRegister(instruction & 0xf); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | bool i = (instruction & (1 << 25)) != 0; |
| 181 | bool s = (instruction & (1 << 20)) != 0; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 182 | opcode << kDataProcessingOperations[(instruction >> 21) & 0xf] |
| 183 | << kConditionCodeNames[cond] |
| 184 | << (s ? "s" : ""); |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 185 | args << ArmRegister(instruction, 12) << ", "; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 186 | if (i) { |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 187 | args << ArmRegister(instruction, 16) << ", " << Imm12(instruction); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 188 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 189 | args << Rm(instruction); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | break; |
| 193 | case 2: // Load/store word and unsigned byte. |
| 194 | { |
| 195 | bool p = (instruction & (1 << 24)) != 0; |
| 196 | bool b = (instruction & (1 << 22)) != 0; |
| 197 | bool w = (instruction & (1 << 21)) != 0; |
| 198 | bool l = (instruction & (1 << 20)) != 0; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 199 | opcode << (l ? "ldr" : "str") << (b ? "b" : "") << kConditionCodeNames[cond]; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 200 | args << ArmRegister(instruction, 12) << ", "; |
| 201 | ArmRegister rn(instruction, 16); |
| 202 | if (rn.r == 0xf) { |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 203 | UNIMPLEMENTED(FATAL) << "literals"; |
| 204 | } else { |
| 205 | bool wback = !p || w; |
| 206 | if (p && !wback) { |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 207 | args << "[" << rn << ", " << Imm12(instruction) << "]"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 208 | } else if (p && wback) { |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 209 | args << "[" << rn << ", " << Imm12(instruction) << "]!"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 210 | } else if (!p && wback) { |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 211 | args << "[" << rn << "], " << Imm12(instruction); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 212 | } else { |
| 213 | LOG(FATAL) << p << " " << w; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | break; |
| 218 | case 4: // Load/store multiple. |
| 219 | { |
| 220 | bool p = (instruction & (1 << 24)) != 0; |
| 221 | bool u = (instruction & (1 << 23)) != 0; |
| 222 | bool w = (instruction & (1 << 21)) != 0; |
| 223 | bool l = (instruction & (1 << 20)) != 0; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 224 | opcode << (l ? "ldm" : "stm") |
| 225 | << (u ? 'i' : 'd') |
| 226 | << (p ? 'b' : 'a') |
| 227 | << kConditionCodeNames[cond]; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 228 | args << ArmRegister(instruction, 16) << (w ? "!" : "") << ", " << RegisterList(instruction); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 229 | } |
| 230 | break; |
| 231 | default: |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 232 | opcode << "???"; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 233 | break; |
| 234 | } |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 235 | // TODO: a more complete ARM disassembler could generate wider opcodes. |
| 236 | os << StringPrintf("\t\t\t%p: %08x\t%-7s ", instr_ptr, instruction, opcode.str().c_str()) << args.str() << '\n'; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | size_t DisassemblerArm::DumpThumb32(std::ostream& os, const uint8_t* instr_ptr) { |
| 240 | uint32_t instr = (ReadU16(instr_ptr) << 16) | ReadU16(instr_ptr + 2); |
| 241 | // |111|1 1|1000000|0000|1111110000000000| |
| 242 | // |5 3|2 1|0987654|3 0|5 0 5 0| |
| 243 | // |---|---|-------|----|----------------| |
| 244 | // |332|2 2|2222222|1111|1111110000000000| |
| 245 | // |1 9|8 7|6543210|9 6|5 0 5 0| |
| 246 | // |---|---|-------|----|----------------| |
| 247 | // |111|op1| op2 | | | |
| 248 | uint32_t op1 = (instr >> 27) & 3; |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 249 | if (op1 == 0) { |
| 250 | return DumpThumb16(os, instr_ptr); |
| 251 | } |
| 252 | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 253 | uint32_t op2 = (instr >> 20) & 0x7F; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 254 | std::ostringstream opcode; |
| 255 | std::ostringstream args; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 256 | switch (op1) { |
| 257 | case 0: |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 258 | break; |
| 259 | case 1: |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 260 | if ((op2 & 0x64) == 0) { // 00x x0xx |
| 261 | // |111|11|10|00|0|00|0000|1111110000000000| |
| 262 | // |5 3|21|09|87|6|54|3 0|5 0 5 0| |
| 263 | // |---|--|--|--|-|--|----|----------------| |
| 264 | // |332|22|22|22|2|22|1111|1111110000000000| |
| 265 | // |1 9|87|65|43|2|10|9 6|5 0 5 0| |
| 266 | // |---|--|--|--|-|--|----|----------------| |
| 267 | // |111|01|00|op|0|WL| Rn | | |
| 268 | // |111|01| op2 | | | |
| 269 | // STM - 111 01 00-01-0-W0 nnnn rrrrrrrrrrrrrrrr |
| 270 | // LDM - 111 01 00-01-0-W1 nnnn rrrrrrrrrrrrrrrr |
| 271 | // PUSH- 111 01 00-01-0-10 1101 0M0rrrrrrrrrrrrr |
| 272 | // POP - 111 01 00-01-0-11 1101 PM0rrrrrrrrrrrrr |
| 273 | uint32_t op = (instr >> 23) & 3; |
| 274 | uint32_t W = (instr >> 21) & 1; |
| 275 | uint32_t L = (instr >> 20) & 1; |
| 276 | ArmRegister Rn(instr, 16); |
| 277 | if (op == 1 || op == 2) { |
| 278 | if (op == 1) { |
| 279 | if (L == 0) { |
| 280 | opcode << "stm"; |
| 281 | args << Rn << (W == 0 ? "" : "!") << ", "; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 282 | } else { |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 283 | if (Rn.r != 13) { |
| 284 | opcode << "ldm"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 285 | args << Rn << (W == 0 ? "" : "!") << ", "; |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 286 | } else { |
| 287 | opcode << "pop"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 288 | } |
| 289 | } |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 290 | } else { |
| 291 | if (L == 0) { |
| 292 | if (Rn.r != 13) { |
| 293 | opcode << "stmdb"; |
| 294 | args << Rn << (W == 0 ? "" : "!") << ", "; |
| 295 | } else { |
| 296 | opcode << "push"; |
| 297 | } |
| 298 | } else { |
| 299 | opcode << "ldmdb"; |
| 300 | args << Rn << (W == 0 ? "" : "!") << ", "; |
| 301 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 302 | } |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 303 | args << RegisterList(instr); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 304 | } |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 305 | } else if ((op2 & 0x60) == 0x20) { // 01x xxxx |
| 306 | // Data-processing (shifted register) |
| 307 | // |111|1110|0000|0|0000|1111|1100|0000|0000| |
| 308 | // |5 3|2109|8765|4|3 0|5 |10 8|7 5 |3 0| |
| 309 | // |---|----|----|-|----|----|----|----|----| |
| 310 | // |332|2222|2222|2|1111|1111|1100|0000|0000| |
| 311 | // |1 9|8765|4321|0|9 6|5 |10 8|7 5 |3 0| |
| 312 | // |---|----|----|-|----|----|----|----|----| |
| 313 | // |111|0101| op3|S| Rn | | Rd | | Rm | |
| 314 | uint32_t op3 = (instr >> 21) & 0xF; |
| 315 | uint32_t S = (instr >> 20) & 1; |
| 316 | uint32_t Rn = (instr >> 16) & 0xF; |
| 317 | ArmRegister Rd(instr, 8); |
| 318 | ArmRegister Rm(instr, 0); |
| 319 | switch (op3) { |
| 320 | case 0x0: |
| 321 | if (Rn != 0xF) { |
| 322 | opcode << "and"; |
| 323 | } else { |
| 324 | opcode << "tst"; |
| 325 | S = 0; // don't print 's' |
| 326 | } |
| 327 | break; |
| 328 | case 0x1: opcode << "bic"; break; |
| 329 | case 0x2: |
| 330 | if (Rn != 0xF) { |
| 331 | opcode << "orr"; |
| 332 | } else { |
| 333 | opcode << "mov"; |
| 334 | } |
| 335 | break; |
| 336 | case 0x3: |
| 337 | if (Rn != 0xF) { |
| 338 | opcode << "orn"; |
| 339 | } else { |
| 340 | opcode << "mvn"; |
| 341 | } |
| 342 | break; |
| 343 | case 0x4: |
| 344 | if (Rn != 0xF) { |
| 345 | opcode << "eor"; |
| 346 | } else { |
| 347 | opcode << "teq"; |
| 348 | S = 0; // don't print 's' |
| 349 | } |
| 350 | break; |
| 351 | case 0x6: opcode << "pkh"; break; |
| 352 | case 0x8: |
| 353 | if (Rn != 0xF) { |
| 354 | opcode << "add"; |
| 355 | } else { |
| 356 | opcode << "cmn"; |
| 357 | S = 0; // don't print 's' |
| 358 | } |
| 359 | break; |
| 360 | case 0xA: opcode << "adc"; break; |
| 361 | case 0xB: opcode << "sbc"; break; |
| 362 | } |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 363 | |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 364 | if (S == 1) { |
| 365 | opcode << "s"; |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 366 | } |
Ian Rogers | c7fe4e0 | 2012-03-29 21:36:21 -0700 | [diff] [blame] | 367 | opcode << ".w"; |
| 368 | args << Rd << ", " << Rm; |
| 369 | } else if ((op2 & 0x40) == 0x40) { // 1xx xxxx |
| 370 | // Co-processor instructions |
| 371 | // |111|1|11|000000|0000|1111|1100|000|0 |0000| |
| 372 | // |5 3|2|10|987654|3 0|54 2|10 8|7 5|4 | 0| |
| 373 | // |---|-|--|------|----|----|----|---|---|----| |
| 374 | // |332|2|22|222222|1111|1111|1100|000|0 |0000| |
| 375 | // |1 9|8|76|543210|9 6|54 2|10 8|7 5|4 | 0| |
| 376 | // |---|-|--|------|----|----|----|---|---|----| |
| 377 | // |111| |11| op3 | Rn | |copr| |op4| | |
| 378 | uint32_t op3 = (instr >> 20) & 0x3F; |
| 379 | uint32_t coproc = (instr >> 8) & 0xF; |
| 380 | uint32_t op4 = (instr >> 4) & 0x1; |
| 381 | if ((op3 & 0x30) == 0x20 && op4 == 0) { // 10 xxxx ... 0 |
| 382 | if ((coproc & 0xE) == 0xA) { |
| 383 | // VFP data-processing instructions |
| 384 | // |111|1|1100|0000|0000|1111|110|0|00 |0|0|0000| |
| 385 | // |5 3|2|1098|7654|3 0|54 2|10 |8|76 |5|4|3 0| |
| 386 | // |---|-|----|----|----|----|---|-|----|-|-|----| |
| 387 | // |332|2|2222|2222|1111|1111|110|0|00 |0|0|0000| |
| 388 | // |1 9|8|7654|3210|9 6|54 2|109|8|76 |5|4|3 0| |
| 389 | // |---|-|----|----|----|----|---|-|----|-|-|----| |
| 390 | // |111|T|1110|opc1|opc2| |101| |opc3| | | | |
| 391 | // 111 0 1110|1111 0100 1110 101 0 01 1 0 1001 - eef4ea69 |
| 392 | uint32_t opc1 = (instr >> 20) & 0xF; |
| 393 | uint32_t opc2 = (instr >> 16) & 0xF; |
| 394 | //uint32_t opc3 = (instr >> 6) & 0x3; |
| 395 | if ((opc1 & 0xB) == 0xB) { // 1x11 |
| 396 | // Other VFP data-processing instructions. |
| 397 | switch (opc2) { |
| 398 | case 0x4: case 0x5: { // Vector compare |
| 399 | // 1110 11101 D 11 0100 dddd 101 sE1M0 mmmm |
| 400 | uint32_t D = (instr >> 22) & 0x1; |
| 401 | uint32_t Vd = (instr >> 12) & 0xF; |
| 402 | uint32_t sz = (instr >> 8) & 1; |
| 403 | uint32_t E = (instr >> 7) & 1; |
| 404 | uint32_t M = (instr >> 5) & 1; |
| 405 | uint32_t Vm = instr & 0xF; |
| 406 | bool dp_operation = sz == 1; |
| 407 | opcode << (E == 0 ? "vcmp" : "vcmpe"); |
| 408 | opcode << (dp_operation ? ".f64" : ".f32"); |
| 409 | if (dp_operation) { |
| 410 | args << "f" << ((D << 4) | Vd) << ", " << "f" << ((M << 4) | Vm); |
| 411 | } else { |
| 412 | args << "f" << ((Vd << 1) | D) << ", " << "f" << ((Vm << 1) | M); |
| 413 | } |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 420 | } |
| 421 | break; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 422 | case 2: |
| 423 | if ((instr & 0x8000) == 0 && (op2 & 0x20) == 0) { |
| 424 | // Data-processing (modified immediate) |
| 425 | // |111|11|10|0000|0|0000|1|111|1100|00000000| |
| 426 | // |5 3|21|09|8765|4|3 0|5|4 2|10 8|7 5 0| |
| 427 | // |---|--|--|----|-|----|-|---|----|--------| |
| 428 | // |332|22|22|2222|2|1111|1|111|1100|00000000| |
| 429 | // |1 9|87|65|4321|0|9 6|5|4 2|10 8|7 5 0| |
| 430 | // |---|--|--|----|-|----|-|---|----|--------| |
| 431 | // |111|10|i0| op3|S| Rn |0|iii| Rd |iiiiiiii| |
| 432 | // 111 10 x0 xxxx x xxxx opxxx xxxx xxxxxxxx |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 433 | uint32_t i = (instr >> 26) & 1; |
| 434 | uint32_t op3 = (instr >> 21) & 0xF; |
| 435 | uint32_t S = (instr >> 20) & 1; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 436 | ArmRegister Rn(instr, 16); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 437 | uint32_t imm3 = (instr >> 12) & 7; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 438 | ArmRegister Rd(instr, 8); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 439 | uint32_t imm8 = instr & 0xFF; |
| 440 | int32_t imm32 = (i << 12) | (imm3 << 8) | imm8; |
| 441 | switch (op3) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 442 | case 0x0: opcode << "and"; break; |
| 443 | case 0x1: opcode << "bic"; break; |
| 444 | case 0x2: opcode << "orr"; break; |
| 445 | case 0x3: opcode << "orn"; break; |
| 446 | case 0x4: opcode << "eor"; break; |
| 447 | case 0x8: opcode << "add"; break; |
| 448 | case 0xA: opcode << "adc"; break; |
| 449 | case 0xB: opcode << "sbc"; break; |
| 450 | case 0xD: opcode << "sub"; break; |
| 451 | case 0xE: opcode << "rsb"; break; |
| 452 | default: opcode << "UNKNOWN DPMI-" << op3; break; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 453 | } |
| 454 | if (S == 1) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 455 | opcode << "s"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 456 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 457 | args << Rd << ", " << Rn << ", ThumbExpand(" << imm32 << ")"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 458 | } else if ((instr & 0x8000) == 0 && (op2 & 0x20) != 0) { |
| 459 | // Data-processing (plain binary immediate) |
| 460 | // |111|11|10|00000|0000|1|111110000000000| |
| 461 | // |5 3|21|09|87654|3 0|5|4 0 5 0| |
| 462 | // |---|--|--|-----|----|-|---------------| |
| 463 | // |332|22|22|22222|1111|1|111110000000000| |
| 464 | // |1 9|87|65|43210|9 6|5|4 0 5 0| |
| 465 | // |---|--|--|-----|----|-|---------------| |
| 466 | // |111|10|x1| op3 | Rn |0|xxxxxxxxxxxxxxx| |
| 467 | uint32_t op3 = (instr >> 20) & 0x1F; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 468 | switch (op3) { |
| 469 | case 0x04: { |
| 470 | // MOVW Rd, #imm16 - 111 10 i0 0010 0 iiii 0 iii dddd iiiiiiii |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 471 | ArmRegister Rd(instr, 8); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 472 | uint32_t i = (instr >> 26) & 1; |
| 473 | uint32_t imm3 = (instr >> 12) & 0x7; |
| 474 | uint32_t imm8 = instr & 0xFF; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 475 | uint32_t Rn = (instr >> 16) & 0xF; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 476 | uint32_t imm16 = (Rn << 12) | (i << 11) | (imm3 << 8) | imm8; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 477 | opcode << "movw"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 478 | args << Rd << ", #" << imm16; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 479 | break; |
| 480 | } |
| 481 | case 0x0A: { |
| 482 | // SUB.W Rd, Rn #imm12 - 111 10 i1 0101 0 nnnn 0 iii dddd iiiiiiii |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 483 | ArmRegister Rd(instr, 8); |
| 484 | ArmRegister Rn(instr, 16); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 485 | uint32_t i = (instr >> 26) & 1; |
| 486 | uint32_t imm3 = (instr >> 12) & 0x7; |
| 487 | uint32_t imm8 = instr & 0xFF; |
| 488 | uint32_t imm12 = (i << 11) | (imm3 << 8) | imm8; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 489 | opcode << "sub.w"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 490 | args << Rd << ", " << Rn << ", #" << imm12; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | } else { |
| 497 | // Branches and miscellaneous control |
| 498 | // |111|11|1000000|0000|1|111|1100|00000000| |
| 499 | // |5 3|21|0987654|3 0|5|4 2|10 8|7 5 0| |
| 500 | // |---|--|-------|----|-|---|----|--------| |
| 501 | // |332|22|2222222|1111|1|111|1100|00000000| |
| 502 | // |1 9|87|6543210|9 6|5|4 2|10 8|7 5 0| |
| 503 | // |---|--|-------|----|-|---|----|--------| |
| 504 | // |111|10| op2 | |1|op3|op4 | | |
| 505 | |
| 506 | uint32_t op3 = (instr >> 12) & 7; |
| 507 | //uint32_t op4 = (instr >> 8) & 0xF; |
| 508 | switch (op3) { |
| 509 | case 0: |
| 510 | if ((op2 & 0x38) != 0x38) { |
| 511 | // Conditional branch |
| 512 | // |111|11|1|0000|000000|1|1|1 |1|1 |10000000000| |
| 513 | // |5 3|21|0|9876|543 0|5|4|3 |2|1 |0 5 0| |
| 514 | // |---|--|-|----|------|-|-|--|-|--|-----------| |
| 515 | // |332|22|2|2222|221111|1|1|1 |1|1 |10000000000| |
| 516 | // |1 9|87|6|5432|109 6|5|4|3 |2|1 |0 5 0| |
| 517 | // |---|--|-|----|------|-|-|--|-|--|-----------| |
| 518 | // |111|10|S|cond| imm6 |1|0|J1|0|J2| imm11 | |
| 519 | uint32_t S = (instr >> 26) & 1; |
| 520 | uint32_t J2 = (instr >> 11) & 1; |
| 521 | uint32_t J1 = (instr >> 13) & 1; |
| 522 | uint32_t imm6 = (instr >> 16) & 0x3F; |
| 523 | uint32_t imm11 = instr & 0x7FF; |
| 524 | uint32_t cond = (instr >> 22) & 0xF; |
| 525 | int32_t imm32 = (S << 20) | (J2 << 19) | (J1 << 18) | (imm6 << 12) | (imm11 << 1); |
| 526 | imm32 = (imm32 << 11) >> 11; // sign extend 21bit immediate |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 527 | opcode << "b"; |
| 528 | DumpCond(opcode, cond); |
| 529 | opcode << ".w"; |
| 530 | DumpBranchTarget(args, instr_ptr + 4, imm32); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 531 | } |
| 532 | break; |
| 533 | case 2: |
| 534 | case 1: case 3: |
| 535 | break; |
| 536 | case 4: case 6: case 5: case 7: { |
| 537 | // BL, BLX (immediate) |
| 538 | // |111|11|1|0000000000|11|1 |1|1 |10000000000| |
| 539 | // |5 3|21|0|9876543 0|54|3 |2|1 |0 5 0| |
| 540 | // |---|--|-|----------|--|--|-|--|-----------| |
| 541 | // |332|22|2|2222221111|11|1 |1|1 |10000000000| |
| 542 | // |1 9|87|6|5 0 6|54|3 |2|1 |0 5 0| |
| 543 | // |---|--|-|----------|--|--|-|--|-----------| |
| 544 | // |111|10|S| imm10 |11|J1|L|J2| imm11 | |
| 545 | uint32_t S = (instr >> 26) & 1; |
| 546 | uint32_t J2 = (instr >> 11) & 1; |
| 547 | uint32_t L = (instr >> 12) & 1; |
| 548 | uint32_t J1 = (instr >> 13) & 1; |
| 549 | uint32_t imm10 = (instr >> 16) & 0x3FF; |
| 550 | uint32_t imm11 = instr & 0x7FF; |
| 551 | if (L == 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 552 | opcode << "bx"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 553 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 554 | opcode << "blx"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 555 | } |
| 556 | uint32_t I1 = ~(J1 ^ S); |
| 557 | uint32_t I2 = ~(J2 ^ S); |
| 558 | int32_t imm32 = (S << 24) | (I1 << 23) | (I2 << 22) | (imm10 << 12) | (imm11 << 1); |
| 559 | imm32 = (imm32 << 8) >> 8; // sign extend 24 bit immediate. |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 560 | DumpBranchTarget(args, instr_ptr + 4, imm32); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 561 | break; |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | break; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 566 | case 3: |
| 567 | switch (op2) { |
| 568 | case 0x00: case 0x02: case 0x04: case 0x06: // 000xxx0 |
| 569 | case 0x08: case 0x0A: case 0x0C: case 0x0E: { |
| 570 | // Store single data item |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 571 | // |111|11|100|000|0|0000|1111|110000|000000| |
| 572 | // |5 3|21|098|765|4|3 0|5 2|10 6|5 0| |
| 573 | // |---|--|---|---|-|----|----|------|------| |
| 574 | // |332|22|222|222|2|1111|1111|110000|000000| |
| 575 | // |1 9|87|654|321|0|9 6|5 2|10 6|5 0| |
| 576 | // |---|--|---|---|-|----|----|------|------| |
| 577 | // |111|11|000|op3|0| | | op4 | | |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 578 | uint32_t op3 = (instr >> 21) & 7; |
| 579 | //uint32_t op4 = (instr >> 6) & 0x3F; |
| 580 | switch (op3) { |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 581 | case 0x0: case 0x4: { |
| 582 | // STRB Rt,[Rn,#+/-imm8] - 111 11 00 0 0 00 0 nnnn tttt 1 PUWii ii iiii |
| 583 | // STRB Rt,[Rn,Rm,lsl #imm2] - 111 11 00 0 0 00 0 nnnn tttt 0 00000 ii mmmm |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 584 | ArmRegister Rn(instr, 16); |
| 585 | ArmRegister Rt(instr, 12); |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 586 | opcode << "strb"; |
| 587 | if ((instr & 0x800) != 0) { |
| 588 | uint32_t imm8 = instr & 0xFF; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 589 | args << Rt << ", [" << Rn << ",#" << imm8 << "]"; |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 590 | } else { |
| 591 | uint32_t imm2 = (instr >> 4) & 3; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 592 | ArmRegister Rm(instr, 0); |
| 593 | args << Rt << ", [" << Rn << ", " << Rm; |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 594 | if (imm2 != 0) { |
| 595 | args << ", " << "lsl #" << imm2; |
| 596 | } |
| 597 | args << "]"; |
| 598 | } |
| 599 | break; |
| 600 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 601 | case 0x2: case 0x6: { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 602 | // STR.W Rt, [Rn, #imm12] - 111 11 000 110 0 nnnn tttt iiiiiiiiiiii |
| 603 | // STR Rt, [Rn, #imm8] - 111 11 000 010 0 nnnn tttt 1PUWiiiiiiii |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 604 | ArmRegister Rn(instr, 16); |
| 605 | ArmRegister Rt(instr, 12); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 606 | if (op3 == 2) { |
| 607 | uint32_t P = (instr >> 10) & 1; |
| 608 | uint32_t U = (instr >> 9) & 1; |
| 609 | uint32_t W = (instr >> 8) & 1; |
| 610 | uint32_t imm8 = instr & 0xFF; |
| 611 | int32_t imm32 = (imm8 << 24) >> 24; // sign-extend imm8 |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 612 | if (Rn.r == 13 && P == 1 && U == 0 && W == 1) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 613 | opcode << "push"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 614 | args << Rt; |
| 615 | } else if (Rn.r == 15 || (P == 0 && W == 0)) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 616 | opcode << "UNDEFINED"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 617 | } else { |
| 618 | if (P == 1 && U == 1 && W == 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 619 | opcode << "strt"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 620 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 621 | opcode << "str"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 622 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 623 | args << Rt << ", [" << Rn; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 624 | if (P == 0 && W == 1) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 625 | args << "], #" << imm32; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 626 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 627 | args << ", #" << imm32 << "]"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 628 | if (W == 1) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 629 | args << "!"; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 630 | } |
| 631 | } |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 632 | } |
| 633 | } else if (op3 == 6) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 634 | uint32_t imm12 = instr & 0xFFF; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 635 | opcode << "str.w"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 636 | args << Rt << ", [" << Rn << ", #" << imm12 << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 637 | } |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 638 | break; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
| 642 | break; |
| 643 | } |
| 644 | case 0x05: case 0x0D: case 0x15: case 0x1D: { // 00xx101 |
| 645 | // Load word |
| 646 | // |111|11|10|0 0|00|0|0000|1111|110000|000000| |
| 647 | // |5 3|21|09|8 7|65|4|3 0|5 2|10 6|5 0| |
| 648 | // |---|--|--|---|--|-|----|----|------|------| |
| 649 | // |332|22|22|2 2|22|2|1111|1111|110000|000000| |
| 650 | // |1 9|87|65|4 3|21|0|9 6|5 2|10 6|5 0| |
| 651 | // |---|--|--|---|--|-|----|----|------|------| |
| 652 | // |111|11|00|op3|10|1| Rn | Rt | op4 | | |
| 653 | // |111|11| op2 | | | imm12 | |
| 654 | uint32_t op3 = (instr >> 23) & 3; |
| 655 | uint32_t op4 = (instr >> 6) & 0x3F; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 656 | ArmRegister Rn(instr, 16); |
| 657 | ArmRegister Rt(instr, 12); |
| 658 | if (op3 == 1 || Rn.r == 15) { |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 659 | // LDR.W Rt, [Rn, #imm12] - 111 11 00 00 101 nnnn tttt iiiiiiiiiiii |
| 660 | // LDR.W Rt, [PC, #imm12] - 111 11 00 0x 101 1111 tttt iiiiiiiiiiii |
| 661 | uint32_t imm12 = instr & 0xFFF; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 662 | opcode << "ldr.w"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 663 | args << Rt << ", [" << Rn << ", #" << imm12 << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 664 | } else if (op4 == 0) { |
| 665 | // LDR.W Rt, [Rn, Rm{, LSL #imm2}] - 111 11 00 00 101 nnnn tttt 000000iimmmm |
| 666 | uint32_t imm2 = (instr >> 4) & 0xF; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 667 | ArmRegister rm(instr, 0); |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 668 | opcode << "ldr.w"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 669 | args << Rt << ", [" << Rn << ", " << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 670 | if (imm2 != 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 671 | args << ", lsl #" << imm2; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 672 | } |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 673 | args << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 674 | } else { |
| 675 | // LDRT Rt, [Rn, #imm8] - 111 11 00 00 101 nnnn tttt 1110iiiiiiii |
| 676 | uint32_t imm8 = instr & 0xFF; |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 677 | opcode << "ldrt"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 678 | args << Rt << ", [" << Rn << ", #" << imm8 << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 679 | } |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | default: |
| 684 | break; |
| 685 | } |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 686 | os << StringPrintf("\t\t\t%p: %08x\t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n'; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 687 | return 4; |
| 688 | } |
| 689 | |
| 690 | size_t DisassemblerArm::DumpThumb16(std::ostream& os, const uint8_t* instr_ptr) { |
| 691 | uint16_t instr = ReadU16(instr_ptr); |
| 692 | bool is_32bit = ((instr & 0xF000) == 0xF000) || ((instr & 0xF800) == 0xE800); |
| 693 | if (is_32bit) { |
| 694 | return DumpThumb32(os, instr_ptr); |
| 695 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 696 | std::ostringstream opcode; |
| 697 | std::ostringstream args; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 698 | uint16_t opcode1 = instr >> 10; |
| 699 | if (opcode1 < 0x10) { |
| 700 | // shift (immediate), add, subtract, move, and compare |
| 701 | uint16_t opcode2 = instr >> 9; |
| 702 | switch (opcode2) { |
| 703 | case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: case 0x5: case 0x6: case 0x7: |
| 704 | case 0x8: case 0x9: case 0xA: case 0xB: { |
| 705 | // Logical shift left - 00 000xx xxxxxxxxx |
| 706 | // Logical shift right - 00 001xx xxxxxxxxx |
| 707 | // Arithmetic shift right - 00 010xx xxxxxxxxx |
| 708 | uint16_t imm5 = (instr >> 6) & 0x1F; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 709 | ThumbRegister rm(instr, 3); |
| 710 | ThumbRegister Rd(instr, 7); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 711 | if (opcode2 <= 3) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 712 | opcode << "lsls"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 713 | } else if (opcode2 <= 7) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 714 | opcode << "lsrs"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 715 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 716 | opcode << "asrs"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 717 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 718 | args << Rd << ", " << rm << ", #" << imm5; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | case 0xC: case 0xD: case 0xE: case 0xF: { |
| 722 | // Add register - 00 01100 mmm nnn ddd |
| 723 | // Sub register - 00 01101 mmm nnn ddd |
| 724 | // Add 3-bit immediate - 00 01110 iii nnn ddd |
| 725 | // Sub 3-bit immediate - 00 01111 iii nnn ddd |
| 726 | uint16_t imm3_or_Rm = (instr >> 6) & 7; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 727 | ThumbRegister Rn(instr, 3); |
| 728 | ThumbRegister Rd(instr, 0); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 729 | if ((opcode2 & 2) != 0 && imm3_or_Rm == 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 730 | opcode << "mov"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 731 | } else { |
| 732 | if ((opcode2 & 1) == 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 733 | opcode << "adds"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 734 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 735 | opcode << "subs"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 736 | } |
| 737 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 738 | args << Rd << ", " << Rn; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 739 | if ((opcode2 & 2) == 0) { |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 740 | ArmRegister Rm(imm3_or_Rm); |
| 741 | args << ", " << Rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 742 | } else if (imm3_or_Rm != 0) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 743 | args << ", #" << imm3_or_Rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 744 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 745 | break; |
| 746 | } |
| 747 | case 0x10: case 0x11: case 0x12: case 0x13: |
| 748 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 749 | case 0x18: case 0x19: case 0x1A: case 0x1B: |
| 750 | case 0x1C: case 0x1D: case 0x1E: case 0x1F: { |
| 751 | // MOVS Rd, #imm8 - 00100 ddd iiiiiiii |
| 752 | // CMP Rn, #imm8 - 00101 nnn iiiiiiii |
| 753 | // ADDS Rn, #imm8 - 00110 nnn iiiiiiii |
| 754 | // SUBS Rn, #imm8 - 00111 nnn iiiiiiii |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 755 | ThumbRegister Rn(instr, 8); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 756 | uint16_t imm8 = instr & 0xFF; |
| 757 | switch (opcode2 >> 2) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 758 | case 4: opcode << "movs"; break; |
| 759 | case 5: opcode << "cmp"; break; |
| 760 | case 6: opcode << "adds"; break; |
| 761 | case 7: opcode << "subs"; break; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 762 | } |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 763 | args << Rn << ", #" << imm8; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 764 | break; |
| 765 | } |
| 766 | default: |
| 767 | break; |
| 768 | } |
Ian Rogers | ad03ef5 | 2012-03-18 19:34:47 -0700 | [diff] [blame] | 769 | } else if (opcode1 == 0x10) { |
| 770 | // Data-processing |
| 771 | uint16_t opcode2 = (instr >> 6) & 0xF; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 772 | ThumbRegister rm(instr, 3); |
| 773 | ThumbRegister rdn(instr, 0); |
Ian Rogers | ad03ef5 | 2012-03-18 19:34:47 -0700 | [diff] [blame] | 774 | opcode << kThumbDataProcessingOperations[opcode2]; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 775 | args << rdn << ", " << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 776 | } else if (opcode1 == 0x11) { |
| 777 | // Special data instructions and branch and exchange |
| 778 | uint16_t opcode2 = (instr >> 6) & 0x0F; |
| 779 | switch (opcode2) { |
| 780 | case 0x0: case 0x1: case 0x2: case 0x3: { |
| 781 | // Add low registers - 010001 0000 xxxxxx |
| 782 | // Add high registers - 010001 0001/001x xxxxxx |
| 783 | uint16_t DN = (instr >> 7) & 1; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 784 | ArmRegister rm(instr, 3); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 785 | uint16_t Rdn = instr & 7; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 786 | ArmRegister DN_Rdn((DN << 3) | Rdn); |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 787 | opcode << "add"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 788 | args << DN_Rdn << ", " << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 789 | break; |
| 790 | } |
| 791 | case 0x8: case 0x9: case 0xA: case 0xB: { |
| 792 | // Move low registers - 010001 1000 xxxxxx |
| 793 | // Move high registers - 010001 1001/101x xxxxxx |
| 794 | uint16_t DN = (instr >> 7) & 1; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 795 | ArmRegister rm(instr, 3); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 796 | uint16_t Rdn = instr & 7; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 797 | ArmRegister DN_Rdn((DN << 3) | Rdn); |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 798 | opcode << "mov"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 799 | args << DN_Rdn << ", " << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 800 | break; |
| 801 | } |
| 802 | case 0x5: case 0x6: case 0x7: { |
| 803 | // Compare high registers - 010001 0101/011x xxxxxx |
| 804 | uint16_t N = (instr >> 7) & 1; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 805 | ArmRegister rm(instr, 3); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 806 | uint16_t Rn = instr & 7; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 807 | ArmRegister N_Rn((N << 3) | Rn); |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 808 | opcode << "cmp"; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 809 | args << N_Rn << ", " << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | case 0xC: case 0xD: case 0xE: case 0xF: { |
| 813 | // Branch and exchange - 010001 110x xxxxxx |
| 814 | // Branch with link and exchange - 010001 111x xxxxxx |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 815 | ArmRegister rm(instr, 3); |
| 816 | opcode << ((opcode2 & 0x2) == 0 ? "bx" : "blx"); |
| 817 | args << rm; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 818 | break; |
| 819 | } |
| 820 | default: |
| 821 | break; |
| 822 | } |
| 823 | } else if ((instr & 0xF000) == 0xB000) { |
| 824 | // Miscellaneous 16-bit instructions |
| 825 | uint16_t opcode2 = (instr >> 5) & 0x7F; |
| 826 | switch (opcode2) { |
| 827 | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: { |
| 828 | // Add immediate to SP - 1011 00000 ii iiiii |
| 829 | // Subtract immediate from SP - 1011 00001 ii iiiii |
| 830 | int imm7 = instr & 0x7F; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 831 | opcode << ((opcode2 & 4) == 0 ? "add" : "sub"); |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 832 | args << "sp, sp, #" << (imm7 << 2); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 833 | break; |
| 834 | } |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 835 | case 0x08: case 0x09: case 0x0A: case 0x0B: // 0001xxx |
| 836 | case 0x0C: case 0x0D: case 0x0E: case 0x0F: { |
| 837 | // CBNZ, CBZ |
| 838 | uint16_t op = (instr >> 11) & 1; |
| 839 | uint16_t i = (instr >> 9) & 1; |
| 840 | uint16_t imm5 = (instr >> 3) & 0x1F; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 841 | ThumbRegister Rn(instr, 0); |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 842 | opcode << (op != 0 ? "cbnz" : "cbz"); |
| 843 | uint32_t imm32 = (i << 7) | (imm5 << 1); |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 844 | args << Rn << ", "; |
Ian Rogers | 087b241 | 2012-03-21 01:30:32 -0700 | [diff] [blame] | 845 | DumpBranchTarget(args, instr_ptr + 4, imm32); |
| 846 | break; |
| 847 | } |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 848 | case 0x78: case 0x79: case 0x7A: case 0x7B: // 1111xxx |
| 849 | case 0x7C: case 0x7D: case 0x7E: case 0x7F: { |
| 850 | // If-Then, and hints |
| 851 | uint16_t opA = (instr >> 4) & 0xF; |
| 852 | uint16_t opB = instr & 0xF; |
| 853 | if (opB == 0) { |
| 854 | switch (opA) { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 855 | case 0: opcode << "nop"; break; |
| 856 | case 1: opcode << "yield"; break; |
| 857 | case 2: opcode << "wfe"; break; |
| 858 | case 3: opcode << "sev"; break; |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 859 | default: break; |
| 860 | } |
| 861 | } else { |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 862 | opcode << "it"; |
| 863 | args << reinterpret_cast<void*>(opB) << " "; |
| 864 | DumpCond(args, opA); |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 865 | } |
| 866 | break; |
| 867 | } |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 868 | default: |
| 869 | break; |
| 870 | } |
| 871 | } else if (((instr & 0xF000) == 0x5000) || ((instr & 0xE000) == 0x6000) || |
| 872 | ((instr & 0xE000) == 0x8000)) { |
| 873 | // Load/store single data item |
| 874 | uint16_t opA = instr >> 12; |
| 875 | //uint16_t opB = (instr >> 9) & 7; |
| 876 | switch (opA) { |
| 877 | case 0x6: { |
| 878 | // STR Rt, Rn, #imm - 01100 iiiii nnn ttt |
| 879 | // LDR Rt, Rn, #imm - 01101 iiiii nnn ttt |
| 880 | uint16_t imm5 = (instr >> 6) & 0x1F; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 881 | ThumbRegister Rn(instr, 3); |
| 882 | ThumbRegister Rt(instr, 7); |
| 883 | opcode << ((instr & 0x800) == 0 ? "str" : "ldr"); |
| 884 | args << Rt << ", [" << Rn << ", #" << (imm5 << 2) << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 885 | break; |
| 886 | } |
| 887 | case 0x9: { |
| 888 | // STR Rt, [SP, #imm] - 01100 ttt iiiiiiii |
| 889 | // LDR Rt, [SP, #imm] - 01101 ttt iiiiiiii |
| 890 | uint16_t imm8 = instr & 0xFF; |
Elliott Hughes | 630e77d | 2012-03-22 19:20:56 -0700 | [diff] [blame] | 891 | ThumbRegister Rt(instr, 8); |
| 892 | opcode << ((instr & 0x800) == 0 ? "str" : "ldr"); |
| 893 | args << Rt << ", [sp, #" << (imm8 << 2) << "]"; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 894 | break; |
| 895 | } |
| 896 | default: |
| 897 | break; |
| 898 | } |
Ian Rogers | 40627db | 2012-03-04 17:31:09 -0800 | [diff] [blame] | 899 | } else if (opcode1 == 0x38 || opcode1 == 0x39) { |
| 900 | uint16_t imm11 = instr & 0x7FFF; |
| 901 | int32_t imm32 = imm11 << 1; |
| 902 | imm32 = (imm32 << 20) >> 20; // sign extend 12 bit immediate |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 903 | opcode << "b"; |
| 904 | DumpBranchTarget(args, instr_ptr + 4, imm32); |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 905 | } |
Elliott Hughes | cbf0b61 | 2012-03-15 16:23:47 -0700 | [diff] [blame] | 906 | os << StringPrintf("\t\t\t%p: %04x \t%-7s ", instr_ptr, instr, opcode.str().c_str()) << args.str() << '\n'; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 907 | } |
| 908 | return 2; |
| 909 | } |
| 910 | |
| 911 | } // namespace arm |
| 912 | } // namespace art |