blob: 9258703fbcae0a1fc3bc73010f19b3510aca354c [file] [log] [blame]
Ben Murdoch8b112d22011-06-08 16:22:53 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
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 Block6ded16b2010-05-10 14:33:55 +010014// v8::internal::EmbeddedVector<char, 256> buffer;
Steve Blocka7e24c12009-10-30 11:49:00 +000015// byte* prev_pc = pc;
Steve Block6ded16b2010-05-10 14:33:55 +010016// pc += d.InstructionDecode(buffer, pc);
Steve Blocka7e24c12009-10-30 11:49:00 +000017// 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 Blocka7e24c12009-10-30 11:49:00 +000027#include <stdarg.h>
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028#include <stdio.h>
Steve Blocka7e24c12009-10-30 11:49:00 +000029#include <string.h>
Steve Blocka7e24c12009-10-30 11:49:00 +000030
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031#if V8_TARGET_ARCH_ARM
Leon Clarkef7060e22010-06-03 12:02:55 +010032
Ben Murdochb8a8cc12014-11-26 15:28:44 +000033#include "src/arm/constants-arm.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034#include "src/base/bits.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035#include "src/base/platform/platform.h"
36#include "src/disasm.h"
37#include "src/macro-assembler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000038
39
Steve Block1e0659c2011-05-24 12:43:12 +010040namespace v8 {
41namespace internal {
Steve Blocka7e24c12009-10-30 11:49:00 +000042
43
44//------------------------------------------------------------------------------
45
46// Decoder decodes and disassembles instructions into an output buffer.
47// It uses the converter to convert register names and call destinations into
48// more informative description.
49class Decoder {
50 public:
51 Decoder(const disasm::NameConverter& converter,
Steve Block1e0659c2011-05-24 12:43:12 +010052 Vector<char> out_buffer)
Steve Blocka7e24c12009-10-30 11:49:00 +000053 : converter_(converter),
54 out_buffer_(out_buffer),
55 out_buffer_pos_(0) {
56 out_buffer_[out_buffer_pos_] = '\0';
57 }
58
59 ~Decoder() {}
60
61 // Writes one disassembled instruction into 'buffer' (0-terminated).
62 // Returns the length of the disassembled machine instruction in bytes.
63 int InstructionDecode(byte* instruction);
64
Steve Block44f0eee2011-05-26 01:26:41 +010065 static bool IsConstantPoolAt(byte* instr_ptr);
66 static int ConstantPoolSizeAt(byte* instr_ptr);
67
Steve Blocka7e24c12009-10-30 11:49:00 +000068 private:
69 // Bottleneck functions to print into the out_buffer.
70 void PrintChar(const char ch);
71 void Print(const char* str);
72
73 // Printing of common values.
74 void PrintRegister(int reg);
Steve Blockd0582a62009-12-15 09:54:21 +000075 void PrintSRegister(int reg);
76 void PrintDRegister(int reg);
Steve Block1e0659c2011-05-24 12:43:12 +010077 int FormatVFPRegister(Instruction* instr, const char* format);
78 void PrintMovwMovt(Instruction* instr);
79 int FormatVFPinstruction(Instruction* instr, const char* format);
80 void PrintCondition(Instruction* instr);
81 void PrintShiftRm(Instruction* instr);
82 void PrintShiftImm(Instruction* instr);
83 void PrintShiftSat(Instruction* instr);
84 void PrintPU(Instruction* instr);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -080085 void PrintSoftwareInterrupt(SoftwareInterruptCodes svc);
Steve Blocka7e24c12009-10-30 11:49:00 +000086
87 // Handle formatting of instructions and their options.
Steve Block1e0659c2011-05-24 12:43:12 +010088 int FormatRegister(Instruction* instr, const char* option);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089 void FormatNeonList(int Vd, int type);
90 void FormatNeonMemory(int Rn, int align, int Rm);
Steve Block1e0659c2011-05-24 12:43:12 +010091 int FormatOption(Instruction* instr, const char* option);
92 void Format(Instruction* instr, const char* format);
93 void Unknown(Instruction* instr);
Steve Blocka7e24c12009-10-30 11:49:00 +000094
95 // Each of these functions decodes one particular instruction type, a 3-bit
96 // field in the instruction encoding.
97 // Types 0 and 1 are combined as they are largely the same except for the way
98 // they interpret the shifter operand.
Steve Block1e0659c2011-05-24 12:43:12 +010099 void DecodeType01(Instruction* instr);
100 void DecodeType2(Instruction* instr);
101 void DecodeType3(Instruction* instr);
102 void DecodeType4(Instruction* instr);
103 void DecodeType5(Instruction* instr);
104 void DecodeType6(Instruction* instr);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800105 // Type 7 includes special Debugger instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100106 int DecodeType7(Instruction* instr);
Steve Blockd0582a62009-12-15 09:54:21 +0000107 // For VFP support.
Steve Block1e0659c2011-05-24 12:43:12 +0100108 void DecodeTypeVFP(Instruction* instr);
109 void DecodeType6CoprocessorIns(Instruction* instr);
Steve Blockd0582a62009-12-15 09:54:21 +0000110
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111 void DecodeSpecialCondition(Instruction* instr);
112
Steve Block1e0659c2011-05-24 12:43:12 +0100113 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr);
114 void DecodeVCMP(Instruction* instr);
115 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr);
116 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000117
118 const disasm::NameConverter& converter_;
Steve Block1e0659c2011-05-24 12:43:12 +0100119 Vector<char> out_buffer_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000120 int out_buffer_pos_;
121
122 DISALLOW_COPY_AND_ASSIGN(Decoder);
123};
124
125
126// Support for assertions in the Decoder formatting functions.
127#define STRING_STARTS_WITH(string, compare_string) \
128 (strncmp(string, compare_string, strlen(compare_string)) == 0)
129
130
131// Append the ch to the output buffer.
132void Decoder::PrintChar(const char ch) {
133 out_buffer_[out_buffer_pos_++] = ch;
134}
135
136
137// Append the str to the output buffer.
138void Decoder::Print(const char* str) {
139 char cur = *str++;
140 while (cur != '\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
141 PrintChar(cur);
142 cur = *str++;
143 }
144 out_buffer_[out_buffer_pos_] = 0;
145}
146
147
148// These condition names are defined in a way to match the native disassembler
149// formatting. See for example the command "objdump -d <binary file>".
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400150static const char* const cond_names[kNumberOfConditions] = {
Steve Blocka7e24c12009-10-30 11:49:00 +0000151 "eq", "ne", "cs" , "cc" , "mi" , "pl" , "vs" , "vc" ,
152 "hi", "ls", "ge", "lt", "gt", "le", "", "invalid",
153};
154
155
156// Print the condition guarding the instruction.
Steve Block1e0659c2011-05-24 12:43:12 +0100157void Decoder::PrintCondition(Instruction* instr) {
158 Print(cond_names[instr->ConditionValue()]);
Steve Blocka7e24c12009-10-30 11:49:00 +0000159}
160
161
162// Print the register name according to the active name converter.
163void Decoder::PrintRegister(int reg) {
164 Print(converter_.NameOfCPURegister(reg));
165}
166
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167
Steve Blockd0582a62009-12-15 09:54:21 +0000168// Print the VFP S register name according to the active name converter.
169void Decoder::PrintSRegister(int reg) {
Steve Block1e0659c2011-05-24 12:43:12 +0100170 Print(VFPRegisters::Name(reg, false));
Steve Blockd0582a62009-12-15 09:54:21 +0000171}
172
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173
174// Print the VFP D register name according to the active name converter.
Steve Blockd0582a62009-12-15 09:54:21 +0000175void Decoder::PrintDRegister(int reg) {
Steve Block1e0659c2011-05-24 12:43:12 +0100176 Print(VFPRegisters::Name(reg, true));
Steve Blockd0582a62009-12-15 09:54:21 +0000177}
178
Steve Blocka7e24c12009-10-30 11:49:00 +0000179
180// These shift names are defined in a way to match the native disassembler
181// formatting. See for example the command "objdump -d <binary file>".
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000182static const char* const shift_names[kNumberOfShifts] = {
Steve Blocka7e24c12009-10-30 11:49:00 +0000183 "lsl", "lsr", "asr", "ror"
184};
185
186
187// Print the register shift operands for the instruction. Generally used for
188// data processing instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100189void Decoder::PrintShiftRm(Instruction* instr) {
190 ShiftOp shift = instr->ShiftField();
191 int shift_index = instr->ShiftValue();
192 int shift_amount = instr->ShiftAmountValue();
193 int rm = instr->RmValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000194
195 PrintRegister(rm);
196
Steve Block1e0659c2011-05-24 12:43:12 +0100197 if ((instr->RegShiftValue() == 0) && (shift == LSL) && (shift_amount == 0)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000198 // Special case for using rm only.
199 return;
200 }
Steve Block1e0659c2011-05-24 12:43:12 +0100201 if (instr->RegShiftValue() == 0) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 // by immediate
203 if ((shift == ROR) && (shift_amount == 0)) {
204 Print(", RRX");
205 return;
206 } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) {
207 shift_amount = 32;
208 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
210 ", %s #%d",
211 shift_names[shift_index],
212 shift_amount);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 } else {
214 // by register
Steve Block1e0659c2011-05-24 12:43:12 +0100215 int rs = instr->RsValue();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000216 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
217 ", %s ", shift_names[shift_index]);
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 PrintRegister(rs);
219 }
220}
221
222
223// Print the immediate operand for the instruction. Generally used for data
224// processing instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100225void Decoder::PrintShiftImm(Instruction* instr) {
226 int rotate = instr->RotateValue() * 2;
227 int immed8 = instr->Immed8Value();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000228 int imm = base::bits::RotateRight32(immed8, rotate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000229 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "#%d", imm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000230}
231
232
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100233// Print the optional shift and immediate used by saturating instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100234void Decoder::PrintShiftSat(Instruction* instr) {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100235 int shift = instr->Bits(11, 7);
236 if (shift > 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
238 ", %s #%d",
239 shift_names[instr->Bit(6) * 2],
240 instr->Bits(11, 7));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100241 }
242}
243
244
Steve Blocka7e24c12009-10-30 11:49:00 +0000245// Print PU formatting to reduce complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100246void Decoder::PrintPU(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000247 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100248 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 Print("da");
250 break;
251 }
Steve Block1e0659c2011-05-24 12:43:12 +0100252 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000253 Print("ia");
254 break;
255 }
Steve Block1e0659c2011-05-24 12:43:12 +0100256 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000257 Print("db");
258 break;
259 }
Steve Block1e0659c2011-05-24 12:43:12 +0100260 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000261 Print("ib");
262 break;
263 }
264 default: {
265 UNREACHABLE();
266 break;
267 }
268 }
269}
270
271
272// Print SoftwareInterrupt codes. Factoring this out reduces the complexity of
273// the FormatOption method.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800274void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) {
275 switch (svc) {
Steve Block1e0659c2011-05-24 12:43:12 +0100276 case kCallRtRedirected:
277 Print("call rt redirected");
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 return;
Steve Block1e0659c2011-05-24 12:43:12 +0100279 case kBreakpoint:
280 Print("breakpoint");
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 return;
282 default:
Steve Block1e0659c2011-05-24 12:43:12 +0100283 if (svc >= kStopCode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
285 "%d - 0x%x",
286 svc & kStopCodeMask,
287 svc & kStopCodeMask);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800288 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
290 "%d",
291 svc);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800292 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000293 return;
294 }
295}
296
297
298// Handle all register based formatting in this function to reduce the
299// complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100300int Decoder::FormatRegister(Instruction* instr, const char* format) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 DCHECK(format[0] == 'r');
Steve Blocka7e24c12009-10-30 11:49:00 +0000302 if (format[1] == 'n') { // 'rn: Rn register
Steve Block1e0659c2011-05-24 12:43:12 +0100303 int reg = instr->RnValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000304 PrintRegister(reg);
305 return 2;
306 } else if (format[1] == 'd') { // 'rd: Rd register
Steve Block1e0659c2011-05-24 12:43:12 +0100307 int reg = instr->RdValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000308 PrintRegister(reg);
309 return 2;
310 } else if (format[1] == 's') { // 'rs: Rs register
Steve Block1e0659c2011-05-24 12:43:12 +0100311 int reg = instr->RsValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000312 PrintRegister(reg);
313 return 2;
314 } else if (format[1] == 'm') { // 'rm: Rm register
Steve Block1e0659c2011-05-24 12:43:12 +0100315 int reg = instr->RmValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000316 PrintRegister(reg);
317 return 2;
Steve Blockd0582a62009-12-15 09:54:21 +0000318 } else if (format[1] == 't') { // 'rt: Rt register
Steve Block1e0659c2011-05-24 12:43:12 +0100319 int reg = instr->RtValue();
Steve Blockd0582a62009-12-15 09:54:21 +0000320 PrintRegister(reg);
321 return 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000322 } else if (format[1] == 'l') {
323 // 'rlist: register list for load and store multiple instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000324 DCHECK(STRING_STARTS_WITH(format, "rlist"));
Steve Block1e0659c2011-05-24 12:43:12 +0100325 int rlist = instr->RlistValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 int reg = 0;
327 Print("{");
328 // Print register list in ascending order, by scanning the bit mask.
329 while (rlist != 0) {
330 if ((rlist & 1) != 0) {
331 PrintRegister(reg);
332 if ((rlist >> 1) != 0) {
333 Print(", ");
334 }
335 }
336 reg++;
337 rlist >>= 1;
338 }
339 Print("}");
340 return 5;
341 }
342 UNREACHABLE();
343 return -1;
344}
345
346
Steve Blockd0582a62009-12-15 09:54:21 +0000347// Handle all VFP register based formatting in this function to reduce the
348// complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100349int Decoder::FormatVFPRegister(Instruction* instr, const char* format) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 DCHECK((format[0] == 'S') || (format[0] == 'D'));
Steve Blockd0582a62009-12-15 09:54:21 +0000351
Ben Murdoch8b112d22011-06-08 16:22:53 +0100352 VFPRegPrecision precision =
353 format[0] == 'D' ? kDoublePrecision : kSinglePrecision;
354
355 int retval = 2;
356 int reg = -1;
Steve Blockd0582a62009-12-15 09:54:21 +0000357 if (format[1] == 'n') {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100358 reg = instr->VFPNRegValue(precision);
Steve Blockd0582a62009-12-15 09:54:21 +0000359 } else if (format[1] == 'm') {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100360 reg = instr->VFPMRegValue(precision);
Steve Blockd0582a62009-12-15 09:54:21 +0000361 } else if (format[1] == 'd') {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000362 if ((instr->TypeValue() == 7) &&
363 (instr->Bit(24) == 0x0) &&
364 (instr->Bits(11, 9) == 0x5) &&
365 (instr->Bit(4) == 0x1)) {
366 // vmov.32 has Vd in a different place.
367 reg = instr->Bits(19, 16) | (instr->Bit(7) << 4);
368 } else {
369 reg = instr->VFPDRegValue(precision);
370 }
371
Ben Murdoch8b112d22011-06-08 16:22:53 +0100372 if (format[2] == '+') {
373 int immed8 = instr->Immed8Value();
374 if (format[0] == 'S') reg += immed8 - 1;
375 if (format[0] == 'D') reg += (immed8 / 2 - 1);
376 }
377 if (format[2] == '+') retval = 3;
378 } else {
379 UNREACHABLE();
Steve Blockd0582a62009-12-15 09:54:21 +0000380 }
381
Ben Murdoch8b112d22011-06-08 16:22:53 +0100382 if (precision == kSinglePrecision) {
383 PrintSRegister(reg);
384 } else {
385 PrintDRegister(reg);
386 }
387
388 return retval;
Steve Blockd0582a62009-12-15 09:54:21 +0000389}
390
391
Steve Block1e0659c2011-05-24 12:43:12 +0100392int Decoder::FormatVFPinstruction(Instruction* instr, const char* format) {
Steve Blockd0582a62009-12-15 09:54:21 +0000393 Print(format);
394 return 0;
395}
396
397
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398void Decoder::FormatNeonList(int Vd, int type) {
399 if (type == nlt_1) {
400 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
401 "{d%d}", Vd);
402 } else if (type == nlt_2) {
403 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
404 "{d%d, d%d}", Vd, Vd + 1);
405 } else if (type == nlt_3) {
406 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
407 "{d%d, d%d, d%d}", Vd, Vd + 1, Vd + 2);
408 } else if (type == nlt_4) {
409 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
410 "{d%d, d%d, d%d, d%d}", Vd, Vd + 1, Vd + 2, Vd + 3);
411 }
412}
413
414
415void Decoder::FormatNeonMemory(int Rn, int align, int Rm) {
416 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
417 "[r%d", Rn);
418 if (align != 0) {
419 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
420 ":%d", (1 << align) << 6);
421 }
422 if (Rm == 15) {
423 Print("]");
424 } else if (Rm == 13) {
425 Print("]!");
426 } else {
427 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
428 "], r%d", Rm);
429 }
430}
431
432
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100433// Print the movw or movt instruction.
Steve Block1e0659c2011-05-24 12:43:12 +0100434void Decoder::PrintMovwMovt(Instruction* instr) {
435 int imm = instr->ImmedMovwMovtValue();
436 int rd = instr->RdValue();
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100437 PrintRegister(rd);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, ", #%d", imm);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100439}
440
441
Steve Blocka7e24c12009-10-30 11:49:00 +0000442// FormatOption takes a formatting string and interprets it based on
443// the current instructions. The format string points to the first
444// character of the option string (the option escape has already been
445// consumed by the caller.) FormatOption returns the number of
446// characters that were consumed from the formatting string.
Steve Block1e0659c2011-05-24 12:43:12 +0100447int Decoder::FormatOption(Instruction* instr, const char* format) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 switch (format[0]) {
449 case 'a': { // 'a: accumulate multiplies
450 if (instr->Bit(21) == 0) {
451 Print("ul");
452 } else {
453 Print("la");
454 }
455 return 1;
456 }
457 case 'b': { // 'b: byte loads or stores
458 if (instr->HasB()) {
459 Print("b");
460 }
461 return 1;
462 }
463 case 'c': { // 'cond: conditional execution
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000464 DCHECK(STRING_STARTS_WITH(format, "cond"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000465 PrintCondition(instr);
466 return 4;
467 }
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100468 case 'd': { // 'd: vmov double immediate.
469 double d = instr->DoubleImmedVmov();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000470 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "#%g", d);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100471 return 1;
472 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100473 case 'f': { // 'f: bitfield instructions - v7 and above.
474 uint32_t lsbit = instr->Bits(11, 7);
475 uint32_t width = instr->Bits(20, 16) + 1;
476 if (instr->Bit(21) == 0) {
477 // BFC/BFI:
478 // Bits 20-16 represent most-significant bit. Covert to width.
479 width -= lsbit;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000480 DCHECK(width > 0);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100481 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000482 DCHECK((width + lsbit) <= 32);
483 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
484 "#%d, #%d", lsbit, width);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100485 return 1;
486 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 case 'h': { // 'h: halfword operation for extra loads and stores
488 if (instr->HasH()) {
489 Print("h");
490 } else {
491 Print("b");
492 }
493 return 1;
494 }
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100495 case 'i': { // 'i: immediate value from adjacent bits.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100496 // Expects tokens in the form imm%02d@%02d, i.e. imm05@07, imm10@16
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100497 int width = (format[3] - '0') * 10 + (format[4] - '0');
498 int lsb = (format[6] - '0') * 10 + (format[7] - '0');
499
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000500 DCHECK((width >= 1) && (width <= 32));
501 DCHECK((lsb >= 0) && (lsb <= 31));
502 DCHECK((width + lsb) <= 32);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100503
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000504 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
505 "%d",
506 instr->Bits(width + lsb - 1, lsb));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100507 return 8;
508 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000509 case 'l': { // 'l: branch and link
510 if (instr->HasLink()) {
511 Print("l");
512 }
513 return 1;
514 }
515 case 'm': {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100516 if (format[1] == 'w') {
517 // 'mw: movt/movw instructions.
518 PrintMovwMovt(instr);
519 return 2;
520 }
521 if (format[1] == 'e') { // 'memop: load/store instructions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000522 DCHECK(STRING_STARTS_WITH(format, "memop"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000523 if (instr->HasL()) {
524 Print("ldr");
525 } else {
Ben Murdoch257744e2011-11-30 15:57:28 +0000526 if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0) &&
527 (instr->Bits(7, 6) == 3) && (instr->Bit(4) == 1)) {
528 if (instr->Bit(5) == 1) {
529 Print("strd");
530 } else {
531 Print("ldrd");
532 }
533 return 5;
534 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000535 Print("str");
536 }
537 return 5;
538 }
539 // 'msg: for simulator break instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000540 DCHECK(STRING_STARTS_WITH(format, "msg"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000541 byte* str =
542 reinterpret_cast<byte*>(instr->InstructionBits() & 0x0fffffff);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000543 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
544 "%s", converter_.NameInCode(str));
Steve Blocka7e24c12009-10-30 11:49:00 +0000545 return 3;
546 }
547 case 'o': {
Andrei Popescu31002712010-02-23 13:46:05 +0000548 if ((format[3] == '1') && (format[4] == '2')) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000549 // 'off12: 12-bit offset for load and store instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550 DCHECK(STRING_STARTS_WITH(format, "off12"));
551 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
552 "%d", instr->Offset12Value());
Steve Blocka7e24c12009-10-30 11:49:00 +0000553 return 5;
Steve Block6ded16b2010-05-10 14:33:55 +0100554 } else if (format[3] == '0') {
555 // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000556 DCHECK(STRING_STARTS_WITH(format, "off0to3and8to19"));
557 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
558 "%d",
559 (instr->Bits(19, 8) << 4) +
560 instr->Bits(3, 0));
Steve Block6ded16b2010-05-10 14:33:55 +0100561 return 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000562 }
563 // 'off8: 8-bit offset for extra load and store instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000564 DCHECK(STRING_STARTS_WITH(format, "off8"));
Steve Block1e0659c2011-05-24 12:43:12 +0100565 int offs8 = (instr->ImmedHValue() << 4) | instr->ImmedLValue();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000566 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", offs8);
Steve Blocka7e24c12009-10-30 11:49:00 +0000567 return 4;
568 }
569 case 'p': { // 'pu: P and U bits for load and store instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000570 DCHECK(STRING_STARTS_WITH(format, "pu"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000571 PrintPU(instr);
572 return 2;
573 }
574 case 'r': {
575 return FormatRegister(instr, format);
576 }
577 case 's': {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100578 if (format[1] == 'h') { // 'shift_op or 'shift_rm or 'shift_sat.
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 if (format[6] == 'o') { // 'shift_op
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000580 DCHECK(STRING_STARTS_WITH(format, "shift_op"));
Steve Block1e0659c2011-05-24 12:43:12 +0100581 if (instr->TypeValue() == 0) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000582 PrintShiftRm(instr);
583 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000584 DCHECK(instr->TypeValue() == 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000585 PrintShiftImm(instr);
586 }
587 return 8;
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100588 } else if (format[6] == 's') { // 'shift_sat.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000589 DCHECK(STRING_STARTS_WITH(format, "shift_sat"));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100590 PrintShiftSat(instr);
591 return 9;
Steve Blocka7e24c12009-10-30 11:49:00 +0000592 } else { // 'shift_rm
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000593 DCHECK(STRING_STARTS_WITH(format, "shift_rm"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000594 PrintShiftRm(instr);
595 return 8;
596 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800597 } else if (format[1] == 'v') { // 'svc
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000598 DCHECK(STRING_STARTS_WITH(format, "svc"));
Steve Block1e0659c2011-05-24 12:43:12 +0100599 PrintSoftwareInterrupt(instr->SvcValue());
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 return 3;
601 } else if (format[1] == 'i') { // 'sign: signed extra loads and stores
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000602 DCHECK(STRING_STARTS_WITH(format, "sign"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000603 if (instr->HasSign()) {
604 Print("s");
605 }
606 return 4;
607 }
608 // 's: S field of data processing instructions
609 if (instr->HasS()) {
610 Print("s");
611 }
612 return 1;
613 }
614 case 't': { // 'target: target of branch instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000615 DCHECK(STRING_STARTS_WITH(format, "target"));
Steve Block1e0659c2011-05-24 12:43:12 +0100616 int off = (instr->SImmed24Value() << 2) + 8;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000617 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
618 "%+d -> %s",
619 off,
620 converter_.NameOfAddress(
621 reinterpret_cast<byte*>(instr) + off));
Steve Blocka7e24c12009-10-30 11:49:00 +0000622 return 6;
623 }
624 case 'u': { // 'u: signed or unsigned multiplies
625 // The manual gets the meaning of bit 22 backwards in the multiply
626 // instruction overview on page A3.16.2. The instructions that
627 // exist in u and s variants are the following:
628 // smull A4.1.87
629 // umull A4.1.129
630 // umlal A4.1.128
631 // smlal A4.1.76
632 // For these 0 means u and 1 means s. As can be seen on their individual
633 // pages. The other 18 mul instructions have the bit set or unset in
634 // arbitrary ways that are unrelated to the signedness of the instruction.
635 // None of these 18 instructions exist in both a 'u' and an 's' variant.
636
637 if (instr->Bit(22) == 0) {
638 Print("u");
639 } else {
640 Print("s");
641 }
642 return 1;
643 }
Steve Blockd0582a62009-12-15 09:54:21 +0000644 case 'v': {
645 return FormatVFPinstruction(instr, format);
646 }
647 case 'S':
648 case 'D': {
649 return FormatVFPRegister(instr, format);
650 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000651 case 'w': { // 'w: W field of load and store instructions
652 if (instr->HasW()) {
653 Print("!");
654 }
655 return 1;
656 }
657 default: {
658 UNREACHABLE();
659 break;
660 }
661 }
662 UNREACHABLE();
663 return -1;
664}
665
666
667// Format takes a formatting string for a whole instruction and prints it into
668// the output buffer. All escaped options are handed to FormatOption to be
669// parsed further.
Steve Block1e0659c2011-05-24 12:43:12 +0100670void Decoder::Format(Instruction* instr, const char* format) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000671 char cur = *format++;
672 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
673 if (cur == '\'') { // Single quote is used as the formatting escape.
674 format += FormatOption(instr, format);
675 } else {
676 out_buffer_[out_buffer_pos_++] = cur;
677 }
678 cur = *format++;
679 }
680 out_buffer_[out_buffer_pos_] = '\0';
681}
682
683
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100684// The disassembler may end up decoding data inlined in the code. We do not want
685// it to crash if the data does not ressemble any known instruction.
686#define VERIFY(condition) \
687if(!(condition)) { \
688 Unknown(instr); \
689 return; \
690}
691
692
Steve Blocka7e24c12009-10-30 11:49:00 +0000693// For currently unimplemented decodings the disassembler calls Unknown(instr)
694// which will just print "unknown" of the instruction bits.
Steve Block1e0659c2011-05-24 12:43:12 +0100695void Decoder::Unknown(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000696 Format(instr, "unknown");
697}
698
699
Steve Block1e0659c2011-05-24 12:43:12 +0100700void Decoder::DecodeType01(Instruction* instr) {
701 int type = instr->TypeValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000702 if ((type == 0) && instr->IsSpecialType0()) {
703 // multiply instruction or extra loads and stores
704 if (instr->Bits(7, 4) == 9) {
705 if (instr->Bit(24) == 0) {
706 // multiply instructions
707 if (instr->Bit(23) == 0) {
708 if (instr->Bit(21) == 0) {
709 // The MUL instruction description (A 4.1.33) refers to Rd as being
710 // the destination for the operation, but it confusingly uses the
711 // Rn field to encode it.
712 Format(instr, "mul'cond's 'rn, 'rm, 'rs");
713 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000714 if (instr->Bit(22) == 0) {
715 // The MLA instruction description (A 4.1.28) refers to the order
716 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
717 // Rn field to encode the Rd register and the Rd field to encode
718 // the Rn register.
719 Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd");
720 } else {
721 // The MLS instruction description (A 4.1.29) refers to the order
722 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
723 // Rn field to encode the Rd register and the Rd field to encode
724 // the Rn register.
725 Format(instr, "mls'cond's 'rn, 'rm, 'rs, 'rd");
726 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000727 }
728 } else {
729 // The signed/long multiply instructions use the terms RdHi and RdLo
730 // when referring to the target registers. They are mapped to the Rn
731 // and Rd fields as follows:
732 // RdLo == Rd field
733 // RdHi == Rn field
734 // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs>
735 Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs");
736 }
737 } else {
738 Unknown(instr); // not used by V8
739 }
Kristian Monsen25f61362010-05-21 11:50:48 +0100740 } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xd) == 0xd)) {
741 // ldrd, strd
742 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100743 case da_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100744 if (instr->Bit(22) == 0) {
745 Format(instr, "'memop'cond's 'rd, ['rn], -'rm");
746 } else {
747 Format(instr, "'memop'cond's 'rd, ['rn], #-'off8");
748 }
749 break;
750 }
Steve Block1e0659c2011-05-24 12:43:12 +0100751 case ia_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100752 if (instr->Bit(22) == 0) {
753 Format(instr, "'memop'cond's 'rd, ['rn], +'rm");
754 } else {
755 Format(instr, "'memop'cond's 'rd, ['rn], #+'off8");
756 }
757 break;
758 }
Steve Block1e0659c2011-05-24 12:43:12 +0100759 case db_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100760 if (instr->Bit(22) == 0) {
761 Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w");
762 } else {
763 Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w");
764 }
765 break;
766 }
Steve Block1e0659c2011-05-24 12:43:12 +0100767 case ib_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100768 if (instr->Bit(22) == 0) {
769 Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w");
770 } else {
771 Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w");
772 }
773 break;
774 }
775 default: {
776 // The PU field is a 2-bit field.
777 UNREACHABLE();
778 break;
779 }
780 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000781 } else {
782 // extra load/store instructions
783 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100784 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000785 if (instr->Bit(22) == 0) {
786 Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm");
787 } else {
788 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8");
789 }
790 break;
791 }
Steve Block1e0659c2011-05-24 12:43:12 +0100792 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000793 if (instr->Bit(22) == 0) {
794 Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm");
795 } else {
796 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8");
797 }
798 break;
799 }
Steve Block1e0659c2011-05-24 12:43:12 +0100800 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000801 if (instr->Bit(22) == 0) {
802 Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w");
803 } else {
804 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w");
805 }
806 break;
807 }
Steve Block1e0659c2011-05-24 12:43:12 +0100808 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000809 if (instr->Bit(22) == 0) {
810 Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w");
811 } else {
812 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w");
813 }
814 break;
815 }
816 default: {
817 // The PU field is a 2-bit field.
818 UNREACHABLE();
819 break;
820 }
821 }
822 return;
823 }
Steve Block6ded16b2010-05-10 14:33:55 +0100824 } else if ((type == 0) && instr->IsMiscType0()) {
825 if (instr->Bits(22, 21) == 1) {
Steve Block1e0659c2011-05-24 12:43:12 +0100826 switch (instr->BitField(7, 4)) {
Steve Block6ded16b2010-05-10 14:33:55 +0100827 case BX:
828 Format(instr, "bx'cond 'rm");
829 break;
830 case BLX:
831 Format(instr, "blx'cond 'rm");
832 break;
833 case BKPT:
834 Format(instr, "bkpt 'off0to3and8to19");
835 break;
836 default:
837 Unknown(instr); // not used by V8
838 break;
839 }
840 } else if (instr->Bits(22, 21) == 3) {
Steve Block1e0659c2011-05-24 12:43:12 +0100841 switch (instr->BitField(7, 4)) {
Steve Block6ded16b2010-05-10 14:33:55 +0100842 case CLZ:
843 Format(instr, "clz'cond 'rd, 'rm");
844 break;
845 default:
846 Unknown(instr); // not used by V8
847 break;
848 }
849 } else {
850 Unknown(instr); // not used by V8
851 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000852 } else if ((type == 1) && instr->IsNopType1()) {
853 Format(instr, "nop'cond");
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 } else {
855 switch (instr->OpcodeField()) {
856 case AND: {
857 Format(instr, "and'cond's 'rd, 'rn, 'shift_op");
858 break;
859 }
860 case EOR: {
861 Format(instr, "eor'cond's 'rd, 'rn, 'shift_op");
862 break;
863 }
864 case SUB: {
865 Format(instr, "sub'cond's 'rd, 'rn, 'shift_op");
866 break;
867 }
868 case RSB: {
869 Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op");
870 break;
871 }
872 case ADD: {
873 Format(instr, "add'cond's 'rd, 'rn, 'shift_op");
874 break;
875 }
876 case ADC: {
877 Format(instr, "adc'cond's 'rd, 'rn, 'shift_op");
878 break;
879 }
880 case SBC: {
881 Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op");
882 break;
883 }
884 case RSC: {
885 Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op");
886 break;
887 }
888 case TST: {
889 if (instr->HasS()) {
890 Format(instr, "tst'cond 'rn, 'shift_op");
891 } else {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100892 Format(instr, "movw'cond 'mw");
Steve Blocka7e24c12009-10-30 11:49:00 +0000893 }
894 break;
895 }
896 case TEQ: {
897 if (instr->HasS()) {
898 Format(instr, "teq'cond 'rn, 'shift_op");
899 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100900 // Other instructions matching this pattern are handled in the
901 // miscellaneous instructions part above.
902 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000903 }
904 break;
905 }
906 case CMP: {
907 if (instr->HasS()) {
908 Format(instr, "cmp'cond 'rn, 'shift_op");
909 } else {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100910 Format(instr, "movt'cond 'mw");
Steve Blocka7e24c12009-10-30 11:49:00 +0000911 }
912 break;
913 }
914 case CMN: {
915 if (instr->HasS()) {
916 Format(instr, "cmn'cond 'rn, 'shift_op");
917 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100918 // Other instructions matching this pattern are handled in the
919 // miscellaneous instructions part above.
920 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000921 }
922 break;
923 }
924 case ORR: {
925 Format(instr, "orr'cond's 'rd, 'rn, 'shift_op");
926 break;
927 }
928 case MOV: {
929 Format(instr, "mov'cond's 'rd, 'shift_op");
930 break;
931 }
932 case BIC: {
933 Format(instr, "bic'cond's 'rd, 'rn, 'shift_op");
934 break;
935 }
936 case MVN: {
937 Format(instr, "mvn'cond's 'rd, 'shift_op");
938 break;
939 }
940 default: {
941 // The Opcode field is a 4-bit field.
942 UNREACHABLE();
943 break;
944 }
945 }
946 }
947}
948
949
Steve Block1e0659c2011-05-24 12:43:12 +0100950void Decoder::DecodeType2(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000951 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100952 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000953 if (instr->HasW()) {
954 Unknown(instr); // not used in V8
Steve Block44f0eee2011-05-26 01:26:41 +0100955 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000956 }
957 Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12");
958 break;
959 }
Steve Block1e0659c2011-05-24 12:43:12 +0100960 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000961 if (instr->HasW()) {
962 Unknown(instr); // not used in V8
Steve Block44f0eee2011-05-26 01:26:41 +0100963 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000964 }
965 Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12");
966 break;
967 }
Steve Block1e0659c2011-05-24 12:43:12 +0100968 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000969 Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w");
970 break;
971 }
Steve Block1e0659c2011-05-24 12:43:12 +0100972 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000973 Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w");
974 break;
975 }
976 default: {
977 // The PU field is a 2-bit field.
978 UNREACHABLE();
979 break;
980 }
981 }
982}
983
984
Steve Block1e0659c2011-05-24 12:43:12 +0100985void Decoder::DecodeType3(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000986 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100987 case da_x: {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100988 VERIFY(!instr->HasW());
Steve Blocka7e24c12009-10-30 11:49:00 +0000989 Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm");
990 break;
991 }
Steve Block1e0659c2011-05-24 12:43:12 +0100992 case ia_x: {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000993 if (instr->Bit(4) == 0) {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100994 Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm");
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000995 } else {
996 if (instr->Bit(5) == 0) {
997 switch (instr->Bits(22, 21)) {
998 case 0:
999 if (instr->Bit(20) == 0) {
1000 if (instr->Bit(6) == 0) {
1001 Format(instr, "pkhbt'cond 'rd, 'rn, 'rm, lsl #'imm05@07");
1002 } else {
1003 if (instr->Bits(11, 7) == 0) {
1004 Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #32");
1005 } else {
1006 Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #'imm05@07");
1007 }
1008 }
1009 } else {
1010 UNREACHABLE();
1011 }
1012 break;
1013 case 1:
1014 UNREACHABLE();
1015 break;
1016 case 2:
1017 UNREACHABLE();
1018 break;
1019 case 3:
1020 Format(instr, "usat 'rd, #'imm05@16, 'rm'shift_sat");
1021 break;
1022 }
1023 } else {
1024 switch (instr->Bits(22, 21)) {
1025 case 0:
1026 UNREACHABLE();
1027 break;
1028 case 1:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001029 if (instr->Bits(9, 6) == 1) {
1030 if (instr->Bit(20) == 0) {
1031 if (instr->Bits(19, 16) == 0xF) {
1032 switch (instr->Bits(11, 10)) {
1033 case 0:
1034 Format(instr, "sxtb'cond 'rd, 'rm");
1035 break;
1036 case 1:
1037 Format(instr, "sxtb'cond 'rd, 'rm, ror #8");
1038 break;
1039 case 2:
1040 Format(instr, "sxtb'cond 'rd, 'rm, ror #16");
1041 break;
1042 case 3:
1043 Format(instr, "sxtb'cond 'rd, 'rm, ror #24");
1044 break;
1045 }
1046 } else {
1047 switch (instr->Bits(11, 10)) {
1048 case 0:
1049 Format(instr, "sxtab'cond 'rd, 'rn, 'rm");
1050 break;
1051 case 1:
1052 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #8");
1053 break;
1054 case 2:
1055 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #16");
1056 break;
1057 case 3:
1058 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #24");
1059 break;
1060 }
1061 }
1062 } else {
1063 if (instr->Bits(19, 16) == 0xF) {
1064 switch (instr->Bits(11, 10)) {
1065 case 0:
1066 Format(instr, "sxth'cond 'rd, 'rm");
1067 break;
1068 case 1:
1069 Format(instr, "sxth'cond 'rd, 'rm, ror #8");
1070 break;
1071 case 2:
1072 Format(instr, "sxth'cond 'rd, 'rm, ror #16");
1073 break;
1074 case 3:
1075 Format(instr, "sxth'cond 'rd, 'rm, ror #24");
1076 break;
1077 }
1078 } else {
1079 switch (instr->Bits(11, 10)) {
1080 case 0:
1081 Format(instr, "sxtah'cond 'rd, 'rn, 'rm");
1082 break;
1083 case 1:
1084 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #8");
1085 break;
1086 case 2:
1087 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #16");
1088 break;
1089 case 3:
1090 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #24");
1091 break;
1092 }
1093 }
1094 }
1095 } else {
1096 UNREACHABLE();
1097 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001098 break;
1099 case 2:
1100 if ((instr->Bit(20) == 0) && (instr->Bits(9, 6) == 1)) {
1101 if (instr->Bits(19, 16) == 0xF) {
1102 switch (instr->Bits(11, 10)) {
1103 case 0:
1104 Format(instr, "uxtb16'cond 'rd, 'rm");
1105 break;
1106 case 1:
1107 Format(instr, "uxtb16'cond 'rd, 'rm, ror #8");
1108 break;
1109 case 2:
1110 Format(instr, "uxtb16'cond 'rd, 'rm, ror #16");
1111 break;
1112 case 3:
1113 Format(instr, "uxtb16'cond 'rd, 'rm, ror #24");
1114 break;
1115 }
1116 } else {
1117 UNREACHABLE();
1118 }
1119 } else {
1120 UNREACHABLE();
1121 }
1122 break;
1123 case 3:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001124 if ((instr->Bits(9, 6) == 1)) {
1125 if ((instr->Bit(20) == 0)) {
1126 if (instr->Bits(19, 16) == 0xF) {
1127 switch (instr->Bits(11, 10)) {
1128 case 0:
1129 Format(instr, "uxtb'cond 'rd, 'rm");
1130 break;
1131 case 1:
1132 Format(instr, "uxtb'cond 'rd, 'rm, ror #8");
1133 break;
1134 case 2:
1135 Format(instr, "uxtb'cond 'rd, 'rm, ror #16");
1136 break;
1137 case 3:
1138 Format(instr, "uxtb'cond 'rd, 'rm, ror #24");
1139 break;
1140 }
1141 } else {
1142 switch (instr->Bits(11, 10)) {
1143 case 0:
1144 Format(instr, "uxtab'cond 'rd, 'rn, 'rm");
1145 break;
1146 case 1:
1147 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #8");
1148 break;
1149 case 2:
1150 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #16");
1151 break;
1152 case 3:
1153 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #24");
1154 break;
1155 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001156 }
1157 } else {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001158 if (instr->Bits(19, 16) == 0xF) {
1159 switch (instr->Bits(11, 10)) {
1160 case 0:
1161 Format(instr, "uxth'cond 'rd, 'rm");
1162 break;
1163 case 1:
1164 Format(instr, "uxth'cond 'rd, 'rm, ror #8");
1165 break;
1166 case 2:
1167 Format(instr, "uxth'cond 'rd, 'rm, ror #16");
1168 break;
1169 case 3:
1170 Format(instr, "uxth'cond 'rd, 'rm, ror #24");
1171 break;
1172 }
1173 } else {
1174 switch (instr->Bits(11, 10)) {
1175 case 0:
1176 Format(instr, "uxtah'cond 'rd, 'rn, 'rm");
1177 break;
1178 case 1:
1179 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #8");
1180 break;
1181 case 2:
1182 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #16");
1183 break;
1184 case 3:
1185 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #24");
1186 break;
1187 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001188 }
1189 }
1190 } else {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001191 // PU == 0b01, BW == 0b11, Bits(9, 6) != 0b0001
1192 if ((instr->Bits(20, 16) == 0x1f) &&
1193 (instr->Bits(11, 4) == 0xf3)) {
1194 Format(instr, "rbit'cond 'rd, 'rm");
1195 } else {
1196 UNREACHABLE();
1197 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001198 }
1199 break;
1200 }
1201 }
Kristian Monsen50ef84f2010-07-29 15:18:00 +01001202 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001203 break;
1204 }
Steve Block1e0659c2011-05-24 12:43:12 +01001205 case db_x: {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001206 if (instr->Bits(22, 20) == 0x5) {
1207 if (instr->Bits(7, 4) == 0x1) {
1208 if (instr->Bits(15, 12) == 0xF) {
1209 Format(instr, "smmul'cond 'rn, 'rm, 'rs");
1210 } else {
1211 // SMMLA (in V8 notation matching ARM ISA format)
1212 Format(instr, "smmla'cond 'rn, 'rm, 'rs, 'rd");
1213 }
1214 break;
1215 }
1216 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001217 if (FLAG_enable_sudiv) {
1218 if (instr->Bits(5, 4) == 0x1) {
1219 if ((instr->Bit(22) == 0x0) && (instr->Bit(20) == 0x1)) {
1220 if (instr->Bit(21) == 0x1) {
1221 // UDIV (in V8 notation matching ARM ISA format) rn = rm/rs
1222 Format(instr, "udiv'cond'b 'rn, 'rm, 'rs");
1223 } else {
1224 // SDIV (in V8 notation matching ARM ISA format) rn = rm/rs
1225 Format(instr, "sdiv'cond'b 'rn, 'rm, 'rs");
1226 }
1227 break;
1228 }
1229 }
1230 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001231 Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w");
1232 break;
1233 }
Steve Block1e0659c2011-05-24 12:43:12 +01001234 case ib_x: {
Andrei Popescu31002712010-02-23 13:46:05 +00001235 if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) {
1236 uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001237 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
Andrei Popescu31002712010-02-23 13:46:05 +00001238 uint32_t msbit = widthminus1 + lsbit;
1239 if (msbit <= 31) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001240 if (instr->Bit(22)) {
1241 Format(instr, "ubfx'cond 'rd, 'rm, 'f");
1242 } else {
1243 Format(instr, "sbfx'cond 'rd, 'rm, 'f");
1244 }
1245 } else {
1246 UNREACHABLE();
1247 }
1248 } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) {
1249 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
1250 uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16));
1251 if (msbit >= lsbit) {
Steve Block1e0659c2011-05-24 12:43:12 +01001252 if (instr->RmValue() == 15) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001253 Format(instr, "bfc'cond 'rd, 'f");
1254 } else {
1255 Format(instr, "bfi'cond 'rd, 'rm, 'f");
1256 }
Andrei Popescu31002712010-02-23 13:46:05 +00001257 } else {
1258 UNREACHABLE();
1259 }
1260 } else {
1261 Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w");
1262 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001263 break;
1264 }
1265 default: {
1266 // The PU field is a 2-bit field.
1267 UNREACHABLE();
1268 break;
1269 }
1270 }
1271}
1272
1273
Steve Block1e0659c2011-05-24 12:43:12 +01001274void Decoder::DecodeType4(Instruction* instr) {
Steve Block44f0eee2011-05-26 01:26:41 +01001275 if (instr->Bit(22) != 0) {
1276 // Privileged mode currently not supported.
1277 Unknown(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001278 } else {
Steve Block44f0eee2011-05-26 01:26:41 +01001279 if (instr->HasL()) {
1280 Format(instr, "ldm'cond'pu 'rn'w, 'rlist");
1281 } else {
1282 Format(instr, "stm'cond'pu 'rn'w, 'rlist");
1283 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001284 }
1285}
1286
1287
Steve Block1e0659c2011-05-24 12:43:12 +01001288void Decoder::DecodeType5(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001289 Format(instr, "b'l'cond 'target");
1290}
1291
1292
Steve Block1e0659c2011-05-24 12:43:12 +01001293void Decoder::DecodeType6(Instruction* instr) {
Steve Blockd0582a62009-12-15 09:54:21 +00001294 DecodeType6CoprocessorIns(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001295}
1296
1297
Steve Block1e0659c2011-05-24 12:43:12 +01001298int Decoder::DecodeType7(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001299 if (instr->Bit(24) == 1) {
Steve Block1e0659c2011-05-24 12:43:12 +01001300 if (instr->SvcValue() >= kStopCode) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001301 Format(instr, "stop'cond 'svc");
1302 // Also print the stop message. Its address is encoded
1303 // in the following 4 bytes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001304 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1305 "\n %p %08x stop message: %s",
1306 reinterpret_cast<void*>(instr
1307 + Instruction::kInstrSize),
1308 *reinterpret_cast<uint32_t*>(instr
1309 + Instruction::kInstrSize),
1310 *reinterpret_cast<char**>(instr
1311 + Instruction::kInstrSize));
Steve Block1e0659c2011-05-24 12:43:12 +01001312 // We have decoded 2 * Instruction::kInstrSize bytes.
1313 return 2 * Instruction::kInstrSize;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001314 } else {
1315 Format(instr, "svc'cond 'svc");
1316 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001317 } else {
Steve Blockd0582a62009-12-15 09:54:21 +00001318 DecodeTypeVFP(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001319 }
Steve Block1e0659c2011-05-24 12:43:12 +01001320 return Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001321}
1322
1323
Steve Block1e0659c2011-05-24 12:43:12 +01001324// void Decoder::DecodeTypeVFP(Instruction* instr)
Leon Clarkee46be812010-01-19 14:06:41 +00001325// vmov: Sn = Rt
1326// vmov: Rt = Sn
1327// vcvt: Dd = Sm
1328// vcvt: Sd = Dm
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001329// vcvt.f64.s32 Dd, Dd, #<fbits>
Steve Block44f0eee2011-05-26 01:26:41 +01001330// Dd = vabs(Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001331// Sd = vabs(Sm)
Steve Block44f0eee2011-05-26 01:26:41 +01001332// Dd = vneg(Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001333// Sd = vneg(Sm)
Leon Clarkee46be812010-01-19 14:06:41 +00001334// Dd = vadd(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001335// Sd = vadd(Sn, Sm)
Leon Clarkee46be812010-01-19 14:06:41 +00001336// Dd = vsub(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001337// Sd = vsub(Sn, Sm)
Leon Clarkee46be812010-01-19 14:06:41 +00001338// Dd = vmul(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001339// Sd = vmul(Sn, Sm)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001340// Dd = vmla(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001341// Sd = vmla(Sn, Sm)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001342// Dd = vmls(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001343// Sd = vmls(Sn, Sm)
Leon Clarkee46be812010-01-19 14:06:41 +00001344// Dd = vdiv(Dn, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001345// Sd = vdiv(Sn, Sm)
Steve Blockd0582a62009-12-15 09:54:21 +00001346// vcmp(Dd, Dm)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001347// vcmp(Sd, Sm)
1348// Dd = vsqrt(Dm)
1349// Sd = vsqrt(Sm)
Steve Block8defd9f2010-07-08 12:39:36 +01001350// vmrs
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001351// vmsr
Steve Block1e0659c2011-05-24 12:43:12 +01001352void Decoder::DecodeTypeVFP(Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001353 VERIFY((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0) );
1354 VERIFY(instr->Bits(11, 9) == 0x5);
Steve Blockd0582a62009-12-15 09:54:21 +00001355
Steve Block6ded16b2010-05-10 14:33:55 +01001356 if (instr->Bit(4) == 0) {
Steve Block1e0659c2011-05-24 12:43:12 +01001357 if (instr->Opc1Value() == 0x7) {
Steve Block6ded16b2010-05-10 14:33:55 +01001358 // Other data processing instructions
Steve Block1e0659c2011-05-24 12:43:12 +01001359 if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x1)) {
Steve Block8defd9f2010-07-08 12:39:36 +01001360 // vmov register to register.
Steve Block1e0659c2011-05-24 12:43:12 +01001361 if (instr->SzValue() == 0x1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001362 Format(instr, "vmov'cond.f64 'Dd, 'Dm");
Steve Block8defd9f2010-07-08 12:39:36 +01001363 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001364 Format(instr, "vmov'cond.f32 'Sd, 'Sm");
Steve Block8defd9f2010-07-08 12:39:36 +01001365 }
Steve Block1e0659c2011-05-24 12:43:12 +01001366 } else if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x3)) {
1367 // vabs
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001368 if (instr->SzValue() == 0x1) {
1369 Format(instr, "vabs'cond.f64 'Dd, 'Dm");
1370 } else {
1371 Format(instr, "vabs'cond.f32 'Sd, 'Sm");
1372 }
Steve Block44f0eee2011-05-26 01:26:41 +01001373 } else if ((instr->Opc2Value() == 0x1) && (instr->Opc3Value() == 0x1)) {
1374 // vneg
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001375 if (instr->SzValue() == 0x1) {
1376 Format(instr, "vneg'cond.f64 'Dd, 'Dm");
1377 } else {
1378 Format(instr, "vneg'cond.f32 'Sd, 'Sm");
1379 }
Steve Block1e0659c2011-05-24 12:43:12 +01001380 } else if ((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001381 DecodeVCVTBetweenDoubleAndSingle(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001382 } else if ((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001383 DecodeVCVTBetweenFloatingPointAndInteger(instr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001384 } else if ((instr->Opc2Value() == 0xA) && (instr->Opc3Value() == 0x3) &&
1385 (instr->Bit(8) == 1)) {
1386 // vcvt.f64.s32 Dd, Dd, #<fbits>
1387 int fraction_bits = 32 - ((instr->Bits(3, 0) << 1) | instr->Bit(5));
1388 Format(instr, "vcvt'cond.f64.s32 'Dd, 'Dd");
1389 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1390 ", #%d", fraction_bits);
Steve Block1e0659c2011-05-24 12:43:12 +01001391 } else if (((instr->Opc2Value() >> 1) == 0x6) &&
1392 (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001393 DecodeVCVTBetweenFloatingPointAndInteger(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001394 } else if (((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
1395 (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001396 DecodeVCMP(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001397 } else if (((instr->Opc2Value() == 0x1)) && (instr->Opc3Value() == 0x3)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001398 if (instr->SzValue() == 0x1) {
1399 Format(instr, "vsqrt'cond.f64 'Dd, 'Dm");
1400 } else {
1401 Format(instr, "vsqrt'cond.f32 'Sd, 'Sm");
1402 }
Steve Block1e0659c2011-05-24 12:43:12 +01001403 } else if (instr->Opc3Value() == 0x0) {
1404 if (instr->SzValue() == 0x1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001405 Format(instr, "vmov'cond.f64 'Dd, 'd");
Ben Murdoch3bec4d22010-07-22 14:51:16 +01001406 } else {
1407 Unknown(instr); // Not used by V8.
1408 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001409 } else if (((instr->Opc2Value() == 0x6)) && instr->Opc3Value() == 0x3) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001410 // vrintz - round towards zero (truncate)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001411 if (instr->SzValue() == 0x1) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001412 Format(instr, "vrintz'cond.f64.f64 'Dd, 'Dm");
1413 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001414 Format(instr, "vrintz'cond.f32.f32 'Sd, 'Sm");
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001415 }
Steve Block6ded16b2010-05-10 14:33:55 +01001416 } else {
1417 Unknown(instr); // Not used by V8.
1418 }
Steve Block1e0659c2011-05-24 12:43:12 +01001419 } else if (instr->Opc1Value() == 0x3) {
1420 if (instr->SzValue() == 0x1) {
1421 if (instr->Opc3Value() & 0x1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001422 Format(instr, "vsub'cond.f64 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001423 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001424 Format(instr, "vadd'cond.f64 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001425 }
1426 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001427 if (instr->Opc3Value() & 0x1) {
1428 Format(instr, "vsub'cond.f32 'Sd, 'Sn, 'Sm");
1429 } else {
1430 Format(instr, "vadd'cond.f32 'Sd, 'Sn, 'Sm");
1431 }
Steve Block6ded16b2010-05-10 14:33:55 +01001432 }
Steve Block1e0659c2011-05-24 12:43:12 +01001433 } else if ((instr->Opc1Value() == 0x2) && !(instr->Opc3Value() & 0x1)) {
1434 if (instr->SzValue() == 0x1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001435 Format(instr, "vmul'cond.f64 'Dd, 'Dn, 'Dm");
1436 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001437 Format(instr, "vmul'cond.f32 'Sd, 'Sn, 'Sm");
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001438 }
1439 } else if ((instr->Opc1Value() == 0x0) && !(instr->Opc3Value() & 0x1)) {
1440 if (instr->SzValue() == 0x1) {
1441 Format(instr, "vmla'cond.f64 'Dd, 'Dn, 'Dm");
1442 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001443 Format(instr, "vmla'cond.f32 'Sd, 'Sn, 'Sm");
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001444 }
1445 } else if ((instr->Opc1Value() == 0x0) && (instr->Opc3Value() & 0x1)) {
1446 if (instr->SzValue() == 0x1) {
1447 Format(instr, "vmls'cond.f64 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001448 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001449 Format(instr, "vmls'cond.f32 'Sd, 'Sn, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001450 }
Steve Block1e0659c2011-05-24 12:43:12 +01001451 } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) {
1452 if (instr->SzValue() == 0x1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001453 Format(instr, "vdiv'cond.f64 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001454 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001455 Format(instr, "vdiv'cond.f32 'Sd, 'Sn, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001456 }
Steve Blockd0582a62009-12-15 09:54:21 +00001457 } else {
1458 Unknown(instr); // Not used by V8.
1459 }
1460 } else {
Steve Block1e0659c2011-05-24 12:43:12 +01001461 if ((instr->VCValue() == 0x0) &&
1462 (instr->VAValue() == 0x0)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001463 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001464 } else if ((instr->VLValue() == 0x0) &&
1465 (instr->VCValue() == 0x1) &&
1466 (instr->Bit(23) == 0x0)) {
1467 if (instr->Bit(21) == 0x0) {
1468 Format(instr, "vmov'cond.32 'Dd[0], 'rt");
1469 } else {
1470 Format(instr, "vmov'cond.32 'Dd[1], 'rt");
1471 }
1472 } else if ((instr->VLValue() == 0x1) &&
1473 (instr->VCValue() == 0x1) &&
1474 (instr->Bit(23) == 0x0)) {
1475 if (instr->Bit(21) == 0x0) {
1476 Format(instr, "vmov'cond.32 'rt, 'Dd[0]");
1477 } else {
1478 Format(instr, "vmov'cond.32 'rt, 'Dd[1]");
1479 }
Steve Block1e0659c2011-05-24 12:43:12 +01001480 } else if ((instr->VCValue() == 0x0) &&
1481 (instr->VAValue() == 0x7) &&
Steve Block6ded16b2010-05-10 14:33:55 +01001482 (instr->Bits(19, 16) == 0x1)) {
Steve Block1e0659c2011-05-24 12:43:12 +01001483 if (instr->VLValue() == 0) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001484 if (instr->Bits(15, 12) == 0xF) {
1485 Format(instr, "vmsr'cond FPSCR, APSR");
1486 } else {
1487 Format(instr, "vmsr'cond FPSCR, 'rt");
1488 }
1489 } else {
1490 if (instr->Bits(15, 12) == 0xF) {
1491 Format(instr, "vmrs'cond APSR, FPSCR");
1492 } else {
1493 Format(instr, "vmrs'cond 'rt, FPSCR");
1494 }
1495 }
Steve Blockd0582a62009-12-15 09:54:21 +00001496 }
1497 }
1498}
1499
1500
Steve Block1e0659c2011-05-24 12:43:12 +01001501void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(
1502 Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001503 VERIFY((instr->Bit(4) == 1) && (instr->VCValue() == 0x0) &&
Steve Block1e0659c2011-05-24 12:43:12 +01001504 (instr->VAValue() == 0x0));
Steve Block6ded16b2010-05-10 14:33:55 +01001505
Steve Block1e0659c2011-05-24 12:43:12 +01001506 bool to_arm_register = (instr->VLValue() == 0x1);
Steve Block6ded16b2010-05-10 14:33:55 +01001507
1508 if (to_arm_register) {
1509 Format(instr, "vmov'cond 'rt, 'Sn");
1510 } else {
1511 Format(instr, "vmov'cond 'Sn, 'rt");
1512 }
1513}
1514
1515
Steve Block1e0659c2011-05-24 12:43:12 +01001516void Decoder::DecodeVCMP(Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001517 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1518 VERIFY(((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
Steve Block1e0659c2011-05-24 12:43:12 +01001519 (instr->Opc3Value() & 0x1));
Steve Block6ded16b2010-05-10 14:33:55 +01001520
1521 // Comparison.
Steve Block1e0659c2011-05-24 12:43:12 +01001522 bool dp_operation = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001523 bool raise_exception_for_qnan = (instr->Bit(7) == 0x1);
1524
1525 if (dp_operation && !raise_exception_for_qnan) {
Steve Block1e0659c2011-05-24 12:43:12 +01001526 if (instr->Opc2Value() == 0x4) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001527 Format(instr, "vcmp'cond.f64 'Dd, 'Dm");
Steve Block1e0659c2011-05-24 12:43:12 +01001528 } else if (instr->Opc2Value() == 0x5) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001529 Format(instr, "vcmp'cond.f64 'Dd, #0.0");
Iain Merrick75681382010-08-19 15:07:18 +01001530 } else {
1531 Unknown(instr); // invalid
1532 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001533 } else if (!raise_exception_for_qnan) {
1534 if (instr->Opc2Value() == 0x4) {
1535 Format(instr, "vcmp'cond.f32 'Sd, 'Sm");
1536 } else if (instr->Opc2Value() == 0x5) {
1537 Format(instr, "vcmp'cond.f32 'Sd, #0.0");
1538 } else {
1539 Unknown(instr); // invalid
1540 }
Steve Block6ded16b2010-05-10 14:33:55 +01001541 } else {
1542 Unknown(instr); // Not used by V8.
1543 }
1544}
1545
1546
Steve Block1e0659c2011-05-24 12:43:12 +01001547void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001548 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1549 VERIFY((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3));
Steve Block6ded16b2010-05-10 14:33:55 +01001550
Steve Block1e0659c2011-05-24 12:43:12 +01001551 bool double_to_single = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001552
1553 if (double_to_single) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001554 Format(instr, "vcvt'cond.f32.f64 'Sd, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001555 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001556 Format(instr, "vcvt'cond.f64.f32 'Dd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001557 }
1558}
1559
1560
Steve Block1e0659c2011-05-24 12:43:12 +01001561void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001562 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1563 VERIFY(((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) ||
Steve Block1e0659c2011-05-24 12:43:12 +01001564 (((instr->Opc2Value() >> 1) == 0x6) && (instr->Opc3Value() & 0x1)));
Steve Block6ded16b2010-05-10 14:33:55 +01001565
1566 bool to_integer = (instr->Bit(18) == 1);
Steve Block1e0659c2011-05-24 12:43:12 +01001567 bool dp_operation = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001568 if (to_integer) {
1569 bool unsigned_integer = (instr->Bit(16) == 0);
1570
1571 if (dp_operation) {
1572 if (unsigned_integer) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001573 Format(instr, "vcvt'cond.u32.f64 'Sd, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001574 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001575 Format(instr, "vcvt'cond.s32.f64 'Sd, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001576 }
1577 } else {
1578 if (unsigned_integer) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001579 Format(instr, "vcvt'cond.u32.f32 'Sd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001580 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001581 Format(instr, "vcvt'cond.s32.f32 'Sd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001582 }
1583 }
1584 } else {
1585 bool unsigned_integer = (instr->Bit(7) == 0);
1586
1587 if (dp_operation) {
1588 if (unsigned_integer) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001589 Format(instr, "vcvt'cond.f64.u32 'Dd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001590 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001591 Format(instr, "vcvt'cond.f64.s32 'Dd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001592 }
1593 } else {
1594 if (unsigned_integer) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001595 Format(instr, "vcvt'cond.f32.u32 'Sd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001596 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001597 Format(instr, "vcvt'cond.f32.s32 'Sd, 'Sm");
Steve Block6ded16b2010-05-10 14:33:55 +01001598 }
1599 }
1600 }
1601}
1602
1603
Steve Blockd0582a62009-12-15 09:54:21 +00001604// Decode Type 6 coprocessor instructions.
Leon Clarkee46be812010-01-19 14:06:41 +00001605// Dm = vmov(Rt, Rt2)
1606// <Rt, Rt2> = vmov(Dm)
Leon Clarked91b9f72010-01-27 17:25:45 +00001607// Ddst = MEM(Rbase + 4*offset).
1608// MEM(Rbase + 4*offset) = Dsrc.
Steve Block1e0659c2011-05-24 12:43:12 +01001609void Decoder::DecodeType6CoprocessorIns(Instruction* instr) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001610 VERIFY(instr->TypeValue() == 6);
Steve Blockd0582a62009-12-15 09:54:21 +00001611
Steve Block1e0659c2011-05-24 12:43:12 +01001612 if (instr->CoprocessorValue() == 0xA) {
1613 switch (instr->OpcodeValue()) {
Steve Block6ded16b2010-05-10 14:33:55 +01001614 case 0x8:
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001615 case 0xA:
Steve Block6ded16b2010-05-10 14:33:55 +01001616 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001617 Format(instr, "vldr'cond 'Sd, ['rn - 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001618 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001619 Format(instr, "vstr'cond 'Sd, ['rn - 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001620 }
1621 break;
1622 case 0xC:
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001623 case 0xE:
Steve Block6ded16b2010-05-10 14:33:55 +01001624 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001625 Format(instr, "vldr'cond 'Sd, ['rn + 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001626 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001627 Format(instr, "vstr'cond 'Sd, ['rn + 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001628 }
1629 break;
Ben Murdoch8b112d22011-06-08 16:22:53 +01001630 case 0x4:
1631 case 0x5:
1632 case 0x6:
1633 case 0x7:
1634 case 0x9:
1635 case 0xB: {
1636 bool to_vfp_register = (instr->VLValue() == 0x1);
1637 if (to_vfp_register) {
1638 Format(instr, "vldm'cond'pu 'rn'w, {'Sd-'Sd+}");
1639 } else {
1640 Format(instr, "vstm'cond'pu 'rn'w, {'Sd-'Sd+}");
1641 }
1642 break;
1643 }
Steve Block6ded16b2010-05-10 14:33:55 +01001644 default:
1645 Unknown(instr); // Not used by V8.
Steve Block6ded16b2010-05-10 14:33:55 +01001646 }
Steve Block1e0659c2011-05-24 12:43:12 +01001647 } else if (instr->CoprocessorValue() == 0xB) {
1648 switch (instr->OpcodeValue()) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001649 case 0x2:
1650 // Load and store double to two GP registers
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001651 if (instr->Bits(7, 6) != 0 || instr->Bit(4) != 1) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001652 Unknown(instr); // Not used by V8.
1653 } else if (instr->HasL()) {
1654 Format(instr, "vmov'cond 'rt, 'rn, 'Dm");
1655 } else {
1656 Format(instr, "vmov'cond 'Dm, 'rt, 'rn");
1657 }
1658 break;
1659 case 0x8:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001660 case 0xA:
Leon Clarked91b9f72010-01-27 17:25:45 +00001661 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001662 Format(instr, "vldr'cond 'Dd, ['rn - 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001663 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001664 Format(instr, "vstr'cond 'Dd, ['rn - 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001665 }
1666 break;
1667 case 0xC:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001668 case 0xE:
Leon Clarked91b9f72010-01-27 17:25:45 +00001669 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001670 Format(instr, "vldr'cond 'Dd, ['rn + 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001671 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001672 Format(instr, "vstr'cond 'Dd, ['rn + 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001673 }
1674 break;
Ben Murdoch8b112d22011-06-08 16:22:53 +01001675 case 0x4:
1676 case 0x5:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001677 case 0x6:
1678 case 0x7:
1679 case 0x9:
1680 case 0xB: {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001681 bool to_vfp_register = (instr->VLValue() == 0x1);
1682 if (to_vfp_register) {
1683 Format(instr, "vldm'cond'pu 'rn'w, {'Dd-'Dd+}");
1684 } else {
1685 Format(instr, "vstm'cond'pu 'rn'w, {'Dd-'Dd+}");
1686 }
1687 break;
1688 }
Leon Clarked91b9f72010-01-27 17:25:45 +00001689 default:
1690 Unknown(instr); // Not used by V8.
Leon Clarked91b9f72010-01-27 17:25:45 +00001691 }
Steve Block6ded16b2010-05-10 14:33:55 +01001692 } else {
Steve Block44f0eee2011-05-26 01:26:41 +01001693 Unknown(instr); // Not used by V8.
1694 }
1695}
1696
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001697
Ben Murdoch097c5b22016-05-18 11:27:45 +01001698static const char* const barrier_option_names[] = {
1699 "invalid", "oshld", "oshst", "osh", "invalid", "nshld", "nshst", "nsh",
1700 "invalid", "ishld", "ishst", "ish", "invalid", "ld", "st", "sy",
1701};
1702
1703
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001704void Decoder::DecodeSpecialCondition(Instruction* instr) {
1705 switch (instr->SpecialValue()) {
1706 case 5:
1707 if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) &&
1708 (instr->Bit(4) == 1)) {
1709 // vmovl signed
1710 if ((instr->VdValue() & 1) != 0) Unknown(instr);
1711 int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1);
1712 int Vm = (instr->Bit(5) << 4) | instr->VmValue();
1713 int imm3 = instr->Bits(21, 19);
1714 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1715 "vmovl.s%d q%d, d%d", imm3*8, Vd, Vm);
1716 } else {
1717 Unknown(instr);
1718 }
1719 break;
1720 case 7:
1721 if ((instr->Bits(18, 16) == 0) && (instr->Bits(11, 6) == 0x28) &&
1722 (instr->Bit(4) == 1)) {
1723 // vmovl unsigned
1724 if ((instr->VdValue() & 1) != 0) Unknown(instr);
1725 int Vd = (instr->Bit(22) << 3) | (instr->VdValue() >> 1);
1726 int Vm = (instr->Bit(5) << 4) | instr->VmValue();
1727 int imm3 = instr->Bits(21, 19);
1728 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1729 "vmovl.u%d q%d, d%d", imm3*8, Vd, Vm);
1730 } else {
1731 Unknown(instr);
1732 }
1733 break;
1734 case 8:
1735 if (instr->Bits(21, 20) == 0) {
1736 // vst1
1737 int Vd = (instr->Bit(22) << 4) | instr->VdValue();
1738 int Rn = instr->VnValue();
1739 int type = instr->Bits(11, 8);
1740 int size = instr->Bits(7, 6);
1741 int align = instr->Bits(5, 4);
1742 int Rm = instr->VmValue();
1743 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1744 "vst1.%d ", (1 << size) << 3);
1745 FormatNeonList(Vd, type);
1746 Print(", ");
1747 FormatNeonMemory(Rn, align, Rm);
1748 } else if (instr->Bits(21, 20) == 2) {
1749 // vld1
1750 int Vd = (instr->Bit(22) << 4) | instr->VdValue();
1751 int Rn = instr->VnValue();
1752 int type = instr->Bits(11, 8);
1753 int size = instr->Bits(7, 6);
1754 int align = instr->Bits(5, 4);
1755 int Rm = instr->VmValue();
1756 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1757 "vld1.%d ", (1 << size) << 3);
1758 FormatNeonList(Vd, type);
1759 Print(", ");
1760 FormatNeonMemory(Rn, align, Rm);
1761 } else {
1762 Unknown(instr);
1763 }
1764 break;
1765 case 0xA:
1766 case 0xB:
1767 if ((instr->Bits(22, 20) == 5) && (instr->Bits(15, 12) == 0xf)) {
1768 int Rn = instr->Bits(19, 16);
1769 int offset = instr->Bits(11, 0);
1770 if (offset == 0) {
1771 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1772 "pld [r%d]", Rn);
1773 } else if (instr->Bit(23) == 0) {
1774 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1775 "pld [r%d, #-%d]", Rn, offset);
1776 } else {
1777 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1778 "pld [r%d, #+%d]", Rn, offset);
1779 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001780 } else if (instr->SpecialValue() == 0xA && instr->Bits(22, 20) == 7) {
1781 int option = instr->Bits(3, 0);
1782 switch (instr->Bits(7, 4)) {
1783 case 4:
1784 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1785 "dsb %s", barrier_option_names[option]);
1786 break;
1787 case 5:
1788 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1789 "dmb %s", barrier_option_names[option]);
1790 break;
1791 case 6:
1792 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1793 "isb %s", barrier_option_names[option]);
1794 break;
1795 default:
1796 Unknown(instr);
1797 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001798 } else {
1799 Unknown(instr);
1800 }
1801 break;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001802 case 0x1D:
1803 if (instr->Opc1Value() == 0x7 && instr->Bits(19, 18) == 0x2 &&
1804 instr->Bits(11, 9) == 0x5 && instr->Bits(7, 6) == 0x1 &&
1805 instr->Bit(4) == 0x0) {
1806 // VRINTA, VRINTN, VRINTP, VRINTM (floating-point)
1807 bool dp_operation = (instr->SzValue() == 1);
1808 int rounding_mode = instr->Bits(17, 16);
1809 switch (rounding_mode) {
1810 case 0x0:
1811 if (dp_operation) {
1812 Format(instr, "vrinta.f64.f64 'Dd, 'Dm");
1813 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001814 Format(instr, "vrinta.f32.f32 'Sd, 'Sm");
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001815 }
1816 break;
1817 case 0x1:
1818 if (dp_operation) {
1819 Format(instr, "vrintn.f64.f64 'Dd, 'Dm");
1820 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001821 Format(instr, "vrintn.f32.f32 'Sd, 'Sm");
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001822 }
1823 break;
1824 case 0x2:
1825 if (dp_operation) {
1826 Format(instr, "vrintp.f64.f64 'Dd, 'Dm");
1827 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001828 Format(instr, "vrintp.f32.f32 'Sd, 'Sm");
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001829 }
1830 break;
1831 case 0x3:
1832 if (dp_operation) {
1833 Format(instr, "vrintm.f64.f64 'Dd, 'Dm");
1834 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001835 Format(instr, "vrintm.f32.f32 'Sd, 'Sm");
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001836 }
1837 break;
1838 default:
1839 UNREACHABLE(); // Case analysis is exhaustive.
1840 break;
1841 }
1842 } else {
1843 Unknown(instr);
1844 }
1845 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001846 default:
1847 Unknown(instr);
1848 break;
1849 }
1850}
1851
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001852#undef VERIFIY
Steve Block44f0eee2011-05-26 01:26:41 +01001853
1854bool Decoder::IsConstantPoolAt(byte* instr_ptr) {
1855 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
1856 return (instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker;
1857}
1858
1859
1860int Decoder::ConstantPoolSizeAt(byte* instr_ptr) {
1861 if (IsConstantPoolAt(instr_ptr)) {
1862 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001863 return DecodeConstantPoolLength(instruction_bits);
Steve Block44f0eee2011-05-26 01:26:41 +01001864 } else {
1865 return -1;
Steve Blockd0582a62009-12-15 09:54:21 +00001866 }
1867}
1868
1869
Steve Blocka7e24c12009-10-30 11:49:00 +00001870// Disassemble the instruction at *instr_ptr into the output buffer.
1871int Decoder::InstructionDecode(byte* instr_ptr) {
Steve Block1e0659c2011-05-24 12:43:12 +01001872 Instruction* instr = Instruction::At(instr_ptr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001873 // Print raw instruction bytes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001874 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1875 "%08x ",
1876 instr->InstructionBits());
Steve Block1e0659c2011-05-24 12:43:12 +01001877 if (instr->ConditionField() == kSpecialCondition) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001878 DecodeSpecialCondition(instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001879 return Instruction::kInstrSize;
1880 }
1881 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
1882 if ((instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001883 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
1884 "constant pool begin (length %d)",
1885 DecodeConstantPoolLength(instruction_bits));
Steve Block1e0659c2011-05-24 12:43:12 +01001886 return Instruction::kInstrSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001887 } else if (instruction_bits == kCodeAgeJumpInstruction) {
1888 // The code age prologue has a constant immediatly following the jump
1889 // instruction.
1890 Instruction* target = Instruction::At(instr_ptr + Instruction::kInstrSize);
1891 DecodeType2(instr);
1892 SNPrintF(out_buffer_ + out_buffer_pos_,
1893 " (0x%08x)", target->InstructionBits());
1894 return 2 * Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001895 }
Steve Block1e0659c2011-05-24 12:43:12 +01001896 switch (instr->TypeValue()) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001897 case 0:
1898 case 1: {
1899 DecodeType01(instr);
1900 break;
1901 }
1902 case 2: {
1903 DecodeType2(instr);
1904 break;
1905 }
1906 case 3: {
1907 DecodeType3(instr);
1908 break;
1909 }
1910 case 4: {
1911 DecodeType4(instr);
1912 break;
1913 }
1914 case 5: {
1915 DecodeType5(instr);
1916 break;
1917 }
1918 case 6: {
1919 DecodeType6(instr);
1920 break;
1921 }
1922 case 7: {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001923 return DecodeType7(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001924 }
1925 default: {
1926 // The type field is 3-bits in the ARM encoding.
1927 UNREACHABLE();
1928 break;
1929 }
1930 }
Steve Block1e0659c2011-05-24 12:43:12 +01001931 return Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001932}
1933
1934
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001935} // namespace internal
1936} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001937
1938
1939//------------------------------------------------------------------------------
1940
1941namespace disasm {
1942
Steve Blocka7e24c12009-10-30 11:49:00 +00001943
1944const char* NameConverter::NameOfAddress(byte* addr) const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001945 v8::internal::SNPrintF(tmp_buffer_, "%p", addr);
Steve Block44f0eee2011-05-26 01:26:41 +01001946 return tmp_buffer_.start();
Steve Blocka7e24c12009-10-30 11:49:00 +00001947}
1948
1949
1950const char* NameConverter::NameOfConstant(byte* addr) const {
1951 return NameOfAddress(addr);
1952}
1953
1954
1955const char* NameConverter::NameOfCPURegister(int reg) const {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001956 return v8::internal::Register::from_code(reg).ToString();
Steve Blocka7e24c12009-10-30 11:49:00 +00001957}
1958
1959
1960const char* NameConverter::NameOfByteCPURegister(int reg) const {
1961 UNREACHABLE(); // ARM does not have the concept of a byte register
1962 return "nobytereg";
1963}
1964
1965
1966const char* NameConverter::NameOfXMMRegister(int reg) const {
1967 UNREACHABLE(); // ARM does not have any XMM registers
1968 return "noxmmreg";
1969}
1970
1971
1972const char* NameConverter::NameInCode(byte* addr) const {
1973 // The default name converter is called for unknown code. So we will not try
1974 // to access any memory.
1975 return "";
1976}
1977
1978
1979//------------------------------------------------------------------------------
1980
1981Disassembler::Disassembler(const NameConverter& converter)
1982 : converter_(converter) {}
1983
1984
1985Disassembler::~Disassembler() {}
1986
1987
1988int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
1989 byte* instruction) {
Steve Block1e0659c2011-05-24 12:43:12 +01001990 v8::internal::Decoder d(converter_, buffer);
Steve Blocka7e24c12009-10-30 11:49:00 +00001991 return d.InstructionDecode(instruction);
1992}
1993
1994
1995int Disassembler::ConstantPoolSizeAt(byte* instruction) {
Steve Block44f0eee2011-05-26 01:26:41 +01001996 return v8::internal::Decoder::ConstantPoolSizeAt(instruction);
Steve Blocka7e24c12009-10-30 11:49:00 +00001997}
1998
1999
2000void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) {
2001 NameConverter converter;
2002 Disassembler d(converter);
2003 for (byte* pc = begin; pc < end;) {
2004 v8::internal::EmbeddedVector<char, 128> buffer;
2005 buffer[0] = '\0';
2006 byte* prev_pc = pc;
2007 pc += d.InstructionDecode(buffer, pc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002008 v8::internal::PrintF(
2009 f, "%p %08x %s\n",
2010 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start());
Steve Blocka7e24c12009-10-30 11:49:00 +00002011 }
2012}
2013
2014
2015} // namespace disasm
Leon Clarkef7060e22010-06-03 12:02:55 +01002016
2017#endif // V8_TARGET_ARCH_ARM