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