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