v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
disasm-arm.cc
Go to the documentation of this file.
1// Copyright 2011 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
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 (uint8_t* pc = begin; pc < end;) {
14// v8::base::EmbeddedVector<char, 256> buffer;
15// uint8_t* prev_pc = pc;
16// pc += d.InstructionDecode(buffer, pc);
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#include <cassert>
26#include <cinttypes>
27#include <cstdarg>
28#include <cstdio>
29#include <cstring>
30
31#if V8_TARGET_ARCH_ARM
32
33#include "src/base/bits.h"
35#include "src/base/strings.h"
36#include "src/base/vector.h"
41
42namespace v8 {
43namespace internal {
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.
50class Decoder {
51 public:
52 Decoder(const disasm::NameConverter& converter, base::Vector<char> out_buffer)
53 : converter_(converter), out_buffer_(out_buffer), out_buffer_pos_(0) {
55 }
56
57 ~Decoder() {}
58 Decoder(const Decoder&) = delete;
59 Decoder& operator=(const Decoder&) = delete;
60
61 // Writes one disassembled instruction into 'buffer' (0-terminated).
62 // Returns the length of the disassembled machine instruction in bytes.
63 int InstructionDecode(uint8_t* instruction);
64
65 static bool IsConstantPoolAt(uint8_t* instr_ptr);
66 static int ConstantPoolSizeAt(uint8_t* instr_ptr);
67
68 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);
75 void PrintSRegister(int reg);
76 void PrintDRegister(int reg);
77 void PrintQRegister(int reg);
78 int FormatVFPRegister(Instruction* instr, const char* format,
80 void PrintMovwMovt(Instruction* instr);
81 int FormatVFPinstruction(Instruction* instr, const char* format);
82 void PrintCondition(Instruction* instr);
83 void PrintShiftRm(Instruction* instr);
84 void PrintShiftImm(Instruction* instr);
85 void PrintShiftSat(Instruction* instr);
86 void PrintPU(Instruction* instr);
87 void PrintSoftwareInterrupt(SoftwareInterruptCodes svc);
88
89 // Handle formatting of instructions and their options.
90 int FormatRegister(Instruction* instr, const char* option);
91 void FormatNeonList(int Vd, int type);
92 void FormatNeonMemory(int Rn, int align, int Rm);
93 int FormatOption(Instruction* instr, const char* option);
94 void Format(Instruction* instr, const char* format);
95 void Unknown(Instruction* instr);
96
97 // Each of these functions decodes one particular instruction type, a 3-bit
98 // field in the instruction encoding.
99 // Types 0 and 1 are combined as they are largely the same except for the way
100 // they interpret the shifter operand.
101 void DecodeType01(Instruction* instr);
102 void DecodeType2(Instruction* instr);
103 void DecodeType3(Instruction* instr);
104 void DecodeType4(Instruction* instr);
105 void DecodeType5(Instruction* instr);
106 void DecodeType6(Instruction* instr);
107 // Type 7 includes special Debugger instructions.
108 int DecodeType7(Instruction* instr);
109 // CP15 coprocessor instructions.
110 void DecodeTypeCP15(Instruction* instr);
111 // For VFP support.
112 void DecodeTypeVFP(Instruction* instr);
113 void DecodeType6CoprocessorIns(Instruction* instr);
114
115 void DecodeSpecialCondition(Instruction* instr);
116
117 // F4.1.14 Floating-point data-processing.
118 void DecodeFloatingPointDataProcessing(Instruction* instr);
119 // F4.1.18 Unconditional instructions.
120 void DecodeUnconditional(Instruction* instr);
121 // F4.1.20 Advanced SIMD data-processing.
122 void DecodeAdvancedSIMDDataProcessing(Instruction* instr);
123 // F4.1.21 Advanced SIMD two registers, or three registers of different
124 // lengths.
125 void DecodeAdvancedSIMDTwoOrThreeRegisters(Instruction* instr);
126 // F4.1.23 Memory hints and barriers.
127 void DecodeMemoryHintsAndBarriers(Instruction* instr);
128 // F4.1.24 Advanced SIMD element or structure load/store.
129 void DecodeAdvancedSIMDElementOrStructureLoadStore(Instruction* instr);
130
131 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr);
132 void DecodeVCMP(Instruction* instr);
133 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr);
134 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr);
135 void DecodeVmovImmediate(Instruction* instr);
136
138 base::Vector<char> out_buffer_;
139 int out_buffer_pos_;
140};
141
142// Support for assertions in the Decoder formatting functions.
143#define STRING_STARTS_WITH(string, compare_string) \
144 (strncmp(string, compare_string, strlen(compare_string)) == 0)
145
146// Append the ch to the output buffer.
147void Decoder::PrintChar(const char ch) { out_buffer_[out_buffer_pos_++] = ch; }
148
149// Append the str to the output buffer.
150void Decoder::Print(const char* str) {
151 char cur = *str++;
152 while (cur != '\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
153 PrintChar(cur);
154 cur = *str++;
155 }
157}
158
159// These condition names are defined in a way to match the native disassembler
160// formatting. See for example the command "objdump -d <binary file>".
161static const char* const cond_names[kNumberOfConditions] = {
162 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
163 "hi", "ls", "ge", "lt", "gt", "le", "", "invalid",
164};
165
166// Print the condition guarding the instruction.
167void Decoder::PrintCondition(Instruction* instr) {
168 Print(cond_names[instr->ConditionValue()]);
169}
170
171// Print the register name according to the active name converter.
172void Decoder::PrintRegister(int reg) {
173 Print(converter_.NameOfCPURegister(reg));
174}
175
176// Print the VFP S register name according to the active name converter.
177void Decoder::PrintSRegister(int reg) { Print(VFPRegisters::Name(reg, false)); }
178
179// Print the VFP D register name according to the active name converter.
180void Decoder::PrintDRegister(int reg) { Print(VFPRegisters::Name(reg, true)); }
181
182// Print the VFP Q register name according to the active name converter.
183void Decoder::PrintQRegister(int reg) {
184 Print(RegisterName(QwNeonRegister::from_code(reg)));
185}
186
187// These shift names are defined in a way to match the native disassembler
188// formatting. See for example the command "objdump -d <binary file>".
189static const char* const shift_names[kNumberOfShifts] = {"lsl", "lsr", "asr",
190 "ror"};
191
192// Print the register shift operands for the instruction. Generally used for
193// data processing instructions.
194void Decoder::PrintShiftRm(Instruction* instr) {
195 ShiftOp shift = instr->ShiftField();
196 int shift_index = instr->ShiftValue();
197 int shift_amount = instr->ShiftAmountValue();
198 int rm = instr->RmValue();
199
200 PrintRegister(rm);
201
202 if ((instr->RegShiftValue() == 0) && (shift == LSL) && (shift_amount == 0)) {
203 // Special case for using rm only.
204 return;
205 }
206 if (instr->RegShiftValue() == 0) {
207 // by immediate
208 if ((shift == ROR) && (shift_amount == 0)) {
209 Print(", RRX");
210 return;
211 } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) {
212 shift_amount = 32;
213 }
215 shift_names[shift_index], shift_amount);
216 } else {
217 // by register
218 int rs = instr->RsValue();
220 shift_names[shift_index]);
221 PrintRegister(rs);
222 }
223}
224
225// Print the immediate operand for the instruction. Generally used for data
226// processing instructions.
227void Decoder::PrintShiftImm(Instruction* instr) {
228 int rotate = instr->RotateValue() * 2;
229 int immed8 = instr->Immed8Value();
230 int imm = base::bits::RotateRight32(immed8, rotate);
232}
233
234// Print the optional shift and immediate used by saturating instructions.
235void Decoder::PrintShiftSat(Instruction* instr) {
236 int shift = instr->Bits(11, 7);
237 if (shift > 0) {
240 shift_names[instr->Bit(6) * 2], instr->Bits(11, 7));
241 }
242}
243
244// Print PU formatting to reduce complexity of FormatOption.
245void Decoder::PrintPU(Instruction* instr) {
246 switch (instr->PUField()) {
247 case da_x: {
248 Print("da");
249 break;
250 }
251 case ia_x: {
252 Print("ia");
253 break;
254 }
255 case db_x: {
256 Print("db");
257 break;
258 }
259 case ib_x: {
260 Print("ib");
261 break;
262 }
263 default: {
264 UNREACHABLE();
265 }
266 }
267}
268
269// Print SoftwareInterrupt codes. Factoring this out reduces the complexity of
270// the FormatOption method.
271void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) {
272 switch (svc) {
274 Print("call rt redirected");
275 return;
276 case kBreakpoint:
277 Print("breakpoint");
278 return;
279 default:
280 if (svc >= kStopCode) {
283 svc & kStopCodeMask, svc & kStopCodeMask);
284 } else {
287 }
288 return;
289 }
290}
291
292// Handle all register based formatting in this function to reduce the
293// complexity of FormatOption.
294int Decoder::FormatRegister(Instruction* instr, const char* format) {
295 DCHECK_EQ(format[0], 'r');
296 if (format[1] == 'n') { // 'rn: Rn register
297 int reg = instr->RnValue();
299 return 2;
300 } else if (format[1] == 'd') { // 'rd: Rd register
301 int reg = instr->RdValue();
303 return 2;
304 } else if (format[1] == 's') { // 'rs: Rs register
305 int reg = instr->RsValue();
307 return 2;
308 } else if (format[1] == 'm') { // 'rm: Rm register
309 int reg = instr->RmValue();
311 return 2;
312 } else if (format[1] == 't') { // 'rt: Rt register
313 int reg = instr->RtValue();
315 return 2;
316 } else if (format[1] == 'l') {
317 // 'rlist: register list for load and store multiple instructions
318 DCHECK(STRING_STARTS_WITH(format, "rlist"));
319 int rlist = instr->RlistValue();
320 int reg = 0;
321 Print("{");
322 // Print register list in ascending order, by scanning the bit mask.
323 while (rlist != 0) {
324 if ((rlist & 1) != 0) {
326 if ((rlist >> 1) != 0) {
327 Print(", ");
328 }
329 }
330 reg++;
331 rlist >>= 1;
332 }
333 Print("}");
334 return 5;
335 }
336 UNREACHABLE();
337}
338
339// Handle all VFP register based formatting in this function to reduce the
340// complexity of FormatOption.
341int Decoder::FormatVFPRegister(Instruction* instr, const char* format,
343 int retval = 2;
344 int reg = -1;
345 if (format[1] == 'n') {
346 reg = instr->VFPNRegValue(precision);
347 } else if (format[1] == 'm') {
348 reg = instr->VFPMRegValue(precision);
349 } else if (format[1] == 'd') {
350 if ((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0) &&
351 (instr->Bits(11, 9) == 0x5) && (instr->Bit(4) == 0x1)) {
352 // vmov.32 has Vd in a different place.
353 reg = instr->Bits(19, 16) | (instr->Bit(7) << 4);
354 } else {
355 reg = instr->VFPDRegValue(precision);
356 }
357
358 if (format[2] == '+') {
359 DCHECK_NE(kSimd128Precision, precision); // Simd128 unimplemented.
360 int immed8 = instr->Immed8Value();
361 if (precision == kSinglePrecision) reg += immed8 - 1;
362 if (precision == kDoublePrecision) reg += (immed8 / 2 - 1);
363 }
364 if (format[2] == '+') retval = 3;
365 } else {
366 UNREACHABLE();
367 }
368
370 PrintSRegister(reg);
371 } else if (precision == kDoublePrecision) {
372 PrintDRegister(reg);
373 } else {
375 PrintQRegister(reg);
376 }
377
378 return retval;
379}
380
381int Decoder::FormatVFPinstruction(Instruction* instr, const char* format) {
382 Print(format);
383 return 0;
384}
385
386void Decoder::FormatNeonList(int Vd, int type) {
387 if (type == nlt_1) {
390 } else if (type == nlt_2) {
392 base::SNPrintF(out_buffer_ + out_buffer_pos_, "{d%d, d%d}", Vd, Vd + 1);
393 } else if (type == nlt_3) {
395 "{d%d, d%d, d%d}", Vd, Vd + 1, Vd + 2);
396 } else if (type == nlt_4) {
398 base::SNPrintF(out_buffer_ + out_buffer_pos_, "{d%d, d%d, d%d, d%d}",
399 Vd, Vd + 1, Vd + 2, Vd + 3);
400 }
401}
402
403void Decoder::FormatNeonMemory(int Rn, int align, int Rm) {
405 converter_.NameOfCPURegister(Rn));
406 if (align != 0) {
408 base::SNPrintF(out_buffer_ + out_buffer_pos_, ":%d", (1 << align) << 6);
409 }
410 if (Rm == 15) {
411 Print("]");
412 } else if (Rm == 13) {
413 Print("]!");
414 } else {
416 converter_.NameOfCPURegister(Rm));
417 }
418}
419
420// Print the movw or movt instruction.
421void Decoder::PrintMovwMovt(Instruction* instr) {
422 int imm = instr->ImmedMovwMovtValue();
423 int rd = instr->RdValue();
424 PrintRegister(rd);
427}
428
429// FormatOption takes a formatting string and interprets it based on
430// the current instructions. The format string points to the first
431// character of the option string (the option escape has already been
432// consumed by the caller.) FormatOption returns the number of
433// characters that were consumed from the formatting string.
434int Decoder::FormatOption(Instruction* instr, const char* format) {
435 switch (format[0]) {
436 case 'a': { // 'a: accumulate multiplies
437 if (instr->Bit(21) == 0) {
438 Print("ul");
439 } else {
440 Print("la");
441 }
442 return 1;
443 }
444 case 'b': { // 'b: byte loads or stores
445 if (instr->HasB()) {
446 Print("b");
447 }
448 return 1;
449 }
450 case 'c': { // 'cond: conditional execution
451 DCHECK(STRING_STARTS_WITH(format, "cond"));
452 PrintCondition(instr);
453 return 4;
454 }
455 case 'd': { // 'd: vmov double immediate.
456 double d = instr->DoubleImmedVmov().get_scalar();
459 return 1;
460 }
461 case 'f': { // 'f: bitfield instructions - v7 and above.
462 uint32_t lsbit = instr->Bits(11, 7);
463 uint32_t width = instr->Bits(20, 16) + 1;
464 if (instr->Bit(21) == 0) {
465 // BFC/BFI:
466 // Bits 20-16 represent most-significant bit. Covert to width.
467 width -= lsbit;
468 DCHECK_GT(width, 0);
469 }
470 DCHECK_LE(width + lsbit, 32);
472 "#%d, #%d", lsbit, width);
473 return 1;
474 }
475 case 'h': { // 'h: halfword operation for extra loads and stores
476 if (instr->HasH()) {
477 Print("h");
478 } else {
479 Print("b");
480 }
481 return 1;
482 }
483 case 'i': { // 'i: immediate value from adjacent bits.
484 // Expects tokens in the form imm%02d@%02d, i.e. imm05@07, imm10@16
485 int width = (format[3] - '0') * 10 + (format[4] - '0');
486 int lsb = (format[6] - '0') * 10 + (format[7] - '0');
487
488 DCHECK((width >= 1) && (width <= 32));
489 DCHECK((lsb >= 0) && (lsb <= 31));
490 DCHECK_LE(width + lsb, 32);
491
493 instr->Bits(width + lsb - 1, lsb));
494 return 8;
495 }
496 case 'l': { // 'l: branch and link
497 if (instr->HasLink()) {
498 Print("l");
499 }
500 return 1;
501 }
502 case 'm': {
503 if (format[1] == 'w') {
504 // 'mw: movt/movw instructions.
505 PrintMovwMovt(instr);
506 return 2;
507 }
508 if (format[1] == 'e') { // 'memop: load/store instructions.
509 DCHECK(STRING_STARTS_WITH(format, "memop"));
510 if (instr->HasL()) {
511 Print("ldr");
512 } else {
513 if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0) &&
514 (instr->Bits(7, 6) == 3) && (instr->Bit(4) == 1)) {
515 if (instr->Bit(5) == 1) {
516 Print("strd");
517 } else {
518 Print("ldrd");
519 }
520 return 5;
521 }
522 Print("str");
523 }
524 return 5;
525 }
526 // 'msg: for simulator break instructions
527 DCHECK(STRING_STARTS_WITH(format, "msg"));
528 uint8_t* str =
529 reinterpret_cast<uint8_t*>(instr->InstructionBits() & 0x0FFFFFFF);
531 converter_.NameInCode(str));
532 return 3;
533 }
534 case 'o': {
535 if ((format[3] == '1') && (format[4] == '2')) {
536 // 'off12: 12-bit offset for load and store instructions
537 DCHECK(STRING_STARTS_WITH(format, "off12"));
539 instr->Offset12Value());
540 return 5;
541 } else if (format[3] == '0') {
542 // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0.
543 DCHECK(STRING_STARTS_WITH(format, "off0to3and8to19"));
546 (instr->Bits(19, 8) << 4) + instr->Bits(3, 0));
547 return 15;
548 }
549 // 'off8: 8-bit offset for extra load and store instructions
550 DCHECK(STRING_STARTS_WITH(format, "off8"));
551 int offs8 = (instr->ImmedHValue() << 4) | instr->ImmedLValue();
554 return 4;
555 }
556 case 'p': { // 'pu: P and U bits for load and store instructions
557 DCHECK(STRING_STARTS_WITH(format, "pu"));
558 PrintPU(instr);
559 return 2;
560 }
561 case 'r': {
562 return FormatRegister(instr, format);
563 }
564 case 's': {
565 if (format[1] == 'h') { // 'shift_op or 'shift_rm or 'shift_sat.
566 if (format[6] == 'o') { // 'shift_op
567 DCHECK(STRING_STARTS_WITH(format, "shift_op"));
568 if (instr->TypeValue() == 0) {
569 PrintShiftRm(instr);
570 } else {
571 DCHECK_EQ(instr->TypeValue(), 1);
572 PrintShiftImm(instr);
573 }
574 return 8;
575 } else if (format[6] == 's') { // 'shift_sat.
576 DCHECK(STRING_STARTS_WITH(format, "shift_sat"));
577 PrintShiftSat(instr);
578 return 9;
579 } else { // 'shift_rm
580 DCHECK(STRING_STARTS_WITH(format, "shift_rm"));
581 PrintShiftRm(instr);
582 return 8;
583 }
584 } else if (format[1] == 'v') { // 'svc
585 DCHECK(STRING_STARTS_WITH(format, "svc"));
586 PrintSoftwareInterrupt(instr->SvcValue());
587 return 3;
588 } else if (format[1] == 'i') { // 'sign: signed extra loads and stores
589 if (format[2] == 'g') {
590 DCHECK(STRING_STARTS_WITH(format, "sign"));
591 if (instr->HasSign()) {
592 Print("s");
593 }
594 return 4;
595 } else {
596 // 'size2 or 'size3, for Advanced SIMD instructions, 2 or 3 registers.
597 DCHECK(STRING_STARTS_WITH(format, "size2") ||
598 STRING_STARTS_WITH(format, "size3"));
599 int sz = 8 << (format[4] == '2' ? instr->Bits(19, 18)
600 : instr->Bits(21, 20));
603 return 5;
604 }
605 } else if (format[1] == 'p') {
606 if (format[8] == '_') { // 'spec_reg_fields
607 DCHECK(STRING_STARTS_WITH(format, "spec_reg_fields"));
608 Print("_");
609 int mask = instr->Bits(19, 16);
610 if (mask == 0) Print("(none)");
611 if ((mask & 0x8) != 0) Print("f");
612 if ((mask & 0x4) != 0) Print("s");
613 if ((mask & 0x2) != 0) Print("x");
614 if ((mask & 0x1) != 0) Print("c");
615 return 15;
616 } else { // 'spec_reg
617 DCHECK(STRING_STARTS_WITH(format, "spec_reg"));
618 if (instr->Bit(22) == 0) {
619 Print("CPSR");
620 } else {
621 Print("SPSR");
622 }
623 return 8;
624 }
625 }
626 // 's: S field of data processing instructions
627 if (instr->HasS()) {
628 Print("s");
629 }
630 return 1;
631 }
632 case 't': { // 'target: target of branch instructions
633 DCHECK(STRING_STARTS_WITH(format, "target"));
634 int off = (static_cast<uint32_t>(instr->SImmed24Value()) << 2) + 8u;
636 out_buffer_ + out_buffer_pos_, "%+d -> %s", off,
637 converter_.NameOfAddress(reinterpret_cast<uint8_t*>(instr) + off));
638 return 6;
639 }
640 case 'u': { // 'u: signed or unsigned multiplies
641 // The manual gets the meaning of bit 22 backwards in the multiply
642 // instruction overview on page A3.16.2. The instructions that
643 // exist in u and s variants are the following:
644 // smull A4.1.87
645 // umull A4.1.129
646 // umlal A4.1.128
647 // smlal A4.1.76
648 // For these 0 means u and 1 means s. As can be seen on their individual
649 // pages. The other 18 mul instructions have the bit set or unset in
650 // arbitrary ways that are unrelated to the signedness of the instruction.
651 // None of these 18 instructions exist in both a 'u' and an 's' variant.
652
653 if (instr->Bit(22) == 0) {
654 Print("u");
655 } else {
656 Print("s");
657 }
658 return 1;
659 }
660 case 'v': {
661 return FormatVFPinstruction(instr, format);
662 }
663 case 'A': {
664 // Print pc-relative address.
665 int offset = instr->Offset12Value();
666 uint8_t* pc =
667 reinterpret_cast<uint8_t*>(instr) + Instruction::kPcLoadDelta;
668 uint8_t* addr;
669 switch (instr->PUField()) {
670 case db_x: {
671 addr = pc - offset;
672 break;
673 }
674 case ib_x: {
675 addr = pc + offset;
676 break;
677 }
678 default: {
679 UNREACHABLE();
680 }
681 }
683 base::SNPrintF(out_buffer_ + out_buffer_pos_, "0x%08" PRIxPTR,
684 reinterpret_cast<uintptr_t>(addr));
685 return 1;
686 }
687 case 'S':
688 return FormatVFPRegister(instr, format, kSinglePrecision);
689 case 'D':
690 return FormatVFPRegister(instr, format, kDoublePrecision);
691 case 'Q':
692 return FormatVFPRegister(instr, format, kSimd128Precision);
693 case 'w': { // 'w: W field of load and store instructions
694 if (instr->HasW()) {
695 Print("!");
696 }
697 return 1;
698 }
699 default: {
700 UNREACHABLE();
701 }
702 }
703 UNREACHABLE();
704}
705
706// Format takes a formatting string for a whole instruction and prints it into
707// the output buffer. All escaped options are handed to FormatOption to be
708// parsed further.
709void Decoder::Format(Instruction* instr, const char* format) {
710 char cur = *format++;
711 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
712 if (cur == '\'') { // Single quote is used as the formatting escape.
713 format += FormatOption(instr, format);
714 } else {
716 }
717 cur = *format++;
718 }
720}
721
722// The disassembler may end up decoding data inlined in the code. We do not want
723// it to crash if the data does not resemble any known instruction.
724#define VERIFY(condition) \
725 if (!(condition)) { \
726 Unknown(instr); \
727 return; \
728 }
729
730// For currently unimplemented decodings the disassembler calls Unknown(instr)
731// which will just print "unknown" of the instruction bits.
732void Decoder::Unknown(Instruction* instr) { Format(instr, "unknown"); }
733
734void Decoder::DecodeType01(Instruction* instr) {
735 int type = instr->TypeValue();
736 if ((type == 0) && instr->IsSpecialType0()) {
737 // multiply instruction or extra loads and stores
738 if (instr->Bits(7, 4) == 9) {
739 if (instr->Bit(24) == 0) {
740 // multiply instructions
741 if (instr->Bit(23) == 0) {
742 if (instr->Bit(21) == 0) {
743 // The MUL instruction description (A 4.1.33) refers to Rd as being
744 // the destination for the operation, but it confusingly uses the
745 // Rn field to encode it.
746 Format(instr, "mul'cond's 'rn, 'rm, 'rs");
747 } else {
748 if (instr->Bit(22) == 0) {
749 // The MLA instruction description (A 4.1.28) refers to the order
750 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
751 // Rn field to encode the Rd register and the Rd field to encode
752 // the Rn register.
753 Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd");
754 } else {
755 // The MLS instruction description (A 4.1.29) refers to the order
756 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
757 // Rn field to encode the Rd register and the Rd field to encode
758 // the Rn register.
759 Format(instr, "mls'cond's 'rn, 'rm, 'rs, 'rd");
760 }
761 }
762 } else {
763 // The signed/long multiply instructions use the terms RdHi and RdLo
764 // when referring to the target registers. They are mapped to the Rn
765 // and Rd fields as follows:
766 // RdLo == Rd field
767 // RdHi == Rn field
768 // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs>
769 Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs");
770 }
771 } else {
772 if (instr->Bits(24, 23) == 3) {
773 if (instr->Bit(20) == 1) {
774 // ldrex
775 switch (instr->Bits(22, 21)) {
776 case 0:
777 Format(instr, "ldrex'cond 'rt, ['rn]");
778 break;
779 case 1:
780 Format(instr, "ldrexd'cond 'rt, ['rn]");
781 break;
782 case 2:
783 Format(instr, "ldrexb'cond 'rt, ['rn]");
784 break;
785 case 3:
786 Format(instr, "ldrexh'cond 'rt, ['rn]");
787 break;
788 default:
789 UNREACHABLE();
790 }
791 } else {
792 // strex
793 // The instruction is documented as strex rd, rt, [rn], but the
794 // "rt" register is using the rm bits.
795 switch (instr->Bits(22, 21)) {
796 case 0:
797 Format(instr, "strex'cond 'rd, 'rm, ['rn]");
798 break;
799 case 1:
800 Format(instr, "strexd'cond 'rd, 'rm, ['rn]");
801 break;
802 case 2:
803 Format(instr, "strexb'cond 'rd, 'rm, ['rn]");
804 break;
805 case 3:
806 Format(instr, "strexh'cond 'rd, 'rm, ['rn]");
807 break;
808 default:
809 UNREACHABLE();
810 }
811 }
812 } else {
813 Unknown(instr); // not used by V8
814 }
815 }
816 } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xD) == 0xD)) {
817 // ldrd, strd
818 switch (instr->PUField()) {
819 case da_x: {
820 if (instr->Bit(22) == 0) {
821 Format(instr, "'memop'cond's 'rd, ['rn], -'rm");
822 } else {
823 Format(instr, "'memop'cond's 'rd, ['rn], #-'off8");
824 }
825 break;
826 }
827 case ia_x: {
828 if (instr->Bit(22) == 0) {
829 Format(instr, "'memop'cond's 'rd, ['rn], +'rm");
830 } else {
831 Format(instr, "'memop'cond's 'rd, ['rn], #+'off8");
832 }
833 break;
834 }
835 case db_x: {
836 if (instr->Bit(22) == 0) {
837 Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w");
838 } else {
839 Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w");
840 }
841 break;
842 }
843 case ib_x: {
844 if (instr->Bit(22) == 0) {
845 Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w");
846 } else {
847 Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w");
848 }
849 break;
850 }
851 default: {
852 // The PU field is a 2-bit field.
853 UNREACHABLE();
854 }
855 }
856 } else {
857 // extra load/store instructions
858 switch (instr->PUField()) {
859 case da_x: {
860 if (instr->Bit(22) == 0) {
861 Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm");
862 } else {
863 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8");
864 }
865 break;
866 }
867 case ia_x: {
868 if (instr->Bit(22) == 0) {
869 Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm");
870 } else {
871 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8");
872 }
873 break;
874 }
875 case db_x: {
876 if (instr->Bit(22) == 0) {
877 Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w");
878 } else {
879 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w");
880 }
881 break;
882 }
883 case ib_x: {
884 if (instr->Bit(22) == 0) {
885 Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w");
886 } else {
887 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w");
888 }
889 break;
890 }
891 default: {
892 // The PU field is a 2-bit field.
893 UNREACHABLE();
894 }
895 }
896 return;
897 }
898 } else if ((type == 0) && instr->IsMiscType0()) {
899 if ((instr->Bits(27, 23) == 2) && (instr->Bits(21, 20) == 2) &&
900 (instr->Bits(15, 4) == 0xF00)) {
901 Format(instr, "msr'cond 'spec_reg'spec_reg_fields, 'rm");
902 } else if ((instr->Bits(27, 23) == 2) && (instr->Bits(21, 20) == 0) &&
903 (instr->Bits(11, 0) == 0)) {
904 Format(instr, "mrs'cond 'rd, 'spec_reg");
905 } else if (instr->Bits(22, 21) == 1) {
906 switch (instr->BitField(7, 4)) {
907 case BX:
908 Format(instr, "bx'cond 'rm");
909 break;
910 case BLX:
911 Format(instr, "blx'cond 'rm");
912 break;
913 case BKPT:
914 Format(instr, "bkpt 'off0to3and8to19");
915 break;
916 default:
917 Unknown(instr); // not used by V8
918 break;
919 }
920 } else if (instr->Bits(22, 21) == 3) {
921 switch (instr->BitField(7, 4)) {
922 case CLZ:
923 Format(instr, "clz'cond 'rd, 'rm");
924 break;
925 default:
926 Unknown(instr); // not used by V8
927 break;
928 }
929 } else {
930 Unknown(instr); // not used by V8
931 }
932 } else if ((type == 1) && instr->IsNopLikeType1()) {
933 if (instr->BitField(7, 0) == 0) {
934 Format(instr, "nop'cond");
935 } else if (instr->BitField(7, 0) == 20) {
936 Format(instr, "csdb");
937 } else {
938 Unknown(instr); // Not used in V8.
939 }
940 } else {
941 switch (instr->OpcodeField()) {
942 case AND: {
943 Format(instr, "and'cond's 'rd, 'rn, 'shift_op");
944 break;
945 }
946 case EOR: {
947 Format(instr, "eor'cond's 'rd, 'rn, 'shift_op");
948 break;
949 }
950 case SUB: {
951 Format(instr, "sub'cond's 'rd, 'rn, 'shift_op");
952 break;
953 }
954 case RSB: {
955 Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op");
956 break;
957 }
958 case ADD: {
959 Format(instr, "add'cond's 'rd, 'rn, 'shift_op");
960 break;
961 }
962 case ADC: {
963 Format(instr, "adc'cond's 'rd, 'rn, 'shift_op");
964 break;
965 }
966 case SBC: {
967 Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op");
968 break;
969 }
970 case RSC: {
971 Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op");
972 break;
973 }
974 case TST: {
975 if (instr->HasS()) {
976 Format(instr, "tst'cond 'rn, 'shift_op");
977 } else {
978 Format(instr, "movw'cond 'mw");
979 }
980 break;
981 }
982 case TEQ: {
983 if (instr->HasS()) {
984 Format(instr, "teq'cond 'rn, 'shift_op");
985 } else {
986 // Other instructions matching this pattern are handled in the
987 // miscellaneous instructions part above.
988 UNREACHABLE();
989 }
990 break;
991 }
992 case CMP: {
993 if (instr->HasS()) {
994 Format(instr, "cmp'cond 'rn, 'shift_op");
995 } else {
996 Format(instr, "movt'cond 'mw");
997 }
998 break;
999 }
1000 case CMN: {
1001 if (instr->HasS()) {
1002 Format(instr, "cmn'cond 'rn, 'shift_op");
1003 } else {
1004 // Other instructions matching this pattern are handled in the
1005 // miscellaneous instructions part above.
1006 UNREACHABLE();
1007 }
1008 break;
1009 }
1010 case ORR: {
1011 Format(instr, "orr'cond's 'rd, 'rn, 'shift_op");
1012 break;
1013 }
1014 case MOV: {
1015 Format(instr, "mov'cond's 'rd, 'shift_op");
1016 break;
1017 }
1018 case BIC: {
1019 Format(instr, "bic'cond's 'rd, 'rn, 'shift_op");
1020 break;
1021 }
1022 case MVN: {
1023 Format(instr, "mvn'cond's 'rd, 'shift_op");
1024 break;
1025 }
1026 default: {
1027 // The Opcode field is a 4-bit field.
1028 UNREACHABLE();
1029 }
1030 }
1031 }
1032}
1033
1034void Decoder::DecodeType2(Instruction* instr) {
1035 switch (instr->PUField()) {
1036 case da_x: {
1037 if (instr->HasW()) {
1038 Unknown(instr); // not used in V8
1039 return;
1040 }
1041 Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12");
1042 break;
1043 }
1044 case ia_x: {
1045 if (instr->HasW()) {
1046 Unknown(instr); // not used in V8
1047 return;
1048 }
1049 Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12");
1050 break;
1051 }
1052 case db_x: {
1053 if (instr->HasL() && (instr->RnValue() == kPCRegister)) {
1054 Format(instr, "'memop'cond'b 'rd, [pc, #-'off12]'w (addr 'A)");
1055 } else {
1056 Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w");
1057 }
1058 break;
1059 }
1060 case ib_x: {
1061 if (instr->HasL() && (instr->RnValue() == kPCRegister)) {
1062 Format(instr, "'memop'cond'b 'rd, [pc, #+'off12]'w (addr 'A)");
1063 } else {
1064 Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w");
1065 }
1066 break;
1067 }
1068 default: {
1069 // The PU field is a 2-bit field.
1070 UNREACHABLE();
1071 }
1072 }
1073}
1074
1075void Decoder::DecodeType3(Instruction* instr) {
1076 switch (instr->PUField()) {
1077 case da_x: {
1078 VERIFY(!instr->HasW());
1079 Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm");
1080 break;
1081 }
1082 case ia_x: {
1083 if (instr->Bit(4) == 0) {
1084 Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm");
1085 } else {
1086 if (instr->Bit(5) == 0) {
1087 switch (instr->Bits(22, 21)) {
1088 case 0:
1089 if (instr->Bit(20) == 0) {
1090 if (instr->Bit(6) == 0) {
1091 Format(instr, "pkhbt'cond 'rd, 'rn, 'rm, lsl #'imm05@07");
1092 } else {
1093 if (instr->Bits(11, 7) == 0) {
1094 Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #32");
1095 } else {
1096 Format(instr, "pkhtb'cond 'rd, 'rn, 'rm, asr #'imm05@07");
1097 }
1098 }
1099 } else {
1100 UNREACHABLE();
1101 }
1102 break;
1103 case 1:
1104 UNREACHABLE();
1105 case 2:
1106 UNREACHABLE();
1107 case 3:
1108 Format(instr, "usat 'rd, #'imm05@16, 'rm'shift_sat");
1109 break;
1110 }
1111 } else {
1112 switch (instr->Bits(22, 21)) {
1113 case 0:
1114 UNREACHABLE();
1115 case 1:
1116 if (instr->Bits(9, 6) == 1) {
1117 if (instr->Bit(20) == 0) {
1118 if (instr->Bits(19, 16) == 0xF) {
1119 switch (instr->Bits(11, 10)) {
1120 case 0:
1121 Format(instr, "sxtb'cond 'rd, 'rm");
1122 break;
1123 case 1:
1124 Format(instr, "sxtb'cond 'rd, 'rm, ror #8");
1125 break;
1126 case 2:
1127 Format(instr, "sxtb'cond 'rd, 'rm, ror #16");
1128 break;
1129 case 3:
1130 Format(instr, "sxtb'cond 'rd, 'rm, ror #24");
1131 break;
1132 }
1133 } else {
1134 switch (instr->Bits(11, 10)) {
1135 case 0:
1136 Format(instr, "sxtab'cond 'rd, 'rn, 'rm");
1137 break;
1138 case 1:
1139 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #8");
1140 break;
1141 case 2:
1142 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #16");
1143 break;
1144 case 3:
1145 Format(instr, "sxtab'cond 'rd, 'rn, 'rm, ror #24");
1146 break;
1147 }
1148 }
1149 } else {
1150 if (instr->Bits(19, 16) == 0xF) {
1151 switch (instr->Bits(11, 10)) {
1152 case 0:
1153 Format(instr, "sxth'cond 'rd, 'rm");
1154 break;
1155 case 1:
1156 Format(instr, "sxth'cond 'rd, 'rm, ror #8");
1157 break;
1158 case 2:
1159 Format(instr, "sxth'cond 'rd, 'rm, ror #16");
1160 break;
1161 case 3:
1162 Format(instr, "sxth'cond 'rd, 'rm, ror #24");
1163 break;
1164 }
1165 } else {
1166 switch (instr->Bits(11, 10)) {
1167 case 0:
1168 Format(instr, "sxtah'cond 'rd, 'rn, 'rm");
1169 break;
1170 case 1:
1171 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #8");
1172 break;
1173 case 2:
1174 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #16");
1175 break;
1176 case 3:
1177 Format(instr, "sxtah'cond 'rd, 'rn, 'rm, ror #24");
1178 break;
1179 }
1180 }
1181 }
1182 } else if (instr->Bits(27, 16) == 0x6BF &&
1183 instr->Bits(11, 4) == 0xF3) {
1184 Format(instr, "rev'cond 'rd, 'rm");
1185 } else {
1186 UNREACHABLE();
1187 }
1188 break;
1189 case 2:
1190 if ((instr->Bit(20) == 0) && (instr->Bits(9, 6) == 1)) {
1191 if (instr->Bits(19, 16) == 0xF) {
1192 switch (instr->Bits(11, 10)) {
1193 case 0:
1194 Format(instr, "uxtb16'cond 'rd, 'rm");
1195 break;
1196 case 1:
1197 Format(instr, "uxtb16'cond 'rd, 'rm, ror #8");
1198 break;
1199 case 2:
1200 Format(instr, "uxtb16'cond 'rd, 'rm, ror #16");
1201 break;
1202 case 3:
1203 Format(instr, "uxtb16'cond 'rd, 'rm, ror #24");
1204 break;
1205 }
1206 } else {
1207 UNREACHABLE();
1208 }
1209 } else {
1210 UNREACHABLE();
1211 }
1212 break;
1213 case 3:
1214 if ((instr->Bits(9, 6) == 1)) {
1215 if ((instr->Bit(20) == 0)) {
1216 if (instr->Bits(19, 16) == 0xF) {
1217 switch (instr->Bits(11, 10)) {
1218 case 0:
1219 Format(instr, "uxtb'cond 'rd, 'rm");
1220 break;
1221 case 1:
1222 Format(instr, "uxtb'cond 'rd, 'rm, ror #8");
1223 break;
1224 case 2:
1225 Format(instr, "uxtb'cond 'rd, 'rm, ror #16");
1226 break;
1227 case 3:
1228 Format(instr, "uxtb'cond 'rd, 'rm, ror #24");
1229 break;
1230 }
1231 } else {
1232 switch (instr->Bits(11, 10)) {
1233 case 0:
1234 Format(instr, "uxtab'cond 'rd, 'rn, 'rm");
1235 break;
1236 case 1:
1237 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #8");
1238 break;
1239 case 2:
1240 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #16");
1241 break;
1242 case 3:
1243 Format(instr, "uxtab'cond 'rd, 'rn, 'rm, ror #24");
1244 break;
1245 }
1246 }
1247 } else {
1248 if (instr->Bits(19, 16) == 0xF) {
1249 switch (instr->Bits(11, 10)) {
1250 case 0:
1251 Format(instr, "uxth'cond 'rd, 'rm");
1252 break;
1253 case 1:
1254 Format(instr, "uxth'cond 'rd, 'rm, ror #8");
1255 break;
1256 case 2:
1257 Format(instr, "uxth'cond 'rd, 'rm, ror #16");
1258 break;
1259 case 3:
1260 Format(instr, "uxth'cond 'rd, 'rm, ror #24");
1261 break;
1262 }
1263 } else {
1264 switch (instr->Bits(11, 10)) {
1265 case 0:
1266 Format(instr, "uxtah'cond 'rd, 'rn, 'rm");
1267 break;
1268 case 1:
1269 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #8");
1270 break;
1271 case 2:
1272 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #16");
1273 break;
1274 case 3:
1275 Format(instr, "uxtah'cond 'rd, 'rn, 'rm, ror #24");
1276 break;
1277 }
1278 }
1279 }
1280 } else {
1281 // PU == 0b01, BW == 0b11, Bits(9, 6) != 0b0001
1282 if ((instr->Bits(20, 16) == 0x1F) &&
1283 (instr->Bits(11, 4) == 0xF3)) {
1284 Format(instr, "rbit'cond 'rd, 'rm");
1285 } else {
1286 UNREACHABLE();
1287 }
1288 }
1289 break;
1290 }
1291 }
1292 }
1293 break;
1294 }
1295 case db_x: {
1296 if (instr->Bits(22, 20) == 0x5) {
1297 if (instr->Bits(7, 4) == 0x1) {
1298 if (instr->Bits(15, 12) == 0xF) {
1299 Format(instr, "smmul'cond 'rn, 'rm, 'rs");
1300 } else {
1301 // SMMLA (in V8 notation matching ARM ISA format)
1302 Format(instr, "smmla'cond 'rn, 'rm, 'rs, 'rd");
1303 }
1304 break;
1305 }
1306 }
1307 if (instr->Bits(5, 4) == 0x1) {
1308 if ((instr->Bit(22) == 0x0) && (instr->Bit(20) == 0x1)) {
1309 if (instr->Bit(21) == 0x1) {
1310 // UDIV (in V8 notation matching ARM ISA format) rn = rm/rs
1311 Format(instr, "udiv'cond'b 'rn, 'rm, 'rs");
1312 } else {
1313 // SDIV (in V8 notation matching ARM ISA format) rn = rm/rs
1314 Format(instr, "sdiv'cond'b 'rn, 'rm, 'rs");
1315 }
1316 break;
1317 }
1318 }
1319 Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w");
1320 break;
1321 }
1322 case ib_x: {
1323 if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) {
1324 uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16));
1325 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
1326 uint32_t msbit = widthminus1 + lsbit;
1327 if (msbit <= 31) {
1328 if (instr->Bit(22)) {
1329 Format(instr, "ubfx'cond 'rd, 'rm, 'f");
1330 } else {
1331 Format(instr, "sbfx'cond 'rd, 'rm, 'f");
1332 }
1333 } else {
1334 UNREACHABLE();
1335 }
1336 } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) {
1337 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
1338 uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16));
1339 if (msbit >= lsbit) {
1340 if (instr->RmValue() == 15) {
1341 Format(instr, "bfc'cond 'rd, 'f");
1342 } else {
1343 Format(instr, "bfi'cond 'rd, 'rm, 'f");
1344 }
1345 } else {
1346 UNREACHABLE();
1347 }
1348 } else {
1349 Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w");
1350 }
1351 break;
1352 }
1353 default: {
1354 // The PU field is a 2-bit field.
1355 UNREACHABLE();
1356 }
1357 }
1358}
1359
1360void Decoder::DecodeType4(Instruction* instr) {
1361 if (instr->Bit(22) != 0) {
1362 // Privileged mode currently not supported.
1363 Unknown(instr);
1364 } else {
1365 if (instr->HasL()) {
1366 Format(instr, "ldm'cond'pu 'rn'w, 'rlist");
1367 } else {
1368 Format(instr, "stm'cond'pu 'rn'w, 'rlist");
1369 }
1370 }
1371}
1372
1373void Decoder::DecodeType5(Instruction* instr) {
1374 Format(instr, "b'l'cond 'target");
1375}
1376
1377void Decoder::DecodeType6(Instruction* instr) {
1378 DecodeType6CoprocessorIns(instr);
1379}
1380
1381int Decoder::DecodeType7(Instruction* instr) {
1382 if (instr->Bit(24) == 1) {
1383 if (instr->SvcValue() >= kStopCode) {
1384 Format(instr, "stop'cond 'svc");
1385 } else {
1386 Format(instr, "svc'cond 'svc");
1387 }
1388 } else {
1389 switch (instr->CoprocessorValue()) {
1390 case 10: // Fall through.
1391 case 11:
1392 DecodeTypeVFP(instr);
1393 break;
1394 case 15:
1395 DecodeTypeCP15(instr);
1396 break;
1397 default:
1398 Unknown(instr);
1399 break;
1400 }
1401 }
1402 return kInstrSize;
1403}
1404
1405// void Decoder::DecodeTypeVFP(Instruction* instr)
1406// vmov: Sn = Rt
1407// vmov: Rt = Sn
1408// vcvt: Dd = Sm
1409// vcvt: Sd = Dm
1410// vcvt.f64.s32 Dd, Dd, #<fbits>
1411// Dd = vabs(Dm)
1412// Sd = vabs(Sm)
1413// Dd = vneg(Dm)
1414// Sd = vneg(Sm)
1415// Dd = vadd(Dn, Dm)
1416// Sd = vadd(Sn, Sm)
1417// Dd = vsub(Dn, Dm)
1418// Sd = vsub(Sn, Sm)
1419// Dd = vmul(Dn, Dm)
1420// Sd = vmul(Sn, Sm)
1421// Dd = vmla(Dn, Dm)
1422// Sd = vmla(Sn, Sm)
1423// Dd = vmls(Dn, Dm)
1424// Sd = vmls(Sn, Sm)
1425// Dd = vdiv(Dn, Dm)
1426// Sd = vdiv(Sn, Sm)
1427// vcmp(Dd, Dm)
1428// vcmp(Sd, Sm)
1429// Dd = vsqrt(Dm)
1430// Sd = vsqrt(Sm)
1431// vmrs
1432// vmsr
1433// Qd = vdup.size(Qd, Rt)
1434// vmov.size: Dd[i] = Rt
1435// vmov.sign.size: Rt = Dn[i]
1436void Decoder::DecodeTypeVFP(Instruction* instr) {
1437 VERIFY((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0));
1438 VERIFY(instr->Bits(11, 9) == 0x5);
1439
1440 if (instr->Bit(4) == 0) {
1441 if (instr->Opc1Value() == 0x7) {
1442 // Other data processing instructions
1443 if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x1)) {
1444 // vmov register to register.
1445 if (instr->SzValue() == 0x1) {
1446 Format(instr, "vmov'cond.f64 'Dd, 'Dm");
1447 } else {
1448 Format(instr, "vmov'cond.f32 'Sd, 'Sm");
1449 }
1450 } else if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x3)) {
1451 // vabs
1452 if (instr->SzValue() == 0x1) {
1453 Format(instr, "vabs'cond.f64 'Dd, 'Dm");
1454 } else {
1455 Format(instr, "vabs'cond.f32 'Sd, 'Sm");
1456 }
1457 } else if ((instr->Opc2Value() == 0x1) && (instr->Opc3Value() == 0x1)) {
1458 // vneg
1459 if (instr->SzValue() == 0x1) {
1460 Format(instr, "vneg'cond.f64 'Dd, 'Dm");
1461 } else {
1462 Format(instr, "vneg'cond.f32 'Sd, 'Sm");
1463 }
1464 } else if ((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)) {
1465 DecodeVCVTBetweenDoubleAndSingle(instr);
1466 } else if ((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) {
1467 DecodeVCVTBetweenFloatingPointAndInteger(instr);
1468 } else if ((instr->Opc2Value() == 0xA) && (instr->Opc3Value() == 0x3) &&
1469 (instr->Bit(8) == 1)) {
1470 // vcvt.f64.s32 Dd, Dd, #<fbits>
1471 int fraction_bits = 32 - ((instr->Bits(3, 0) << 1) | instr->Bit(5));
1472 Format(instr, "vcvt'cond.f64.s32 'Dd, 'Dd");
1474 ", #%d", fraction_bits);
1475 } else if (((instr->Opc2Value() >> 1) == 0x6) &&
1476 (instr->Opc3Value() & 0x1)) {
1477 DecodeVCVTBetweenFloatingPointAndInteger(instr);
1478 } else if (((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
1479 (instr->Opc3Value() & 0x1)) {
1480 DecodeVCMP(instr);
1481 } else if (((instr->Opc2Value() == 0x1)) && (instr->Opc3Value() == 0x3)) {
1482 if (instr->SzValue() == 0x1) {
1483 Format(instr, "vsqrt'cond.f64 'Dd, 'Dm");
1484 } else {
1485 Format(instr, "vsqrt'cond.f32 'Sd, 'Sm");
1486 }
1487 } else if (instr->Opc3Value() == 0x0) {
1488 if (instr->SzValue() == 0x1) {
1489 Format(instr, "vmov'cond.f64 'Dd, 'd");
1490 } else {
1491 Format(instr, "vmov'cond.f32 'Sd, 'd");
1492 }
1493 } else if (((instr->Opc2Value() == 0x6)) && instr->Opc3Value() == 0x3) {
1494 // vrintz - round towards zero (truncate)
1495 if (instr->SzValue() == 0x1) {
1496 Format(instr, "vrintz'cond.f64.f64 'Dd, 'Dm");
1497 } else {
1498 Format(instr, "vrintz'cond.f32.f32 'Sd, 'Sm");
1499 }
1500 } else {
1501 Unknown(instr); // Not used by V8.
1502 }
1503 } else if (instr->Opc1Value() == 0x3) {
1504 if (instr->SzValue() == 0x1) {
1505 if (instr->Opc3Value() & 0x1) {
1506 Format(instr, "vsub'cond.f64 'Dd, 'Dn, 'Dm");
1507 } else {
1508 Format(instr, "vadd'cond.f64 'Dd, 'Dn, 'Dm");
1509 }
1510 } else {
1511 if (instr->Opc3Value() & 0x1) {
1512 Format(instr, "vsub'cond.f32 'Sd, 'Sn, 'Sm");
1513 } else {
1514 Format(instr, "vadd'cond.f32 'Sd, 'Sn, 'Sm");
1515 }
1516 }
1517 } else if ((instr->Opc1Value() == 0x2) && !(instr->Opc3Value() & 0x1)) {
1518 if (instr->SzValue() == 0x1) {
1519 Format(instr, "vmul'cond.f64 'Dd, 'Dn, 'Dm");
1520 } else {
1521 Format(instr, "vmul'cond.f32 'Sd, 'Sn, 'Sm");
1522 }
1523 } else if ((instr->Opc1Value() == 0x0) && !(instr->Opc3Value() & 0x1)) {
1524 if (instr->SzValue() == 0x1) {
1525 Format(instr, "vmla'cond.f64 'Dd, 'Dn, 'Dm");
1526 } else {
1527 Format(instr, "vmla'cond.f32 'Sd, 'Sn, 'Sm");
1528 }
1529 } else if ((instr->Opc1Value() == 0x0) && (instr->Opc3Value() & 0x1)) {
1530 if (instr->SzValue() == 0x1) {
1531 Format(instr, "vmls'cond.f64 'Dd, 'Dn, 'Dm");
1532 } else {
1533 Format(instr, "vmls'cond.f32 'Sd, 'Sn, 'Sm");
1534 }
1535 } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) {
1536 if (instr->SzValue() == 0x1) {
1537 Format(instr, "vdiv'cond.f64 'Dd, 'Dn, 'Dm");
1538 } else {
1539 Format(instr, "vdiv'cond.f32 'Sd, 'Sn, 'Sm");
1540 }
1541 } else {
1542 Unknown(instr); // Not used by V8.
1543 }
1544 } else {
1545 if ((instr->VCValue() == 0x0) && (instr->VAValue() == 0x0)) {
1546 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr);
1547 } else if ((instr->VLValue() == 0x0) && (instr->VCValue() == 0x1)) {
1548 const char* rt_name = converter_.NameOfCPURegister(instr->RtValue());
1549 if (instr->Bit(23) == 0) {
1550 int opc1_opc2 = (instr->Bits(22, 21) << 2) | instr->Bits(6, 5);
1551 if ((opc1_opc2 & 0xB) == 0) {
1552 // NeonS32/NeonU32
1553 if (instr->Bit(21) == 0x0) {
1554 Format(instr, "vmov'cond.32 'Dd[0], 'rt");
1555 } else {
1556 Format(instr, "vmov'cond.32 'Dd[1], 'rt");
1557 }
1558 } else {
1559 int vd = instr->VFPNRegValue(kDoublePrecision);
1560 if ((opc1_opc2 & 0x8) != 0) {
1561 // NeonS8 / NeonU8
1562 int i = opc1_opc2 & 0x7;
1565 "vmov.8 d%d[%d], %s", vd, i, rt_name);
1566 } else if ((opc1_opc2 & 0x1) != 0) {
1567 // NeonS16 / NeonU16
1568 int i = (opc1_opc2 >> 1) & 0x3;
1571 "vmov.16 d%d[%d], %s", vd, i, rt_name);
1572 } else {
1573 Unknown(instr);
1574 }
1575 }
1576 } else {
1577 int size = 32;
1578 if (instr->Bit(5) != 0) {
1579 size = 16;
1580 } else if (instr->Bit(22) != 0) {
1581 size = 8;
1582 }
1583 int Vd = instr->VFPNRegValue(kSimd128Precision);
1585 "vdup.%i q%d, %s", size, Vd, rt_name);
1586 }
1587 } else if ((instr->VLValue() == 0x1) && (instr->VCValue() == 0x1)) {
1588 int opc1_opc2 = (instr->Bits(22, 21) << 2) | instr->Bits(6, 5);
1589 if ((opc1_opc2 & 0xB) == 0) {
1590 // NeonS32 / NeonU32
1591 if (instr->Bit(21) == 0x0) {
1592 Format(instr, "vmov'cond.32 'rt, 'Dd[0]");
1593 } else {
1594 Format(instr, "vmov'cond.32 'rt, 'Dd[1]");
1595 }
1596 } else {
1597 char sign = instr->Bit(23) != 0 ? 'u' : 's';
1598 const char* rt_name = converter_.NameOfCPURegister(instr->RtValue());
1599 int vn = instr->VFPNRegValue(kDoublePrecision);
1600 if ((opc1_opc2 & 0x8) != 0) {
1601 // NeonS8 / NeonU8
1602 int i = opc1_opc2 & 0x7;
1605 "vmov.%c8 %s, d%d[%d]", sign, rt_name, vn, i);
1606 } else if ((opc1_opc2 & 0x1) != 0) {
1607 // NeonS16 / NeonU16
1608 int i = (opc1_opc2 >> 1) & 0x3;
1611 "vmov.%c16 %s, d%d[%d]", sign, rt_name, vn, i);
1612 } else {
1613 Unknown(instr);
1614 }
1615 }
1616 } else if ((instr->VCValue() == 0x0) && (instr->VAValue() == 0x7) &&
1617 (instr->Bits(19, 16) == 0x1)) {
1618 if (instr->VLValue() == 0) {
1619 if (instr->Bits(15, 12) == 0xF) {
1620 Format(instr, "vmsr'cond FPSCR, APSR");
1621 } else {
1622 Format(instr, "vmsr'cond FPSCR, 'rt");
1623 }
1624 } else {
1625 if (instr->Bits(15, 12) == 0xF) {
1626 Format(instr, "vmrs'cond APSR, FPSCR");
1627 } else {
1628 Format(instr, "vmrs'cond 'rt, FPSCR");
1629 }
1630 }
1631 } else {
1632 Unknown(instr); // Not used by V8.
1633 }
1634 }
1635}
1636
1637void Decoder::DecodeTypeCP15(Instruction* instr) {
1638 VERIFY((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0));
1639 VERIFY(instr->CoprocessorValue() == 15);
1640
1641 if (instr->Bit(4) == 1) {
1642 int crn = instr->Bits(19, 16);
1643 int crm = instr->Bits(3, 0);
1644 int opc1 = instr->Bits(23, 21);
1645 int opc2 = instr->Bits(7, 5);
1646 if ((opc1 == 0) && (crn == 7)) {
1647 // ARMv6 memory barrier operations.
1648 // Details available in ARM DDI 0406C.b, B3-1750.
1649 if ((crm == 10) && (opc2 == 5)) {
1650 Format(instr, "mcr'cond (CP15DMB)");
1651 } else if ((crm == 10) && (opc2 == 4)) {
1652 Format(instr, "mcr'cond (CP15DSB)");
1653 } else if ((crm == 5) && (opc2 == 4)) {
1654 Format(instr, "mcr'cond (CP15ISB)");
1655 } else {
1656 Unknown(instr);
1657 }
1658 } else {
1659 Unknown(instr);
1660 }
1661 } else {
1662 Unknown(instr);
1663 }
1664}
1665
1666void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(
1667 Instruction* instr) {
1668 VERIFY((instr->Bit(4) == 1) && (instr->VCValue() == 0x0) &&
1669 (instr->VAValue() == 0x0));
1670
1671 bool to_arm_register = (instr->VLValue() == 0x1);
1672
1673 if (to_arm_register) {
1674 Format(instr, "vmov'cond 'rt, 'Sn");
1675 } else {
1676 Format(instr, "vmov'cond 'Sn, 'rt");
1677 }
1678}
1679
1680void Decoder::DecodeVCMP(Instruction* instr) {
1681 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1682 VERIFY(((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
1683 (instr->Opc3Value() & 0x1));
1684
1685 // Comparison.
1686 bool dp_operation = (instr->SzValue() == 1);
1687 bool raise_exception_for_qnan = (instr->Bit(7) == 0x1);
1688
1689 if (dp_operation && !raise_exception_for_qnan) {
1690 if (instr->Opc2Value() == 0x4) {
1691 Format(instr, "vcmp'cond.f64 'Dd, 'Dm");
1692 } else if (instr->Opc2Value() == 0x5) {
1693 Format(instr, "vcmp'cond.f64 'Dd, #0.0");
1694 } else {
1695 Unknown(instr); // invalid
1696 }
1697 } else if (!raise_exception_for_qnan) {
1698 if (instr->Opc2Value() == 0x4) {
1699 Format(instr, "vcmp'cond.f32 'Sd, 'Sm");
1700 } else if (instr->Opc2Value() == 0x5) {
1701 Format(instr, "vcmp'cond.f32 'Sd, #0.0");
1702 } else {
1703 Unknown(instr); // invalid
1704 }
1705 } else {
1706 Unknown(instr); // Not used by V8.
1707 }
1708}
1709
1710void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instruction* instr) {
1711 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1712 VERIFY((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3));
1713
1714 bool double_to_single = (instr->SzValue() == 1);
1715
1716 if (double_to_single) {
1717 Format(instr, "vcvt'cond.f32.f64 'Sd, 'Dm");
1718 } else {
1719 Format(instr, "vcvt'cond.f64.f32 'Dd, 'Sm");
1720 }
1721}
1722
1723void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr) {
1724 VERIFY((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1725 VERIFY(((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) ||
1726 (((instr->Opc2Value() >> 1) == 0x6) && (instr->Opc3Value() & 0x1)));
1727
1728 bool to_integer = (instr->Bit(18) == 1);
1729 bool dp_operation = (instr->SzValue() == 1);
1730 if (to_integer) {
1731 bool unsigned_integer = (instr->Bit(16) == 0);
1732
1733 if (dp_operation) {
1734 if (unsigned_integer) {
1735 Format(instr, "vcvt'cond.u32.f64 'Sd, 'Dm");
1736 } else {
1737 Format(instr, "vcvt'cond.s32.f64 'Sd, 'Dm");
1738 }
1739 } else {
1740 if (unsigned_integer) {
1741 Format(instr, "vcvt'cond.u32.f32 'Sd, 'Sm");
1742 } else {
1743 Format(instr, "vcvt'cond.s32.f32 'Sd, 'Sm");
1744 }
1745 }
1746 } else {
1747 bool unsigned_integer = (instr->Bit(7) == 0);
1748
1749 if (dp_operation) {
1750 if (unsigned_integer) {
1751 Format(instr, "vcvt'cond.f64.u32 'Dd, 'Sm");
1752 } else {
1753 Format(instr, "vcvt'cond.f64.s32 'Dd, 'Sm");
1754 }
1755 } else {
1756 if (unsigned_integer) {
1757 Format(instr, "vcvt'cond.f32.u32 'Sd, 'Sm");
1758 } else {
1759 Format(instr, "vcvt'cond.f32.s32 'Sd, 'Sm");
1760 }
1761 }
1762 }
1763}
1764
1765void Decoder::DecodeVmovImmediate(Instruction* instr) {
1766 uint8_t cmode = instr->Bits(11, 8);
1767 int vd = instr->VFPDRegValue(kSimd128Precision);
1768 int a = instr->Bit(24);
1769 int bcd = instr->Bits(18, 16);
1770 int efgh = instr->Bits(3, 0);
1771 uint8_t imm = a << 7 | bcd << 4 | efgh;
1772 switch (cmode) {
1773 case 0: {
1774 uint32_t imm32 = imm;
1776 "vmov.i32 q%d, %d", vd, imm32);
1777 break;
1778 }
1779 case 0xe: {
1781 "vmov.i8 q%d, %d", vd, imm);
1782 break;
1783 }
1784 default:
1785 Unknown(instr);
1786 }
1787}
1788
1789// Decode Type 6 coprocessor instructions.
1790// Dm = vmov(Rt, Rt2)
1791// <Rt, Rt2> = vmov(Dm)
1792// Ddst = MEM(Rbase + 4*offset).
1793// MEM(Rbase + 4*offset) = Dsrc.
1794void Decoder::DecodeType6CoprocessorIns(Instruction* instr) {
1795 VERIFY(instr->TypeValue() == 6);
1796
1797 if (instr->CoprocessorValue() == 0xA) {
1798 switch (instr->OpcodeValue()) {
1799 case 0x8:
1800 case 0xA:
1801 if (instr->HasL()) {
1802 Format(instr, "vldr'cond 'Sd, ['rn - 4*'imm08@00]");
1803 } else {
1804 Format(instr, "vstr'cond 'Sd, ['rn - 4*'imm08@00]");
1805 }
1806 break;
1807 case 0xC:
1808 case 0xE:
1809 if (instr->HasL()) {
1810 Format(instr, "vldr'cond 'Sd, ['rn + 4*'imm08@00]");
1811 } else {
1812 Format(instr, "vstr'cond 'Sd, ['rn + 4*'imm08@00]");
1813 }
1814 break;
1815 case 0x4:
1816 case 0x5:
1817 case 0x6:
1818 case 0x7:
1819 case 0x9:
1820 case 0xB: {
1821 bool to_vfp_register = (instr->VLValue() == 0x1);
1822 if (to_vfp_register) {
1823 Format(instr, "vldm'cond'pu 'rn'w, {'Sd-'Sd+}");
1824 } else {
1825 Format(instr, "vstm'cond'pu 'rn'w, {'Sd-'Sd+}");
1826 }
1827 break;
1828 }
1829 default:
1830 Unknown(instr); // Not used by V8.
1831 }
1832 } else if (instr->CoprocessorValue() == 0xB) {
1833 switch (instr->OpcodeValue()) {
1834 case 0x2:
1835 // Load and store double to two GP registers
1836 if (instr->Bits(7, 6) != 0 || instr->Bit(4) != 1) {
1837 Unknown(instr); // Not used by V8.
1838 } else if (instr->HasL()) {
1839 Format(instr, "vmov'cond 'rt, 'rn, 'Dm");
1840 } else {
1841 Format(instr, "vmov'cond 'Dm, 'rt, 'rn");
1842 }
1843 break;
1844 case 0x8:
1845 case 0xA:
1846 if (instr->HasL()) {
1847 Format(instr, "vldr'cond 'Dd, ['rn - 4*'imm08@00]");
1848 } else {
1849 Format(instr, "vstr'cond 'Dd, ['rn - 4*'imm08@00]");
1850 }
1851 break;
1852 case 0xC:
1853 case 0xE:
1854 if (instr->HasL()) {
1855 Format(instr, "vldr'cond 'Dd, ['rn + 4*'imm08@00]");
1856 } else {
1857 Format(instr, "vstr'cond 'Dd, ['rn + 4*'imm08@00]");
1858 }
1859 break;
1860 case 0x4:
1861 case 0x5:
1862 case 0x6:
1863 case 0x7:
1864 case 0x9:
1865 case 0xB: {
1866 bool to_vfp_register = (instr->VLValue() == 0x1);
1867 if (to_vfp_register) {
1868 Format(instr, "vldm'cond'pu 'rn'w, {'Dd-'Dd+}");
1869 } else {
1870 Format(instr, "vstm'cond'pu 'rn'w, {'Dd-'Dd+}");
1871 }
1872 break;
1873 }
1874 default:
1875 Unknown(instr); // Not used by V8.
1876 }
1877 } else {
1878 Unknown(instr); // Not used by V8.
1879 }
1880}
1881
1882static const char* const barrier_option_names[] = {
1883 "invalid", "oshld", "oshst", "osh", "invalid", "nshld", "nshst", "nsh",
1884 "invalid", "ishld", "ishst", "ish", "invalid", "ld", "st", "sy",
1885};
1886
1887void Decoder::DecodeSpecialCondition(Instruction* instr) {
1888 int op0 = instr->Bits(25, 24);
1889 int op1 = instr->Bits(11, 9);
1890 int op2 = instr->Bit(4);
1891
1892 if (instr->Bit(27) == 0) {
1893 DecodeUnconditional(instr);
1894 } else if ((instr->Bits(27, 26) == 0b11) && (op0 == 0b10) &&
1895 ((op1 >> 1) == 0b10) && !op2) {
1896 DecodeFloatingPointDataProcessing(instr);
1897 } else {
1898 Unknown(instr);
1899 }
1900}
1901
1902void Decoder::DecodeFloatingPointDataProcessing(Instruction* instr) {
1903 // Floating-point data processing, F4.1.14.
1904 int op0 = instr->Bits(23, 20);
1905 int op1 = instr->Bits(19, 16);
1906 int op2 = instr->Bits(9, 8);
1907 int op3 = instr->Bit(6);
1908 if (((op0 & 0b1000) == 0) && op2 && !op3) {
1909 // Floating-point conditional select.
1910 // VSEL* (floating-point)
1911 bool dp_operation = (instr->SzValue() == 1);
1912 switch (instr->Bits(21, 20)) {
1913 case 0x0:
1914 if (dp_operation) {
1915 Format(instr, "vseleq.f64 'Dd, 'Dn, 'Dm");
1916 } else {
1917 Format(instr, "vseleq.f32 'Sd, 'Sn, 'Sm");
1918 }
1919 break;
1920 case 0x1:
1921 if (dp_operation) {
1922 Format(instr, "vselvs.f64 'Dd, 'Dn, 'Dm");
1923 } else {
1924 Format(instr, "vselvs.f32 'Sd, 'Sn, 'Sm");
1925 }
1926 break;
1927 case 0x2:
1928 if (dp_operation) {
1929 Format(instr, "vselge.f64 'Dd, 'Dn, 'Dm");
1930 } else {
1931 Format(instr, "vselge.f32 'Sd, 'Sn, 'Sm");
1932 }
1933 break;
1934 case 0x3:
1935 if (dp_operation) {
1936 Format(instr, "vselgt.f64 'Dd, 'Dn, 'Dm");
1937 } else {
1938 Format(instr, "vselgt.f32 'Sd, 'Sn, 'Sm");
1939 }
1940 break;
1941 default:
1942 UNREACHABLE(); // Case analysis is exhaustive.
1943 }
1944 } else if (instr->Opc1Value() == 0x4 && op2) {
1945 // Floating-point minNum/maxNum.
1946 // VMAXNM, VMINNM (floating-point)
1947 if (instr->SzValue() == 0x1) {
1948 if (instr->Bit(6) == 0x1) {
1949 Format(instr, "vminnm.f64 'Dd, 'Dn, 'Dm");
1950 } else {
1951 Format(instr, "vmaxnm.f64 'Dd, 'Dn, 'Dm");
1952 }
1953 } else {
1954 if (instr->Bit(6) == 0x1) {
1955 Format(instr, "vminnm.f32 'Sd, 'Sn, 'Sm");
1956 } else {
1957 Format(instr, "vmaxnm.f32 'Sd, 'Sn, 'Sm");
1958 }
1959 }
1960 } else if (instr->Opc1Value() == 0x7 && (op1 >> 3) && op2 && op3) {
1961 // Floating-point directed convert to integer.
1962 // VRINTA, VRINTN, VRINTP, VRINTM (floating-point)
1963 bool dp_operation = (instr->SzValue() == 1);
1964 int rounding_mode = instr->Bits(17, 16);
1965 switch (rounding_mode) {
1966 case 0x0:
1967 if (dp_operation) {
1968 Format(instr, "vrinta.f64.f64 'Dd, 'Dm");
1969 } else {
1970 Format(instr, "vrinta.f32.f32 'Sd, 'Sm");
1971 }
1972 break;
1973 case 0x1:
1974 if (dp_operation) {
1975 Format(instr, "vrintn.f64.f64 'Dd, 'Dm");
1976 } else {
1977 Format(instr, "vrintn.f32.f32 'Sd, 'Sm");
1978 }
1979 break;
1980 case 0x2:
1981 if (dp_operation) {
1982 Format(instr, "vrintp.f64.f64 'Dd, 'Dm");
1983 } else {
1984 Format(instr, "vrintp.f32.f32 'Sd, 'Sm");
1985 }
1986 break;
1987 case 0x3:
1988 if (dp_operation) {
1989 Format(instr, "vrintm.f64.f64 'Dd, 'Dm");
1990 } else {
1991 Format(instr, "vrintm.f32.f32 'Sd, 'Sm");
1992 }
1993 break;
1994 default:
1995 UNREACHABLE(); // Case analysis is exhaustive.
1996 }
1997 } else {
1998 Unknown(instr);
1999 }
2000 // One class of decoding is missing here: Floating-point extraction and
2001 // insertion, but it is not used in V8 now, and thus omitted.
2002}
2003
2004void Decoder::DecodeUnconditional(Instruction* instr) {
2005 // This follows the decoding in F4.1.18 Unconditional instructions.
2006 int op0 = instr->Bits(26, 25);
2007 int op1 = instr->Bit(20);
2008
2009 // Four classes of decoding:
2010 // - Miscellaneous (omitted, no instructions used in V8).
2011 // - Advanced SIMD data-processing.
2012 // - Memory hints and barriers.
2013 // - Advanced SIMD element or structure load/store.
2014 if (op0 == 0b01) {
2015 DecodeAdvancedSIMDDataProcessing(instr);
2016 } else if ((op0 & 0b10) == 0b10 && op1) {
2017 DecodeMemoryHintsAndBarriers(instr);
2018 } else if (op0 == 0b10 && !op1) {
2019 DecodeAdvancedSIMDElementOrStructureLoadStore(instr);
2020 } else {
2021 Unknown(instr);
2022 }
2023}
2024
2025void Decoder::DecodeAdvancedSIMDDataProcessing(Instruction* instr) {
2026 int op0 = instr->Bit(23);
2027 int op1 = instr->Bit(4);
2028 if (op0 == 0) {
2029 // Advanced SIMD three registers of same length.
2030 int Vm, Vn;
2031 if (instr->Bit(6) == 0) {
2032 Vm = instr->VFPMRegValue(kDoublePrecision);
2033 Vn = instr->VFPNRegValue(kDoublePrecision);
2034 } else {
2035 Vm = instr->VFPMRegValue(kSimd128Precision);
2036 Vn = instr->VFPNRegValue(kSimd128Precision);
2037 }
2038
2039 int u = instr->Bit(24);
2040 int opc = instr->Bits(11, 8);
2041 int q = instr->Bit(6);
2042 int sz = instr->Bits(21, 20);
2043
2044 if (!u && opc == 0 && op1) {
2045 Format(instr, "vqadd.s'size3 'Qd, 'Qn, 'Qm");
2046 } else if (!u && opc == 1 && sz == 2 && q && op1) {
2047 if (Vm == Vn) {
2048 Format(instr, "vmov 'Qd, 'Qm");
2049 } else {
2050 Format(instr, "vorr 'Qd, 'Qn, 'Qm");
2051 }
2052 } else if (!u && opc == 1 && sz == 1 && q && op1) {
2053 Format(instr, "vbic 'Qd, 'Qn, 'Qm");
2054 } else if (!u && opc == 1 && sz == 0 && q && op1) {
2055 Format(instr, "vand 'Qd, 'Qn, 'Qm");
2056 } else if (!u && opc == 2 && op1) {
2057 Format(instr, "vqsub.s'size3 'Qd, 'Qn, 'Qm");
2058 } else if (!u && opc == 3 && op1) {
2059 Format(instr, "vcge.s'size3 'Qd, 'Qn, 'Qm");
2060 } else if (!u && opc == 3 && !op1) {
2061 Format(instr, "vcgt.s'size3 'Qd, 'Qn, 'Qm");
2062 } else if (!u && opc == 4 && !op1) {
2063 Format(instr, "vshl.s'size3 'Qd, 'Qm, 'Qn");
2064 } else if (!u && opc == 6 && op1) {
2065 Format(instr, "vmin.s'size3 'Qd, 'Qn, 'Qm");
2066 } else if (!u && opc == 6 && !op1) {
2067 Format(instr, "vmax.s'size3 'Qd, 'Qn, 'Qm");
2068 } else if (!u && opc == 8 && op1) {
2069 Format(instr, "vtst.i'size3 'Qd, 'Qn, 'Qm");
2070 } else if (!u && opc == 8 && !op1) {
2071 Format(instr, "vadd.i'size3 'Qd, 'Qn, 'Qm");
2072 } else if (opc == 9 && op1) {
2073 Format(instr, "vmul.i'size3 'Qd, 'Qn, 'Qm");
2074 } else if (!u && opc == 0xA && op1) {
2075 Format(instr, "vpmin.s'size3 'Dd, 'Dn, 'Dm");
2076 } else if (!u && opc == 0xA && !op1) {
2077 Format(instr, "vpmax.s'size3 'Dd, 'Dn, 'Dm");
2078 } else if (u && opc == 0XB) {
2079 Format(instr, "vqrdmulh.s'size3 'Qd, 'Qn, 'Qm");
2080 } else if (!u && opc == 0xB) {
2081 Format(instr, "vpadd.i'size3 'Dd, 'Dn, 'Dm");
2082 } else if (!u && !(sz >> 1) && opc == 0xD && !op1) {
2083 Format(instr, "vadd.f32 'Qd, 'Qn, 'Qm");
2084 } else if (!u && (sz >> 1) && opc == 0xD && !op1) {
2085 Format(instr, "vsub.f32 'Qd, 'Qn, 'Qm");
2086 } else if (!u && opc == 0xE && !sz && !op1) {
2087 Format(instr, "vceq.f32 'Qd, 'Qn, 'Qm");
2088 } else if (!u && !(sz >> 1) && opc == 0xF && op1) {
2089 Format(instr, "vrecps.f32 'Qd, 'Qn, 'Qm");
2090 } else if (!u && (sz >> 1) && opc == 0xF && op1) {
2091 Format(instr, "vrsqrts.f32 'Qd, 'Qn, 'Qm");
2092 } else if (!u && !(sz >> 1) && opc == 0xF && !op1) {
2093 Format(instr, "vmax.f32 'Qd, 'Qn, 'Qm");
2094 } else if (!u && (sz >> 1) && opc == 0xF && !op1) {
2095 Format(instr, "vmin.f32 'Qd, 'Qn, 'Qm");
2096 } else if (u && opc == 0 && op1) {
2097 Format(instr, "vqadd.u'size3 'Qd, 'Qn, 'Qm");
2098 } else if (u && opc == 1 && sz == 1 && op1) {
2099 Format(instr, "vbsl 'Qd, 'Qn, 'Qm");
2100 } else if (u && opc == 1 && sz == 0 && q && op1) {
2101 Format(instr, "veor 'Qd, 'Qn, 'Qm");
2102 } else if (u && opc == 1 && sz == 0 && !q && op1) {
2103 Format(instr, "veor 'Dd, 'Dn, 'Dm");
2104 } else if (u && opc == 1 && !op1) {
2105 Format(instr, "vrhadd.u'size3 'Qd, 'Qn, 'Qm");
2106 } else if (u && opc == 2 && op1) {
2107 Format(instr, "vqsub.u'size3 'Qd, 'Qn, 'Qm");
2108 } else if (u && opc == 3 && op1) {
2109 Format(instr, "vcge.u'size3 'Qd, 'Qn, 'Qm");
2110 } else if (u && opc == 3 && !op1) {
2111 Format(instr, "vcgt.u'size3 'Qd, 'Qn, 'Qm");
2112 } else if (u && opc == 4 && !op1) {
2113 Format(instr, "vshl.u'size3 'Qd, 'Qm, 'Qn");
2114 } else if (u && opc == 6 && op1) {
2115 Format(instr, "vmin.u'size3 'Qd, 'Qn, 'Qm");
2116 } else if (u && opc == 6 && !op1) {
2117 Format(instr, "vmax.u'size3 'Qd, 'Qn, 'Qm");
2118 } else if (u && opc == 8 && op1) {
2119 Format(instr, "vceq.i'size3 'Qd, 'Qn, 'Qm");
2120 } else if (u && opc == 8 && !op1) {
2121 Format(instr, "vsub.i'size3 'Qd, 'Qn, 'Qm");
2122 } else if (u && opc == 0xA && op1) {
2123 Format(instr, "vpmin.u'size3 'Dd, 'Dn, 'Dm");
2124 } else if (u && opc == 0xA && !op1) {
2125 Format(instr, "vpmax.u'size3 'Dd, 'Dn, 'Dm");
2126 } else if (u && opc == 0xD && sz == 0 && q && op1) {
2127 Format(instr, "vmul.f32 'Qd, 'Qn, 'Qm");
2128 } else if (u && opc == 0xD && sz == 0 && !q && !op1) {
2129 Format(instr, "vpadd.f32 'Dd, 'Dn, 'Dm");
2130 } else if (u && opc == 0xE && !(sz >> 1) && !op1) {
2131 Format(instr, "vcge.f32 'Qd, 'Qn, 'Qm");
2132 } else if (u && opc == 0xE && (sz >> 1) && !op1) {
2133 Format(instr, "vcgt.f32 'Qd, 'Qn, 'Qm");
2134 } else {
2135 Unknown(instr);
2136 }
2137 } else if (op0 == 1 && op1 == 0) {
2138 DecodeAdvancedSIMDTwoOrThreeRegisters(instr);
2139 } else if (op0 == 1 && op1 == 1) {
2140 // Advanced SIMD shifts and immediate generation.
2141 if (instr->Bits(21, 19) == 0 && instr->Bit(7) == 0) {
2142 // Advanced SIMD one register and modified immediate.
2143 DecodeVmovImmediate(instr);
2144 } else {
2145 // Advanced SIMD two registers and shift amount.
2146 int u = instr->Bit(24);
2147 int imm3H = instr->Bits(21, 19);
2148 int imm3L = instr->Bits(18, 16);
2149 int opc = instr->Bits(11, 8);
2150 int l = instr->Bit(7);
2151 int q = instr->Bit(6);
2152 int imm3H_L = imm3H << 1 | l;
2153
2154 if (imm3H_L != 0 && opc == 0) {
2155 // vshr.s<size> Qd, Qm, shift
2156 int imm7 = (l << 6) | instr->Bits(21, 16);
2157 int size = base::bits::RoundDownToPowerOfTwo32(imm7);
2158 int shift = 2 * size - imm7;
2159 if (q) {
2160 int Vd = instr->VFPDRegValue(kSimd128Precision);
2161 int Vm = instr->VFPMRegValue(kSimd128Precision);
2163 "vshr.%s%d q%d, q%d, #%d",
2164 u ? "u" : "s", size, Vd, Vm, shift);
2165 } else {
2166 int Vd = instr->VFPDRegValue(kDoublePrecision);
2167 int Vm = instr->VFPMRegValue(kDoublePrecision);
2169 "vshr.%s%d d%d, d%d, #%d",
2170 u ? "u" : "s", size, Vd, Vm, shift);
2171 }
2172 } else if (imm3H_L != 0 && opc == 1) {
2173 // vsra.<type><size> Qd, Qm, shift
2174 // vsra.<type><size> Dd, Dm, shift
2175 int imm7 = (l << 6) | instr->Bits(21, 16);
2176 int size = base::bits::RoundDownToPowerOfTwo32(imm7);
2177 int shift = 2 * size - imm7;
2178 if (q) {
2179 int Vd = instr->VFPDRegValue(kSimd128Precision);
2180 int Vm = instr->VFPMRegValue(kSimd128Precision);
2182 "vsra.%s%d q%d, q%d, #%d",
2183 u ? "u" : "s", size, Vd, Vm, shift);
2184 } else {
2185 int Vd = instr->VFPDRegValue(kDoublePrecision);
2186 int Vm = instr->VFPMRegValue(kDoublePrecision);
2188 "vsra.%s%d d%d, d%d, #%d",
2189 u ? "u" : "s", size, Vd, Vm, shift);
2190 }
2191 } else if (imm3H_L != 0 && imm3L == 0 && opc == 0b1010 && !q) {
2192 // vmovl
2193 if ((instr->VdValue() & 1) != 0) Unknown(instr);
2194 int Vd = instr->VFPDRegValue(kSimd128Precision);
2195 int Vm = instr->VFPMRegValue(kDoublePrecision);
2196 int imm3H = instr->Bits(21, 19);
2198 base::SNPrintF(out_buffer_ + out_buffer_pos_, "vmovl.%s%d q%d, d%d",
2199 u ? "u" : "s", imm3H * 8, Vd, Vm);
2200 } else if (!u && imm3H_L != 0 && opc == 0b0101) {
2201 // vshl.i<size> Qd, Qm, shift
2202 int imm7 = (l << 6) | instr->Bits(21, 16);
2203 int size = base::bits::RoundDownToPowerOfTwo32(imm7);
2204 int shift = imm7 - size;
2205 int Vd = instr->VFPDRegValue(kSimd128Precision);
2206 int Vm = instr->VFPMRegValue(kSimd128Precision);
2209 "vshl.i%d q%d, q%d, #%d", size, Vd, Vm, shift);
2210 } else if (u && imm3H_L != 0 && (opc & 0b1110) == 0b0100) {
2211 // vsli.<size> Dd, Dm, shift
2212 // vsri.<size> Dd, Dm, shift
2213 int imm7 = (l << 6) | instr->Bits(21, 16);
2214 int size = base::bits::RoundDownToPowerOfTwo32(imm7);
2215 int shift;
2216 char direction;
2217 if (instr->Bit(8) == 1) {
2218 shift = imm7 - size;
2219 direction = 'l'; // vsli
2220 } else {
2221 shift = 2 * size - imm7;
2222 direction = 'r'; // vsri
2223 }
2224 int Vd = instr->VFPDRegValue(kDoublePrecision);
2225 int Vm = instr->VFPMRegValue(kDoublePrecision);
2227 "vs%ci.%d d%d, d%d, #%d", direction,
2228 size, Vd, Vm, shift);
2229 }
2230 }
2231 } else {
2232 Unknown(instr);
2233 }
2234}
2235
2236void Decoder::DecodeAdvancedSIMDTwoOrThreeRegisters(Instruction* instr) {
2237 // Advanced SIMD two registers, or three registers of different lengths.
2238 int op0 = instr->Bit(24);
2239 int op1 = instr->Bits(21, 20);
2240 int op2 = instr->Bits(11, 10);
2241 int op3 = instr->Bit(6);
2242 if (!op0 && op1 == 0b11) {
2243 // vext.8 Qd, Qm, Qn, imm4
2244 int imm4 = instr->Bits(11, 8);
2245 int Vd = instr->VFPDRegValue(kSimd128Precision);
2246 int Vm = instr->VFPMRegValue(kSimd128Precision);
2247 int Vn = instr->VFPNRegValue(kSimd128Precision);
2250 "vext.8 q%d, q%d, q%d, #%d", Vd, Vn, Vm, imm4);
2251 } else if (op0 && op1 == 0b11 && ((op2 >> 1) == 0)) {
2252 // Advanced SIMD two registers misc
2253 int size = instr->Bits(19, 18);
2254 int opc1 = instr->Bits(17, 16);
2255 int opc2 = instr->Bits(10, 7);
2256 int q = instr->Bit(6);
2257 int Vd = instr->VFPDRegValue(q ? kSimd128Precision : kDoublePrecision);
2258 int Vm = instr->VFPMRegValue(q ? kSimd128Precision : kDoublePrecision);
2259
2260 int esize = kBitsPerByte * (1 << size);
2261 if (opc1 == 0 && (opc2 >> 2) == 0) {
2262 int op = kBitsPerByte << (static_cast<int>(Neon64) - instr->Bits(8, 7));
2263 // vrev<op>.<esize> Qd, Qm.
2265 base::SNPrintF(out_buffer_ + out_buffer_pos_, "vrev%d.%d q%d, q%d",
2266 op, esize, Vd, Vm);
2267 } else if (opc1 == 0 && opc2 == 0b1100) {
2268 Format(instr, q ? "vpadal.s'size2 'Qd, 'Qm" : "vpadal.s'size2 'Dd, 'Dm");
2269 } else if (opc1 == 0 && opc2 == 0b1101) {
2270 Format(instr, q ? "vpadal.u'size2 'Qd, 'Qm" : "vpadal.u'size2 'Dd, 'Dm");
2271 } else if (opc1 == 0 && opc2 == 0b0100) {
2272 Format(instr, q ? "vpaddl.s'size2 'Qd, 'Qm" : "vpaddl.s'size2 'Dd, 'Dm");
2273 } else if (opc1 == 0 && opc2 == 0b0101) {
2274 Format(instr, q ? "vpaddl.u'size2 'Qd, 'Qm" : "vpaddl.u'size2 'Dd, 'Dm");
2275 } else if (size == 0 && opc1 == 0b10 && opc2 == 0) {
2276 Format(instr, q ? "vswp 'Qd, 'Qm" : "vswp 'Dd, 'Dm");
2277 } else if (opc1 == 0 && opc2 == 0b1010) {
2278 DCHECK_EQ(0, size);
2279 Format(instr, q ? "vcnt.8 'Qd, 'Qm" : "vcnt.8 'Dd, 'Dm");
2280 } else if (opc1 == 0 && opc2 == 0b1011) {
2281 Format(instr, "vmvn 'Qd, 'Qm");
2282 } else if (opc1 == 0b01 && opc2 == 0b0010) {
2283 DCHECK_NE(0b11, size);
2284 Format(instr,
2285 q ? "vceq.s'size2 'Qd, 'Qm, #0" : "vceq.s.'size2 'Dd, 'Dm, #0");
2286 } else if (opc1 == 0b01 && opc2 == 0b0100) {
2287 DCHECK_NE(0b11, size);
2288 Format(instr,
2289 q ? "vclt.s'size2 'Qd, 'Qm, #0" : "vclt.s.'size2 'Dd, 'Dm, #0");
2290 } else if (opc1 == 0b01 && opc2 == 0b0110) {
2291 Format(instr, q ? "vabs.s'size2 'Qd, 'Qm" : "vabs.s.'size2 'Dd, 'Dm");
2292 } else if (opc1 == 0b01 && opc2 == 0b1110) {
2293 Format(instr, q ? "vabs.f'size2 'Qd, 'Qm" : "vabs.f.'size2 'Dd, 'Dm");
2294 } else if (opc1 == 0b01 && opc2 == 0b0111) {
2295 Format(instr, q ? "vneg.s'size2 'Qd, 'Qm" : "vneg.s.'size2 'Dd, 'Dm");
2296 } else if (opc1 == 0b01 && opc2 == 0b1111) {
2297 Format(instr, q ? "vneg.f'size2 'Qd, 'Qm" : "vneg.f.'size2 'Dd, 'Dm");
2298 } else if (opc1 == 0b10 && opc2 == 0b0001) {
2299 Format(instr, q ? "vtrn.'size2 'Qd, 'Qm" : "vtrn.'size2 'Dd, 'Dm");
2300 } else if (opc1 == 0b10 && opc2 == 0b0010) {
2301 Format(instr, q ? "vuzp.'size2 'Qd, 'Qm" : "vuzp.'size2 'Dd, 'Dm");
2302 } else if (opc1 == 0b10 && opc2 == 0b0011) {
2303 Format(instr, q ? "vzip.'size2 'Qd, 'Qm" : "vzip.'size2 'Dd, 'Dm");
2304 } else if (opc1 == 0b10 && (opc2 & 0b1110) == 0b0100) {
2305 // vqmov{u}n.<type><esize> Dd, Qm.
2306 int Vd = instr->VFPDRegValue(kDoublePrecision);
2307 int Vm = instr->VFPMRegValue(kSimd128Precision);
2308 int op = instr->Bits(7, 6);
2309 const char* name = op == 0b01 ? "vqmovun" : "vqmovn";
2310 char type = op == 0b11 ? 'u' : 's';
2312 base::SNPrintF(out_buffer_ + out_buffer_pos_, "%s.%c%i d%d, q%d",
2313 name, type, esize << 1, Vd, Vm);
2314 } else if (opc1 == 0b10 && opc2 == 0b1000) {
2315 Format(instr, q ? "vrintn.f32 'Qd, 'Qm" : "vrintn.f32 'Dd, 'Dm");
2316 } else if (opc1 == 0b10 && opc2 == 0b1011) {
2317 Format(instr, q ? "vrintz.f32 'Qd, 'Qm" : "vrintz.f32 'Dd, 'Dm");
2318 } else if (opc1 == 0b10 && opc2 == 0b1101) {
2319 Format(instr, q ? "vrintm.f32 'Qd, 'Qm" : "vrintm.f32 'Qd, 'Qm");
2320 } else if (opc1 == 0b10 && opc2 == 0b1111) {
2321 Format(instr, q ? "vrintp.f32 'Qd, 'Qm" : "vrintp.f32 'Qd, 'Qm");
2322 } else if (opc1 == 0b11 && (opc2 & 0b1101) == 0b1000) {
2323 Format(instr, "vrecpe.f32 'Qd, 'Qm");
2324 } else if (opc1 == 0b11 && (opc2 & 0b1101) == 0b1001) {
2325 Format(instr, "vrsqrte.f32 'Qd, 'Qm");
2326 } else if (opc1 == 0b11 && (opc2 & 0b1100) == 0b1100) {
2327 const char* suffix = nullptr;
2328 int op = instr->Bits(8, 7);
2329 switch (op) {
2330 case 0:
2331 suffix = "f32.s32";
2332 break;
2333 case 1:
2334 suffix = "f32.u32";
2335 break;
2336 case 2:
2337 suffix = "s32.f32";
2338 break;
2339 case 3:
2340 suffix = "u32.f32";
2341 break;
2342 }
2344 "vcvt.%s q%d, q%d", suffix, Vd, Vm);
2345 }
2346 } else if (op0 && op1 == 0b11 && op2 == 0b10) {
2347 // VTBL, VTBX
2348 int Vd = instr->VFPDRegValue(kDoublePrecision);
2349 int Vn = instr->VFPNRegValue(kDoublePrecision);
2350 int Vm = instr->VFPMRegValue(kDoublePrecision);
2351 int len = instr->Bits(9, 8);
2352 NeonListOperand list(DwVfpRegister::from_code(Vn), len + 1);
2355 instr->Bit(6) == 0 ? "vtbl.8" : "vtbx.8", Vd);
2356 FormatNeonList(Vn, list.type());
2357 Print(", ");
2358 PrintDRegister(Vm);
2359 } else if (op0 && op1 == 0b11 && op2 == 0b11) {
2360 // Advanced SIMD duplicate (scalar)
2361 if (instr->Bits(9, 7) == 0) {
2362 // VDUP (scalar)
2363 int Vm = instr->VFPMRegValue(kDoublePrecision);
2364 int imm4 = instr->Bits(19, 16);
2365 int esize = 0, index = 0;
2366 if ((imm4 & 0x1) != 0) {
2367 esize = 8;
2368 index = imm4 >> 1;
2369 } else if ((imm4 & 0x2) != 0) {
2370 esize = 16;
2371 index = imm4 >> 2;
2372 } else {
2373 esize = 32;
2374 index = imm4 >> 3;
2375 }
2376 if (instr->Bit(6) == 0) {
2377 int Vd = instr->VFPDRegValue(kDoublePrecision);
2380 "vdup.%i d%d, d%d[%d]", esize, Vd, Vm, index);
2381 } else {
2382 int Vd = instr->VFPDRegValue(kSimd128Precision);
2385 "vdup.%i q%d, d%d[%d]", esize, Vd, Vm, index);
2386 }
2387 } else {
2388 Unknown(instr);
2389 }
2390 } else if (op1 != 0b11 && !op3) {
2391 // Advanced SIMD three registers of different lengths.
2392 int u = instr->Bit(24);
2393 int opc = instr->Bits(11, 8);
2394 if (opc == 0b1000) {
2395 Format(instr,
2396 u ? "vmlal.u'size3 'Qd, 'Dn, 'Dm" : "vmlal.s'size3 'Qd, 'Dn, 'Dm");
2397 } else if (opc == 0b1100) {
2398 Format(instr,
2399 u ? "vmull.u'size3 'Qd, 'Dn, 'Dm" : "vmull.s'size3 'Qd, 'Dn, 'Dm");
2400 }
2401 } else if (op1 != 0b11 && op3) {
2402 // The instructions specified by this encoding are not used in V8.
2403 Unknown(instr);
2404 } else {
2405 Unknown(instr);
2406 }
2407}
2408
2409void Decoder::DecodeMemoryHintsAndBarriers(Instruction* instr) {
2410 int op0 = instr->Bits(25, 21);
2411 if (op0 == 0b01011) {
2412 // Barriers.
2413 int option = instr->Bits(3, 0);
2414 switch (instr->Bits(7, 4)) {
2415 case 4:
2418 barrier_option_names[option]);
2419 break;
2420 case 5:
2423 barrier_option_names[option]);
2424 break;
2425 case 6:
2428 barrier_option_names[option]);
2429 break;
2430 default:
2431 Unknown(instr);
2432 }
2433 } else if ((op0 & 0b10001) == 0b00000 && !instr->Bit(4)) {
2434 // Preload (immediate).
2435 const char* rn_name = converter_.NameOfCPURegister(instr->Bits(19, 16));
2436 int offset = instr->Bits(11, 0);
2437 if (offset == 0) {
2439 base::SNPrintF(out_buffer_ + out_buffer_pos_, "pld [%s]", rn_name);
2440 } else if (instr->Bit(23) == 0) {
2442 "pld [%s, #-%d]", rn_name, offset);
2443 } else {
2445 "pld [%s, #+%d]", rn_name, offset);
2446 }
2447 } else {
2448 Unknown(instr);
2449 }
2450}
2451
2452void Decoder::DecodeAdvancedSIMDElementOrStructureLoadStore(
2453 Instruction* instr) {
2454 int op0 = instr->Bit(23);
2455 int op1 = instr->Bits(11, 10);
2456 int l = instr->Bit(21);
2457 int n = instr->Bits(9, 8);
2458 int Vd = instr->VFPDRegValue(kDoublePrecision);
2459 int Rn = instr->VnValue();
2460 int Rm = instr->VmValue();
2461
2462 if (op0 == 0) {
2463 // Advanced SIMD load/store multiple structures.
2464 int itype = instr->Bits(11, 8);
2465 if (itype == nlt_1 || itype == nlt_2 || itype == nlt_3 || itype == nlt_4) {
2466 // vld1/vst1
2467 int size = instr->Bits(7, 6);
2468 int align = instr->Bits(5, 4);
2469 const char* op = l ? "vld1.%d " : "vst1.%d ";
2471 base::SNPrintF(out_buffer_ + out_buffer_pos_, op, (1 << size) << 3);
2472 FormatNeonList(Vd, itype);
2473 Print(", ");
2474 FormatNeonMemory(Rn, align, Rm);
2475 } else {
2476 Unknown(instr);
2477 }
2478 } else if (op1 == 0b11) {
2479 // Advanced SIMD load single structure to all lanes.
2480 if (l && n == 0b00) {
2481 // vld1r(replicate) single element to all lanes.
2482 int size = instr->Bits(7, 6);
2483 DCHECK_NE(0b11, size);
2484 int type = instr->Bit(5) ? nlt_2 : nlt_1;
2486 "vld1.%d ", (1 << size) << 3);
2487 FormatNeonList(Vd, type);
2488 DCHECK_EQ(0, instr->Bit(4)); // Alignment not supported.
2489 Print(", ");
2490 FormatNeonMemory(Rn, 0, Rm);
2491 } else {
2492 Unknown(instr);
2493 }
2494 } else if (op1 != 0b11) {
2495 // Advanced SIMD load/store single structure to one lane.
2496 int size = op1; // size and op1 occupy the same bits in decoding.
2497 int index_align = instr->Bits(7, 4);
2498 int index = index_align >> (size + 1);
2499 if (n == 0b00) {
2500 // vld1 (single element to one lane) - A1, A2, A3.
2501 // vst1 (single element to one lane) - A1, A2, A3.
2502 // Omit alignment.
2504 base::SNPrintF(out_buffer_ + out_buffer_pos_, "v%s1.%d {d%d[%d]}",
2505 (l ? "ld" : "st"), (1 << size) << 3, Vd, index);
2506 Print(", ");
2507 FormatNeonMemory(Rn, 0, Rm);
2508 } else {
2509 Unknown(instr);
2510 }
2511 } else {
2512 Unknown(instr);
2513 }
2514}
2515
2516#undef VERIFY
2517
2518bool Decoder::IsConstantPoolAt(uint8_t* instr_ptr) {
2519 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
2520 return (instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker;
2521}
2522
2523int Decoder::ConstantPoolSizeAt(uint8_t* instr_ptr) {
2524 if (IsConstantPoolAt(instr_ptr)) {
2525 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
2526 return DecodeConstantPoolLength(instruction_bits);
2527 } else {
2528 return -1;
2529 }
2530}
2531
2532// Disassemble the instruction at *instr_ptr into the output buffer.
2533int Decoder::InstructionDecode(uint8_t* instr_ptr) {
2534 Instruction* instr = Instruction::At(reinterpret_cast<Address>(instr_ptr));
2535 // Print raw instruction bytes.
2537 "%08x ", instr->InstructionBits());
2538 if (instr->ConditionField() == kSpecialCondition) {
2539 DecodeSpecialCondition(instr);
2540 return kInstrSize;
2541 }
2542 int instruction_bits = *(reinterpret_cast<int*>(instr_ptr));
2543 if ((instruction_bits & kConstantPoolMarkerMask) == kConstantPoolMarker) {
2545 out_buffer_ + out_buffer_pos_, "constant pool begin (length %d)",
2546 DecodeConstantPoolLength(instruction_bits));
2547 return kInstrSize;
2548 }
2549 switch (instr->TypeValue()) {
2550 case 0:
2551 case 1: {
2552 DecodeType01(instr);
2553 break;
2554 }
2555 case 2: {
2556 DecodeType2(instr);
2557 break;
2558 }
2559 case 3: {
2560 DecodeType3(instr);
2561 break;
2562 }
2563 case 4: {
2564 DecodeType4(instr);
2565 break;
2566 }
2567 case 5: {
2568 DecodeType5(instr);
2569 break;
2570 }
2571 case 6: {
2572 DecodeType6(instr);
2573 break;
2574 }
2575 case 7: {
2576 return DecodeType7(instr);
2577 }
2578 default: {
2579 // The type field is 3-bits in the ARM encoding.
2580 UNREACHABLE();
2581 }
2582 }
2583 return kInstrSize;
2584}
2585
2586} // namespace internal
2587} // namespace v8
2588
2589//------------------------------------------------------------------------------
2590
2591namespace disasm {
2592
2593const char* NameConverter::NameOfAddress(uint8_t* addr) const {
2594 v8::base::SNPrintF(tmp_buffer_, "%p", static_cast<void*>(addr));
2595 return tmp_buffer_.begin();
2596}
2597
2598const char* NameConverter::NameOfConstant(uint8_t* addr) const {
2599 return NameOfAddress(addr);
2600}
2601
2602const char* NameConverter::NameOfCPURegister(int reg) const {
2603 return RegisterName(i::Register::from_code(reg));
2604}
2605
2606const char* NameConverter::NameOfByteCPURegister(int reg) const {
2607 UNREACHABLE(); // ARM does not have the concept of a byte register
2608}
2609
2610const char* NameConverter::NameOfXMMRegister(int reg) const {
2611 UNREACHABLE(); // ARM does not have any XMM registers
2612}
2613
2614const char* NameConverter::NameInCode(uint8_t* addr) const {
2615 // The default name converter is called for unknown code. So we will not try
2616 // to access any memory.
2617 return "";
2618}
2619
2620//------------------------------------------------------------------------------
2621
2623 uint8_t* instruction) {
2625 return d.InstructionDecode(instruction);
2626}
2627
2628int Disassembler::ConstantPoolSizeAt(uint8_t* instruction) {
2629 return v8::internal::Decoder::ConstantPoolSizeAt(instruction);
2630}
2631
2632void Disassembler::Disassemble(FILE* f, uint8_t* begin, uint8_t* end,
2633 UnimplementedOpcodeAction unimplemented_action) {
2634 NameConverter converter;
2635 Disassembler d(converter, unimplemented_action);
2636 for (uint8_t* pc = begin; pc < end;) {
2638 buffer[0] = '\0';
2639 uint8_t* prev_pc = pc;
2640 pc += d.InstructionDecode(buffer, pc);
2641 v8::internal::PrintF(f, "%p %08x %s\n", static_cast<void*>(prev_pc),
2642 *reinterpret_cast<int32_t*>(prev_pc), buffer.begin());
2643 }
2644}
2645
2646#undef STRING_STARTS_WITH
2647
2648} // namespace disasm
2649
2650#endif // V8_TARGET_ARCH_ARM
static V8_EXPORT_PRIVATE void Disassemble(FILE *f, uint8_t *begin, uint8_t *end, UnimplementedOpcodeAction unimplemented_action=kAbortOnUnimplementedOpcode)
V8_EXPORT_PRIVATE int InstructionDecode(v8::base::Vector< char > buffer, uint8_t *instruction)
int ConstantPoolSizeAt(uint8_t *instruction)
Disassembler(const NameConverter &converter, UnimplementedOpcodeAction unimplemented_opcode_action=kAbortOnUnimplementedOpcode)
Definition disasm.h:44
const NameConverter & converter_
Definition disasm.h:71
virtual const char * NameOfAddress(uint8_t *addr) const
virtual const char * NameOfXMMRegister(int reg) const
virtual const char * NameInCode(uint8_t *addr) const
virtual const char * NameOfConstant(uint8_t *addr) const
v8::base::EmbeddedVector< char, 128 > tmp_buffer_
Definition disasm.h:32
virtual const char * NameOfByteCPURegister(int reg) const
virtual const char * NameOfCPURegister(int reg) const
int length() const
Definition vector.h:64
constexpr T * begin() const
Definition vector.h:96
void Format(Instruction *instr, const char *format)
int InstructionDecode(uint8_t *instruction)
void Unknown(Instruction *instr)
const disasm::NameConverter & converter_
void PrintRegister(int reg)
void PrintChar(const char ch)
v8::base::Vector< char > out_buffer_
int FormatOption(Instruction *instr, const char *option)
int FormatRegister(Instruction *instr, const char *option)
void Print(const char *str)
Decoder & operator=(const Decoder &)=delete
static constexpr int kPcLoadDelta
static Instruction * At(Address pc)
static constexpr QwNeonRegister from_code(int8_t code)
static const char * Name(int reg, bool is_double)
int end
#define STRING_STARTS_WITH(string, compare_string)
ArrayReduceDirection direction
Precision precision
RoundingMode rounding_mode
Instruction * instr
LiftoffRegister reg
uint32_t const mask
int int32_t
Definition unicode.cc:40
uint32_t RoundDownToPowerOfTwo32(uint32_t value)
Definition bits.h:265
constexpr uint32_t RotateRight32(uint32_t value, uint32_t shift)
Definition bits.h:274
int SNPrintF(Vector< char > str, const char *format,...)
Definition strings.cc:20
constexpr Opcode ADD
constexpr MiscInstructionsBits74 CLZ
constexpr Opcode ORR
constexpr BlockAddrMode ia_x
constexpr Opcode AND
constexpr Opcode BIC
constexpr int kBitsPerByte
Definition globals.h:682
constexpr int kPCRegister
constexpr SoftwareInterruptCodes kStopCode
constexpr BlockAddrMode db_x
constexpr Opcode RSC
void PrintF(const char *format,...)
Definition utils.cc:39
int DecodeConstantPoolLength(int instr)
constexpr Opcode MOV
constexpr ShiftOp LSR
constexpr NeonSize Neon64
constexpr ShiftOp ASR
constexpr NeonListType nlt_3
constexpr ShiftOp LSL
constexpr NeonListType nlt_2
constexpr MiscInstructionsBits74 BKPT
constexpr SoftwareInterruptCodes kBreakpoint
constexpr VFPRegPrecision kDoublePrecision
constexpr SoftwareInterruptCodes kCallRtRedirected
constexpr Opcode SBC
constexpr BlockAddrMode da_x
constexpr Opcode MVN
const int kConstantPoolMarkerMask
constexpr ShiftOp kNumberOfShifts
constexpr Opcode TEQ
constexpr MiscInstructionsBits74 BLX
constexpr Opcode SUB
constexpr Opcode CMN
constexpr ShiftOp ROR
constexpr Opcode TST
constexpr uint8_t kInstrSize
constexpr Opcode ADC
constexpr Opcode EOR
constexpr Opcode CMP
constexpr NeonListType nlt_1
constexpr Opcode RSB
constexpr MiscInstructionsBits74 BX
constexpr NeonListType nlt_4
constexpr VFPRegPrecision kSinglePrecision
constexpr VFPRegPrecision kSimd128Precision
constexpr BlockAddrMode ib_x
const int kConstantPoolMarker
constexpr uint32_t kStopCodeMask
#define UNREACHABLE()
Definition logging.h:67
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define DCHECK_GT(v1, v2)
Definition logging.h:487