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