blob: 1c05bc3a4a4916d84a0ca4afd1ca75e74a00cd35 [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 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100404 case 'f': { // 'f: bitfield instructions - v7 and above.
405 uint32_t lsbit = instr->Bits(11, 7);
406 uint32_t width = instr->Bits(20, 16) + 1;
407 if (instr->Bit(21) == 0) {
408 // BFC/BFI:
409 // Bits 20-16 represent most-significant bit. Covert to width.
410 width -= lsbit;
411 ASSERT(width > 0);
412 }
413 ASSERT((width + lsbit) <= 32);
414 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
415 "#%d, #%d", lsbit, width);
416 return 1;
417 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000418 case 'h': { // 'h: halfword operation for extra loads and stores
419 if (instr->HasH()) {
420 Print("h");
421 } else {
422 Print("b");
423 }
424 return 1;
425 }
426 case 'l': { // 'l: branch and link
427 if (instr->HasLink()) {
428 Print("l");
429 }
430 return 1;
431 }
432 case 'm': {
433 if (format[1] == 'e') { // 'memop: load/store instructions
434 ASSERT(STRING_STARTS_WITH(format, "memop"));
435 if (instr->HasL()) {
436 Print("ldr");
Kristian Monsen25f61362010-05-21 11:50:48 +0100437 } else if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0)) {
438 if (instr->Bits(7, 4) == 0xf) {
439 Print("strd");
440 } else {
441 Print("ldrd");
442 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000443 } else {
444 Print("str");
445 }
446 return 5;
447 }
448 // 'msg: for simulator break instructions
449 ASSERT(STRING_STARTS_WITH(format, "msg"));
450 byte* str =
451 reinterpret_cast<byte*>(instr->InstructionBits() & 0x0fffffff);
452 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
453 "%s", converter_.NameInCode(str));
454 return 3;
455 }
456 case 'o': {
Andrei Popescu31002712010-02-23 13:46:05 +0000457 if ((format[3] == '1') && (format[4] == '2')) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000458 // 'off12: 12-bit offset for load and store instructions
459 ASSERT(STRING_STARTS_WITH(format, "off12"));
460 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
461 "%d", instr->Offset12Field());
462 return 5;
Steve Block6ded16b2010-05-10 14:33:55 +0100463 } else if (format[3] == '0') {
464 // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0.
465 ASSERT(STRING_STARTS_WITH(format, "off0to3and8to19"));
466 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
467 "%d",
468 (instr->Bits(19, 8) << 4) +
469 instr->Bits(3, 0));
470 return 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000471 }
472 // 'off8: 8-bit offset for extra load and store instructions
473 ASSERT(STRING_STARTS_WITH(format, "off8"));
474 int offs8 = (instr->ImmedHField() << 4) | instr->ImmedLField();
475 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
476 "%d", offs8);
477 return 4;
478 }
479 case 'p': { // 'pu: P and U bits for load and store instructions
480 ASSERT(STRING_STARTS_WITH(format, "pu"));
481 PrintPU(instr);
482 return 2;
483 }
484 case 'r': {
485 return FormatRegister(instr, format);
486 }
487 case 's': {
488 if (format[1] == 'h') { // 'shift_op or 'shift_rm
489 if (format[6] == 'o') { // 'shift_op
490 ASSERT(STRING_STARTS_WITH(format, "shift_op"));
491 if (instr->TypeField() == 0) {
492 PrintShiftRm(instr);
493 } else {
494 ASSERT(instr->TypeField() == 1);
495 PrintShiftImm(instr);
496 }
497 return 8;
498 } else { // 'shift_rm
499 ASSERT(STRING_STARTS_WITH(format, "shift_rm"));
500 PrintShiftRm(instr);
501 return 8;
502 }
503 } else if (format[1] == 'w') { // 'swi
504 ASSERT(STRING_STARTS_WITH(format, "swi"));
505 PrintSoftwareInterrupt(instr->SwiField());
506 return 3;
507 } else if (format[1] == 'i') { // 'sign: signed extra loads and stores
508 ASSERT(STRING_STARTS_WITH(format, "sign"));
509 if (instr->HasSign()) {
510 Print("s");
511 }
512 return 4;
513 }
514 // 's: S field of data processing instructions
515 if (instr->HasS()) {
516 Print("s");
517 }
518 return 1;
519 }
520 case 't': { // 'target: target of branch instructions
521 ASSERT(STRING_STARTS_WITH(format, "target"));
522 int off = (instr->SImmed24Field() << 2) + 8;
523 out_buffer_pos_ += v8i::OS::SNPrintF(
524 out_buffer_ + out_buffer_pos_,
525 "%+d -> %s",
526 off,
527 converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + off));
528 return 6;
529 }
530 case 'u': { // 'u: signed or unsigned multiplies
531 // The manual gets the meaning of bit 22 backwards in the multiply
532 // instruction overview on page A3.16.2. The instructions that
533 // exist in u and s variants are the following:
534 // smull A4.1.87
535 // umull A4.1.129
536 // umlal A4.1.128
537 // smlal A4.1.76
538 // For these 0 means u and 1 means s. As can be seen on their individual
539 // pages. The other 18 mul instructions have the bit set or unset in
540 // arbitrary ways that are unrelated to the signedness of the instruction.
541 // None of these 18 instructions exist in both a 'u' and an 's' variant.
542
543 if (instr->Bit(22) == 0) {
544 Print("u");
545 } else {
546 Print("s");
547 }
548 return 1;
549 }
Steve Blockd0582a62009-12-15 09:54:21 +0000550 case 'v': {
551 return FormatVFPinstruction(instr, format);
552 }
553 case 'S':
554 case 'D': {
555 return FormatVFPRegister(instr, format);
556 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000557 case 'w': { // 'w: W field of load and store instructions
558 if (instr->HasW()) {
559 Print("!");
560 }
561 return 1;
562 }
563 default: {
564 UNREACHABLE();
565 break;
566 }
567 }
568 UNREACHABLE();
569 return -1;
570}
571
572
573// Format takes a formatting string for a whole instruction and prints it into
574// the output buffer. All escaped options are handed to FormatOption to be
575// parsed further.
576void Decoder::Format(Instr* instr, const char* format) {
577 char cur = *format++;
578 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
579 if (cur == '\'') { // Single quote is used as the formatting escape.
580 format += FormatOption(instr, format);
581 } else {
582 out_buffer_[out_buffer_pos_++] = cur;
583 }
584 cur = *format++;
585 }
586 out_buffer_[out_buffer_pos_] = '\0';
587}
588
589
590// For currently unimplemented decodings the disassembler calls Unknown(instr)
591// which will just print "unknown" of the instruction bits.
592void Decoder::Unknown(Instr* instr) {
593 Format(instr, "unknown");
594}
595
596
597void Decoder::DecodeType01(Instr* instr) {
598 int type = instr->TypeField();
599 if ((type == 0) && instr->IsSpecialType0()) {
600 // multiply instruction or extra loads and stores
601 if (instr->Bits(7, 4) == 9) {
602 if (instr->Bit(24) == 0) {
603 // multiply instructions
604 if (instr->Bit(23) == 0) {
605 if (instr->Bit(21) == 0) {
606 // The MUL instruction description (A 4.1.33) refers to Rd as being
607 // the destination for the operation, but it confusingly uses the
608 // Rn field to encode it.
609 Format(instr, "mul'cond's 'rn, 'rm, 'rs");
610 } else {
611 // The MLA instruction description (A 4.1.28) refers to the order
612 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
613 // Rn field to encode the Rd register and the Rd field to encode
614 // the Rn register.
615 Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd");
616 }
617 } else {
618 // The signed/long multiply instructions use the terms RdHi and RdLo
619 // when referring to the target registers. They are mapped to the Rn
620 // and Rd fields as follows:
621 // RdLo == Rd field
622 // RdHi == Rn field
623 // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs>
624 Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs");
625 }
626 } else {
627 Unknown(instr); // not used by V8
628 }
Kristian Monsen25f61362010-05-21 11:50:48 +0100629 } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xd) == 0xd)) {
630 // ldrd, strd
631 switch (instr->PUField()) {
632 case 0: {
633 if (instr->Bit(22) == 0) {
634 Format(instr, "'memop'cond's 'rd, ['rn], -'rm");
635 } else {
636 Format(instr, "'memop'cond's 'rd, ['rn], #-'off8");
637 }
638 break;
639 }
640 case 1: {
641 if (instr->Bit(22) == 0) {
642 Format(instr, "'memop'cond's 'rd, ['rn], +'rm");
643 } else {
644 Format(instr, "'memop'cond's 'rd, ['rn], #+'off8");
645 }
646 break;
647 }
648 case 2: {
649 if (instr->Bit(22) == 0) {
650 Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w");
651 } else {
652 Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w");
653 }
654 break;
655 }
656 case 3: {
657 if (instr->Bit(22) == 0) {
658 Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w");
659 } else {
660 Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w");
661 }
662 break;
663 }
664 default: {
665 // The PU field is a 2-bit field.
666 UNREACHABLE();
667 break;
668 }
669 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000670 } else {
671 // extra load/store instructions
672 switch (instr->PUField()) {
673 case 0: {
674 if (instr->Bit(22) == 0) {
675 Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm");
676 } else {
677 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8");
678 }
679 break;
680 }
681 case 1: {
682 if (instr->Bit(22) == 0) {
683 Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm");
684 } else {
685 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8");
686 }
687 break;
688 }
689 case 2: {
690 if (instr->Bit(22) == 0) {
691 Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w");
692 } else {
693 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w");
694 }
695 break;
696 }
697 case 3: {
698 if (instr->Bit(22) == 0) {
699 Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w");
700 } else {
701 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w");
702 }
703 break;
704 }
705 default: {
706 // The PU field is a 2-bit field.
707 UNREACHABLE();
708 break;
709 }
710 }
711 return;
712 }
Steve Block6ded16b2010-05-10 14:33:55 +0100713 } else if ((type == 0) && instr->IsMiscType0()) {
714 if (instr->Bits(22, 21) == 1) {
715 switch (instr->Bits(7, 4)) {
716 case BX:
717 Format(instr, "bx'cond 'rm");
718 break;
719 case BLX:
720 Format(instr, "blx'cond 'rm");
721 break;
722 case BKPT:
723 Format(instr, "bkpt 'off0to3and8to19");
724 break;
725 default:
726 Unknown(instr); // not used by V8
727 break;
728 }
729 } else if (instr->Bits(22, 21) == 3) {
730 switch (instr->Bits(7, 4)) {
731 case CLZ:
732 Format(instr, "clz'cond 'rd, 'rm");
733 break;
734 default:
735 Unknown(instr); // not used by V8
736 break;
737 }
738 } else {
739 Unknown(instr); // not used by V8
740 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000741 } else {
742 switch (instr->OpcodeField()) {
743 case AND: {
744 Format(instr, "and'cond's 'rd, 'rn, 'shift_op");
745 break;
746 }
747 case EOR: {
748 Format(instr, "eor'cond's 'rd, 'rn, 'shift_op");
749 break;
750 }
751 case SUB: {
752 Format(instr, "sub'cond's 'rd, 'rn, 'shift_op");
753 break;
754 }
755 case RSB: {
756 Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op");
757 break;
758 }
759 case ADD: {
760 Format(instr, "add'cond's 'rd, 'rn, 'shift_op");
761 break;
762 }
763 case ADC: {
764 Format(instr, "adc'cond's 'rd, 'rn, 'shift_op");
765 break;
766 }
767 case SBC: {
768 Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op");
769 break;
770 }
771 case RSC: {
772 Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op");
773 break;
774 }
775 case TST: {
776 if (instr->HasS()) {
777 Format(instr, "tst'cond 'rn, 'shift_op");
778 } else {
779 Unknown(instr); // not used by V8
780 }
781 break;
782 }
783 case TEQ: {
784 if (instr->HasS()) {
785 Format(instr, "teq'cond 'rn, 'shift_op");
786 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100787 // Other instructions matching this pattern are handled in the
788 // miscellaneous instructions part above.
789 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000790 }
791 break;
792 }
793 case CMP: {
794 if (instr->HasS()) {
795 Format(instr, "cmp'cond 'rn, 'shift_op");
796 } else {
797 Unknown(instr); // not used by V8
798 }
799 break;
800 }
801 case CMN: {
802 if (instr->HasS()) {
803 Format(instr, "cmn'cond 'rn, 'shift_op");
804 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100805 // Other instructions matching this pattern are handled in the
806 // miscellaneous instructions part above.
807 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000808 }
809 break;
810 }
811 case ORR: {
812 Format(instr, "orr'cond's 'rd, 'rn, 'shift_op");
813 break;
814 }
815 case MOV: {
816 Format(instr, "mov'cond's 'rd, 'shift_op");
817 break;
818 }
819 case BIC: {
820 Format(instr, "bic'cond's 'rd, 'rn, 'shift_op");
821 break;
822 }
823 case MVN: {
824 Format(instr, "mvn'cond's 'rd, 'shift_op");
825 break;
826 }
827 default: {
828 // The Opcode field is a 4-bit field.
829 UNREACHABLE();
830 break;
831 }
832 }
833 }
834}
835
836
837void Decoder::DecodeType2(Instr* instr) {
838 switch (instr->PUField()) {
839 case 0: {
840 if (instr->HasW()) {
841 Unknown(instr); // not used in V8
842 }
843 Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12");
844 break;
845 }
846 case 1: {
847 if (instr->HasW()) {
848 Unknown(instr); // not used in V8
849 }
850 Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12");
851 break;
852 }
853 case 2: {
854 Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w");
855 break;
856 }
857 case 3: {
858 Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w");
859 break;
860 }
861 default: {
862 // The PU field is a 2-bit field.
863 UNREACHABLE();
864 break;
865 }
866 }
867}
868
869
870void Decoder::DecodeType3(Instr* instr) {
871 switch (instr->PUField()) {
872 case 0: {
873 ASSERT(!instr->HasW());
874 Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm");
875 break;
876 }
877 case 1: {
878 ASSERT(!instr->HasW());
879 Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm");
880 break;
881 }
882 case 2: {
883 Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w");
884 break;
885 }
886 case 3: {
Andrei Popescu31002712010-02-23 13:46:05 +0000887 if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) {
888 uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100889 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
Andrei Popescu31002712010-02-23 13:46:05 +0000890 uint32_t msbit = widthminus1 + lsbit;
891 if (msbit <= 31) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100892 if (instr->Bit(22)) {
893 Format(instr, "ubfx'cond 'rd, 'rm, 'f");
894 } else {
895 Format(instr, "sbfx'cond 'rd, 'rm, 'f");
896 }
897 } else {
898 UNREACHABLE();
899 }
900 } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) {
901 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
902 uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16));
903 if (msbit >= lsbit) {
904 if (instr->RmField() == 15) {
905 Format(instr, "bfc'cond 'rd, 'f");
906 } else {
907 Format(instr, "bfi'cond 'rd, 'rm, 'f");
908 }
Andrei Popescu31002712010-02-23 13:46:05 +0000909 } else {
910 UNREACHABLE();
911 }
912 } else {
913 Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w");
914 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000915 break;
916 }
917 default: {
918 // The PU field is a 2-bit field.
919 UNREACHABLE();
920 break;
921 }
922 }
923}
924
925
926void Decoder::DecodeType4(Instr* instr) {
927 ASSERT(instr->Bit(22) == 0); // Privileged mode currently not supported.
928 if (instr->HasL()) {
929 Format(instr, "ldm'cond'pu 'rn'w, 'rlist");
930 } else {
931 Format(instr, "stm'cond'pu 'rn'w, 'rlist");
932 }
933}
934
935
936void Decoder::DecodeType5(Instr* instr) {
937 Format(instr, "b'l'cond 'target");
938}
939
940
941void Decoder::DecodeType6(Instr* instr) {
Steve Blockd0582a62009-12-15 09:54:21 +0000942 DecodeType6CoprocessorIns(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000943}
944
945
946void Decoder::DecodeType7(Instr* instr) {
947 if (instr->Bit(24) == 1) {
948 Format(instr, "swi'cond 'swi");
949 } else {
Steve Blockd0582a62009-12-15 09:54:21 +0000950 DecodeTypeVFP(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000951 }
952}
953
Steve Blocka7e24c12009-10-30 11:49:00 +0000954void Decoder::DecodeUnconditional(Instr* instr) {
955 if (instr->Bits(7, 4) == 0xB && instr->Bits(27, 25) == 0 && instr->HasL()) {
956 Format(instr, "'memop'h'pu 'rd, ");
957 bool immediate = instr->HasB();
958 switch (instr->PUField()) {
959 case 0: {
960 // Post index, negative.
961 if (instr->HasW()) {
962 Unknown(instr);
963 break;
964 }
965 if (immediate) {
966 Format(instr, "['rn], #-'imm12");
967 } else {
968 Format(instr, "['rn], -'rm");
969 }
970 break;
971 }
972 case 1: {
973 // Post index, positive.
974 if (instr->HasW()) {
975 Unknown(instr);
976 break;
977 }
978 if (immediate) {
979 Format(instr, "['rn], #+'imm12");
980 } else {
981 Format(instr, "['rn], +'rm");
982 }
983 break;
984 }
985 case 2: {
986 // Pre index or offset, negative.
987 if (immediate) {
988 Format(instr, "['rn, #-'imm12]'w");
989 } else {
990 Format(instr, "['rn, -'rm]'w");
991 }
992 break;
993 }
994 case 3: {
995 // Pre index or offset, positive.
996 if (immediate) {
997 Format(instr, "['rn, #+'imm12]'w");
998 } else {
999 Format(instr, "['rn, +'rm]'w");
1000 }
1001 break;
1002 }
1003 default: {
1004 // The PU field is a 2-bit field.
1005 UNREACHABLE();
1006 break;
1007 }
1008 }
1009 return;
1010 }
1011 Format(instr, "break 'msg");
1012}
1013
1014
Steve Blockd0582a62009-12-15 09:54:21 +00001015// void Decoder::DecodeTypeVFP(Instr* instr)
Leon Clarkee46be812010-01-19 14:06:41 +00001016// vmov: Sn = Rt
1017// vmov: Rt = Sn
1018// vcvt: Dd = Sm
1019// vcvt: Sd = Dm
1020// Dd = vadd(Dn, Dm)
1021// Dd = vsub(Dn, Dm)
1022// Dd = vmul(Dn, Dm)
1023// Dd = vdiv(Dn, Dm)
Steve Blockd0582a62009-12-15 09:54:21 +00001024// vcmp(Dd, Dm)
1025// VMRS
1026void Decoder::DecodeTypeVFP(Instr* instr) {
1027 ASSERT((instr->TypeField() == 7) && (instr->Bit(24) == 0x0) );
Steve Block6ded16b2010-05-10 14:33:55 +01001028 ASSERT(instr->Bits(11, 9) == 0x5);
Steve Blockd0582a62009-12-15 09:54:21 +00001029
Steve Block6ded16b2010-05-10 14:33:55 +01001030 if (instr->Bit(4) == 0) {
1031 if (instr->Opc1Field() == 0x7) {
1032 // Other data processing instructions
1033 if ((instr->Opc2Field() == 0x7) && (instr->Opc3Field() == 0x3)) {
1034 DecodeVCVTBetweenDoubleAndSingle(instr);
1035 } else if ((instr->Opc2Field() == 0x8) && (instr->Opc3Field() & 0x1)) {
1036 DecodeVCVTBetweenFloatingPointAndInteger(instr);
1037 } else if (((instr->Opc2Field() >> 1) == 0x6) &&
1038 (instr->Opc3Field() & 0x1)) {
1039 DecodeVCVTBetweenFloatingPointAndInteger(instr);
1040 } else if (((instr->Opc2Field() == 0x4) || (instr->Opc2Field() == 0x5)) &&
1041 (instr->Opc3Field() & 0x1)) {
1042 DecodeVCMP(instr);
1043 } else {
1044 Unknown(instr); // Not used by V8.
1045 }
1046 } else if (instr->Opc1Field() == 0x3) {
1047 if (instr->SzField() == 0x1) {
1048 if (instr->Opc3Field() & 0x1) {
1049 Format(instr, "vsub.f64'cond 'Dd, 'Dn, 'Dm");
1050 } else {
1051 Format(instr, "vadd.f64'cond 'Dd, 'Dn, 'Dm");
1052 }
1053 } else {
1054 Unknown(instr); // Not used by V8.
1055 }
1056 } else if ((instr->Opc1Field() == 0x2) && !(instr->Opc3Field() & 0x1)) {
1057 if (instr->SzField() == 0x1) {
1058 Format(instr, "vmul.f64'cond 'Dd, 'Dn, 'Dm");
1059 } else {
1060 Unknown(instr); // Not used by V8.
1061 }
1062 } else if ((instr->Opc1Field() == 0x4) && !(instr->Opc3Field() & 0x1)) {
1063 if (instr->SzField() == 0x1) {
Steve Blockd0582a62009-12-15 09:54:21 +00001064 Format(instr, "vdiv.f64'cond 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001065 } else {
1066 Unknown(instr); // Not used by V8.
1067 }
Steve Blockd0582a62009-12-15 09:54:21 +00001068 } else {
1069 Unknown(instr); // Not used by V8.
1070 }
1071 } else {
Steve Block6ded16b2010-05-10 14:33:55 +01001072 if ((instr->VCField() == 0x0) &&
1073 (instr->VAField() == 0x0)) {
1074 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr);
1075 } else if ((instr->VLField() == 0x1) &&
1076 (instr->VCField() == 0x0) &&
1077 (instr->VAField() == 0x7) &&
1078 (instr->Bits(19, 16) == 0x1)) {
1079 if (instr->Bits(15, 12) == 0xF)
1080 Format(instr, "vmrs'cond APSR, FPSCR");
1081 else
1082 Unknown(instr); // Not used by V8.
Steve Blockd0582a62009-12-15 09:54:21 +00001083 } else {
1084 Unknown(instr); // Not used by V8.
1085 }
1086 }
1087}
1088
1089
Steve Block6ded16b2010-05-10 14:33:55 +01001090void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instr* instr) {
1091 ASSERT((instr->Bit(4) == 1) && (instr->VCField() == 0x0) &&
1092 (instr->VAField() == 0x0));
1093
1094 bool to_arm_register = (instr->VLField() == 0x1);
1095
1096 if (to_arm_register) {
1097 Format(instr, "vmov'cond 'rt, 'Sn");
1098 } else {
1099 Format(instr, "vmov'cond 'Sn, 'rt");
1100 }
1101}
1102
1103
1104void Decoder::DecodeVCMP(Instr* instr) {
1105 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7));
1106 ASSERT(((instr->Opc2Field() == 0x4) || (instr->Opc2Field() == 0x5)) &&
1107 (instr->Opc3Field() & 0x1));
1108
1109 // Comparison.
1110 bool dp_operation = (instr->SzField() == 1);
1111 bool raise_exception_for_qnan = (instr->Bit(7) == 0x1);
1112
1113 if (dp_operation && !raise_exception_for_qnan) {
1114 Format(instr, "vcmp.f64'cond 'Dd, 'Dm");
1115 } else {
1116 Unknown(instr); // Not used by V8.
1117 }
1118}
1119
1120
1121void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instr* instr) {
1122 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7));
1123 ASSERT((instr->Opc2Field() == 0x7) && (instr->Opc3Field() == 0x3));
1124
1125 bool double_to_single = (instr->SzField() == 1);
1126
1127 if (double_to_single) {
1128 Format(instr, "vcvt.f32.f64'cond 'Sd, 'Dm");
1129 } else {
1130 Format(instr, "vcvt.f64.f32'cond 'Dd, 'Sm");
1131 }
1132}
1133
1134
1135void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instr* instr) {
1136 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Field() == 0x7));
1137 ASSERT(((instr->Opc2Field() == 0x8) && (instr->Opc3Field() & 0x1)) ||
1138 (((instr->Opc2Field() >> 1) == 0x6) && (instr->Opc3Field() & 0x1)));
1139
1140 bool to_integer = (instr->Bit(18) == 1);
1141 bool dp_operation = (instr->SzField() == 1);
1142 if (to_integer) {
1143 bool unsigned_integer = (instr->Bit(16) == 0);
1144
1145 if (dp_operation) {
1146 if (unsigned_integer) {
1147 Format(instr, "vcvt.u32.f64'cond 'Sd, 'Dm");
1148 } else {
1149 Format(instr, "vcvt.s32.f64'cond 'Sd, 'Dm");
1150 }
1151 } else {
1152 if (unsigned_integer) {
1153 Format(instr, "vcvt.u32.f32'cond 'Sd, 'Sm");
1154 } else {
1155 Format(instr, "vcvt.s32.f32'cond 'Sd, 'Sm");
1156 }
1157 }
1158 } else {
1159 bool unsigned_integer = (instr->Bit(7) == 0);
1160
1161 if (dp_operation) {
1162 if (unsigned_integer) {
1163 Format(instr, "vcvt.f64.u32'cond 'Dd, 'Sm");
1164 } else {
1165 Format(instr, "vcvt.f64.s32'cond 'Dd, 'Sm");
1166 }
1167 } else {
1168 if (unsigned_integer) {
1169 Format(instr, "vcvt.f32.u32'cond 'Sd, 'Sm");
1170 } else {
1171 Format(instr, "vcvt.f32.s32'cond 'Sd, 'Sm");
1172 }
1173 }
1174 }
1175}
1176
1177
Steve Blockd0582a62009-12-15 09:54:21 +00001178// Decode Type 6 coprocessor instructions.
Leon Clarkee46be812010-01-19 14:06:41 +00001179// Dm = vmov(Rt, Rt2)
1180// <Rt, Rt2> = vmov(Dm)
Leon Clarked91b9f72010-01-27 17:25:45 +00001181// Ddst = MEM(Rbase + 4*offset).
1182// MEM(Rbase + 4*offset) = Dsrc.
Steve Blockd0582a62009-12-15 09:54:21 +00001183void Decoder::DecodeType6CoprocessorIns(Instr* instr) {
1184 ASSERT((instr->TypeField() == 6));
1185
Steve Block6ded16b2010-05-10 14:33:55 +01001186 if (instr->CoprocessorField() == 0xA) {
1187 switch (instr->OpcodeField()) {
1188 case 0x8:
1189 if (instr->HasL()) {
1190 Format(instr, "vldr'cond 'Sd, ['rn - 4*'off8]");
1191 } else {
1192 Format(instr, "vstr'cond 'Sd, ['rn - 4*'off8]");
1193 }
1194 break;
1195 case 0xC:
1196 if (instr->HasL()) {
1197 Format(instr, "vldr'cond 'Sd, ['rn + 4*'off8]");
1198 } else {
1199 Format(instr, "vstr'cond 'Sd, ['rn + 4*'off8]");
1200 }
1201 break;
1202 default:
1203 Unknown(instr); // Not used by V8.
1204 break;
1205 }
1206 } else if (instr->CoprocessorField() == 0xB) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001207 switch (instr->OpcodeField()) {
1208 case 0x2:
1209 // Load and store double to two GP registers
1210 if (instr->Bits(7, 4) != 0x1) {
1211 Unknown(instr); // Not used by V8.
1212 } else if (instr->HasL()) {
1213 Format(instr, "vmov'cond 'rt, 'rn, 'Dm");
1214 } else {
1215 Format(instr, "vmov'cond 'Dm, 'rt, 'rn");
1216 }
1217 break;
1218 case 0x8:
1219 if (instr->HasL()) {
1220 Format(instr, "vldr'cond 'Dd, ['rn - 4*'off8]");
1221 } else {
1222 Format(instr, "vstr'cond 'Dd, ['rn - 4*'off8]");
1223 }
1224 break;
1225 case 0xC:
1226 if (instr->HasL()) {
1227 Format(instr, "vldr'cond 'Dd, ['rn + 4*'off8]");
1228 } else {
1229 Format(instr, "vstr'cond 'Dd, ['rn + 4*'off8]");
1230 }
1231 break;
1232 default:
1233 Unknown(instr); // Not used by V8.
1234 break;
1235 }
Steve Block6ded16b2010-05-10 14:33:55 +01001236 } else {
1237 UNIMPLEMENTED(); // Not used by V8.
Steve Blockd0582a62009-12-15 09:54:21 +00001238 }
1239}
1240
1241
Steve Blocka7e24c12009-10-30 11:49:00 +00001242// Disassemble the instruction at *instr_ptr into the output buffer.
1243int Decoder::InstructionDecode(byte* instr_ptr) {
1244 Instr* instr = Instr::At(instr_ptr);
1245 // Print raw instruction bytes.
1246 out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_,
1247 "%08x ",
1248 instr->InstructionBits());
1249 if (instr->ConditionField() == special_condition) {
1250 DecodeUnconditional(instr);
1251 return Instr::kInstrSize;
1252 }
1253 switch (instr->TypeField()) {
1254 case 0:
1255 case 1: {
1256 DecodeType01(instr);
1257 break;
1258 }
1259 case 2: {
1260 DecodeType2(instr);
1261 break;
1262 }
1263 case 3: {
1264 DecodeType3(instr);
1265 break;
1266 }
1267 case 4: {
1268 DecodeType4(instr);
1269 break;
1270 }
1271 case 5: {
1272 DecodeType5(instr);
1273 break;
1274 }
1275 case 6: {
1276 DecodeType6(instr);
1277 break;
1278 }
1279 case 7: {
1280 DecodeType7(instr);
1281 break;
1282 }
1283 default: {
1284 // The type field is 3-bits in the ARM encoding.
1285 UNREACHABLE();
1286 break;
1287 }
1288 }
1289 return Instr::kInstrSize;
1290}
1291
1292
1293} } // namespace assembler::arm
1294
1295
1296
1297//------------------------------------------------------------------------------
1298
1299namespace disasm {
1300
1301namespace v8i = v8::internal;
1302
1303
1304const char* NameConverter::NameOfAddress(byte* addr) const {
1305 static v8::internal::EmbeddedVector<char, 32> tmp_buffer;
1306 v8::internal::OS::SNPrintF(tmp_buffer, "%p", addr);
1307 return tmp_buffer.start();
1308}
1309
1310
1311const char* NameConverter::NameOfConstant(byte* addr) const {
1312 return NameOfAddress(addr);
1313}
1314
1315
1316const char* NameConverter::NameOfCPURegister(int reg) const {
1317 return assembler::arm::Registers::Name(reg);
1318}
1319
1320
1321const char* NameConverter::NameOfByteCPURegister(int reg) const {
1322 UNREACHABLE(); // ARM does not have the concept of a byte register
1323 return "nobytereg";
1324}
1325
1326
1327const char* NameConverter::NameOfXMMRegister(int reg) const {
1328 UNREACHABLE(); // ARM does not have any XMM registers
1329 return "noxmmreg";
1330}
1331
1332
1333const char* NameConverter::NameInCode(byte* addr) const {
1334 // The default name converter is called for unknown code. So we will not try
1335 // to access any memory.
1336 return "";
1337}
1338
1339
1340//------------------------------------------------------------------------------
1341
1342Disassembler::Disassembler(const NameConverter& converter)
1343 : converter_(converter) {}
1344
1345
1346Disassembler::~Disassembler() {}
1347
1348
1349int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
1350 byte* instruction) {
1351 assembler::arm::Decoder d(converter_, buffer);
1352 return d.InstructionDecode(instruction);
1353}
1354
1355
1356int Disassembler::ConstantPoolSizeAt(byte* instruction) {
1357 int instruction_bits = *(reinterpret_cast<int*>(instruction));
1358 if ((instruction_bits & 0xfff00000) == 0x03000000) {
1359 return instruction_bits & 0x0000ffff;
1360 } else {
1361 return -1;
1362 }
1363}
1364
1365
1366void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) {
1367 NameConverter converter;
1368 Disassembler d(converter);
1369 for (byte* pc = begin; pc < end;) {
1370 v8::internal::EmbeddedVector<char, 128> buffer;
1371 buffer[0] = '\0';
1372 byte* prev_pc = pc;
1373 pc += d.InstructionDecode(buffer, pc);
1374 fprintf(f, "%p %08x %s\n",
1375 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start());
1376 }
1377}
1378
1379
1380} // namespace disasm
Leon Clarkef7060e22010-06-03 12:02:55 +01001381
1382#endif // V8_TARGET_ARCH_ARM