Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | // A Disassembler object is used to disassemble a block of code instruction by |
| 6 | // instruction. The default implementation of the NameConverter object can be |
| 7 | // overriden to modify register names or to do symbol lookup on addresses. |
| 8 | // |
| 9 | // The example below will disassemble a block of code and print it to stdout. |
| 10 | // |
| 11 | // NameConverter converter; |
| 12 | // Disassembler d(converter); |
| 13 | // for (byte* pc = begin; pc < end;) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 14 | // v8::internal::EmbeddedVector<char, 256> buffer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 15 | // byte* prev_pc = pc; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 16 | // pc += d.InstructionDecode(buffer, pc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 17 | // printf("%p %08x %s\n", |
| 18 | // prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer); |
| 19 | // } |
| 20 | // |
| 21 | // The Disassembler class also has a convenience method to disassemble a block |
| 22 | // of code into a FILE*, meaning that the above functionality could also be |
| 23 | // achieved by just calling Disassembler::Disassemble(stdout, begin, end); |
| 24 | |
| 25 | |
| 26 | #include <assert.h> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | #include <string.h> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | #if V8_TARGET_ARCH_ARM |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 32 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 33 | #include "src/arm/constants-arm.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | #include "src/base/bits.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | #include "src/base/platform/platform.h" |
| 36 | #include "src/disasm.h" |
| 37 | #include "src/macro-assembler.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | |
| 39 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 43 | const auto GetRegConfig = RegisterConfiguration::Crankshaft; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | |
| 45 | //------------------------------------------------------------------------------ |
| 46 | |
| 47 | // Decoder decodes and disassembles instructions into an output buffer. |
| 48 | // It uses the converter to convert register names and call destinations into |
| 49 | // more informative description. |
| 50 | class Decoder { |
| 51 | public: |
| 52 | Decoder(const disasm::NameConverter& converter, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 53 | Vector<char> out_buffer) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | : converter_(converter), |
| 55 | out_buffer_(out_buffer), |
| 56 | out_buffer_pos_(0) { |
| 57 | out_buffer_[out_buffer_pos_] = '\0'; |
| 58 | } |
| 59 | |
| 60 | ~Decoder() {} |
| 61 | |
| 62 | // Writes one disassembled instruction into 'buffer' (0-terminated). |
| 63 | // Returns the length of the disassembled machine instruction in bytes. |
| 64 | int InstructionDecode(byte* instruction); |
| 65 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 66 | static bool IsConstantPoolAt(byte* instr_ptr); |
| 67 | static int ConstantPoolSizeAt(byte* instr_ptr); |
| 68 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 69 | private: |
| 70 | // Bottleneck functions to print into the out_buffer. |
| 71 | void PrintChar(const char ch); |
| 72 | void Print(const char* str); |
| 73 | |
| 74 | // Printing of common values. |
| 75 | void PrintRegister(int reg); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 76 | void PrintSRegister(int reg); |
| 77 | void PrintDRegister(int reg); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 78 | int FormatVFPRegister(Instruction* instr, const char* format); |
| 79 | void PrintMovwMovt(Instruction* instr); |
| 80 | int FormatVFPinstruction(Instruction* instr, const char* format); |
| 81 | void PrintCondition(Instruction* instr); |
| 82 | void PrintShiftRm(Instruction* instr); |
| 83 | void PrintShiftImm(Instruction* instr); |
| 84 | void PrintShiftSat(Instruction* instr); |
| 85 | void PrintPU(Instruction* instr); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 86 | void PrintSoftwareInterrupt(SoftwareInterruptCodes svc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | |
| 88 | // Handle formatting of instructions and their options. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 89 | int FormatRegister(Instruction* instr, const char* option); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | void FormatNeonList(int Vd, int type); |
| 91 | void FormatNeonMemory(int Rn, int align, int Rm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 92 | int FormatOption(Instruction* instr, const char* option); |
| 93 | void Format(Instruction* instr, const char* format); |
| 94 | void Unknown(Instruction* instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 95 | |
| 96 | // Each of these functions decodes one particular instruction type, a 3-bit |
| 97 | // field in the instruction encoding. |
| 98 | // Types 0 and 1 are combined as they are largely the same except for the way |
| 99 | // they interpret the shifter operand. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 100 | void DecodeType01(Instruction* instr); |
| 101 | void DecodeType2(Instruction* instr); |
| 102 | void DecodeType3(Instruction* instr); |
| 103 | void DecodeType4(Instruction* instr); |
| 104 | void DecodeType5(Instruction* instr); |
| 105 | void DecodeType6(Instruction* instr); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 106 | // Type 7 includes special Debugger instructions. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 107 | int DecodeType7(Instruction* instr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 108 | // For VFP support. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 109 | void DecodeTypeVFP(Instruction* instr); |
| 110 | void DecodeType6CoprocessorIns(Instruction* instr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 111 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | void DecodeSpecialCondition(Instruction* instr); |
| 113 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 114 | void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr); |
| 115 | void DecodeVCMP(Instruction* instr); |
| 116 | void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr); |
| 117 | void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | |
| 119 | const disasm::NameConverter& converter_; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 120 | Vector<char> out_buffer_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 121 | int out_buffer_pos_; |
| 122 | |
| 123 | DISALLOW_COPY_AND_ASSIGN(Decoder); |
| 124 | }; |
| 125 | |
| 126 | |
| 127 | // Support for assertions in the Decoder formatting functions. |
| 128 | #define STRING_STARTS_WITH(string, compare_string) \ |
| 129 | (strncmp(string, compare_string, strlen(compare_string)) == 0) |
| 130 | |
| 131 | |
| 132 | // Append the ch to the output buffer. |
| 133 | void Decoder::PrintChar(const char ch) { |
| 134 | out_buffer_[out_buffer_pos_++] = ch; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | // Append the str to the output buffer. |
| 139 | void Decoder::Print(const char* str) { |
| 140 | char cur = *str++; |
| 141 | while (cur != '\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 142 | PrintChar(cur); |
| 143 | cur = *str++; |
| 144 | } |
| 145 | out_buffer_[out_buffer_pos_] = 0; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | // These condition names are defined in a way to match the native disassembler |
| 150 | // formatting. See for example the command "objdump -d <binary file>". |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 151 | static const char* const cond_names[kNumberOfConditions] = { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 152 | "eq", "ne", "cs" , "cc" , "mi" , "pl" , "vs" , "vc" , |
| 153 | "hi", "ls", "ge", "lt", "gt", "le", "", "invalid", |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | // Print the condition guarding the instruction. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 158 | void Decoder::PrintCondition(Instruction* instr) { |
| 159 | Print(cond_names[instr->ConditionValue()]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | // Print the register name according to the active name converter. |
| 164 | void Decoder::PrintRegister(int reg) { |
| 165 | Print(converter_.NameOfCPURegister(reg)); |
| 166 | } |
| 167 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 168 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 169 | // Print the VFP S register name according to the active name converter. |
| 170 | void Decoder::PrintSRegister(int reg) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 171 | Print(VFPRegisters::Name(reg, false)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | |
| 175 | // Print the VFP D register name according to the active name converter. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 176 | void Decoder::PrintDRegister(int reg) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 177 | Print(VFPRegisters::Name(reg, true)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 180 | |
| 181 | // These shift names are defined in a way to match the native disassembler |
| 182 | // formatting. See for example the command "objdump -d <binary file>". |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 183 | static const char* const shift_names[kNumberOfShifts] = { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | "lsl", "lsr", "asr", "ror" |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | // Print the register shift operands for the instruction. Generally used for |
| 189 | // data processing instructions. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 190 | void Decoder::PrintShiftRm(Instruction* instr) { |
| 191 | ShiftOp shift = instr->ShiftField(); |
| 192 | int shift_index = instr->ShiftValue(); |
| 193 | int shift_amount = instr->ShiftAmountValue(); |
| 194 | int rm = instr->RmValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 195 | |
| 196 | PrintRegister(rm); |
| 197 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 198 | if ((instr->RegShiftValue() == 0) && (shift == LSL) && (shift_amount == 0)) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | // Special case for using rm only. |
| 200 | return; |
| 201 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 202 | if (instr->RegShiftValue() == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 203 | // by immediate |
| 204 | if ((shift == ROR) && (shift_amount == 0)) { |
| 205 | Print(", RRX"); |
| 206 | return; |
| 207 | } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) { |
| 208 | shift_amount = 32; |
| 209 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 211 | ", %s #%d", |
| 212 | shift_names[shift_index], |
| 213 | shift_amount); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | } else { |
| 215 | // by register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 216 | int rs = instr->RsValue(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 217 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 218 | ", %s ", shift_names[shift_index]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | PrintRegister(rs); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | |
| 224 | // Print the immediate operand for the instruction. Generally used for data |
| 225 | // processing instructions. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 226 | void Decoder::PrintShiftImm(Instruction* instr) { |
| 227 | int rotate = instr->RotateValue() * 2; |
| 228 | int immed8 = instr->Immed8Value(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 229 | int imm = base::bits::RotateRight32(immed8, rotate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "#%d", imm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 234 | // Print the optional shift and immediate used by saturating instructions. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 235 | void Decoder::PrintShiftSat(Instruction* instr) { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 236 | int shift = instr->Bits(11, 7); |
| 237 | if (shift > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 239 | ", %s #%d", |
| 240 | shift_names[instr->Bit(6) * 2], |
| 241 | instr->Bits(11, 7)); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 246 | // Print PU formatting to reduce complexity of FormatOption. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 247 | void Decoder::PrintPU(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 249 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | Print("da"); |
| 251 | break; |
| 252 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 253 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 254 | Print("ia"); |
| 255 | break; |
| 256 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 257 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | Print("db"); |
| 259 | break; |
| 260 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 261 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | Print("ib"); |
| 263 | break; |
| 264 | } |
| 265 | default: { |
| 266 | UNREACHABLE(); |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | |
| 273 | // Print SoftwareInterrupt codes. Factoring this out reduces the complexity of |
| 274 | // the FormatOption method. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 275 | void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) { |
| 276 | switch (svc) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 277 | case kCallRtRedirected: |
| 278 | Print("call rt redirected"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | return; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 280 | case kBreakpoint: |
| 281 | Print("breakpoint"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 282 | return; |
| 283 | default: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 284 | if (svc >= kStopCode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 285 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 286 | "%d - 0x%x", |
| 287 | svc & kStopCodeMask, |
| 288 | svc & kStopCodeMask); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 289 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 290 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 291 | "%d", |
| 292 | svc); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 293 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 294 | return; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | |
| 299 | // Handle all register based formatting in this function to reduce the |
| 300 | // complexity of FormatOption. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 301 | int Decoder::FormatRegister(Instruction* instr, const char* format) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | DCHECK(format[0] == 'r'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 303 | if (format[1] == 'n') { // 'rn: Rn register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 304 | int reg = instr->RnValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | PrintRegister(reg); |
| 306 | return 2; |
| 307 | } else if (format[1] == 'd') { // 'rd: Rd register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 308 | int reg = instr->RdValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 309 | PrintRegister(reg); |
| 310 | return 2; |
| 311 | } else if (format[1] == 's') { // 'rs: Rs register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 312 | int reg = instr->RsValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | PrintRegister(reg); |
| 314 | return 2; |
| 315 | } else if (format[1] == 'm') { // 'rm: Rm register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 316 | int reg = instr->RmValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | PrintRegister(reg); |
| 318 | return 2; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 319 | } else if (format[1] == 't') { // 'rt: Rt register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 320 | int reg = instr->RtValue(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 321 | PrintRegister(reg); |
| 322 | return 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 323 | } else if (format[1] == 'l') { |
| 324 | // 'rlist: register list for load and store multiple instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 325 | DCHECK(STRING_STARTS_WITH(format, "rlist")); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 326 | int rlist = instr->RlistValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | int reg = 0; |
| 328 | Print("{"); |
| 329 | // Print register list in ascending order, by scanning the bit mask. |
| 330 | while (rlist != 0) { |
| 331 | if ((rlist & 1) != 0) { |
| 332 | PrintRegister(reg); |
| 333 | if ((rlist >> 1) != 0) { |
| 334 | Print(", "); |
| 335 | } |
| 336 | } |
| 337 | reg++; |
| 338 | rlist >>= 1; |
| 339 | } |
| 340 | Print("}"); |
| 341 | return 5; |
| 342 | } |
| 343 | UNREACHABLE(); |
| 344 | return -1; |
| 345 | } |
| 346 | |
| 347 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 348 | // Handle all VFP register based formatting in this function to reduce the |
| 349 | // complexity of FormatOption. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 350 | int Decoder::FormatVFPRegister(Instruction* instr, const char* format) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | DCHECK((format[0] == 'S') || (format[0] == 'D')); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 352 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 353 | VFPRegPrecision precision = |
| 354 | format[0] == 'D' ? kDoublePrecision : kSinglePrecision; |
| 355 | |
| 356 | int retval = 2; |
| 357 | int reg = -1; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 358 | if (format[1] == 'n') { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 359 | reg = instr->VFPNRegValue(precision); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 360 | } else if (format[1] == 'm') { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 361 | reg = instr->VFPMRegValue(precision); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 362 | } else if (format[1] == 'd') { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | if ((instr->TypeValue() == 7) && |
| 364 | (instr->Bit(24) == 0x0) && |
| 365 | (instr->Bits(11, 9) == 0x5) && |
| 366 | (instr->Bit(4) == 0x1)) { |
| 367 | // vmov.32 has Vd in a different place. |
| 368 | reg = instr->Bits(19, 16) | (instr->Bit(7) << 4); |
| 369 | } else { |
| 370 | reg = instr->VFPDRegValue(precision); |
| 371 | } |
| 372 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 373 | if (format[2] == '+') { |
| 374 | int immed8 = instr->Immed8Value(); |
| 375 | if (format[0] == 'S') reg += immed8 - 1; |
| 376 | if (format[0] == 'D') reg += (immed8 / 2 - 1); |
| 377 | } |
| 378 | if (format[2] == '+') retval = 3; |
| 379 | } else { |
| 380 | UNREACHABLE(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 383 | if (precision == kSinglePrecision) { |
| 384 | PrintSRegister(reg); |
| 385 | } else { |
| 386 | PrintDRegister(reg); |
| 387 | } |
| 388 | |
| 389 | return retval; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 393 | int Decoder::FormatVFPinstruction(Instruction* instr, const char* format) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 394 | Print(format); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 399 | void Decoder::FormatNeonList(int Vd, int type) { |
| 400 | if (type == nlt_1) { |
| 401 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 402 | "{d%d}", Vd); |
| 403 | } else if (type == nlt_2) { |
| 404 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 405 | "{d%d, d%d}", Vd, Vd + 1); |
| 406 | } else if (type == nlt_3) { |
| 407 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 408 | "{d%d, d%d, d%d}", Vd, Vd + 1, Vd + 2); |
| 409 | } else if (type == nlt_4) { |
| 410 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 411 | "{d%d, d%d, d%d, d%d}", Vd, Vd + 1, Vd + 2, Vd + 3); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| 416 | void Decoder::FormatNeonMemory(int Rn, int align, int Rm) { |
| 417 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 418 | "[r%d", Rn); |
| 419 | if (align != 0) { |
| 420 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 421 | ":%d", (1 << align) << 6); |
| 422 | } |
| 423 | if (Rm == 15) { |
| 424 | Print("]"); |
| 425 | } else if (Rm == 13) { |
| 426 | Print("]!"); |
| 427 | } else { |
| 428 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 429 | "], r%d", Rm); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 434 | // Print the movw or movt instruction. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 435 | void Decoder::PrintMovwMovt(Instruction* instr) { |
| 436 | int imm = instr->ImmedMovwMovtValue(); |
| 437 | int rd = instr->RdValue(); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 438 | PrintRegister(rd); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 439 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, ", #%d", imm); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | // FormatOption takes a formatting string and interprets it based on |
| 444 | // the current instructions. The format string points to the first |
| 445 | // character of the option string (the option escape has already been |
| 446 | // consumed by the caller.) FormatOption returns the number of |
| 447 | // characters that were consumed from the formatting string. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 448 | int Decoder::FormatOption(Instruction* instr, const char* format) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 449 | switch (format[0]) { |
| 450 | case 'a': { // 'a: accumulate multiplies |
| 451 | if (instr->Bit(21) == 0) { |
| 452 | Print("ul"); |
| 453 | } else { |
| 454 | Print("la"); |
| 455 | } |
| 456 | return 1; |
| 457 | } |
| 458 | case 'b': { // 'b: byte loads or stores |
| 459 | if (instr->HasB()) { |
| 460 | Print("b"); |
| 461 | } |
| 462 | return 1; |
| 463 | } |
| 464 | case 'c': { // 'cond: conditional execution |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 465 | DCHECK(STRING_STARTS_WITH(format, "cond")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | PrintCondition(instr); |
| 467 | return 4; |
| 468 | } |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 469 | case 'd': { // 'd: vmov double immediate. |
| 470 | double d = instr->DoubleImmedVmov(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 471 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "#%g", d); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 472 | return 1; |
| 473 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 474 | case 'f': { // 'f: bitfield instructions - v7 and above. |
| 475 | uint32_t lsbit = instr->Bits(11, 7); |
| 476 | uint32_t width = instr->Bits(20, 16) + 1; |
| 477 | if (instr->Bit(21) == 0) { |
| 478 | // BFC/BFI: |
| 479 | // Bits 20-16 represent most-significant bit. Covert to width. |
| 480 | width -= lsbit; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 481 | DCHECK(width > 0); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 482 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | DCHECK((width + lsbit) <= 32); |
| 484 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 485 | "#%d, #%d", lsbit, width); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 486 | return 1; |
| 487 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | case 'h': { // 'h: halfword operation for extra loads and stores |
| 489 | if (instr->HasH()) { |
| 490 | Print("h"); |
| 491 | } else { |
| 492 | Print("b"); |
| 493 | } |
| 494 | return 1; |
| 495 | } |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 496 | case 'i': { // 'i: immediate value from adjacent bits. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 497 | // Expects tokens in the form imm%02d@%02d, i.e. imm05@07, imm10@16 |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 498 | int width = (format[3] - '0') * 10 + (format[4] - '0'); |
| 499 | int lsb = (format[6] - '0') * 10 + (format[7] - '0'); |
| 500 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 501 | DCHECK((width >= 1) && (width <= 32)); |
| 502 | DCHECK((lsb >= 0) && (lsb <= 31)); |
| 503 | DCHECK((width + lsb) <= 32); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 504 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 505 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 506 | "%d", |
| 507 | instr->Bits(width + lsb - 1, lsb)); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 508 | return 8; |
| 509 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | case 'l': { // 'l: branch and link |
| 511 | if (instr->HasLink()) { |
| 512 | Print("l"); |
| 513 | } |
| 514 | return 1; |
| 515 | } |
| 516 | case 'm': { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 517 | if (format[1] == 'w') { |
| 518 | // 'mw: movt/movw instructions. |
| 519 | PrintMovwMovt(instr); |
| 520 | return 2; |
| 521 | } |
| 522 | if (format[1] == 'e') { // 'memop: load/store instructions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 523 | DCHECK(STRING_STARTS_WITH(format, "memop")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | if (instr->HasL()) { |
| 525 | Print("ldr"); |
| 526 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 527 | if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0) && |
| 528 | (instr->Bits(7, 6) == 3) && (instr->Bit(4) == 1)) { |
| 529 | if (instr->Bit(5) == 1) { |
| 530 | Print("strd"); |
| 531 | } else { |
| 532 | Print("ldrd"); |
| 533 | } |
| 534 | return 5; |
| 535 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | Print("str"); |
| 537 | } |
| 538 | return 5; |
| 539 | } |
| 540 | // 'msg: for simulator break instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | DCHECK(STRING_STARTS_WITH(format, "msg")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | byte* str = |
| 543 | reinterpret_cast<byte*>(instr->InstructionBits() & 0x0fffffff); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 545 | "%s", converter_.NameInCode(str)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 546 | return 3; |
| 547 | } |
| 548 | case 'o': { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 549 | if ((format[3] == '1') && (format[4] == '2')) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | // 'off12: 12-bit offset for load and store instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 551 | DCHECK(STRING_STARTS_WITH(format, "off12")); |
| 552 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 553 | "%d", instr->Offset12Value()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | return 5; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 555 | } else if (format[3] == '0') { |
| 556 | // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 557 | DCHECK(STRING_STARTS_WITH(format, "off0to3and8to19")); |
| 558 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 559 | "%d", |
| 560 | (instr->Bits(19, 8) << 4) + |
| 561 | instr->Bits(3, 0)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 562 | return 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 563 | } |
| 564 | // 'off8: 8-bit offset for extra load and store instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 565 | DCHECK(STRING_STARTS_WITH(format, "off8")); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 566 | int offs8 = (instr->ImmedHValue() << 4) | instr->ImmedLValue(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 567 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", offs8); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | return 4; |
| 569 | } |
| 570 | case 'p': { // 'pu: P and U bits for load and store instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 571 | DCHECK(STRING_STARTS_WITH(format, "pu")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | PrintPU(instr); |
| 573 | return 2; |
| 574 | } |
| 575 | case 'r': { |
| 576 | return FormatRegister(instr, format); |
| 577 | } |
| 578 | case 's': { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 579 | if (format[1] == 'h') { // 'shift_op or 'shift_rm or 'shift_sat. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | if (format[6] == 'o') { // 'shift_op |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 581 | DCHECK(STRING_STARTS_WITH(format, "shift_op")); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 582 | if (instr->TypeValue() == 0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 583 | PrintShiftRm(instr); |
| 584 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 585 | DCHECK(instr->TypeValue() == 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | PrintShiftImm(instr); |
| 587 | } |
| 588 | return 8; |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 589 | } else if (format[6] == 's') { // 'shift_sat. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 590 | DCHECK(STRING_STARTS_WITH(format, "shift_sat")); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 591 | PrintShiftSat(instr); |
| 592 | return 9; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | } else { // 'shift_rm |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 594 | DCHECK(STRING_STARTS_WITH(format, "shift_rm")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | PrintShiftRm(instr); |
| 596 | return 8; |
| 597 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 598 | } else if (format[1] == 'v') { // 'svc |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | DCHECK(STRING_STARTS_WITH(format, "svc")); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 600 | PrintSoftwareInterrupt(instr->SvcValue()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 601 | return 3; |
| 602 | } else if (format[1] == 'i') { // 'sign: signed extra loads and stores |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 603 | DCHECK(STRING_STARTS_WITH(format, "sign")); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | if (instr->HasSign()) { |
| 605 | Print("s"); |
| 606 | } |
| 607 | return 4; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 608 | } else if (format[1] == 'p') { |
| 609 | if (format[8] == '_') { // 'spec_reg_fields |
| 610 | DCHECK(STRING_STARTS_WITH(format, "spec_reg_fields")); |
| 611 | Print("_"); |
| 612 | int mask = instr->Bits(19, 16); |
| 613 | if (mask == 0) Print("(none)"); |
| 614 | if ((mask & 0x8) != 0) Print("f"); |
| 615 | if ((mask & 0x4) != 0) Print("s"); |
| 616 | if ((mask & 0x2) != 0) Print("x"); |
| 617 | if ((mask & 0x1) != 0) Print("c"); |
| 618 | return 15; |
| 619 | } else { // 'spec_reg |
| 620 | DCHECK(STRING_STARTS_WITH(format, "spec_reg")); |
| 621 | if (instr->Bit(22) == 0) { |
| 622 | Print("CPSR"); |
| 623 | } else { |
| 624 | Print("SPSR"); |
| 625 | } |
| 626 | return 8; |
| 627 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | } |
| 629 | // 's: S field of data processing instructions |
| 630 | if (instr->HasS()) { |
| 631 | Print("s"); |
| 632 | } |
| 633 | return 1; |
| 634 | } |
| 635 | case 't': { // 'target: target of branch instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 636 | DCHECK(STRING_STARTS_WITH(format, "target")); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 637 | int off = (instr->SImmed24Value() << 2) + 8; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 638 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 639 | "%+d -> %s", |
| 640 | off, |
| 641 | converter_.NameOfAddress( |
| 642 | reinterpret_cast<byte*>(instr) + off)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | return 6; |
| 644 | } |
| 645 | case 'u': { // 'u: signed or unsigned multiplies |
| 646 | // The manual gets the meaning of bit 22 backwards in the multiply |
| 647 | // instruction overview on page A3.16.2. The instructions that |
| 648 | // exist in u and s variants are the following: |
| 649 | // smull A4.1.87 |
| 650 | // umull A4.1.129 |
| 651 | // umlal A4.1.128 |
| 652 | // smlal A4.1.76 |
| 653 | // For these 0 means u and 1 means s. As can be seen on their individual |
| 654 | // pages. The other 18 mul instructions have the bit set or unset in |
| 655 | // arbitrary ways that are unrelated to the signedness of the instruction. |
| 656 | // None of these 18 instructions exist in both a 'u' and an 's' variant. |
| 657 | |
| 658 | if (instr->Bit(22) == 0) { |
| 659 | Print("u"); |
| 660 | } else { |
| 661 | Print("s"); |
| 662 | } |
| 663 | return 1; |
| 664 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 665 | case 'v': { |
| 666 | return FormatVFPinstruction(instr, format); |
| 667 | } |
| 668 | case 'S': |
| 669 | case 'D': { |
| 670 | return FormatVFPRegister(instr, format); |
| 671 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 672 | case 'w': { // 'w: W field of load and store instructions |
| 673 | if (instr->HasW()) { |
| 674 | Print("!"); |
| 675 | } |
| 676 | return 1; |
| 677 | } |
| 678 | default: { |
| 679 | UNREACHABLE(); |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | UNREACHABLE(); |
| 684 | return -1; |
| 685 | } |
| 686 | |
| 687 | |
| 688 | // Format takes a formatting string for a whole instruction and prints it into |
| 689 | // the output buffer. All escaped options are handed to FormatOption to be |
| 690 | // parsed further. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 691 | void Decoder::Format(Instruction* instr, const char* format) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 692 | char cur = *format++; |
| 693 | while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 694 | if (cur == '\'') { // Single quote is used as the formatting escape. |
| 695 | format += FormatOption(instr, format); |
| 696 | } else { |
| 697 | out_buffer_[out_buffer_pos_++] = cur; |
| 698 | } |
| 699 | cur = *format++; |
| 700 | } |
| 701 | out_buffer_[out_buffer_pos_] = '\0'; |
| 702 | } |
| 703 | |
| 704 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 705 | // The disassembler may end up decoding data inlined in the code. We do not want |
| 706 | // it to crash if the data does not ressemble any known instruction. |
| 707 | #define VERIFY(condition) \ |
| 708 | if(!(condition)) { \ |
| 709 | Unknown(instr); \ |
| 710 | return; \ |
| 711 | } |
| 712 | |
| 713 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | // For currently unimplemented decodings the disassembler calls Unknown(instr) |
| 715 | // which will just print "unknown" of the instruction bits. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 716 | void Decoder::Unknown(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 717 | Format(instr, "unknown"); |
| 718 | } |
| 719 | |
| 720 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 721 | void Decoder::DecodeType01(Instruction* instr) { |
| 722 | int type = instr->TypeValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 723 | if ((type == 0) && instr->IsSpecialType0()) { |
| 724 | // multiply instruction or extra loads and stores |
| 725 | if (instr->Bits(7, 4) == 9) { |
| 726 | if (instr->Bit(24) == 0) { |
| 727 | // multiply instructions |
| 728 | if (instr->Bit(23) == 0) { |
| 729 | if (instr->Bit(21) == 0) { |
| 730 | // The MUL instruction description (A 4.1.33) refers to Rd as being |
| 731 | // the destination for the operation, but it confusingly uses the |
| 732 | // Rn field to encode it. |
| 733 | Format(instr, "mul'cond's 'rn, 'rm, 'rs"); |
| 734 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 735 | if (instr->Bit(22) == 0) { |
| 736 | // The MLA instruction description (A 4.1.28) refers to the order |
| 737 | // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the |
| 738 | // Rn field to encode the Rd register and the Rd field to encode |
| 739 | // the Rn register. |
| 740 | Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd"); |
| 741 | } else { |
| 742 | // The MLS instruction description (A 4.1.29) refers to the order |
| 743 | // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the |
| 744 | // Rn field to encode the Rd register and the Rd field to encode |
| 745 | // the Rn register. |
| 746 | Format(instr, "mls'cond's 'rn, 'rm, 'rs, 'rd"); |
| 747 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 748 | } |
| 749 | } else { |
| 750 | // The signed/long multiply instructions use the terms RdHi and RdLo |
| 751 | // when referring to the target registers. They are mapped to the Rn |
| 752 | // and Rd fields as follows: |
| 753 | // RdLo == Rd field |
| 754 | // RdHi == Rn field |
| 755 | // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs> |
| 756 | Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs"); |
| 757 | } |
| 758 | } else { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 759 | if (instr->Bits(24, 23) == 3) { |
| 760 | if (instr->Bit(20) == 1) { |
| 761 | // ldrex |
| 762 | switch (instr->Bits(22, 21)) { |
| 763 | case 0: |
| 764 | Format(instr, "ldrex'cond 'rt, ['rn]"); |
| 765 | break; |
| 766 | case 2: |
| 767 | Format(instr, "ldrexb'cond 'rt, ['rn]"); |
| 768 | break; |
| 769 | case 3: |
| 770 | Format(instr, "ldrexh'cond 'rt, ['rn]"); |
| 771 | break; |
| 772 | default: |
| 773 | UNREACHABLE(); |
| 774 | break; |
| 775 | } |
| 776 | } else { |
| 777 | // strex |
| 778 | // The instruction is documented as strex rd, rt, [rn], but the |
| 779 | // "rt" register is using the rm bits. |
| 780 | switch (instr->Bits(22, 21)) { |
| 781 | case 0: |
| 782 | Format(instr, "strex'cond 'rd, 'rm, ['rn]"); |
| 783 | break; |
| 784 | case 2: |
| 785 | Format(instr, "strexb'cond 'rd, 'rm, ['rn]"); |
| 786 | break; |
| 787 | case 3: |
| 788 | Format(instr, "strexh'cond 'rd, 'rm, ['rn]"); |
| 789 | break; |
| 790 | default: |
| 791 | UNREACHABLE(); |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } else { |
| 796 | Unknown(instr); // not used by V8 |
| 797 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 798 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 799 | } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xd) == 0xd)) { |
| 800 | // ldrd, strd |
| 801 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 802 | case da_x: { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 803 | if (instr->Bit(22) == 0) { |
| 804 | Format(instr, "'memop'cond's 'rd, ['rn], -'rm"); |
| 805 | } else { |
| 806 | Format(instr, "'memop'cond's 'rd, ['rn], #-'off8"); |
| 807 | } |
| 808 | break; |
| 809 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 810 | case ia_x: { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 811 | if (instr->Bit(22) == 0) { |
| 812 | Format(instr, "'memop'cond's 'rd, ['rn], +'rm"); |
| 813 | } else { |
| 814 | Format(instr, "'memop'cond's 'rd, ['rn], #+'off8"); |
| 815 | } |
| 816 | break; |
| 817 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 818 | case db_x: { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 819 | if (instr->Bit(22) == 0) { |
| 820 | Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w"); |
| 821 | } else { |
| 822 | Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w"); |
| 823 | } |
| 824 | break; |
| 825 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 826 | case ib_x: { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 827 | if (instr->Bit(22) == 0) { |
| 828 | Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w"); |
| 829 | } else { |
| 830 | Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w"); |
| 831 | } |
| 832 | break; |
| 833 | } |
| 834 | default: { |
| 835 | // The PU field is a 2-bit field. |
| 836 | UNREACHABLE(); |
| 837 | break; |
| 838 | } |
| 839 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 840 | } else { |
| 841 | // extra load/store instructions |
| 842 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 843 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | if (instr->Bit(22) == 0) { |
| 845 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm"); |
| 846 | } else { |
| 847 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8"); |
| 848 | } |
| 849 | break; |
| 850 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 851 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 852 | if (instr->Bit(22) == 0) { |
| 853 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm"); |
| 854 | } else { |
| 855 | Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8"); |
| 856 | } |
| 857 | break; |
| 858 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 859 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 860 | if (instr->Bit(22) == 0) { |
| 861 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w"); |
| 862 | } else { |
| 863 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w"); |
| 864 | } |
| 865 | break; |
| 866 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 867 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 868 | if (instr->Bit(22) == 0) { |
| 869 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w"); |
| 870 | } else { |
| 871 | Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w"); |
| 872 | } |
| 873 | break; |
| 874 | } |
| 875 | default: { |
| 876 | // The PU field is a 2-bit field. |
| 877 | UNREACHABLE(); |
| 878 | break; |
| 879 | } |
| 880 | } |
| 881 | return; |
| 882 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 883 | } else if ((type == 0) && instr->IsMiscType0()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 884 | if ((instr->Bits(27, 23) == 2) && (instr->Bits(21, 20) == 2) && |
| 885 | (instr->Bits(15, 4) == 0xf00)) { |
| 886 | Format(instr, "msr'cond 'spec_reg'spec_reg_fields, 'rm"); |
| 887 | } else if ((instr->Bits(27, 23) == 2) && (instr->Bits(21, 20) == 0) && |
| 888 | (instr->Bits(11, 0) == 0)) { |
| 889 | Format(instr, "mrs'cond 'rd, 'spec_reg"); |
| 890 | } else if (instr->Bits(22, 21) == 1) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 891 | switch (instr->BitField(7, 4)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 892 | case BX: |
| 893 | Format(instr, "bx'cond 'rm"); |
| 894 | break; |
| 895 | case BLX: |
| 896 | Format(instr, "blx'cond 'rm"); |
| 897 | break; |
| 898 | case BKPT: |
| 899 | Format(instr, "bkpt 'off0to3and8to19"); |
| 900 | break; |
| 901 | default: |
| 902 | Unknown(instr); // not used by V8 |
| 903 | break; |
| 904 | } |
| 905 | } else if (instr->Bits(22, 21) == 3) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 906 | switch (instr->BitField(7, 4)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 907 | case CLZ: |
| 908 | Format(instr, "clz'cond 'rd, 'rm"); |
| 909 | break; |
| 910 | default: |
| 911 | Unknown(instr); // not used by V8 |
| 912 | break; |
| 913 | } |
| 914 | } else { |
| 915 | Unknown(instr); // not used by V8 |
| 916 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | } else if ((type == 1) && instr->IsNopType1()) { |
| 918 | Format(instr, "nop'cond"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 919 | } else { |
| 920 | switch (instr->OpcodeField()) { |
| 921 | case AND: { |
| 922 | Format(instr, "and'cond's 'rd, 'rn, 'shift_op"); |
| 923 | break; |
| 924 | } |
| 925 | case EOR: { |
| 926 | Format(instr, "eor'cond's 'rd, 'rn, 'shift_op"); |
| 927 | break; |
| 928 | } |
| 929 | case SUB: { |
| 930 | Format(instr, "sub'cond's 'rd, 'rn, 'shift_op"); |
| 931 | break; |
| 932 | } |
| 933 | case RSB: { |
| 934 | Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op"); |
| 935 | break; |
| 936 | } |
| 937 | case ADD: { |
| 938 | Format(instr, "add'cond's 'rd, 'rn, 'shift_op"); |
| 939 | break; |
| 940 | } |
| 941 | case ADC: { |
| 942 | Format(instr, "adc'cond's 'rd, 'rn, 'shift_op"); |
| 943 | break; |
| 944 | } |
| 945 | case SBC: { |
| 946 | Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op"); |
| 947 | break; |
| 948 | } |
| 949 | case RSC: { |
| 950 | Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op"); |
| 951 | break; |
| 952 | } |
| 953 | case TST: { |
| 954 | if (instr->HasS()) { |
| 955 | Format(instr, "tst'cond 'rn, 'shift_op"); |
| 956 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 957 | Format(instr, "movw'cond 'mw"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 958 | } |
| 959 | break; |
| 960 | } |
| 961 | case TEQ: { |
| 962 | if (instr->HasS()) { |
| 963 | Format(instr, "teq'cond 'rn, 'shift_op"); |
| 964 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 965 | // Other instructions matching this pattern are handled in the |
| 966 | // miscellaneous instructions part above. |
| 967 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 968 | } |
| 969 | break; |
| 970 | } |
| 971 | case CMP: { |
| 972 | if (instr->HasS()) { |
| 973 | Format(instr, "cmp'cond 'rn, 'shift_op"); |
| 974 | } else { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 975 | Format(instr, "movt'cond 'mw"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 976 | } |
| 977 | break; |
| 978 | } |
| 979 | case CMN: { |
| 980 | if (instr->HasS()) { |
| 981 | Format(instr, "cmn'cond 'rn, 'shift_op"); |
| 982 | } else { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 983 | // Other instructions matching this pattern are handled in the |
| 984 | // miscellaneous instructions part above. |
| 985 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | } |
| 987 | break; |
| 988 | } |
| 989 | case ORR: { |
| 990 | Format(instr, "orr'cond's 'rd, 'rn, 'shift_op"); |
| 991 | break; |
| 992 | } |
| 993 | case MOV: { |
| 994 | Format(instr, "mov'cond's 'rd, 'shift_op"); |
| 995 | break; |
| 996 | } |
| 997 | case BIC: { |
| 998 | Format(instr, "bic'cond's 'rd, 'rn, 'shift_op"); |
| 999 | break; |
| 1000 | } |
| 1001 | case MVN: { |
| 1002 | Format(instr, "mvn'cond's 'rd, 'shift_op"); |
| 1003 | break; |
| 1004 | } |
| 1005 | default: { |
| 1006 | // The Opcode field is a 4-bit field. |
| 1007 | UNREACHABLE(); |
| 1008 | break; |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1015 | void Decoder::DecodeType2(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1016 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1017 | case da_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1018 | if (instr->HasW()) { |
| 1019 | Unknown(instr); // not used in V8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1020 | return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1021 | } |
| 1022 | Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12"); |
| 1023 | break; |
| 1024 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1025 | case ia_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1026 | if (instr->HasW()) { |
| 1027 | Unknown(instr); // not used in V8 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1028 | return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1029 | } |
| 1030 | Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12"); |
| 1031 | break; |
| 1032 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1033 | case db_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1034 | Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w"); |
| 1035 | break; |
| 1036 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1037 | case ib_x: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1038 | Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w"); |
| 1039 | break; |
| 1040 | } |
| 1041 | default: { |
| 1042 | // The PU field is a 2-bit field. |
| 1043 | UNREACHABLE(); |
| 1044 | break; |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1050 | void Decoder::DecodeType3(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1051 | switch (instr->PUField()) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1052 | case da_x: { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1053 | VERIFY(!instr->HasW()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1054 | Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm"); |
| 1055 | break; |
| 1056 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1057 | case ia_x: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1058 | if (instr->Bit(4) == 0) { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 1059 | Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1060 | } else { |
| 1061 | if (instr->Bit(5) == 0) { |
| 1062 | switch (instr->Bits(22, 21)) { |
| 1063 | case 0: |
| 1064 | if (instr->Bit(20) == 0) { |
| 1065 | if (instr->Bit(6) == 0) { |
| 1066 | Format(instr, "pkhbt'cond 'rd, 'rn, 'rm, lsl #'imm05@07"); |
| 1067 | } else { |
| 1068 | if (instr->Bits(11, 7) == 0) { |
| 1069 | Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #32"); |
| 1070 | } else { |
| 1071 | Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #'imm05@07"); |
| 1072 | } |
| 1073 | } |
| 1074 | } else { |
| 1075 | UNREACHABLE(); |
| 1076 | } |
| 1077 | break; |
| 1078 | case 1: |
| 1079 | UNREACHABLE(); |
| 1080 | break; |
| 1081 | case 2: |
| 1082 | UNREACHABLE(); |
| 1083 | break; |
| 1084 | case 3: |
| 1085 | Format(instr, "usat 'rd, #'imm05@16, 'rm'shift_sat"); |
| 1086 | break; |
| 1087 | } |
| 1088 | } else { |
| 1089 | switch (instr->Bits(22, 21)) { |
| 1090 | case 0: |
| 1091 | UNREACHABLE(); |
| 1092 | break; |
| 1093 | case 1: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1094 | if (instr->Bits(9, 6) == 1) { |
| 1095 | if (instr->Bit(20) == 0) { |
| 1096 | if (instr->Bits(19, 16) == 0xF) { |
| 1097 | switch (instr->Bits(11, 10)) { |
| 1098 | case 0: |
| 1099 | Format(instr, "sxtb'cond 'rd, 'rm"); |
| 1100 | break; |
| 1101 | case 1: |
| 1102 | Format(instr, "sxtb'cond 'rd, 'rm, ror #8"); |
| 1103 | break; |
| 1104 | case 2: |
| 1105 | Format(instr, "sxtb'cond 'rd, 'rm, ror #16"); |
| 1106 | break; |
| 1107 | case 3: |
| 1108 | Format(instr, "sxtb'cond 'rd, 'rm, ror #24"); |
| 1109 | break; |
| 1110 | } |
| 1111 | } else { |
| 1112 | switch (instr->Bits(11, 10)) { |
| 1113 | case 0: |
| 1114 | Format(instr, "sxtab'cond 'rd, 'rn, 'rm"); |
| 1115 | break; |
| 1116 | case 1: |
| 1117 | Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #8"); |
| 1118 | break; |
| 1119 | case 2: |
| 1120 | Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #16"); |
| 1121 | break; |
| 1122 | case 3: |
| 1123 | Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #24"); |
| 1124 | break; |
| 1125 | } |
| 1126 | } |
| 1127 | } else { |
| 1128 | if (instr->Bits(19, 16) == 0xF) { |
| 1129 | switch (instr->Bits(11, 10)) { |
| 1130 | case 0: |
| 1131 | Format(instr, "sxth'cond 'rd, 'rm"); |
| 1132 | break; |
| 1133 | case 1: |
| 1134 | Format(instr, "sxth'cond 'rd, 'rm, ror #8"); |
| 1135 | break; |
| 1136 | case 2: |
| 1137 | Format(instr, "sxth'cond 'rd, 'rm, ror #16"); |
| 1138 | break; |
| 1139 | case 3: |
| 1140 | Format(instr, "sxth'cond 'rd, 'rm, ror #24"); |
| 1141 | break; |
| 1142 | } |
| 1143 | } else { |
| 1144 | switch (instr->Bits(11, 10)) { |
| 1145 | case 0: |
| 1146 | Format(instr, "sxtah'cond 'rd, 'rn, 'rm"); |
| 1147 | break; |
| 1148 | case 1: |
| 1149 | Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #8"); |
| 1150 | break; |
| 1151 | case 2: |
| 1152 | Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #16"); |
| 1153 | break; |
| 1154 | case 3: |
| 1155 | Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #24"); |
| 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | } else { |
| 1161 | UNREACHABLE(); |
| 1162 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | case 2: |
| 1165 | if ((instr->Bit(20) == 0) && (instr->Bits(9, 6) == 1)) { |
| 1166 | if (instr->Bits(19, 16) == 0xF) { |
| 1167 | switch (instr->Bits(11, 10)) { |
| 1168 | case 0: |
| 1169 | Format(instr, "uxtb16'cond 'rd, 'rm"); |
| 1170 | break; |
| 1171 | case 1: |
| 1172 | Format(instr, "uxtb16'cond 'rd, 'rm, ror #8"); |
| 1173 | break; |
| 1174 | case 2: |
| 1175 | Format(instr, "uxtb16'cond 'rd, 'rm, ror #16"); |
| 1176 | break; |
| 1177 | case 3: |
| 1178 | Format(instr, "uxtb16'cond 'rd, 'rm, ror #24"); |
| 1179 | break; |
| 1180 | } |
| 1181 | } else { |
| 1182 | UNREACHABLE(); |
| 1183 | } |
| 1184 | } else { |
| 1185 | UNREACHABLE(); |
| 1186 | } |
| 1187 | break; |
| 1188 | case 3: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1189 | if ((instr->Bits(9, 6) == 1)) { |
| 1190 | if ((instr->Bit(20) == 0)) { |
| 1191 | if (instr->Bits(19, 16) == 0xF) { |
| 1192 | switch (instr->Bits(11, 10)) { |
| 1193 | case 0: |
| 1194 | Format(instr, "uxtb'cond 'rd, 'rm"); |
| 1195 | break; |
| 1196 | case 1: |
| 1197 | Format(instr, "uxtb'cond 'rd, 'rm, ror #8"); |
| 1198 | break; |
| 1199 | case 2: |
| 1200 | Format(instr, "uxtb'cond 'rd, 'rm, ror #16"); |
| 1201 | break; |
| 1202 | case 3: |
| 1203 | Format(instr, "uxtb'cond 'rd, 'rm, ror #24"); |
| 1204 | break; |
| 1205 | } |
| 1206 | } else { |
| 1207 | switch (instr->Bits(11, 10)) { |
| 1208 | case 0: |
| 1209 | Format(instr, "uxtab'cond 'rd, 'rn, 'rm"); |
| 1210 | break; |
| 1211 | case 1: |
| 1212 | Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #8"); |
| 1213 | break; |
| 1214 | case 2: |
| 1215 | Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #16"); |
| 1216 | break; |
| 1217 | case 3: |
| 1218 | Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #24"); |
| 1219 | break; |
| 1220 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1221 | } |
| 1222 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1223 | if (instr->Bits(19, 16) == 0xF) { |
| 1224 | switch (instr->Bits(11, 10)) { |
| 1225 | case 0: |
| 1226 | Format(instr, "uxth'cond 'rd, 'rm"); |
| 1227 | break; |
| 1228 | case 1: |
| 1229 | Format(instr, "uxth'cond 'rd, 'rm, ror #8"); |
| 1230 | break; |
| 1231 | case 2: |
| 1232 | Format(instr, "uxth'cond 'rd, 'rm, ror #16"); |
| 1233 | break; |
| 1234 | case 3: |
| 1235 | Format(instr, "uxth'cond 'rd, 'rm, ror #24"); |
| 1236 | break; |
| 1237 | } |
| 1238 | } else { |
| 1239 | switch (instr->Bits(11, 10)) { |
| 1240 | case 0: |
| 1241 | Format(instr, "uxtah'cond 'rd, 'rn, 'rm"); |
| 1242 | break; |
| 1243 | case 1: |
| 1244 | Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #8"); |
| 1245 | break; |
| 1246 | case 2: |
| 1247 | Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #16"); |
| 1248 | break; |
| 1249 | case 3: |
| 1250 | Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #24"); |
| 1251 | break; |
| 1252 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1256 | // PU == 0b01, BW == 0b11, Bits(9, 6) != 0b0001 |
| 1257 | if ((instr->Bits(20, 16) == 0x1f) && |
| 1258 | (instr->Bits(11, 4) == 0xf3)) { |
| 1259 | Format(instr, "rbit'cond 'rd, 'rm"); |
| 1260 | } else { |
| 1261 | UNREACHABLE(); |
| 1262 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1263 | } |
| 1264 | break; |
| 1265 | } |
| 1266 | } |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 1267 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1268 | break; |
| 1269 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1270 | case db_x: { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1271 | if (instr->Bits(22, 20) == 0x5) { |
| 1272 | if (instr->Bits(7, 4) == 0x1) { |
| 1273 | if (instr->Bits(15, 12) == 0xF) { |
| 1274 | Format(instr, "smmul'cond 'rn, 'rm, 'rs"); |
| 1275 | } else { |
| 1276 | // SMMLA (in V8 notation matching ARM ISA format) |
| 1277 | Format(instr, "smmla'cond 'rn, 'rm, 'rs, 'rd"); |
| 1278 | } |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1282 | if (FLAG_enable_sudiv) { |
| 1283 | if (instr->Bits(5, 4) == 0x1) { |
| 1284 | if ((instr->Bit(22) == 0x0) && (instr->Bit(20) == 0x1)) { |
| 1285 | if (instr->Bit(21) == 0x1) { |
| 1286 | // UDIV (in V8 notation matching ARM ISA format) rn = rm/rs |
| 1287 | Format(instr, "udiv'cond'b 'rn, 'rm, 'rs"); |
| 1288 | } else { |
| 1289 | // SDIV (in V8 notation matching ARM ISA format) rn = rm/rs |
| 1290 | Format(instr, "sdiv'cond'b 'rn, 'rm, 'rs"); |
| 1291 | } |
| 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1296 | Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w"); |
| 1297 | break; |
| 1298 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1299 | case ib_x: { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1300 | if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) { |
| 1301 | uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1302 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1303 | uint32_t msbit = widthminus1 + lsbit; |
| 1304 | if (msbit <= 31) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1305 | if (instr->Bit(22)) { |
| 1306 | Format(instr, "ubfx'cond 'rd, 'rm, 'f"); |
| 1307 | } else { |
| 1308 | Format(instr, "sbfx'cond 'rd, 'rm, 'f"); |
| 1309 | } |
| 1310 | } else { |
| 1311 | UNREACHABLE(); |
| 1312 | } |
| 1313 | } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) { |
| 1314 | uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7)); |
| 1315 | uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16)); |
| 1316 | if (msbit >= lsbit) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1317 | if (instr->RmValue() == 15) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1318 | Format(instr, "bfc'cond 'rd, 'f"); |
| 1319 | } else { |
| 1320 | Format(instr, "bfi'cond 'rd, 'rm, 'f"); |
| 1321 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1322 | } else { |
| 1323 | UNREACHABLE(); |
| 1324 | } |
| 1325 | } else { |
| 1326 | Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w"); |
| 1327 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1328 | break; |
| 1329 | } |
| 1330 | default: { |
| 1331 | // The PU field is a 2-bit field. |
| 1332 | UNREACHABLE(); |
| 1333 | break; |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1339 | void Decoder::DecodeType4(Instruction* instr) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1340 | if (instr->Bit(22) != 0) { |
| 1341 | // Privileged mode currently not supported. |
| 1342 | Unknown(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1343 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1344 | if (instr->HasL()) { |
| 1345 | Format(instr, "ldm'cond'pu 'rn'w, 'rlist"); |
| 1346 | } else { |
| 1347 | Format(instr, "stm'cond'pu 'rn'w, 'rlist"); |
| 1348 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1353 | void Decoder::DecodeType5(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1354 | Format(instr, "b'l'cond 'target"); |
| 1355 | } |
| 1356 | |
| 1357 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1358 | void Decoder::DecodeType6(Instruction* instr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1359 | DecodeType6CoprocessorIns(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1363 | int Decoder::DecodeType7(Instruction* instr) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1364 | if (instr->Bit(24) == 1) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1365 | if (instr->SvcValue() >= kStopCode) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1366 | Format(instr, "stop'cond 'svc"); |
| 1367 | // Also print the stop message. Its address is encoded |
| 1368 | // in the following 4 bytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1369 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1370 | "\n %p %08x stop message: %s", |
| 1371 | reinterpret_cast<void*>(instr |
| 1372 | + Instruction::kInstrSize), |
| 1373 | *reinterpret_cast<uint32_t*>(instr |
| 1374 | + Instruction::kInstrSize), |
| 1375 | *reinterpret_cast<char**>(instr |
| 1376 | + Instruction::kInstrSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1377 | // We have decoded 2 * Instruction::kInstrSize bytes. |
| 1378 | return 2 * Instruction::kInstrSize; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1379 | } else { |
| 1380 | Format(instr, "svc'cond 'svc"); |
| 1381 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1382 | } else { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1383 | DecodeTypeVFP(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1384 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1385 | return Instruction::kInstrSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1389 | // void Decoder::DecodeTypeVFP(Instruction* instr) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1390 | // vmov: Sn = Rt |
| 1391 | // vmov: Rt = Sn |
| 1392 | // vcvt: Dd = Sm |
| 1393 | // vcvt: Sd = Dm |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1394 | // vcvt.f64.s32 Dd, Dd, #<fbits> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1395 | // Dd = vabs(Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1396 | // Sd = vabs(Sm) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1397 | // Dd = vneg(Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1398 | // Sd = vneg(Sm) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1399 | // Dd = vadd(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1400 | // Sd = vadd(Sn, Sm) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1401 | // Dd = vsub(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1402 | // Sd = vsub(Sn, Sm) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1403 | // Dd = vmul(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1404 | // Sd = vmul(Sn, Sm) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1405 | // Dd = vmla(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1406 | // Sd = vmla(Sn, Sm) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1407 | // Dd = vmls(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1408 | // Sd = vmls(Sn, Sm) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1409 | // Dd = vdiv(Dn, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1410 | // Sd = vdiv(Sn, Sm) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1411 | // vcmp(Dd, Dm) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1412 | // vcmp(Sd, Sm) |
| 1413 | // Dd = vsqrt(Dm) |
| 1414 | // Sd = vsqrt(Sm) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1415 | // vmrs |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1416 | // vmsr |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1417 | void Decoder::DecodeTypeVFP(Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1418 | VERIFY((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0) ); |
| 1419 | VERIFY(instr->Bits(11, 9) == 0x5); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1420 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1421 | if (instr->Bit(4) == 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1422 | if (instr->Opc1Value() == 0x7) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1423 | // Other data processing instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1424 | if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x1)) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1425 | // vmov register to register. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1426 | if (instr->SzValue() == 0x1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1427 | Format(instr, "vmov'cond.f64 'Dd, 'Dm"); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1428 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1429 | Format(instr, "vmov'cond.f32 'Sd, 'Sm"); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1430 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1431 | } else if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x3)) { |
| 1432 | // vabs |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1433 | if (instr->SzValue() == 0x1) { |
| 1434 | Format(instr, "vabs'cond.f64 'Dd, 'Dm"); |
| 1435 | } else { |
| 1436 | Format(instr, "vabs'cond.f32 'Sd, 'Sm"); |
| 1437 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1438 | } else if ((instr->Opc2Value() == 0x1) && (instr->Opc3Value() == 0x1)) { |
| 1439 | // vneg |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1440 | if (instr->SzValue() == 0x1) { |
| 1441 | Format(instr, "vneg'cond.f64 'Dd, 'Dm"); |
| 1442 | } else { |
| 1443 | Format(instr, "vneg'cond.f32 'Sd, 'Sm"); |
| 1444 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1445 | } else if ((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1446 | DecodeVCVTBetweenDoubleAndSingle(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1447 | } else if ((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1448 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1449 | } else if ((instr->Opc2Value() == 0xA) && (instr->Opc3Value() == 0x3) && |
| 1450 | (instr->Bit(8) == 1)) { |
| 1451 | // vcvt.f64.s32 Dd, Dd, #<fbits> |
| 1452 | int fraction_bits = 32 - ((instr->Bits(3, 0) << 1) | instr->Bit(5)); |
| 1453 | Format(instr, "vcvt'cond.f64.s32 'Dd, 'Dd"); |
| 1454 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1455 | ", #%d", fraction_bits); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1456 | } else if (((instr->Opc2Value() >> 1) == 0x6) && |
| 1457 | (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1458 | DecodeVCVTBetweenFloatingPointAndInteger(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1459 | } else if (((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) && |
| 1460 | (instr->Opc3Value() & 0x1)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1461 | DecodeVCMP(instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1462 | } else if (((instr->Opc2Value() == 0x1)) && (instr->Opc3Value() == 0x3)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1463 | if (instr->SzValue() == 0x1) { |
| 1464 | Format(instr, "vsqrt'cond.f64 'Dd, 'Dm"); |
| 1465 | } else { |
| 1466 | Format(instr, "vsqrt'cond.f32 'Sd, 'Sm"); |
| 1467 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1468 | } else if (instr->Opc3Value() == 0x0) { |
| 1469 | if (instr->SzValue() == 0x1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1470 | Format(instr, "vmov'cond.f64 'Dd, 'd"); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 1471 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1472 | Format(instr, "vmov'cond.f32 'Sd, 'd"); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 1473 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1474 | } else if (((instr->Opc2Value() == 0x6)) && instr->Opc3Value() == 0x3) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1475 | // vrintz - round towards zero (truncate) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1476 | if (instr->SzValue() == 0x1) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1477 | Format(instr, "vrintz'cond.f64.f64 'Dd, 'Dm"); |
| 1478 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1479 | Format(instr, "vrintz'cond.f32.f32 'Sd, 'Sm"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1480 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1481 | } else { |
| 1482 | Unknown(instr); // Not used by V8. |
| 1483 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1484 | } else if (instr->Opc1Value() == 0x3) { |
| 1485 | if (instr->SzValue() == 0x1) { |
| 1486 | if (instr->Opc3Value() & 0x1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1487 | Format(instr, "vsub'cond.f64 'Dd, 'Dn, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1488 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1489 | Format(instr, "vadd'cond.f64 'Dd, 'Dn, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1490 | } |
| 1491 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1492 | if (instr->Opc3Value() & 0x1) { |
| 1493 | Format(instr, "vsub'cond.f32 'Sd, 'Sn, 'Sm"); |
| 1494 | } else { |
| 1495 | Format(instr, "vadd'cond.f32 'Sd, 'Sn, 'Sm"); |
| 1496 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1497 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1498 | } else if ((instr->Opc1Value() == 0x2) && !(instr->Opc3Value() & 0x1)) { |
| 1499 | if (instr->SzValue() == 0x1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1500 | Format(instr, "vmul'cond.f64 'Dd, 'Dn, 'Dm"); |
| 1501 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1502 | Format(instr, "vmul'cond.f32 'Sd, 'Sn, 'Sm"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1503 | } |
| 1504 | } else if ((instr->Opc1Value() == 0x0) && !(instr->Opc3Value() & 0x1)) { |
| 1505 | if (instr->SzValue() == 0x1) { |
| 1506 | Format(instr, "vmla'cond.f64 'Dd, 'Dn, 'Dm"); |
| 1507 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1508 | Format(instr, "vmla'cond.f32 'Sd, 'Sn, 'Sm"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1509 | } |
| 1510 | } else if ((instr->Opc1Value() == 0x0) && (instr->Opc3Value() & 0x1)) { |
| 1511 | if (instr->SzValue() == 0x1) { |
| 1512 | Format(instr, "vmls'cond.f64 'Dd, 'Dn, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1513 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1514 | Format(instr, "vmls'cond.f32 'Sd, 'Sn, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1515 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1516 | } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) { |
| 1517 | if (instr->SzValue() == 0x1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1518 | Format(instr, "vdiv'cond.f64 'Dd, 'Dn, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1519 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1520 | Format(instr, "vdiv'cond.f32 'Sd, 'Sn, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1521 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1522 | } else { |
| 1523 | Unknown(instr); // Not used by V8. |
| 1524 | } |
| 1525 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1526 | if ((instr->VCValue() == 0x0) && |
| 1527 | (instr->VAValue() == 0x0)) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1528 | DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | } else if ((instr->VLValue() == 0x0) && |
| 1530 | (instr->VCValue() == 0x1) && |
| 1531 | (instr->Bit(23) == 0x0)) { |
| 1532 | if (instr->Bit(21) == 0x0) { |
| 1533 | Format(instr, "vmov'cond.32 'Dd[0], 'rt"); |
| 1534 | } else { |
| 1535 | Format(instr, "vmov'cond.32 'Dd[1], 'rt"); |
| 1536 | } |
| 1537 | } else if ((instr->VLValue() == 0x1) && |
| 1538 | (instr->VCValue() == 0x1) && |
| 1539 | (instr->Bit(23) == 0x0)) { |
| 1540 | if (instr->Bit(21) == 0x0) { |
| 1541 | Format(instr, "vmov'cond.32 'rt, 'Dd[0]"); |
| 1542 | } else { |
| 1543 | Format(instr, "vmov'cond.32 'rt, 'Dd[1]"); |
| 1544 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1545 | } else if ((instr->VCValue() == 0x0) && |
| 1546 | (instr->VAValue() == 0x7) && |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1547 | (instr->Bits(19, 16) == 0x1)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1548 | if (instr->VLValue() == 0) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1549 | if (instr->Bits(15, 12) == 0xF) { |
| 1550 | Format(instr, "vmsr'cond FPSCR, APSR"); |
| 1551 | } else { |
| 1552 | Format(instr, "vmsr'cond FPSCR, 'rt"); |
| 1553 | } |
| 1554 | } else { |
| 1555 | if (instr->Bits(15, 12) == 0xF) { |
| 1556 | Format(instr, "vmrs'cond APSR, FPSCR"); |
| 1557 | } else { |
| 1558 | Format(instr, "vmrs'cond 'rt, FPSCR"); |
| 1559 | } |
| 1560 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1566 | void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters( |
| 1567 | Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1568 | VERIFY((instr->Bit(4) == 1) && (instr->VCValue() == 0x0) && |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1569 | (instr->VAValue() == 0x0)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1570 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1571 | bool to_arm_register = (instr->VLValue() == 0x1); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1572 | |
| 1573 | if (to_arm_register) { |
| 1574 | Format(instr, "vmov'cond 'rt, 'Sn"); |
| 1575 | } else { |
| 1576 | Format(instr, "vmov'cond 'Sn, 'rt"); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1581 | void Decoder::DecodeVCMP(Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1582 | VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7)); |
| 1583 | VERIFY(((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) && |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1584 | (instr->Opc3Value() & 0x1)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1585 | |
| 1586 | // Comparison. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1587 | bool dp_operation = (instr->SzValue() == 1); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1588 | bool raise_exception_for_qnan = (instr->Bit(7) == 0x1); |
| 1589 | |
| 1590 | if (dp_operation && !raise_exception_for_qnan) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1591 | if (instr->Opc2Value() == 0x4) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1592 | Format(instr, "vcmp'cond.f64 'Dd, 'Dm"); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1593 | } else if (instr->Opc2Value() == 0x5) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1594 | Format(instr, "vcmp'cond.f64 'Dd, #0.0"); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1595 | } else { |
| 1596 | Unknown(instr); // invalid |
| 1597 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1598 | } else if (!raise_exception_for_qnan) { |
| 1599 | if (instr->Opc2Value() == 0x4) { |
| 1600 | Format(instr, "vcmp'cond.f32 'Sd, 'Sm"); |
| 1601 | } else if (instr->Opc2Value() == 0x5) { |
| 1602 | Format(instr, "vcmp'cond.f32 'Sd, #0.0"); |
| 1603 | } else { |
| 1604 | Unknown(instr); // invalid |
| 1605 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1606 | } else { |
| 1607 | Unknown(instr); // Not used by V8. |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1612 | void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1613 | VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7)); |
| 1614 | VERIFY((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1615 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1616 | bool double_to_single = (instr->SzValue() == 1); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1617 | |
| 1618 | if (double_to_single) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1619 | Format(instr, "vcvt'cond.f32.f64 'Sd, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1620 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1621 | Format(instr, "vcvt'cond.f64.f32 'Dd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1626 | void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1627 | VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7)); |
| 1628 | VERIFY(((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) || |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1629 | (((instr->Opc2Value() >> 1) == 0x6) && (instr->Opc3Value() & 0x1))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1630 | |
| 1631 | bool to_integer = (instr->Bit(18) == 1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1632 | bool dp_operation = (instr->SzValue() == 1); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1633 | if (to_integer) { |
| 1634 | bool unsigned_integer = (instr->Bit(16) == 0); |
| 1635 | |
| 1636 | if (dp_operation) { |
| 1637 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1638 | Format(instr, "vcvt'cond.u32.f64 'Sd, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1639 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1640 | Format(instr, "vcvt'cond.s32.f64 'Sd, 'Dm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1641 | } |
| 1642 | } else { |
| 1643 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1644 | Format(instr, "vcvt'cond.u32.f32 'Sd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1645 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1646 | Format(instr, "vcvt'cond.s32.f32 'Sd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | } else { |
| 1650 | bool unsigned_integer = (instr->Bit(7) == 0); |
| 1651 | |
| 1652 | if (dp_operation) { |
| 1653 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1654 | Format(instr, "vcvt'cond.f64.u32 'Dd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1655 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1656 | Format(instr, "vcvt'cond.f64.s32 'Dd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1657 | } |
| 1658 | } else { |
| 1659 | if (unsigned_integer) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1660 | Format(instr, "vcvt'cond.f32.u32 'Sd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1661 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1662 | Format(instr, "vcvt'cond.f32.s32 'Sd, 'Sm"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1669 | // Decode Type 6 coprocessor instructions. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1670 | // Dm = vmov(Rt, Rt2) |
| 1671 | // <Rt, Rt2> = vmov(Dm) |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1672 | // Ddst = MEM(Rbase + 4*offset). |
| 1673 | // MEM(Rbase + 4*offset) = Dsrc. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1674 | void Decoder::DecodeType6CoprocessorIns(Instruction* instr) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1675 | VERIFY(instr->TypeValue() == 6); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1676 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1677 | if (instr->CoprocessorValue() == 0xA) { |
| 1678 | switch (instr->OpcodeValue()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1679 | case 0x8: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1680 | case 0xA: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1681 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1682 | Format(instr, "vldr'cond 'Sd, ['rn - 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1683 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1684 | Format(instr, "vstr'cond 'Sd, ['rn - 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1685 | } |
| 1686 | break; |
| 1687 | case 0xC: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1688 | case 0xE: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1689 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1690 | Format(instr, "vldr'cond 'Sd, ['rn + 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1691 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1692 | Format(instr, "vstr'cond 'Sd, ['rn + 4*'imm08@00]"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1693 | } |
| 1694 | break; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1695 | case 0x4: |
| 1696 | case 0x5: |
| 1697 | case 0x6: |
| 1698 | case 0x7: |
| 1699 | case 0x9: |
| 1700 | case 0xB: { |
| 1701 | bool to_vfp_register = (instr->VLValue() == 0x1); |
| 1702 | if (to_vfp_register) { |
| 1703 | Format(instr, "vldm'cond'pu 'rn'w, {'Sd-'Sd+}"); |
| 1704 | } else { |
| 1705 | Format(instr, "vstm'cond'pu 'rn'w, {'Sd-'Sd+}"); |
| 1706 | } |
| 1707 | break; |
| 1708 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1709 | default: |
| 1710 | Unknown(instr); // Not used by V8. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1711 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1712 | } else if (instr->CoprocessorValue() == 0xB) { |
| 1713 | switch (instr->OpcodeValue()) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1714 | case 0x2: |
| 1715 | // Load and store double to two GP registers |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1716 | if (instr->Bits(7, 6) != 0 || instr->Bit(4) != 1) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1717 | Unknown(instr); // Not used by V8. |
| 1718 | } else if (instr->HasL()) { |
| 1719 | Format(instr, "vmov'cond 'rt, 'rn, 'Dm"); |
| 1720 | } else { |
| 1721 | Format(instr, "vmov'cond 'Dm, 'rt, 'rn"); |
| 1722 | } |
| 1723 | break; |
| 1724 | case 0x8: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1725 | case 0xA: |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1726 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1727 | Format(instr, "vldr'cond 'Dd, ['rn - 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1728 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1729 | Format(instr, "vstr'cond 'Dd, ['rn - 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1730 | } |
| 1731 | break; |
| 1732 | case 0xC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1733 | case 0xE: |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1734 | if (instr->HasL()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1735 | Format(instr, "vldr'cond 'Dd, ['rn + 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1736 | } else { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1737 | Format(instr, "vstr'cond 'Dd, ['rn + 4*'imm08@00]"); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1738 | } |
| 1739 | break; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1740 | case 0x4: |
| 1741 | case 0x5: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1742 | case 0x6: |
| 1743 | case 0x7: |
| 1744 | case 0x9: |
| 1745 | case 0xB: { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1746 | bool to_vfp_register = (instr->VLValue() == 0x1); |
| 1747 | if (to_vfp_register) { |
| 1748 | Format(instr, "vldm'cond'pu 'rn'w, {'Dd-'Dd+}"); |
| 1749 | } else { |
| 1750 | Format(instr, "vstm'cond'pu 'rn'w, {'Dd-'Dd+}"); |
| 1751 | } |
| 1752 | break; |
| 1753 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1754 | default: |
| 1755 | Unknown(instr); // Not used by V8. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1756 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1757 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1758 | Unknown(instr); // Not used by V8. |
| 1759 | } |
| 1760 | } |
| 1761 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1762 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1763 | static const char* const barrier_option_names[] = { |
| 1764 | "invalid", "oshld", "oshst", "osh", "invalid", "nshld", "nshst", "nsh", |
| 1765 | "invalid", "ishld", "ishst", "ish", "invalid", "ld", "st", "sy", |
| 1766 | }; |
| 1767 | |
| 1768 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1769 | void Decoder::DecodeSpecialCondition(Instruction* instr) { |
| 1770 | switch (instr->SpecialValue()) { |
| 1771 | case 5: |
| 1772 | if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) && |
| 1773 | (instr->Bit(4) == 1)) { |
| 1774 | // vmovl signed |
| 1775 | if ((instr->VdValue() & 1) != 0) Unknown(instr); |
| 1776 | int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1); |
| 1777 | int Vm = (instr->Bit(5) << 4) | instr->VmValue(); |
| 1778 | int imm3 = instr->Bits(21, 19); |
| 1779 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1780 | "vmovl.s%d q%d, d%d", imm3*8, Vd, Vm); |
| 1781 | } else { |
| 1782 | Unknown(instr); |
| 1783 | } |
| 1784 | break; |
| 1785 | case 7: |
| 1786 | if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) && |
| 1787 | (instr->Bit(4) == 1)) { |
| 1788 | // vmovl unsigned |
| 1789 | if ((instr->VdValue() & 1) != 0) Unknown(instr); |
| 1790 | int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1); |
| 1791 | int Vm = (instr->Bit(5) << 4) | instr->VmValue(); |
| 1792 | int imm3 = instr->Bits(21, 19); |
| 1793 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1794 | "vmovl.u%d q%d, d%d", imm3*8, Vd, Vm); |
| 1795 | } else { |
| 1796 | Unknown(instr); |
| 1797 | } |
| 1798 | break; |
| 1799 | case 8: |
| 1800 | if (instr->Bits(21, 20) == 0) { |
| 1801 | // vst1 |
| 1802 | int Vd = (instr->Bit(22) << 4) | instr->VdValue(); |
| 1803 | int Rn = instr->VnValue(); |
| 1804 | int type = instr->Bits(11, 8); |
| 1805 | int size = instr->Bits(7, 6); |
| 1806 | int align = instr->Bits(5, 4); |
| 1807 | int Rm = instr->VmValue(); |
| 1808 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1809 | "vst1.%d ", (1 << size) << 3); |
| 1810 | FormatNeonList(Vd, type); |
| 1811 | Print(", "); |
| 1812 | FormatNeonMemory(Rn, align, Rm); |
| 1813 | } else if (instr->Bits(21, 20) == 2) { |
| 1814 | // vld1 |
| 1815 | int Vd = (instr->Bit(22) << 4) | instr->VdValue(); |
| 1816 | int Rn = instr->VnValue(); |
| 1817 | int type = instr->Bits(11, 8); |
| 1818 | int size = instr->Bits(7, 6); |
| 1819 | int align = instr->Bits(5, 4); |
| 1820 | int Rm = instr->VmValue(); |
| 1821 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1822 | "vld1.%d ", (1 << size) << 3); |
| 1823 | FormatNeonList(Vd, type); |
| 1824 | Print(", "); |
| 1825 | FormatNeonMemory(Rn, align, Rm); |
| 1826 | } else { |
| 1827 | Unknown(instr); |
| 1828 | } |
| 1829 | break; |
| 1830 | case 0xA: |
| 1831 | case 0xB: |
| 1832 | if ((instr->Bits(22, 20) == 5) && (instr->Bits(15, 12) == 0xf)) { |
| 1833 | int Rn = instr->Bits(19, 16); |
| 1834 | int offset = instr->Bits(11, 0); |
| 1835 | if (offset == 0) { |
| 1836 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1837 | "pld [r%d]", Rn); |
| 1838 | } else if (instr->Bit(23) == 0) { |
| 1839 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1840 | "pld [r%d, #-%d]", Rn, offset); |
| 1841 | } else { |
| 1842 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1843 | "pld [r%d, #+%d]", Rn, offset); |
| 1844 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1845 | } else if (instr->SpecialValue() == 0xA && instr->Bits(22, 20) == 7) { |
| 1846 | int option = instr->Bits(3, 0); |
| 1847 | switch (instr->Bits(7, 4)) { |
| 1848 | case 4: |
| 1849 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1850 | "dsb %s", barrier_option_names[option]); |
| 1851 | break; |
| 1852 | case 5: |
| 1853 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1854 | "dmb %s", barrier_option_names[option]); |
| 1855 | break; |
| 1856 | case 6: |
| 1857 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1858 | "isb %s", barrier_option_names[option]); |
| 1859 | break; |
| 1860 | default: |
| 1861 | Unknown(instr); |
| 1862 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1863 | } else { |
| 1864 | Unknown(instr); |
| 1865 | } |
| 1866 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1867 | case 0x1D: |
| 1868 | if (instr->Opc1Value() == 0x7 && instr->Bits(19, 18) == 0x2 && |
| 1869 | instr->Bits(11, 9) == 0x5 && instr->Bits(7, 6) == 0x1 && |
| 1870 | instr->Bit(4) == 0x0) { |
| 1871 | // VRINTA, VRINTN, VRINTP, VRINTM (floating-point) |
| 1872 | bool dp_operation = (instr->SzValue() == 1); |
| 1873 | int rounding_mode = instr->Bits(17, 16); |
| 1874 | switch (rounding_mode) { |
| 1875 | case 0x0: |
| 1876 | if (dp_operation) { |
| 1877 | Format(instr, "vrinta.f64.f64 'Dd, 'Dm"); |
| 1878 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1879 | Format(instr, "vrinta.f32.f32 'Sd, 'Sm"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1880 | } |
| 1881 | break; |
| 1882 | case 0x1: |
| 1883 | if (dp_operation) { |
| 1884 | Format(instr, "vrintn.f64.f64 'Dd, 'Dm"); |
| 1885 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1886 | Format(instr, "vrintn.f32.f32 'Sd, 'Sm"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1887 | } |
| 1888 | break; |
| 1889 | case 0x2: |
| 1890 | if (dp_operation) { |
| 1891 | Format(instr, "vrintp.f64.f64 'Dd, 'Dm"); |
| 1892 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1893 | Format(instr, "vrintp.f32.f32 'Sd, 'Sm"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1894 | } |
| 1895 | break; |
| 1896 | case 0x3: |
| 1897 | if (dp_operation) { |
| 1898 | Format(instr, "vrintm.f64.f64 'Dd, 'Dm"); |
| 1899 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1900 | Format(instr, "vrintm.f32.f32 'Sd, 'Sm"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1901 | } |
| 1902 | break; |
| 1903 | default: |
| 1904 | UNREACHABLE(); // Case analysis is exhaustive. |
| 1905 | break; |
| 1906 | } |
| 1907 | } else { |
| 1908 | Unknown(instr); |
| 1909 | } |
| 1910 | break; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 1911 | case 0x1C: |
| 1912 | if ((instr->Bits(11, 9) == 0x5) && (instr->Bit(6) == 0) && |
| 1913 | (instr->Bit(4) == 0)) { |
| 1914 | // VSEL* (floating-point) |
| 1915 | bool dp_operation = (instr->SzValue() == 1); |
| 1916 | switch (instr->Bits(21, 20)) { |
| 1917 | case 0x0: |
| 1918 | if (dp_operation) { |
| 1919 | Format(instr, "vseleq.f64 'Dd, 'Dn, 'Dm"); |
| 1920 | } else { |
| 1921 | Format(instr, "vseleq.f32 'Sd, 'Sn, 'Sm"); |
| 1922 | } |
| 1923 | break; |
| 1924 | case 0x1: |
| 1925 | if (dp_operation) { |
| 1926 | Format(instr, "vselvs.f64 'Dd, 'Dn, 'Dm"); |
| 1927 | } else { |
| 1928 | Format(instr, "vselvs.f32 'Sd, 'Sn, 'Sm"); |
| 1929 | } |
| 1930 | break; |
| 1931 | case 0x2: |
| 1932 | if (dp_operation) { |
| 1933 | Format(instr, "vselge.f64 'Dd, 'Dn, 'Dm"); |
| 1934 | } else { |
| 1935 | Format(instr, "vselge.f32 'Sd, 'Sn, 'Sm"); |
| 1936 | } |
| 1937 | break; |
| 1938 | case 0x3: |
| 1939 | if (dp_operation) { |
| 1940 | Format(instr, "vselgt.f64 'Dd, 'Dn, 'Dm"); |
| 1941 | } else { |
| 1942 | Format(instr, "vselgt.f32 'Sd, 'Sn, 'Sm"); |
| 1943 | } |
| 1944 | break; |
| 1945 | default: |
| 1946 | UNREACHABLE(); // Case analysis is exhaustive. |
| 1947 | break; |
| 1948 | } |
| 1949 | } else { |
| 1950 | Unknown(instr); |
| 1951 | } |
| 1952 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1953 | default: |
| 1954 | Unknown(instr); |
| 1955 | break; |
| 1956 | } |
| 1957 | } |
| 1958 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1959 | #undef VERIFIY |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1960 | |
| 1961 | bool Decoder::IsConstantPoolAt(byte* instr_ptr) { |
| 1962 | int instruction_bits = *(reinterpret_cast<int*>(instr_ptr)); |
| 1963 | return (instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | int Decoder::ConstantPoolSizeAt(byte* instr_ptr) { |
| 1968 | if (IsConstantPoolAt(instr_ptr)) { |
| 1969 | int instruction_bits = *(reinterpret_cast<int*>(instr_ptr)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1970 | return DecodeConstantPoolLength(instruction_bits); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1971 | } else { |
| 1972 | return -1; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1977 | // Disassemble the instruction at *instr_ptr into the output buffer. |
| 1978 | int Decoder::InstructionDecode(byte* instr_ptr) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1979 | Instruction* instr = Instruction::At(instr_ptr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1980 | // Print raw instruction bytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1981 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1982 | "%08x ", |
| 1983 | instr->InstructionBits()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1984 | if (instr->ConditionField() == kSpecialCondition) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1985 | DecodeSpecialCondition(instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1986 | return Instruction::kInstrSize; |
| 1987 | } |
| 1988 | int instruction_bits = *(reinterpret_cast<int*>(instr_ptr)); |
| 1989 | if ((instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1990 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
| 1991 | "constant pool begin (length %d)", |
| 1992 | DecodeConstantPoolLength(instruction_bits)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1993 | return Instruction::kInstrSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1994 | } else if (instruction_bits == kCodeAgeJumpInstruction) { |
| 1995 | // The code age prologue has a constant immediatly following the jump |
| 1996 | // instruction. |
| 1997 | Instruction* target = Instruction::At(instr_ptr + Instruction::kInstrSize); |
| 1998 | DecodeType2(instr); |
| 1999 | SNPrintF(out_buffer_ + out_buffer_pos_, |
| 2000 | " (0x%08x)", target->InstructionBits()); |
| 2001 | return 2 * Instruction::kInstrSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2002 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2003 | switch (instr->TypeValue()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2004 | case 0: |
| 2005 | case 1: { |
| 2006 | DecodeType01(instr); |
| 2007 | break; |
| 2008 | } |
| 2009 | case 2: { |
| 2010 | DecodeType2(instr); |
| 2011 | break; |
| 2012 | } |
| 2013 | case 3: { |
| 2014 | DecodeType3(instr); |
| 2015 | break; |
| 2016 | } |
| 2017 | case 4: { |
| 2018 | DecodeType4(instr); |
| 2019 | break; |
| 2020 | } |
| 2021 | case 5: { |
| 2022 | DecodeType5(instr); |
| 2023 | break; |
| 2024 | } |
| 2025 | case 6: { |
| 2026 | DecodeType6(instr); |
| 2027 | break; |
| 2028 | } |
| 2029 | case 7: { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2030 | return DecodeType7(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2031 | } |
| 2032 | default: { |
| 2033 | // The type field is 3-bits in the ARM encoding. |
| 2034 | UNREACHABLE(); |
| 2035 | break; |
| 2036 | } |
| 2037 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2038 | return Instruction::kInstrSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2042 | } // namespace internal |
| 2043 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2044 | |
| 2045 | |
| 2046 | //------------------------------------------------------------------------------ |
| 2047 | |
| 2048 | namespace disasm { |
| 2049 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2050 | |
| 2051 | const char* NameConverter::NameOfAddress(byte* addr) const { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2052 | v8::internal::SNPrintF(tmp_buffer_, "%p", static_cast<void*>(addr)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2053 | return tmp_buffer_.start(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | |
| 2057 | const char* NameConverter::NameOfConstant(byte* addr) const { |
| 2058 | return NameOfAddress(addr); |
| 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | const char* NameConverter::NameOfCPURegister(int reg) const { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2063 | return v8::internal::GetRegConfig()->GetGeneralRegisterName(reg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
| 2067 | const char* NameConverter::NameOfByteCPURegister(int reg) const { |
| 2068 | UNREACHABLE(); // ARM does not have the concept of a byte register |
| 2069 | return "nobytereg"; |
| 2070 | } |
| 2071 | |
| 2072 | |
| 2073 | const char* NameConverter::NameOfXMMRegister(int reg) const { |
| 2074 | UNREACHABLE(); // ARM does not have any XMM registers |
| 2075 | return "noxmmreg"; |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | const char* NameConverter::NameInCode(byte* addr) const { |
| 2080 | // The default name converter is called for unknown code. So we will not try |
| 2081 | // to access any memory. |
| 2082 | return ""; |
| 2083 | } |
| 2084 | |
| 2085 | |
| 2086 | //------------------------------------------------------------------------------ |
| 2087 | |
| 2088 | Disassembler::Disassembler(const NameConverter& converter) |
| 2089 | : converter_(converter) {} |
| 2090 | |
| 2091 | |
| 2092 | Disassembler::~Disassembler() {} |
| 2093 | |
| 2094 | |
| 2095 | int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer, |
| 2096 | byte* instruction) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2097 | v8::internal::Decoder d(converter_, buffer); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2098 | return d.InstructionDecode(instruction); |
| 2099 | } |
| 2100 | |
| 2101 | |
| 2102 | int Disassembler::ConstantPoolSizeAt(byte* instruction) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2103 | return v8::internal::Decoder::ConstantPoolSizeAt(instruction); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) { |
| 2108 | NameConverter converter; |
| 2109 | Disassembler d(converter); |
| 2110 | for (byte* pc = begin; pc < end;) { |
| 2111 | v8::internal::EmbeddedVector<char, 128> buffer; |
| 2112 | buffer[0] = '\0'; |
| 2113 | byte* prev_pc = pc; |
| 2114 | pc += d.InstructionDecode(buffer, pc); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 2115 | v8::internal::PrintF(f, "%p %08x %s\n", static_cast<void*>(prev_pc), |
| 2116 | *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | } // namespace disasm |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2122 | |
| 2123 | #endif // V8_TARGET_ARCH_ARM |