Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | // A Disassembler object is used to disassemble a block of code instruction by |
| 29 | // instruction. The default implementation of the NameConverter object can be |
| 30 | // overriden to modify register names or to do symbol lookup on addresses. |
| 31 | // |
| 32 | // The example below will disassemble a block of code and print it to stdout. |
| 33 | // |
| 34 | // NameConverter converter; |
| 35 | // Disassembler d(converter); |
| 36 | // for (byte* pc = begin; pc < end;) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 37 | // v8::internal::EmbeddedVector<char, 256> buffer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | // byte* prev_pc = pc; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 39 | // pc += d.InstructionDecode(buffer, pc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 40 | // printf("%p %08x %s\n", |
| 41 | // prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer); |
| 42 | // } |
| 43 | // |
| 44 | // The Disassembler class also has a convenience method to disassemble a block |
| 45 | // of code into a FILE*, meaning that the above functionality could also be |
| 46 | // achieved by just calling Disassembler::Disassemble(stdout, begin, end); |
| 47 | |
| 48 | |
| 49 | #include <assert.h> |
| 50 | #include <stdio.h> |
| 51 | #include <stdarg.h> |
| 52 | #include <string.h> |
| 53 | #ifndef WIN32 |
| 54 | #include <stdint.h> |
| 55 | #endif |
| 56 | |
| 57 | #include "v8.h" |
| 58 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 59 | #if defined(V8_TARGET_ARCH_ARM) |
| 60 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | #include "constants-arm.h" |
| 62 | #include "disasm.h" |
| 63 | #include "macro-assembler.h" |
| 64 | #include "platform.h" |
| 65 | |
| 66 | |
| 67 | namespace assembler { |
| 68 | namespace arm { |
| 69 | |
| 70 | namespace v8i = v8::internal; |
| 71 | |
| 72 | |
| 73 | //------------------------------------------------------------------------------ |
| 74 | |
| 75 | // Decoder decodes and disassembles instructions into an output buffer. |
| 76 | // It uses the converter to convert register names and call destinations into |
| 77 | // more informative description. |
| 78 | class Decoder { |
| 79 | public: |
| 80 | Decoder(const disasm::NameConverter& converter, |
| 81 | v8::internal::Vector<char> out_buffer) |
| 82 | : converter_(converter), |
| 83 | out_buffer_(out_buffer), |
| 84 | out_buffer_pos_(0) { |
| 85 | out_buffer_[out_buffer_pos_] = '\0'; |
| 86 | } |
| 87 | |
| 88 | ~Decoder() {} |
| 89 | |
| 90 | // Writes one disassembled instruction into 'buffer' (0-terminated). |
| 91 | // Returns the length of the disassembled machine instruction in bytes. |
| 92 | int InstructionDecode(byte* instruction); |
| 93 | |
| 94 | private: |
| 95 | // Bottleneck functions to print into the out_buffer. |
| 96 | void PrintChar(const char ch); |
| 97 | void Print(const char* str); |
| 98 | |
| 99 | // Printing of common values. |
| 100 | void PrintRegister(int reg); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 101 | void PrintSRegister(int reg); |
| 102 | void PrintDRegister(int reg); |
| 103 | int FormatVFPRegister(Instr* instr, const char* format); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 104 | void PrintMovwMovt(Instr* instr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 105 | int FormatVFPinstruction(Instr* instr, const char* format); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | void PrintCondition(Instr* instr); |
| 107 | void PrintShiftRm(Instr* instr); |
| 108 | void PrintShiftImm(Instr* instr); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 109 | void PrintShiftSat(Instr* instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 110 | void PrintPU(Instr* instr); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 111 | void PrintSoftwareInterrupt(SoftwareInterruptCodes svc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | |
| 113 | // Handle formatting of instructions and their options. |
| 114 | int FormatRegister(Instr* instr, const char* option); |
| 115 | int FormatOption(Instr* instr, const char* option); |
| 116 | void Format(Instr* instr, const char* format); |
| 117 | void Unknown(Instr* instr); |
| 118 | |
| 119 | // Each of these functions decodes one particular instruction type, a 3-bit |
| 120 | // field in the instruction encoding. |
| 121 | // Types 0 and 1 are combined as they are largely the same except for the way |
| 122 | // they interpret the shifter operand. |
| 123 | void DecodeType01(Instr* instr); |
| 124 | void DecodeType2(Instr* instr); |
| 125 | void DecodeType3(Instr* instr); |
| 126 | void DecodeType4(Instr* instr); |
| 127 | void DecodeType5(Instr* instr); |
| 128 | void DecodeType6(Instr* instr); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 129 | // Type 7 includes special Debugger instructions. |
| 130 | int DecodeType7(Instr* instr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 131 | // For VFP support. |
| 132 | void DecodeTypeVFP(Instr* instr); |
| 133 | void DecodeType6CoprocessorIns(Instr* instr); |
| 134 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 135 | void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instr* instr); |
| 136 | void DecodeVCMP(Instr* instr); |
| 137 | void DecodeVCVTBetweenDoubleAndSingle(Instr* instr); |
| 138 | void DecodeVCVTBetweenFloatingPointAndInteger(Instr* instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | |
| 140 | const disasm::NameConverter& converter_; |
| 141 | v8::internal::Vector<char> out_buffer_; |
| 142 | int out_buffer_pos_; |
| 143 | |
| 144 | DISALLOW_COPY_AND_ASSIGN(Decoder); |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | // Support for assertions in the Decoder formatting functions. |
| 149 | #define STRING_STARTS_WITH(string, compare_string) \ |
| 150 | (strncmp(string, compare_string, strlen(compare_string)) == 0) |
| 151 | |
| 152 | |
| 153 | // Append the ch to the output buffer. |
| 154 | void Decoder::PrintChar(const char ch) { |
| 155 | out_buffer_[out_buffer_pos_++] = ch; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | // Append the str to the output buffer. |
| 160 | void Decoder::Print(const char* str) { |
| 161 | char cur = *str++; |
| 162 | while (cur != '\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 163 | PrintChar(cur); |
| 164 | cur = *str++; |
| 165 | } |
| 166 | out_buffer_[out_buffer_pos_] = 0; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | // These condition names are defined in a way to match the native disassembler |
| 171 | // formatting. See for example the command "objdump -d <binary file>". |
| 172 | static const char* cond_names[max_condition] = { |
| 173 | "eq", "ne", "cs" , "cc" , "mi" , "pl" , "vs" , "vc" , |
| 174 | "hi", "ls", "ge", "lt", "gt", "le", "", "invalid", |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | // Print the condition guarding the instruction. |
| 179 | void Decoder::PrintCondition(Instr* instr) { |
| 180 | Print(cond_names[instr->ConditionField()]); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | // Print the register name according to the active name converter. |
| 185 | void Decoder::PrintRegister(int reg) { |
| 186 | Print(converter_.NameOfCPURegister(reg)); |
| 187 | } |
| 188 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 189 | // Print the VFP S register name according to the active name converter. |
| 190 | void Decoder::PrintSRegister(int reg) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 191 | Print(assembler::arm::VFPRegisters::Name(reg, false)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Print the VFP D register name according to the active name converter. |
| 195 | void Decoder::PrintDRegister(int reg) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 196 | Print(assembler::arm::VFPRegisters::Name(reg, true)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | |
| 200 | // These shift names are defined in a way to match the native disassembler |
| 201 | // formatting. See for example the command "objdump -d <binary file>". |
| 202 | static const char* shift_names[max_shift] = { |
| 203 | "lsl", "lsr", "asr", "ror" |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | // Print the register shift operands for the instruction. Generally used for |
| 208 | // data processing instructions. |
| 209 | void Decoder::PrintShiftRm(Instr* instr) { |
| 210 | Shift shift = instr->ShiftField(); |
| 211 | int shift_amount = instr->ShiftAmountField(); |
| 212 | int rm = instr->RmField(); |
| 213 | |
| 214 | PrintRegister(rm); |
| 215 | |
| 216 | if ((instr->RegShiftField() == 0) && (shift == LSL) && (shift_amount == 0)) { |
| 217 | // Special case for using rm only. |
| 218 | return; |
| 219 | } |
| 220 | if (instr->RegShiftField() == 0) { |
| 221 | // by immediate |
| 222 | if ((shift == ROR) && (shift_amount == 0)) { |
| 223 | Print(", RRX"); |
| 224 | return; |
| 225 | } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) { |
| 226 | shift_amount = 32; |
| 227 | } |
| 228 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 229 | ", %s #%d", |
| 230 | shift_names[shift], shift_amount); |
| 231 | } else { |
| 232 | // by register |
| 233 | int rs = instr->RsField(); |
| 234 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 235 | ", %s ", shift_names[shift]); |
| 236 | PrintRegister(rs); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | |
| 241 | // Print the immediate operand for the instruction. Generally used for data |
| 242 | // processing instructions. |
| 243 | void Decoder::PrintShiftImm(Instr* instr) { |
| 244 | int rotate = instr->RotateField() * 2; |
| 245 | int immed8 = instr->Immed8Field(); |
| 246 | int imm = (immed8 >> rotate) | (immed8 << (32 - rotate)); |
| 247 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 248 | "#%d", imm); |
| 249 | } |
| 250 | |
| 251 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 252 | // Print the optional shift and immediate used by saturating instructions. |
| 253 | void Decoder::PrintShiftSat(Instr* instr) { |
| 254 | int shift = instr->Bits(11, 7); |
| 255 | if (shift > 0) { |
| 256 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 257 | ", %s #%d", |
| 258 | shift_names[instr->Bit(6) * 2], |
| 259 | instr->Bits(11, 7)); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 264 | // Print PU formatting to reduce complexity of FormatOption. |
| 265 | void Decoder::PrintPU(Instr* instr) { |
| 266 | switch (instr->PUField()) { |
| 267 | case 0: { |
| 268 | Print("da"); |
| 269 | break; |
| 270 | } |
| 271 | case 1: { |
| 272 | Print("ia"); |
| 273 | break; |
| 274 | } |
| 275 | case 2: { |
| 276 | Print("db"); |
| 277 | break; |
| 278 | } |
| 279 | case 3: { |
| 280 | Print("ib"); |
| 281 | break; |
| 282 | } |
| 283 | default: { |
| 284 | UNREACHABLE(); |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | |
| 291 | // Print SoftwareInterrupt codes. Factoring this out reduces the complexity of |
| 292 | // the FormatOption method. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 293 | void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) { |
| 294 | switch (svc) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | case call_rt_redirected: |
| 296 | Print("call_rt_redirected"); |
| 297 | return; |
| 298 | case break_point: |
| 299 | Print("break_point"); |
| 300 | return; |
| 301 | default: |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 302 | if (svc >= stop) { |
| 303 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 304 | "%d - 0x%x", |
| 305 | svc & kStopCodeMask, |
| 306 | svc & kStopCodeMask); |
| 307 | } else { |
| 308 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 309 | "%d", |
| 310 | svc); |
| 311 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | // Handle all register based formatting in this function to reduce the |
| 318 | // complexity of FormatOption. |
| 319 | int Decoder::FormatRegister(Instr* instr, const char* format) { |
| 320 | ASSERT(format[0] == 'r'); |
| 321 | if (format[1] == 'n') { // 'rn: Rn register |
| 322 | int reg = instr->RnField(); |
| 323 | PrintRegister(reg); |
| 324 | return 2; |
| 325 | } else if (format[1] == 'd') { // 'rd: Rd register |
| 326 | int reg = instr->RdField(); |
| 327 | PrintRegister(reg); |
| 328 | return 2; |
| 329 | } else if (format[1] == 's') { // 'rs: Rs register |
| 330 | int reg = instr->RsField(); |
| 331 | PrintRegister(reg); |
| 332 | return 2; |
| 333 | } else if (format[1] == 'm') { // 'rm: Rm register |
| 334 | int reg = instr->RmField(); |
| 335 | PrintRegister(reg); |
| 336 | return 2; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 337 | } else if (format[1] == 't') { // 'rt: Rt register |
| 338 | int reg = instr->RtField(); |
| 339 | PrintRegister(reg); |
| 340 | return 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 341 | } else if (format[1] == 'l') { |
| 342 | // 'rlist: register list for load and store multiple instructions |
| 343 | ASSERT(STRING_STARTS_WITH(format, "rlist")); |
| 344 | int rlist = instr->RlistField(); |
| 345 | int reg = 0; |
| 346 | Print("{"); |
| 347 | // Print register list in ascending order, by scanning the bit mask. |
| 348 | while (rlist != 0) { |
| 349 | if ((rlist & 1) != 0) { |
| 350 | PrintRegister(reg); |
| 351 | if ((rlist >> 1) != 0) { |
| 352 | Print(", "); |
| 353 | } |
| 354 | } |
| 355 | reg++; |
| 356 | rlist >>= 1; |
| 357 | } |
| 358 | Print("}"); |
| 359 | return 5; |
| 360 | } |
| 361 | UNREACHABLE(); |
| 362 | return -1; |
| 363 | } |
| 364 | |
| 365 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 366 | // Handle all VFP register based formatting in this function to reduce the |
| 367 | // complexity of FormatOption. |
| 368 | int Decoder::FormatVFPRegister(Instr* instr, const char* format) { |
| 369 | ASSERT((format[0] == 'S') || (format[0] == 'D')); |
| 370 | |
| 371 | if (format[1] == 'n') { |
| 372 | int reg = instr->VnField(); |
| 373 | if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->NField())); |
| 374 | if (format[0] == 'D') PrintDRegister(reg); |
| 375 | return 2; |
| 376 | } else if (format[1] == 'm') { |
| 377 | int reg = instr->VmField(); |
| 378 | if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->MField())); |
| 379 | if (format[0] == 'D') PrintDRegister(reg); |
| 380 | return 2; |
| 381 | } else if (format[1] == 'd') { |
| 382 | int reg = instr->VdField(); |
| 383 | if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->DField())); |
| 384 | if (format[0] == 'D') PrintDRegister(reg); |
| 385 | return 2; |
| 386 | } |
| 387 | |
| 388 | UNREACHABLE(); |
| 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | int Decoder::FormatVFPinstruction(Instr* instr, const char* format) { |
| 394 | Print(format); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 399 | // Print the movw or movt instruction. |
| 400 | void Decoder::PrintMovwMovt(Instr* instr) { |
| 401 | int imm = instr->ImmedMovwMovtField(); |
| 402 | int rd = instr->RdField(); |
| 403 | PrintRegister(rd); |
| 404 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 405 | ", #%d", imm); |
| 406 | } |
| 407 | |
| 408 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 409 | // FormatOption takes a formatting string and interprets it based on |
| 410 | // the current instructions. The format string points to the first |
| 411 | // character of the option string (the option escape has already been |
| 412 | // consumed by the caller.) FormatOption returns the number of |
| 413 | // characters that were consumed from the formatting string. |
| 414 | int Decoder::FormatOption(Instr* instr, const char* format) { |
| 415 | switch (format[0]) { |
| 416 | case 'a': { // 'a: accumulate multiplies |
| 417 | if (instr->Bit(21) == 0) { |
| 418 | Print("ul"); |
| 419 | } else { |
| 420 | Print("la"); |
| 421 | } |
| 422 | return 1; |
| 423 | } |
| 424 | case 'b': { // 'b: byte loads or stores |
| 425 | if (instr->HasB()) { |
| 426 | Print("b"); |
| 427 | } |
| 428 | return 1; |
| 429 | } |
| 430 | case 'c': { // 'cond: conditional execution |
| 431 | ASSERT(STRING_STARTS_WITH(format, "cond")); |
| 432 | PrintCondition(instr); |
| 433 | return 4; |
| 434 | } |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 435 | case 'd': { // 'd: vmov double immediate. |
| 436 | double d = instr->DoubleImmedVmov(); |
| 437 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 438 | "#%g", d); |
| 439 | return 1; |
| 440 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 441 | case 'f': { // 'f: bitfield instructions - v7 and above. |
| 442 | uint32_t lsbit = instr->Bits(11, 7); |
| 443 | uint32_t width = instr->Bits(20, 16) + 1; |
| 444 | if (instr->Bit(21) == 0) { |
| 445 | // BFC/BFI: |
| 446 | // Bits 20-16 represent most-significant bit. Covert to width. |
| 447 | width -= lsbit; |
| 448 | ASSERT(width > 0); |
| 449 | } |
| 450 | ASSERT((width + lsbit) <= 32); |
| 451 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 452 | "#%d, #%d", lsbit, width); |
| 453 | return 1; |
| 454 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | case 'h': { // 'h: halfword operation for extra loads and stores |
| 456 | if (instr->HasH()) { |
| 457 | Print("h"); |
| 458 | } else { |
| 459 | Print("b"); |
| 460 | } |
| 461 | return 1; |
| 462 | } |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 463 | case 'i': { // 'i: immediate value from adjacent bits. |
| 464 | // Expects tokens in the form imm%02d@%02d, ie. imm05@07, imm10@16 |
| 465 | int width = (format[3] - '0') * 10 + (format[4] - '0'); |
| 466 | int lsb = (format[6] - '0') * 10 + (format[7] - '0'); |
| 467 | |
| 468 | ASSERT((width >= 1) && (width <= 32)); |
| 469 | ASSERT((lsb >= 0) && (lsb <= 31)); |
| 470 | ASSERT((width + lsb) <= 32); |
| 471 | |
| 472 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 473 | "%d", |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 474 | instr->Bits(width + lsb - 1, lsb)); |
| 475 | return 8; |
| 476 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 477 | case 'l': { // 'l: branch and link |
| 478 | if (instr->HasLink()) { |
| 479 | Print("l"); |
| 480 | } |
| 481 | return 1; |
| 482 | } |
| 483 | case 'm': { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 484 | if (format[1] == 'w') { |
| 485 | // 'mw: movt/movw instructions. |
| 486 | PrintMovwMovt(instr); |
| 487 | return 2; |
| 488 | } |
| 489 | if (format[1] == 'e') { // 'memop: load/store instructions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | ASSERT(STRING_STARTS_WITH(format, "memop")); |
| 491 | if (instr->HasL()) { |
| 492 | Print("ldr"); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 493 | } else if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0)) { |
| 494 | if (instr->Bits(7, 4) == 0xf) { |
| 495 | Print("strd"); |
| 496 | } else { |
| 497 | Print("ldrd"); |
| 498 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | } else { |
| 500 | Print("str"); |
| 501 | } |
| 502 | return 5; |
| 503 | } |
| 504 | // 'msg: for simulator break instructions |
| 505 | ASSERT(STRING_STARTS_WITH(format, "msg")); |
| 506 | byte* str = |
| 507 | reinterpret_cast<byte*>(instr->InstructionBits() & 0x0fffffff); |
| 508 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 509 | "%s", converter_.NameInCode(str)); |
| 510 | return 3; |
| 511 | } |
| 512 | case 'o': { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 513 | if ((format[3] == '1') && (format[4] == '2')) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | // 'off12: 12-bit offset for load and store instructions |
| 515 | ASSERT(STRING_STARTS_WITH(format, "off12")); |
| 516 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 517 | "%d", instr->Offset12Field()); |
| 518 | return 5; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 519 | } else if (format[3] == '0') { |
| 520 | // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0. |
| 521 | ASSERT(STRING_STARTS_WITH(format, "off0to3and8to19")); |
| 522 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 523 | "%d", |
| 524 | (instr->Bits(19, 8) << 4) + |
| 525 | instr->Bits(3, 0)); |
| 526 | return 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | } |
| 528 | // 'off8: 8-bit offset for extra load and store instructions |
| 529 | ASSERT(STRING_STARTS_WITH(format, "off8")); |
| 530 | int offs8 = (instr->ImmedHField() << 4) | instr->ImmedLField(); |
| 531 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 532 | "%d", offs8); |
| 533 | return 4; |
| 534 | } |
| 535 | case 'p': { // 'pu: P and U bits for load and store instructions |
| 536 | ASSERT(STRING_STARTS_WITH(format, "pu")); |
| 537 | PrintPU(instr); |
| 538 | return 2; |
| 539 | } |
| 540 | case 'r': { |
| 541 | return FormatRegister(instr, format); |
| 542 | } |
| 543 | case 's': { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 544 | if (format[1] == 'h') { // 'shift_op or 'shift_rm or 'shift_sat. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | if (format[6] == 'o') { // 'shift_op |
| 546 | ASSERT(STRING_STARTS_WITH(format, "shift_op")); |
| 547 | if (instr->TypeField() == 0) { |
| 548 | PrintShiftRm(instr); |
| 549 | } else { |
| 550 | ASSERT(instr->TypeField() == 1); |
| 551 | PrintShiftImm(instr); |
| 552 | } |
| 553 | return 8; |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 554 | } else if (format[6] == 's') { // 'shift_sat. |
| 555 | ASSERT(STRING_STARTS_WITH(format, "shift_sat")); |
| 556 | PrintShiftSat(instr); |
| 557 | return 9; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | } else { // 'shift_rm |
| 559 | ASSERT(STRING_STARTS_WITH(format, "shift_rm")); |
| 560 | PrintShiftRm(instr); |
| 561 | return 8; |
| 562 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 563 | } else if (format[1] == 'v') { // 'svc |
| 564 | ASSERT(STRING_STARTS_WITH(format, "svc")); |
| 565 | PrintSoftwareInterrupt(instr->SvcField()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | return 3; |
| 567 | } else if (format[1] == 'i') { // 'sign: signed extra loads and stores |
| 568 | ASSERT(STRING_STARTS_WITH(format, "sign")); |
| 569 | if (instr->HasSign()) { |
| 570 | Print("s"); |
| 571 | } |
| 572 | return 4; |
| 573 | } |
| 574 | // 's: S field of data processing instructions |
| 575 | if (instr->HasS()) { |
| 576 | Print("s"); |
| 577 | } |
| 578 | return 1; |
| 579 | } |
| 580 | case 't': { // 'target: target of branch instructions |
| 581 | ASSERT(STRING_STARTS_WITH(format, "target")); |
| 582 | int off = (instr->SImmed24Field() << 2) + 8; |
| 583 | out_buffer_pos_ += v8i::OS::SNPrintF( |
| 584 | out_buffer_ + out_buffer_pos_, |
| 585 | "%+d -> %s", |
| 586 | off, |
| 587 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + off)); |
| 588 | return 6; |
| 589 | } |
| 590 | case 'u': { // 'u: signed or unsigned multiplies |
| 591 | // The manual gets the meaning of bit 22 backwards in the multiply |
| 592 | // instruction overview on page A3.16.2. The instructions that |
| 593 | // exist in u and s variants are the following: |
| 594 | // smull A4.1.87 |
| 595 | // umull A4.1.129 |
| 596 | // umlal A4.1.128 |
| 597 | // smlal A4.1.76 |
| 598 | // For these 0 means u and 1 means s. As can be seen on their individual |
| 599 | // pages. The other 18 mul instructions have the bit set or unset in |
| 600 | // arbitrary ways that are unrelated to the signedness of the instruction. |
| 601 | // None of these 18 instructions exist in both a 'u' and an 's' variant. |
| 602 | |
| 603 | if (instr->Bit(22) == 0) { |
| 604 | Print("u"); |
| 605 | } else { |
| 606 | Print("s"); |
| 607 | } |
| 608 | return 1; |
| 609 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 610 | case 'v': { |
| 611 | return FormatVFPinstruction(instr, format); |
| 612 | } |
| 613 | case 'S': |
| 614 | case 'D': { |
| 615 | return FormatVFPRegister(instr, format); |
| 616 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 617 | case 'w': { // 'w: W field of load and store instructions |
| 618 | if (instr->HasW()) { |
| 619 | Print("!"); |
| 620 | } |
| 621 | return 1; |
| 622 | } |
| 623 | default: { |
| 624 | UNREACHABLE(); |
| 625 | break; |
| 626 | } |
| 627 | } |
| 628 | UNREACHABLE(); |
| 629 | return -1; |
| 630 | } |
| 631 | |
| 632 | |
| 633 | // Format takes a formatting string for a whole instruction and prints it into |
| 634 | // the output buffer. All escaped options are handed to FormatOption to be |
| 635 | // parsed further. |
| 636 | void Decoder::Format(Instr* instr, const char* format) { |
| 637 | char cur = *format++; |
| 638 | while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 639 | if (cur == '\'') { // Single quote is used as the formatting escape. |
| 640 | format += FormatOption(instr, format); |
| 641 | } else { |
| 642 | out_buffer_[out_buffer_pos_++] = cur; |
| 643 | } |
| 644 | cur = *format++; |
| 645 | } |
| 646 | out_buffer_[out_buffer_pos_] = '\0'; |
| 647 | } |
| 648 | |
| 649 | |
| 650 | // For currently unimplemented decodings the disassembler calls Unknown(instr) |
| 651 | // which will just print "unknown" of the instruction bits. |
| 652 | void Decoder::Unknown(Instr* instr) { |
| 653 | Format(instr, "unknown"); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | void Decoder::DecodeType01(Instr* instr) { |
| 658 | int type = instr->TypeField(); |
| 659 | if ((type == 0) && instr->IsSpecialType0()) { |
| 660 | // multiply instruction or extra loads and stores |
| 661 | if (instr->Bits(7, 4) == 9) { |
| 662 | if (instr->Bit(24) == 0) { |
| 663 | // multiply instructions |
| 664 | if (instr->Bit(23) == 0) { |
| 665 | if (instr->Bit(21) == 0) { |
| 666 | // The MUL instruction description (A 4.1.33) refers to Rd as being |
| 667 | // the destination for the operation, but it confusingly uses the |
| 668 | // Rn field to encode it. |
| 669 | Format(instr, "mul'cond's 'rn, 'rm, 'rs"); |
| 670 | } else { |
| 671 | // The MLA instruction description (A 4.1.28) refers to the order |
| 672 | // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the |
| 673 | // Rn field to encode the Rd register and the Rd field to encode |
| 674 | // the Rn register. |
| 675 | Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd"); |
| 676 | } |
| 677 | } else { |
| 678 | // The signed/long multiply instructions use the terms RdHi and RdLo |
| 679 | // when referring to the target registers. They are mapped to the Rn |
| 680 | // and Rd fields as follows: |
| 681 | // RdLo == Rd field |
| 682 | // RdHi == Rn field |
| 683 | // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs> |
| 684 | Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs"); |
| 685 | } |
| 686 | } else { |
| 687 | Unknown(instr); // not used by V8 |
| 688 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 689 | } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xd) == 0xd)) { |
| 690 | // ldrd, strd |
| 691 | switch (instr->PUField()) { |
| 692 | case 0: { |
| 693 | if (instr->Bit(22) == 0) { |
| 694 | Format(instr, "'memop'cond's 'rd, ['rn], -'rm"); |
| 695 | } else { |
| 696 | Format(instr, "'memop'cond's 'rd, ['rn], #-'off8"); |
| 697 | } |
| 698 | break; |
| 699 | } |
| 700 | case 1: { |
| 701 | if (instr->Bit(22) == 0) { |
| 702 | Format(instr, "'memop'cond's 'rd, ['rn], +'rm"); |
| 703 | } else { |
| 704 | Format(instr, "'memop'cond's 'rd, ['rn], #+'off8"); |
| 705 | } |
| 706 | break; |
| 707 | } |
| 708 | case 2: { |
| 709 | if (instr->Bit(22) == 0) { |
| 710 | Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w"); |
| 711 | } else { |
| 712 | Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w"); |
| 713 | } |
| 714 | break; |
| 715 | } |
| 716 | case 3: { |
| 717 | if (instr->Bit(22) == 0) { |
| 718 | Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w"); |
| 719 | } else { |
| 720 | Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w"); |
| 721 | } |
| 722 | break; |
| 723 | } |
| 724 | default: { |
| 725 | // The PU field is a 2-bit field. |
| 726 | UNREACHABLE(); |
| 727 | break; |
| 728 | } |
| 729 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 730 | } else { |
| 731 | // extra load/store instructions |
| 732 | switch (instr->PUField()) { |
| 733 | case 0: { |
| 734 | if (instr->Bit(22) == 0) { |
| 735 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm"); |
| 736 | } else { |
| 737 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8"); |
| 738 | } |
| 739 | break; |
| 740 | } |
| 741 | case 1: { |
| 742 | if (instr->Bit(22) == 0) { |
| 743 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm"); |
| 744 | } else { |
| 745 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8"); |
| 746 | } |
| 747 | break; |
| 748 | } |
| 749 | case 2: { |
| 750 | if (instr->Bit(22) == 0) { |
| 751 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w"); |
| 752 | } else { |
| 753 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w"); |
| 754 | } |
| 755 | break; |
| 756 | } |
| 757 | case 3: { |
| 758 | if (instr->Bit(22) == 0) { |
| 759 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w"); |
| 760 | } else { |
| 761 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w"); |
| 762 | } |
| 763 | break; |
| 764 | } |
| 765 | default: { |
| 766 | // The PU field is a 2-bit field. |
| 767 | UNREACHABLE(); |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | return; |
| 772 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 773 | } else if ((type == 0) && instr->IsMiscType0()) { |
| 774 | if (instr->Bits(22, 21) == 1) { |
| 775 | switch (instr->Bits(7, 4)) { |
| 776 | case BX: |
| 777 | Format(instr, "bx'cond 'rm"); |
| 778 | break; |
| 779 | case BLX: |
| 780 | Format(instr, "blx'cond 'rm"); |
| 781 | break; |
| 782 | case BKPT: |
| 783 | Format(instr, "bkpt 'off0to3and8to19"); |
| 784 | break; |
| 785 | default: |
| 786 | Unknown(instr); // not used by V8 |
| 787 | break; |
| 788 | } |
| 789 | } else if (instr->Bits(22, 21) == 3) { |
| 790 | switch (instr->Bits(7, 4)) { |
| 791 | case CLZ: |
| 792 | Format(instr, "clz'cond 'rd, 'rm"); |
| 793 | break; |
| 794 | default: |
| 795 | Unknown(instr); // not used by V8 |
| 796 | break; |
| 797 | } |
| 798 | } else { |
| 799 | Unknown(instr); // not used by V8 |
| 800 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | } else { |
| 802 | switch (instr->OpcodeField()) { |
| 803 | case AND: { |
| 804 | Format(instr, "and'cond's 'rd, 'rn, 'shift_op"); |
| 805 | break; |
| 806 | } |
| 807 | case EOR: { |
| 808 | Format(instr, "eor'cond's 'rd, 'rn, 'shift_op"); |
| 809 | break; |
| 810 | } |
| 811 | case SUB: { |
| 812 | Format(instr, "sub'cond's 'rd, 'rn, 'shift_op"); |
| 813 | break; |
| 814 | } |
| 815 | case RSB: { |
| 816 | Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op"); |
| 817 | break; |
| 818 | } |
| 819 | case ADD: { |
| 820 | Format(instr, "add'cond's 'rd, 'rn, 'shift_op"); |
| 821 | break; |
| 822 | } |
| 823 | case ADC: { |
| 824 | Format(instr, "adc'cond's 'rd, 'rn, 'shift_op"); |
| 825 | break; |
| 826 | } |
| 827 | case SBC: { |
| 828 | Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op"); |
| 829 | break; |
| 830 | } |
| 831 | case RSC: { |
| 832 | Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op"); |
| 833 | break; |
| 834 | } |
| 835 | case TST: { |
| 836 | if (instr->HasS()) { |
| 837 | Format(instr, "tst'cond 'rn, 'shift_op"); |
| 838 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 839 | Format(instr, "movw'cond 'mw"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 840 | } |
| 841 | break; |
| 842 | } |
| 843 | case TEQ: { |
| 844 | if (instr->HasS()) { |
| 845 | Format(instr, "teq'cond 'rn, 'shift_op"); |
| 846 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 847 | // Other instructions matching this pattern are handled in the |
| 848 | // miscellaneous instructions part above. |
| 849 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 850 | } |
| 851 | break; |
| 852 | } |
| 853 | case CMP: { |
| 854 | if (instr->HasS()) { |
| 855 | Format(instr, "cmp'cond 'rn, 'shift_op"); |
| 856 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 857 | Format(instr, "movt'cond 'mw"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 858 | } |
| 859 | break; |
| 860 | } |
| 861 | case CMN: { |
| 862 | if (instr->HasS()) { |
| 863 | Format(instr, "cmn'cond 'rn, 'shift_op"); |
| 864 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 865 | // Other instructions matching this pattern are handled in the |
| 866 | // miscellaneous instructions part above. |
| 867 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 868 | } |
| 869 | break; |
| 870 | } |
| 871 | case ORR: { |
| 872 | Format(instr, "orr'cond's 'rd, 'rn, 'shift_op"); |
| 873 | break; |
| 874 | } |
| 875 | case MOV: { |
| 876 | Format(instr, "mov'cond's 'rd, 'shift_op"); |
| 877 | break; |
| 878 | } |
| 879 | case BIC: { |
| 880 | Format(instr, "bic'cond's 'rd, 'rn, 'shift_op"); |
| 881 | break; |
| 882 | } |
| 883 | case MVN: { |
| 884 | Format(instr, "mvn'cond's 'rd, 'shift_op"); |
| 885 | break; |
| 886 | } |
| 887 | default: { |
| 888 | // The Opcode field is a 4-bit field. |
| 889 | UNREACHABLE(); |
| 890 | break; |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | |
| 897 | void Decoder::DecodeType2(Instr* instr) { |
| 898 | switch (instr->PUField()) { |
| 899 | case 0: { |
| 900 | if (instr->HasW()) { |
| 901 | Unknown(instr); // not used in V8 |
| 902 | } |
| 903 | Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12"); |
| 904 | break; |
| 905 | } |
| 906 | case 1: { |
| 907 | if (instr->HasW()) { |
| 908 | Unknown(instr); // not used in V8 |
| 909 | } |
| 910 | Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12"); |
| 911 | break; |
| 912 | } |
| 913 | case 2: { |
| 914 | Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w"); |
| 915 | break; |
| 916 | } |
| 917 | case 3: { |
| 918 | Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w"); |
| 919 | break; |
| 920 | } |
| 921 | default: { |
| 922 | // The PU field is a 2-bit field. |
| 923 | UNREACHABLE(); |
| 924 | break; |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | |
| 930 | void Decoder::DecodeType3(Instr* instr) { |
| 931 | switch (instr->PUField()) { |
| 932 | case 0: { |
| 933 | ASSERT(!instr->HasW()); |
| 934 | Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm"); |
| 935 | break; |
| 936 | } |
| 937 | case 1: { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 938 | if (instr->HasW()) { |
| 939 | ASSERT(instr->Bits(5, 4) == 0x1); |
| 940 | if (instr->Bit(22) == 0x1) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 941 | Format(instr, "usat 'rd, #'imm05@16, 'rm'shift_sat"); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 942 | } else { |
| 943 | UNREACHABLE(); // SSAT. |
| 944 | } |
| 945 | } else { |
| 946 | Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm"); |
| 947 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 948 | break; |
| 949 | } |
| 950 | case 2: { |
| 951 | Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w"); |
| 952 | break; |
| 953 | } |
| 954 | case 3: { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 955 | if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) { |
| 956 | uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 957 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 958 | uint32_t msbit = widthminus1 + lsbit; |
| 959 | if (msbit <= 31) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 960 | if (instr->Bit(22)) { |
| 961 | Format(instr, "ubfx'cond 'rd, 'rm, 'f"); |
| 962 | } else { |
| 963 | Format(instr, "sbfx'cond 'rd, 'rm, 'f"); |
| 964 | } |
| 965 | } else { |
| 966 | UNREACHABLE(); |
| 967 | } |
| 968 | } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) { |
| 969 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
| 970 | uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16)); |
| 971 | if (msbit >= lsbit) { |
| 972 | if (instr->RmField() == 15) { |
| 973 | Format(instr, "bfc'cond 'rd, 'f"); |
| 974 | } else { |
| 975 | Format(instr, "bfi'cond 'rd, 'rm, 'f"); |
| 976 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 977 | } else { |
| 978 | UNREACHABLE(); |
| 979 | } |
| 980 | } else { |
| 981 | Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w"); |
| 982 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | break; |
| 984 | } |
| 985 | default: { |
| 986 | // The PU field is a 2-bit field. |
| 987 | UNREACHABLE(); |
| 988 | break; |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | |
| 994 | void Decoder::DecodeType4(Instr* instr) { |
| 995 | ASSERT(instr->Bit(22) == 0); // Privileged mode currently not supported. |
| 996 | if (instr->HasL()) { |
| 997 | Format(instr, "ldm'cond'pu 'rn'w, 'rlist"); |
| 998 | } else { |
| 999 | Format(instr, "stm'cond'pu 'rn'w, 'rlist"); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | void Decoder::DecodeType5(Instr* instr) { |
| 1005 | Format(instr, "b'l'cond 'target"); |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | void Decoder::DecodeType6(Instr* instr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1010 | DecodeType6CoprocessorIns(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 1014 | int Decoder::DecodeType7(Instr* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1015 | if (instr->Bit(24) == 1) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 1016 | if (instr->SvcField() >= stop) { |
| 1017 | Format(instr, "stop'cond 'svc"); |
| 1018 | // Also print the stop message. Its address is encoded |
| 1019 | // in the following 4 bytes. |
| 1020 | out_buffer_pos_ += |
| 1021 | v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1022 | "\n %p %08x stop message: %s", |
| 1023 | reinterpret_cast<int32_t*>(instr + Instr::kInstrSize), |
| 1024 | *reinterpret_cast<char**>(instr + Instr::kInstrSize), |
| 1025 | *reinterpret_cast<char**>(instr + Instr::kInstrSize)); |
| 1026 | // We have decoded 2 * Instr::kInstrSize bytes. |
| 1027 | return 2 * Instr::kInstrSize; |
| 1028 | } else { |
| 1029 | Format(instr, "svc'cond 'svc"); |
| 1030 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1031 | } else { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1032 | DecodeTypeVFP(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1033 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 1034 | return Instr::kInstrSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1038 | // void Decoder::DecodeTypeVFP(Instr* instr) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1039 | // vmov: Sn = Rt |
| 1040 | // vmov: Rt = Sn |
| 1041 | // vcvt: Dd = Sm |
| 1042 | // vcvt: Sd = Dm |
| 1043 | // Dd = vadd(Dn, Dm) |
| 1044 | // Dd = vsub(Dn, Dm) |
| 1045 | // Dd = vmul(Dn, Dm) |
| 1046 | // Dd = vdiv(Dn, Dm) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1047 | // vcmp(Dd, Dm) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1048 | // vmrs |
| 1049 | // Dd = vsqrt(Dm) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1050 | void Decoder::DecodeTypeVFP(Instr* instr) { |
| 1051 | ASSERT((instr->TypeField() == 7) && (instr->Bit(24) == 0x0) ); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1052 | ASSERT(instr->Bits(11, 9) == 0x5); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1053 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1054 | if (instr->Bit(4) == 0) { |
| 1055 | if (instr->Opc1Field() == 0x7) { |
| 1056 | // Other data processing instructions |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1057 | if ((instr->Opc2Field() == 0x0) && (instr->Opc3Field() == 0x1)) { |
| 1058 | // vmov register to register. |
| 1059 | if (instr->SzField() == 0x1) { |
| 1060 | Format(instr, "vmov.f64'cond 'Dd, 'Dm"); |
| 1061 | } else { |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 1062 | Format(instr, "vmov.f32'cond 'Sd, 'Sm"); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1063 | } |
| 1064 | } else if ((instr->Opc2Field() == 0x7) && (instr->Opc3Field() == 0x3)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1065 | DecodeVCVTBetweenDoubleAndSingle(instr); |
| 1066 | } else if ((instr->Opc2Field() == 0x8) && (instr->Opc3Field() & 0x1)) { |
| 1067 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
| 1068 | } else if (((instr->Opc2Field() >> 1) == 0x6) && |
| 1069 | (instr->Opc3Field() & 0x1)) { |
| 1070 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
| 1071 | } else if (((instr->Opc2Field() == 0x4) || (instr->Opc2Field() == 0x5)) && |
| 1072 | (instr->Opc3Field() & 0x1)) { |
| 1073 | DecodeVCMP(instr); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1074 | } else if (((instr->Opc2Field() == 0x1)) && (instr->Opc3Field() == 0x3)) { |
| 1075 | Format(instr, "vsqrt.f64'cond 'Dd, 'Dm"); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 1076 | } else if (instr->Opc3Field() == 0x0) { |
| 1077 | if (instr->SzField() == 0x1) { |
| 1078 | Format(instr, "vmov.f64'cond 'Dd, 'd"); |
| 1079 | } else { |
| 1080 | Unknown(instr); // Not used by V8. |
| 1081 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1082 | } else { |
| 1083 | Unknown(instr); // Not used by V8. |
| 1084 | } |
| 1085 | } else if (instr->Opc1Field() == 0x3) { |
| 1086 | if (instr->SzField() == 0x1) { |
| 1087 | if (instr->Opc3Field() & 0x1) { |
| 1088 | Format(instr, "vsub.f64'cond 'Dd, 'Dn, 'Dm"); |
| 1089 | } else { |
| 1090 | Format(instr, "vadd.f64'cond 'Dd, 'Dn, 'Dm"); |
| 1091 | } |
| 1092 | } else { |
| 1093 | Unknown(instr); // Not used by V8. |
| 1094 | } |
| 1095 | } else if ((instr->Opc1Field() == 0x2) && !(instr->Opc3Field() & 0x1)) { |
| 1096 | if (instr->SzField() == 0x1) { |
| 1097 | Format(instr, "vmul.f64'cond 'Dd, 'Dn, 'Dm"); |
| 1098 | } else { |
| 1099 | Unknown(instr); // Not used by V8. |
| 1100 | } |
| 1101 | } else if ((instr->Opc1Field() == 0x4) && !(instr->Opc3Field() & 0x1)) { |
| 1102 | if (instr->SzField() == 0x1) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1103 | Format(instr, "vdiv.f64'cond 'Dd, 'Dn, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1104 | } else { |
| 1105 | Unknown(instr); // Not used by V8. |
| 1106 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1107 | } else { |
| 1108 | Unknown(instr); // Not used by V8. |
| 1109 | } |
| 1110 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1111 | if ((instr->VCField() == 0x0) && |
| 1112 | (instr->VAField() == 0x0)) { |
| 1113 | DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr); |
| 1114 | } else if ((instr->VLField() == 0x1) && |
| 1115 | (instr->VCField() == 0x0) && |
| 1116 | (instr->VAField() == 0x7) && |
| 1117 | (instr->Bits(19, 16) == 0x1)) { |
| 1118 | if (instr->Bits(15, 12) == 0xF) |
| 1119 | Format(instr, "vmrs'cond APSR, FPSCR"); |
| 1120 | else |
| 1121 | Unknown(instr); // Not used by V8. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1122 | } else { |
| 1123 | Unknown(instr); // Not used by V8. |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1129 | void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instr* instr) { |
| 1130 | ASSERT((instr->Bit(4) == 1) && (instr->VCField() == 0x0) && |
| 1131 | (instr->VAField() == 0x0)); |
| 1132 | |
| 1133 | bool to_arm_register = (instr->VLField() == 0x1); |
| 1134 | |
| 1135 | if (to_arm_register) { |
| 1136 | Format(instr, "vmov'cond 'rt, 'Sn"); |
| 1137 | } else { |
| 1138 | Format(instr, "vmov'cond 'Sn, 'rt"); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | void Decoder::DecodeVCMP(Instr* instr) { |
| 1144 | ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7)); |
| 1145 | ASSERT(((instr->Opc2Field() == 0x4) || (instr->Opc2Field() == 0x5)) && |
| 1146 | (instr->Opc3Field() & 0x1)); |
| 1147 | |
| 1148 | // Comparison. |
| 1149 | bool dp_operation = (instr->SzField() == 1); |
| 1150 | bool raise_exception_for_qnan = (instr->Bit(7) == 0x1); |
| 1151 | |
| 1152 | if (dp_operation && !raise_exception_for_qnan) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1153 | if (instr->Opc2Field() == 0x4) { |
| 1154 | Format(instr, "vcmp.f64'cond 'Dd, 'Dm"); |
| 1155 | } else if (instr->Opc2Field() == 0x5) { |
| 1156 | Format(instr, "vcmp.f64'cond 'Dd, #0.0"); |
| 1157 | } else { |
| 1158 | Unknown(instr); // invalid |
| 1159 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1160 | } else { |
| 1161 | Unknown(instr); // Not used by V8. |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instr* instr) { |
| 1167 | ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7)); |
| 1168 | ASSERT((instr->Opc2Field() == 0x7) && (instr->Opc3Field() == 0x3)); |
| 1169 | |
| 1170 | bool double_to_single = (instr->SzField() == 1); |
| 1171 | |
| 1172 | if (double_to_single) { |
| 1173 | Format(instr, "vcvt.f32.f64'cond 'Sd, 'Dm"); |
| 1174 | } else { |
| 1175 | Format(instr, "vcvt.f64.f32'cond 'Dd, 'Sm"); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instr* instr) { |
| 1181 | ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7)); |
| 1182 | ASSERT(((instr->Opc2Field() == 0x8) && (instr->Opc3Field() & 0x1)) || |
| 1183 | (((instr->Opc2Field() >> 1) == 0x6) && (instr->Opc3Field() & 0x1))); |
| 1184 | |
| 1185 | bool to_integer = (instr->Bit(18) == 1); |
| 1186 | bool dp_operation = (instr->SzField() == 1); |
| 1187 | if (to_integer) { |
| 1188 | bool unsigned_integer = (instr->Bit(16) == 0); |
| 1189 | |
| 1190 | if (dp_operation) { |
| 1191 | if (unsigned_integer) { |
| 1192 | Format(instr, "vcvt.u32.f64'cond 'Sd, 'Dm"); |
| 1193 | } else { |
| 1194 | Format(instr, "vcvt.s32.f64'cond 'Sd, 'Dm"); |
| 1195 | } |
| 1196 | } else { |
| 1197 | if (unsigned_integer) { |
| 1198 | Format(instr, "vcvt.u32.f32'cond 'Sd, 'Sm"); |
| 1199 | } else { |
| 1200 | Format(instr, "vcvt.s32.f32'cond 'Sd, 'Sm"); |
| 1201 | } |
| 1202 | } |
| 1203 | } else { |
| 1204 | bool unsigned_integer = (instr->Bit(7) == 0); |
| 1205 | |
| 1206 | if (dp_operation) { |
| 1207 | if (unsigned_integer) { |
| 1208 | Format(instr, "vcvt.f64.u32'cond 'Dd, 'Sm"); |
| 1209 | } else { |
| 1210 | Format(instr, "vcvt.f64.s32'cond 'Dd, 'Sm"); |
| 1211 | } |
| 1212 | } else { |
| 1213 | if (unsigned_integer) { |
| 1214 | Format(instr, "vcvt.f32.u32'cond 'Sd, 'Sm"); |
| 1215 | } else { |
| 1216 | Format(instr, "vcvt.f32.s32'cond 'Sd, 'Sm"); |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1223 | // Decode Type 6 coprocessor instructions. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1224 | // Dm = vmov(Rt, Rt2) |
| 1225 | // <Rt, Rt2> = vmov(Dm) |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1226 | // Ddst = MEM(Rbase + 4*offset). |
| 1227 | // MEM(Rbase + 4*offset) = Dsrc. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1228 | void Decoder::DecodeType6CoprocessorIns(Instr* instr) { |
| 1229 | ASSERT((instr->TypeField() == 6)); |
| 1230 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1231 | if (instr->CoprocessorField() == 0xA) { |
| 1232 | switch (instr->OpcodeField()) { |
| 1233 | case 0x8: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1234 | case 0xA: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1235 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1236 | Format(instr, "vldr'cond 'Sd, ['rn - 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1237 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1238 | Format(instr, "vstr'cond 'Sd, ['rn - 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1239 | } |
| 1240 | break; |
| 1241 | case 0xC: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1242 | case 0xE: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1243 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1244 | Format(instr, "vldr'cond 'Sd, ['rn + 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1245 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1246 | Format(instr, "vstr'cond 'Sd, ['rn + 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1247 | } |
| 1248 | break; |
| 1249 | default: |
| 1250 | Unknown(instr); // Not used by V8. |
| 1251 | break; |
| 1252 | } |
| 1253 | } else if (instr->CoprocessorField() == 0xB) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1254 | switch (instr->OpcodeField()) { |
| 1255 | case 0x2: |
| 1256 | // Load and store double to two GP registers |
| 1257 | if (instr->Bits(7, 4) != 0x1) { |
| 1258 | Unknown(instr); // Not used by V8. |
| 1259 | } else if (instr->HasL()) { |
| 1260 | Format(instr, "vmov'cond 'rt, 'rn, 'Dm"); |
| 1261 | } else { |
| 1262 | Format(instr, "vmov'cond 'Dm, 'rt, 'rn"); |
| 1263 | } |
| 1264 | break; |
| 1265 | case 0x8: |
| 1266 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1267 | Format(instr, "vldr'cond 'Dd, ['rn - 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1268 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1269 | Format(instr, "vstr'cond 'Dd, ['rn - 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1270 | } |
| 1271 | break; |
| 1272 | case 0xC: |
| 1273 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1274 | Format(instr, "vldr'cond 'Dd, ['rn + 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1275 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1276 | Format(instr, "vstr'cond 'Dd, ['rn + 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1277 | } |
| 1278 | break; |
| 1279 | default: |
| 1280 | Unknown(instr); // Not used by V8. |
| 1281 | break; |
| 1282 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1283 | } else { |
| 1284 | UNIMPLEMENTED(); // Not used by V8. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1289 | // Disassemble the instruction at *instr_ptr into the output buffer. |
| 1290 | int Decoder::InstructionDecode(byte* instr_ptr) { |
| 1291 | Instr* instr = Instr::At(instr_ptr); |
| 1292 | // Print raw instruction bytes. |
| 1293 | out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1294 | "%08x ", |
| 1295 | instr->InstructionBits()); |
| 1296 | if (instr->ConditionField() == special_condition) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 1297 | UNIMPLEMENTED(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1298 | return Instr::kInstrSize; |
| 1299 | } |
| 1300 | switch (instr->TypeField()) { |
| 1301 | case 0: |
| 1302 | case 1: { |
| 1303 | DecodeType01(instr); |
| 1304 | break; |
| 1305 | } |
| 1306 | case 2: { |
| 1307 | DecodeType2(instr); |
| 1308 | break; |
| 1309 | } |
| 1310 | case 3: { |
| 1311 | DecodeType3(instr); |
| 1312 | break; |
| 1313 | } |
| 1314 | case 4: { |
| 1315 | DecodeType4(instr); |
| 1316 | break; |
| 1317 | } |
| 1318 | case 5: { |
| 1319 | DecodeType5(instr); |
| 1320 | break; |
| 1321 | } |
| 1322 | case 6: { |
| 1323 | DecodeType6(instr); |
| 1324 | break; |
| 1325 | } |
| 1326 | case 7: { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame^] | 1327 | return DecodeType7(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1328 | } |
| 1329 | default: { |
| 1330 | // The type field is 3-bits in the ARM encoding. |
| 1331 | UNREACHABLE(); |
| 1332 | break; |
| 1333 | } |
| 1334 | } |
| 1335 | return Instr::kInstrSize; |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | } } // namespace assembler::arm |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | //------------------------------------------------------------------------------ |
| 1344 | |
| 1345 | namespace disasm { |
| 1346 | |
| 1347 | namespace v8i = v8::internal; |
| 1348 | |
| 1349 | |
| 1350 | const char* NameConverter::NameOfAddress(byte* addr) const { |
| 1351 | static v8::internal::EmbeddedVector<char, 32> tmp_buffer; |
| 1352 | v8::internal::OS::SNPrintF(tmp_buffer, "%p", addr); |
| 1353 | return tmp_buffer.start(); |
| 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | const char* NameConverter::NameOfConstant(byte* addr) const { |
| 1358 | return NameOfAddress(addr); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | const char* NameConverter::NameOfCPURegister(int reg) const { |
| 1363 | return assembler::arm::Registers::Name(reg); |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | const char* NameConverter::NameOfByteCPURegister(int reg) const { |
| 1368 | UNREACHABLE(); // ARM does not have the concept of a byte register |
| 1369 | return "nobytereg"; |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | const char* NameConverter::NameOfXMMRegister(int reg) const { |
| 1374 | UNREACHABLE(); // ARM does not have any XMM registers |
| 1375 | return "noxmmreg"; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | const char* NameConverter::NameInCode(byte* addr) const { |
| 1380 | // The default name converter is called for unknown code. So we will not try |
| 1381 | // to access any memory. |
| 1382 | return ""; |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | //------------------------------------------------------------------------------ |
| 1387 | |
| 1388 | Disassembler::Disassembler(const NameConverter& converter) |
| 1389 | : converter_(converter) {} |
| 1390 | |
| 1391 | |
| 1392 | Disassembler::~Disassembler() {} |
| 1393 | |
| 1394 | |
| 1395 | int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer, |
| 1396 | byte* instruction) { |
| 1397 | assembler::arm::Decoder d(converter_, buffer); |
| 1398 | return d.InstructionDecode(instruction); |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | int Disassembler::ConstantPoolSizeAt(byte* instruction) { |
| 1403 | int instruction_bits = *(reinterpret_cast<int*>(instruction)); |
| 1404 | if ((instruction_bits & 0xfff00000) == 0x03000000) { |
| 1405 | return instruction_bits & 0x0000ffff; |
| 1406 | } else { |
| 1407 | return -1; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) { |
| 1413 | NameConverter converter; |
| 1414 | Disassembler d(converter); |
| 1415 | for (byte* pc = begin; pc < end;) { |
| 1416 | v8::internal::EmbeddedVector<char, 128> buffer; |
| 1417 | buffer[0] = '\0'; |
| 1418 | byte* prev_pc = pc; |
| 1419 | pc += d.InstructionDecode(buffer, pc); |
| 1420 | fprintf(f, "%p %08x %s\n", |
| 1421 | prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | |
| 1426 | } // namespace disasm |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1427 | |
| 1428 | #endif // V8_TARGET_ARCH_ARM |