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