blob: 08f605b16429cc4f6c76eb6d8ba1e6f0f475cd0f [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
Steve Block1e0659c2011-05-24 12:43:12 +010067namespace v8 {
68namespace internal {
Steve Blocka7e24c12009-10-30 11:49:00 +000069
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,
Steve Block1e0659c2011-05-24 12:43:12 +010079 Vector<char> out_buffer)
Steve Blocka7e24c12009-10-30 11:49:00 +000080 : 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);
Steve Block1e0659c2011-05-24 12:43:12 +0100101 int FormatVFPRegister(Instruction* instr, const char* format);
102 void PrintMovwMovt(Instruction* instr);
103 int FormatVFPinstruction(Instruction* instr, const char* format);
104 void PrintCondition(Instruction* instr);
105 void PrintShiftRm(Instruction* instr);
106 void PrintShiftImm(Instruction* instr);
107 void PrintShiftSat(Instruction* instr);
108 void PrintPU(Instruction* instr);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800109 void PrintSoftwareInterrupt(SoftwareInterruptCodes svc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000110
111 // Handle formatting of instructions and their options.
Steve Block1e0659c2011-05-24 12:43:12 +0100112 int FormatRegister(Instruction* instr, const char* option);
113 int FormatOption(Instruction* instr, const char* option);
114 void Format(Instruction* instr, const char* format);
115 void Unknown(Instruction* instr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000116
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.
Steve Block1e0659c2011-05-24 12:43:12 +0100121 void DecodeType01(Instruction* instr);
122 void DecodeType2(Instruction* instr);
123 void DecodeType3(Instruction* instr);
124 void DecodeType4(Instruction* instr);
125 void DecodeType5(Instruction* instr);
126 void DecodeType6(Instruction* instr);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800127 // Type 7 includes special Debugger instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100128 int DecodeType7(Instruction* instr);
Steve Blockd0582a62009-12-15 09:54:21 +0000129 // For VFP support.
Steve Block1e0659c2011-05-24 12:43:12 +0100130 void DecodeTypeVFP(Instruction* instr);
131 void DecodeType6CoprocessorIns(Instruction* instr);
Steve Blockd0582a62009-12-15 09:54:21 +0000132
Steve Block1e0659c2011-05-24 12:43:12 +0100133 void DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(Instruction* instr);
134 void DecodeVCMP(Instruction* instr);
135 void DecodeVCVTBetweenDoubleAndSingle(Instruction* instr);
136 void DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000137
138 const disasm::NameConverter& converter_;
Steve Block1e0659c2011-05-24 12:43:12 +0100139 Vector<char> out_buffer_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000140 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>".
Steve Block1e0659c2011-05-24 12:43:12 +0100170static const char* cond_names[kNumberOfConditions] = {
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 "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.
Steve Block1e0659c2011-05-24 12:43:12 +0100177void Decoder::PrintCondition(Instruction* instr) {
178 Print(cond_names[instr->ConditionValue()]);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179}
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 Block1e0659c2011-05-24 12:43:12 +0100189 Print(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 Block1e0659c2011-05-24 12:43:12 +0100194 Print(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>".
Steve Block1e0659c2011-05-24 12:43:12 +0100200static const char* shift_names[kNumberOfShifts] = {
Steve Blocka7e24c12009-10-30 11:49:00 +0000201 "lsl", "lsr", "asr", "ror"
202};
203
204
205// Print the register shift operands for the instruction. Generally used for
206// data processing instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100207void Decoder::PrintShiftRm(Instruction* instr) {
208 ShiftOp shift = instr->ShiftField();
209 int shift_index = instr->ShiftValue();
210 int shift_amount = instr->ShiftAmountValue();
211 int rm = instr->RmValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000212
213 PrintRegister(rm);
214
Steve Block1e0659c2011-05-24 12:43:12 +0100215 if ((instr->RegShiftValue() == 0) && (shift == LSL) && (shift_amount == 0)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 // Special case for using rm only.
217 return;
218 }
Steve Block1e0659c2011-05-24 12:43:12 +0100219 if (instr->RegShiftValue() == 0) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 // by immediate
221 if ((shift == ROR) && (shift_amount == 0)) {
222 Print(", RRX");
223 return;
224 } else if (((shift == LSR) || (shift == ASR)) && (shift_amount == 0)) {
225 shift_amount = 32;
226 }
Steve Block1e0659c2011-05-24 12:43:12 +0100227 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
228 ", %s #%d",
229 shift_names[shift_index],
230 shift_amount);
Steve Blocka7e24c12009-10-30 11:49:00 +0000231 } else {
232 // by register
Steve Block1e0659c2011-05-24 12:43:12 +0100233 int rs = instr->RsValue();
234 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
235 ", %s ", shift_names[shift_index]);
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 PrintRegister(rs);
237 }
238}
239
240
241// Print the immediate operand for the instruction. Generally used for data
242// processing instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100243void Decoder::PrintShiftImm(Instruction* instr) {
244 int rotate = instr->RotateValue() * 2;
245 int immed8 = instr->Immed8Value();
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 int imm = (immed8 >> rotate) | (immed8 << (32 - rotate));
Steve Block1e0659c2011-05-24 12:43:12 +0100247 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
248 "#%d", imm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000249}
250
251
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100252// Print the optional shift and immediate used by saturating instructions.
Steve Block1e0659c2011-05-24 12:43:12 +0100253void Decoder::PrintShiftSat(Instruction* instr) {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100254 int shift = instr->Bits(11, 7);
255 if (shift > 0) {
Steve Block1e0659c2011-05-24 12:43:12 +0100256 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
257 ", %s #%d",
258 shift_names[instr->Bit(6) * 2],
259 instr->Bits(11, 7));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100260 }
261}
262
263
Steve Blocka7e24c12009-10-30 11:49:00 +0000264// Print PU formatting to reduce complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100265void Decoder::PrintPU(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000266 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100267 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000268 Print("da");
269 break;
270 }
Steve Block1e0659c2011-05-24 12:43:12 +0100271 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000272 Print("ia");
273 break;
274 }
Steve Block1e0659c2011-05-24 12:43:12 +0100275 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000276 Print("db");
277 break;
278 }
Steve Block1e0659c2011-05-24 12:43:12 +0100279 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 Print("ib");
281 break;
282 }
283 default: {
284 UNREACHABLE();
285 break;
286 }
287 }
288}
289
290
291// Print SoftwareInterrupt codes. Factoring this out reduces the complexity of
292// the FormatOption method.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800293void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) {
294 switch (svc) {
Steve Block1e0659c2011-05-24 12:43:12 +0100295 case kCallRtRedirected:
296 Print("call rt redirected");
Steve Blocka7e24c12009-10-30 11:49:00 +0000297 return;
Steve Block1e0659c2011-05-24 12:43:12 +0100298 case kBreakpoint:
299 Print("breakpoint");
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 return;
301 default:
Steve Block1e0659c2011-05-24 12:43:12 +0100302 if (svc >= kStopCode) {
303 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
304 "%d - 0x%x",
305 svc & kStopCodeMask,
306 svc & kStopCodeMask);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800307 } else {
Steve Block1e0659c2011-05-24 12:43:12 +0100308 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
309 "%d",
310 svc);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800311 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000312 return;
313 }
314}
315
316
317// Handle all register based formatting in this function to reduce the
318// complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100319int Decoder::FormatRegister(Instruction* instr, const char* format) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 ASSERT(format[0] == 'r');
321 if (format[1] == 'n') { // 'rn: Rn register
Steve Block1e0659c2011-05-24 12:43:12 +0100322 int reg = instr->RnValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 PrintRegister(reg);
324 return 2;
325 } else if (format[1] == 'd') { // 'rd: Rd register
Steve Block1e0659c2011-05-24 12:43:12 +0100326 int reg = instr->RdValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 PrintRegister(reg);
328 return 2;
329 } else if (format[1] == 's') { // 'rs: Rs register
Steve Block1e0659c2011-05-24 12:43:12 +0100330 int reg = instr->RsValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 PrintRegister(reg);
332 return 2;
333 } else if (format[1] == 'm') { // 'rm: Rm register
Steve Block1e0659c2011-05-24 12:43:12 +0100334 int reg = instr->RmValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 PrintRegister(reg);
336 return 2;
Steve Blockd0582a62009-12-15 09:54:21 +0000337 } else if (format[1] == 't') { // 'rt: Rt register
Steve Block1e0659c2011-05-24 12:43:12 +0100338 int reg = instr->RtValue();
Steve Blockd0582a62009-12-15 09:54:21 +0000339 PrintRegister(reg);
340 return 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 } else if (format[1] == 'l') {
342 // 'rlist: register list for load and store multiple instructions
343 ASSERT(STRING_STARTS_WITH(format, "rlist"));
Steve Block1e0659c2011-05-24 12:43:12 +0100344 int rlist = instr->RlistValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 int reg = 0;
346 Print("{");
347 // Print register list in ascending order, by scanning the bit mask.
348 while (rlist != 0) {
349 if ((rlist & 1) != 0) {
350 PrintRegister(reg);
351 if ((rlist >> 1) != 0) {
352 Print(", ");
353 }
354 }
355 reg++;
356 rlist >>= 1;
357 }
358 Print("}");
359 return 5;
360 }
361 UNREACHABLE();
362 return -1;
363}
364
365
Steve Blockd0582a62009-12-15 09:54:21 +0000366// Handle all VFP register based formatting in this function to reduce the
367// complexity of FormatOption.
Steve Block1e0659c2011-05-24 12:43:12 +0100368int Decoder::FormatVFPRegister(Instruction* instr, const char* format) {
Steve Blockd0582a62009-12-15 09:54:21 +0000369 ASSERT((format[0] == 'S') || (format[0] == 'D'));
370
371 if (format[1] == 'n') {
Steve Block1e0659c2011-05-24 12:43:12 +0100372 int reg = instr->VnValue();
373 if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->NValue()));
Steve Blockd0582a62009-12-15 09:54:21 +0000374 if (format[0] == 'D') PrintDRegister(reg);
375 return 2;
376 } else if (format[1] == 'm') {
Steve Block1e0659c2011-05-24 12:43:12 +0100377 int reg = instr->VmValue();
378 if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->MValue()));
Steve Blockd0582a62009-12-15 09:54:21 +0000379 if (format[0] == 'D') PrintDRegister(reg);
380 return 2;
381 } else if (format[1] == 'd') {
Steve Block1e0659c2011-05-24 12:43:12 +0100382 int reg = instr->VdValue();
383 if (format[0] == 'S') PrintSRegister(((reg << 1) | instr->DValue()));
Steve Blockd0582a62009-12-15 09:54:21 +0000384 if (format[0] == 'D') PrintDRegister(reg);
385 return 2;
386 }
387
388 UNREACHABLE();
389 return -1;
390}
391
392
Steve Block1e0659c2011-05-24 12:43:12 +0100393int Decoder::FormatVFPinstruction(Instruction* instr, const char* format) {
Steve Blockd0582a62009-12-15 09:54:21 +0000394 Print(format);
395 return 0;
396}
397
398
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100399// Print the movw or movt instruction.
Steve Block1e0659c2011-05-24 12:43:12 +0100400void Decoder::PrintMovwMovt(Instruction* instr) {
401 int imm = instr->ImmedMovwMovtValue();
402 int rd = instr->RdValue();
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100403 PrintRegister(rd);
Steve Block1e0659c2011-05-24 12:43:12 +0100404 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
405 ", #%d", imm);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100406}
407
408
Steve Blocka7e24c12009-10-30 11:49:00 +0000409// FormatOption takes a formatting string and interprets it based on
410// the current instructions. The format string points to the first
411// character of the option string (the option escape has already been
412// consumed by the caller.) FormatOption returns the number of
413// characters that were consumed from the formatting string.
Steve Block1e0659c2011-05-24 12:43:12 +0100414int Decoder::FormatOption(Instruction* instr, const char* format) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 switch (format[0]) {
416 case 'a': { // 'a: accumulate multiplies
417 if (instr->Bit(21) == 0) {
418 Print("ul");
419 } else {
420 Print("la");
421 }
422 return 1;
423 }
424 case 'b': { // 'b: byte loads or stores
425 if (instr->HasB()) {
426 Print("b");
427 }
428 return 1;
429 }
430 case 'c': { // 'cond: conditional execution
431 ASSERT(STRING_STARTS_WITH(format, "cond"));
432 PrintCondition(instr);
433 return 4;
434 }
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100435 case 'd': { // 'd: vmov double immediate.
436 double d = instr->DoubleImmedVmov();
Steve Block1e0659c2011-05-24 12:43:12 +0100437 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
438 "#%g", d);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100439 return 1;
440 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100441 case 'f': { // 'f: bitfield instructions - v7 and above.
442 uint32_t lsbit = instr->Bits(11, 7);
443 uint32_t width = instr->Bits(20, 16) + 1;
444 if (instr->Bit(21) == 0) {
445 // BFC/BFI:
446 // Bits 20-16 represent most-significant bit. Covert to width.
447 width -= lsbit;
448 ASSERT(width > 0);
449 }
450 ASSERT((width + lsbit) <= 32);
Steve Block1e0659c2011-05-24 12:43:12 +0100451 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
452 "#%d, #%d", lsbit, width);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100453 return 1;
454 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000455 case 'h': { // 'h: halfword operation for extra loads and stores
456 if (instr->HasH()) {
457 Print("h");
458 } else {
459 Print("b");
460 }
461 return 1;
462 }
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100463 case 'i': { // 'i: immediate value from adjacent bits.
464 // Expects tokens in the form imm%02d@%02d, ie. imm05@07, imm10@16
465 int width = (format[3] - '0') * 10 + (format[4] - '0');
466 int lsb = (format[6] - '0') * 10 + (format[7] - '0');
467
468 ASSERT((width >= 1) && (width <= 32));
469 ASSERT((lsb >= 0) && (lsb <= 31));
470 ASSERT((width + lsb) <= 32);
471
Steve Block1e0659c2011-05-24 12:43:12 +0100472 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
473 "%d",
474 instr->Bits(width + lsb - 1, lsb));
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100475 return 8;
476 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000477 case 'l': { // 'l: branch and link
478 if (instr->HasLink()) {
479 Print("l");
480 }
481 return 1;
482 }
483 case 'm': {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100484 if (format[1] == 'w') {
485 // 'mw: movt/movw instructions.
486 PrintMovwMovt(instr);
487 return 2;
488 }
489 if (format[1] == 'e') { // 'memop: load/store instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 ASSERT(STRING_STARTS_WITH(format, "memop"));
491 if (instr->HasL()) {
492 Print("ldr");
Kristian Monsen25f61362010-05-21 11:50:48 +0100493 } else if ((instr->Bits(27, 25) == 0) && (instr->Bit(20) == 0)) {
494 if (instr->Bits(7, 4) == 0xf) {
495 Print("strd");
496 } else {
497 Print("ldrd");
498 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 } else {
500 Print("str");
501 }
502 return 5;
503 }
504 // 'msg: for simulator break instructions
505 ASSERT(STRING_STARTS_WITH(format, "msg"));
506 byte* str =
507 reinterpret_cast<byte*>(instr->InstructionBits() & 0x0fffffff);
Steve Block1e0659c2011-05-24 12:43:12 +0100508 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
509 "%s", converter_.NameInCode(str));
Steve Blocka7e24c12009-10-30 11:49:00 +0000510 return 3;
511 }
512 case 'o': {
Andrei Popescu31002712010-02-23 13:46:05 +0000513 if ((format[3] == '1') && (format[4] == '2')) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 // 'off12: 12-bit offset for load and store instructions
515 ASSERT(STRING_STARTS_WITH(format, "off12"));
Steve Block1e0659c2011-05-24 12:43:12 +0100516 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
517 "%d", instr->Offset12Value());
Steve Blocka7e24c12009-10-30 11:49:00 +0000518 return 5;
Steve Block6ded16b2010-05-10 14:33:55 +0100519 } else if (format[3] == '0') {
520 // 'off0to3and8to19 16-bit immediate encoded in bits 19-8 and 3-0.
521 ASSERT(STRING_STARTS_WITH(format, "off0to3and8to19"));
Steve Block1e0659c2011-05-24 12:43:12 +0100522 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
523 "%d",
524 (instr->Bits(19, 8) << 4) +
525 instr->Bits(3, 0));
Steve Block6ded16b2010-05-10 14:33:55 +0100526 return 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000527 }
528 // 'off8: 8-bit offset for extra load and store instructions
529 ASSERT(STRING_STARTS_WITH(format, "off8"));
Steve Block1e0659c2011-05-24 12:43:12 +0100530 int offs8 = (instr->ImmedHValue() << 4) | instr->ImmedLValue();
531 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
532 "%d", offs8);
Steve Blocka7e24c12009-10-30 11:49:00 +0000533 return 4;
534 }
535 case 'p': { // 'pu: P and U bits for load and store instructions
536 ASSERT(STRING_STARTS_WITH(format, "pu"));
537 PrintPU(instr);
538 return 2;
539 }
540 case 'r': {
541 return FormatRegister(instr, format);
542 }
543 case 's': {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100544 if (format[1] == 'h') { // 'shift_op or 'shift_rm or 'shift_sat.
Steve Blocka7e24c12009-10-30 11:49:00 +0000545 if (format[6] == 'o') { // 'shift_op
546 ASSERT(STRING_STARTS_WITH(format, "shift_op"));
Steve Block1e0659c2011-05-24 12:43:12 +0100547 if (instr->TypeValue() == 0) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000548 PrintShiftRm(instr);
549 } else {
Steve Block1e0659c2011-05-24 12:43:12 +0100550 ASSERT(instr->TypeValue() == 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000551 PrintShiftImm(instr);
552 }
553 return 8;
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100554 } else if (format[6] == 's') { // 'shift_sat.
555 ASSERT(STRING_STARTS_WITH(format, "shift_sat"));
556 PrintShiftSat(instr);
557 return 9;
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 } else { // 'shift_rm
559 ASSERT(STRING_STARTS_WITH(format, "shift_rm"));
560 PrintShiftRm(instr);
561 return 8;
562 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800563 } else if (format[1] == 'v') { // 'svc
564 ASSERT(STRING_STARTS_WITH(format, "svc"));
Steve Block1e0659c2011-05-24 12:43:12 +0100565 PrintSoftwareInterrupt(instr->SvcValue());
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 return 3;
567 } else if (format[1] == 'i') { // 'sign: signed extra loads and stores
568 ASSERT(STRING_STARTS_WITH(format, "sign"));
569 if (instr->HasSign()) {
570 Print("s");
571 }
572 return 4;
573 }
574 // 's: S field of data processing instructions
575 if (instr->HasS()) {
576 Print("s");
577 }
578 return 1;
579 }
580 case 't': { // 'target: target of branch instructions
581 ASSERT(STRING_STARTS_WITH(format, "target"));
Steve Block1e0659c2011-05-24 12:43:12 +0100582 int off = (instr->SImmed24Value() << 2) + 8;
583 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
584 "%+d -> %s",
585 off,
586 converter_.NameOfAddress(
587 reinterpret_cast<byte*>(instr) + off));
Steve Blocka7e24c12009-10-30 11:49:00 +0000588 return 6;
589 }
590 case 'u': { // 'u: signed or unsigned multiplies
591 // The manual gets the meaning of bit 22 backwards in the multiply
592 // instruction overview on page A3.16.2. The instructions that
593 // exist in u and s variants are the following:
594 // smull A4.1.87
595 // umull A4.1.129
596 // umlal A4.1.128
597 // smlal A4.1.76
598 // For these 0 means u and 1 means s. As can be seen on their individual
599 // pages. The other 18 mul instructions have the bit set or unset in
600 // arbitrary ways that are unrelated to the signedness of the instruction.
601 // None of these 18 instructions exist in both a 'u' and an 's' variant.
602
603 if (instr->Bit(22) == 0) {
604 Print("u");
605 } else {
606 Print("s");
607 }
608 return 1;
609 }
Steve Blockd0582a62009-12-15 09:54:21 +0000610 case 'v': {
611 return FormatVFPinstruction(instr, format);
612 }
613 case 'S':
614 case 'D': {
615 return FormatVFPRegister(instr, format);
616 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000617 case 'w': { // 'w: W field of load and store instructions
618 if (instr->HasW()) {
619 Print("!");
620 }
621 return 1;
622 }
623 default: {
624 UNREACHABLE();
625 break;
626 }
627 }
628 UNREACHABLE();
629 return -1;
630}
631
632
633// Format takes a formatting string for a whole instruction and prints it into
634// the output buffer. All escaped options are handed to FormatOption to be
635// parsed further.
Steve Block1e0659c2011-05-24 12:43:12 +0100636void Decoder::Format(Instruction* instr, const char* format) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000637 char cur = *format++;
638 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
639 if (cur == '\'') { // Single quote is used as the formatting escape.
640 format += FormatOption(instr, format);
641 } else {
642 out_buffer_[out_buffer_pos_++] = cur;
643 }
644 cur = *format++;
645 }
646 out_buffer_[out_buffer_pos_] = '\0';
647}
648
649
650// For currently unimplemented decodings the disassembler calls Unknown(instr)
651// which will just print "unknown" of the instruction bits.
Steve Block1e0659c2011-05-24 12:43:12 +0100652void Decoder::Unknown(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000653 Format(instr, "unknown");
654}
655
656
Steve Block1e0659c2011-05-24 12:43:12 +0100657void Decoder::DecodeType01(Instruction* instr) {
658 int type = instr->TypeValue();
Steve Blocka7e24c12009-10-30 11:49:00 +0000659 if ((type == 0) && instr->IsSpecialType0()) {
660 // multiply instruction or extra loads and stores
661 if (instr->Bits(7, 4) == 9) {
662 if (instr->Bit(24) == 0) {
663 // multiply instructions
664 if (instr->Bit(23) == 0) {
665 if (instr->Bit(21) == 0) {
666 // The MUL instruction description (A 4.1.33) refers to Rd as being
667 // the destination for the operation, but it confusingly uses the
668 // Rn field to encode it.
669 Format(instr, "mul'cond's 'rn, 'rm, 'rs");
670 } else {
671 // The MLA instruction description (A 4.1.28) refers to the order
672 // of registers as "Rd, Rm, Rs, Rn". But confusingly it uses the
673 // Rn field to encode the Rd register and the Rd field to encode
674 // the Rn register.
675 Format(instr, "mla'cond's 'rn, 'rm, 'rs, 'rd");
676 }
677 } else {
678 // The signed/long multiply instructions use the terms RdHi and RdLo
679 // when referring to the target registers. They are mapped to the Rn
680 // and Rd fields as follows:
681 // RdLo == Rd field
682 // RdHi == Rn field
683 // The order of registers is: <RdLo>, <RdHi>, <Rm>, <Rs>
684 Format(instr, "'um'al'cond's 'rd, 'rn, 'rm, 'rs");
685 }
686 } else {
687 Unknown(instr); // not used by V8
688 }
Kristian Monsen25f61362010-05-21 11:50:48 +0100689 } else if ((instr->Bit(20) == 0) && ((instr->Bits(7, 4) & 0xd) == 0xd)) {
690 // ldrd, strd
691 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100692 case da_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100693 if (instr->Bit(22) == 0) {
694 Format(instr, "'memop'cond's 'rd, ['rn], -'rm");
695 } else {
696 Format(instr, "'memop'cond's 'rd, ['rn], #-'off8");
697 }
698 break;
699 }
Steve Block1e0659c2011-05-24 12:43:12 +0100700 case ia_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100701 if (instr->Bit(22) == 0) {
702 Format(instr, "'memop'cond's 'rd, ['rn], +'rm");
703 } else {
704 Format(instr, "'memop'cond's 'rd, ['rn], #+'off8");
705 }
706 break;
707 }
Steve Block1e0659c2011-05-24 12:43:12 +0100708 case db_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100709 if (instr->Bit(22) == 0) {
710 Format(instr, "'memop'cond's 'rd, ['rn, -'rm]'w");
711 } else {
712 Format(instr, "'memop'cond's 'rd, ['rn, #-'off8]'w");
713 }
714 break;
715 }
Steve Block1e0659c2011-05-24 12:43:12 +0100716 case ib_x: {
Kristian Monsen25f61362010-05-21 11:50:48 +0100717 if (instr->Bit(22) == 0) {
718 Format(instr, "'memop'cond's 'rd, ['rn, +'rm]'w");
719 } else {
720 Format(instr, "'memop'cond's 'rd, ['rn, #+'off8]'w");
721 }
722 break;
723 }
724 default: {
725 // The PU field is a 2-bit field.
726 UNREACHABLE();
727 break;
728 }
729 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000730 } else {
731 // extra load/store instructions
732 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100733 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000734 if (instr->Bit(22) == 0) {
735 Format(instr, "'memop'cond'sign'h 'rd, ['rn], -'rm");
736 } else {
737 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #-'off8");
738 }
739 break;
740 }
Steve Block1e0659c2011-05-24 12:43:12 +0100741 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000742 if (instr->Bit(22) == 0) {
743 Format(instr, "'memop'cond'sign'h 'rd, ['rn], +'rm");
744 } else {
745 Format(instr, "'memop'cond'sign'h 'rd, ['rn], #+'off8");
746 }
747 break;
748 }
Steve Block1e0659c2011-05-24 12:43:12 +0100749 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000750 if (instr->Bit(22) == 0) {
751 Format(instr, "'memop'cond'sign'h 'rd, ['rn, -'rm]'w");
752 } else {
753 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #-'off8]'w");
754 }
755 break;
756 }
Steve Block1e0659c2011-05-24 12:43:12 +0100757 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000758 if (instr->Bit(22) == 0) {
759 Format(instr, "'memop'cond'sign'h 'rd, ['rn, +'rm]'w");
760 } else {
761 Format(instr, "'memop'cond'sign'h 'rd, ['rn, #+'off8]'w");
762 }
763 break;
764 }
765 default: {
766 // The PU field is a 2-bit field.
767 UNREACHABLE();
768 break;
769 }
770 }
771 return;
772 }
Steve Block6ded16b2010-05-10 14:33:55 +0100773 } else if ((type == 0) && instr->IsMiscType0()) {
774 if (instr->Bits(22, 21) == 1) {
Steve Block1e0659c2011-05-24 12:43:12 +0100775 switch (instr->BitField(7, 4)) {
Steve Block6ded16b2010-05-10 14:33:55 +0100776 case BX:
777 Format(instr, "bx'cond 'rm");
778 break;
779 case BLX:
780 Format(instr, "blx'cond 'rm");
781 break;
782 case BKPT:
783 Format(instr, "bkpt 'off0to3and8to19");
784 break;
785 default:
786 Unknown(instr); // not used by V8
787 break;
788 }
789 } else if (instr->Bits(22, 21) == 3) {
Steve Block1e0659c2011-05-24 12:43:12 +0100790 switch (instr->BitField(7, 4)) {
Steve Block6ded16b2010-05-10 14:33:55 +0100791 case CLZ:
792 Format(instr, "clz'cond 'rd, 'rm");
793 break;
794 default:
795 Unknown(instr); // not used by V8
796 break;
797 }
798 } else {
799 Unknown(instr); // not used by V8
800 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000801 } else {
802 switch (instr->OpcodeField()) {
803 case AND: {
804 Format(instr, "and'cond's 'rd, 'rn, 'shift_op");
805 break;
806 }
807 case EOR: {
808 Format(instr, "eor'cond's 'rd, 'rn, 'shift_op");
809 break;
810 }
811 case SUB: {
812 Format(instr, "sub'cond's 'rd, 'rn, 'shift_op");
813 break;
814 }
815 case RSB: {
816 Format(instr, "rsb'cond's 'rd, 'rn, 'shift_op");
817 break;
818 }
819 case ADD: {
820 Format(instr, "add'cond's 'rd, 'rn, 'shift_op");
821 break;
822 }
823 case ADC: {
824 Format(instr, "adc'cond's 'rd, 'rn, 'shift_op");
825 break;
826 }
827 case SBC: {
828 Format(instr, "sbc'cond's 'rd, 'rn, 'shift_op");
829 break;
830 }
831 case RSC: {
832 Format(instr, "rsc'cond's 'rd, 'rn, 'shift_op");
833 break;
834 }
835 case TST: {
836 if (instr->HasS()) {
837 Format(instr, "tst'cond 'rn, 'shift_op");
838 } else {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100839 Format(instr, "movw'cond 'mw");
Steve Blocka7e24c12009-10-30 11:49:00 +0000840 }
841 break;
842 }
843 case TEQ: {
844 if (instr->HasS()) {
845 Format(instr, "teq'cond 'rn, 'shift_op");
846 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100847 // Other instructions matching this pattern are handled in the
848 // miscellaneous instructions part above.
849 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000850 }
851 break;
852 }
853 case CMP: {
854 if (instr->HasS()) {
855 Format(instr, "cmp'cond 'rn, 'shift_op");
856 } else {
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100857 Format(instr, "movt'cond 'mw");
Steve Blocka7e24c12009-10-30 11:49:00 +0000858 }
859 break;
860 }
861 case CMN: {
862 if (instr->HasS()) {
863 Format(instr, "cmn'cond 'rn, 'shift_op");
864 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100865 // Other instructions matching this pattern are handled in the
866 // miscellaneous instructions part above.
867 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000868 }
869 break;
870 }
871 case ORR: {
872 Format(instr, "orr'cond's 'rd, 'rn, 'shift_op");
873 break;
874 }
875 case MOV: {
876 Format(instr, "mov'cond's 'rd, 'shift_op");
877 break;
878 }
879 case BIC: {
880 Format(instr, "bic'cond's 'rd, 'rn, 'shift_op");
881 break;
882 }
883 case MVN: {
884 Format(instr, "mvn'cond's 'rd, 'shift_op");
885 break;
886 }
887 default: {
888 // The Opcode field is a 4-bit field.
889 UNREACHABLE();
890 break;
891 }
892 }
893 }
894}
895
896
Steve Block1e0659c2011-05-24 12:43:12 +0100897void Decoder::DecodeType2(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000898 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100899 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000900 if (instr->HasW()) {
901 Unknown(instr); // not used in V8
902 }
903 Format(instr, "'memop'cond'b 'rd, ['rn], #-'off12");
904 break;
905 }
Steve Block1e0659c2011-05-24 12:43:12 +0100906 case ia_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000907 if (instr->HasW()) {
908 Unknown(instr); // not used in V8
909 }
910 Format(instr, "'memop'cond'b 'rd, ['rn], #+'off12");
911 break;
912 }
Steve Block1e0659c2011-05-24 12:43:12 +0100913 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000914 Format(instr, "'memop'cond'b 'rd, ['rn, #-'off12]'w");
915 break;
916 }
Steve Block1e0659c2011-05-24 12:43:12 +0100917 case ib_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000918 Format(instr, "'memop'cond'b 'rd, ['rn, #+'off12]'w");
919 break;
920 }
921 default: {
922 // The PU field is a 2-bit field.
923 UNREACHABLE();
924 break;
925 }
926 }
927}
928
929
Steve Block1e0659c2011-05-24 12:43:12 +0100930void Decoder::DecodeType3(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000931 switch (instr->PUField()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100932 case da_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000933 ASSERT(!instr->HasW());
934 Format(instr, "'memop'cond'b 'rd, ['rn], -'shift_rm");
935 break;
936 }
Steve Block1e0659c2011-05-24 12:43:12 +0100937 case ia_x: {
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100938 if (instr->HasW()) {
939 ASSERT(instr->Bits(5, 4) == 0x1);
940 if (instr->Bit(22) == 0x1) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100941 Format(instr, "usat 'rd, #'imm05@16, 'rm'shift_sat");
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100942 } else {
943 UNREACHABLE(); // SSAT.
944 }
945 } else {
946 Format(instr, "'memop'cond'b 'rd, ['rn], +'shift_rm");
947 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000948 break;
949 }
Steve Block1e0659c2011-05-24 12:43:12 +0100950 case db_x: {
Steve Blocka7e24c12009-10-30 11:49:00 +0000951 Format(instr, "'memop'cond'b 'rd, ['rn, -'shift_rm]'w");
952 break;
953 }
Steve Block1e0659c2011-05-24 12:43:12 +0100954 case ib_x: {
Andrei Popescu31002712010-02-23 13:46:05 +0000955 if (instr->HasW() && (instr->Bits(6, 4) == 0x5)) {
956 uint32_t widthminus1 = static_cast<uint32_t>(instr->Bits(20, 16));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100957 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
Andrei Popescu31002712010-02-23 13:46:05 +0000958 uint32_t msbit = widthminus1 + lsbit;
959 if (msbit <= 31) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100960 if (instr->Bit(22)) {
961 Format(instr, "ubfx'cond 'rd, 'rm, 'f");
962 } else {
963 Format(instr, "sbfx'cond 'rd, 'rm, 'f");
964 }
965 } else {
966 UNREACHABLE();
967 }
968 } else if (!instr->HasW() && (instr->Bits(6, 4) == 0x1)) {
969 uint32_t lsbit = static_cast<uint32_t>(instr->Bits(11, 7));
970 uint32_t msbit = static_cast<uint32_t>(instr->Bits(20, 16));
971 if (msbit >= lsbit) {
Steve Block1e0659c2011-05-24 12:43:12 +0100972 if (instr->RmValue() == 15) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100973 Format(instr, "bfc'cond 'rd, 'f");
974 } else {
975 Format(instr, "bfi'cond 'rd, 'rm, 'f");
976 }
Andrei Popescu31002712010-02-23 13:46:05 +0000977 } else {
978 UNREACHABLE();
979 }
980 } else {
981 Format(instr, "'memop'cond'b 'rd, ['rn, +'shift_rm]'w");
982 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000983 break;
984 }
985 default: {
986 // The PU field is a 2-bit field.
987 UNREACHABLE();
988 break;
989 }
990 }
991}
992
993
Steve Block1e0659c2011-05-24 12:43:12 +0100994void Decoder::DecodeType4(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000995 ASSERT(instr->Bit(22) == 0); // Privileged mode currently not supported.
996 if (instr->HasL()) {
997 Format(instr, "ldm'cond'pu 'rn'w, 'rlist");
998 } else {
999 Format(instr, "stm'cond'pu 'rn'w, 'rlist");
1000 }
1001}
1002
1003
Steve Block1e0659c2011-05-24 12:43:12 +01001004void Decoder::DecodeType5(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001005 Format(instr, "b'l'cond 'target");
1006}
1007
1008
Steve Block1e0659c2011-05-24 12:43:12 +01001009void Decoder::DecodeType6(Instruction* instr) {
Steve Blockd0582a62009-12-15 09:54:21 +00001010 DecodeType6CoprocessorIns(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001011}
1012
1013
Steve Block1e0659c2011-05-24 12:43:12 +01001014int Decoder::DecodeType7(Instruction* instr) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001015 if (instr->Bit(24) == 1) {
Steve Block1e0659c2011-05-24 12:43:12 +01001016 if (instr->SvcValue() >= kStopCode) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001017 Format(instr, "stop'cond 'svc");
1018 // Also print the stop message. Its address is encoded
1019 // in the following 4 bytes.
Steve Block1e0659c2011-05-24 12:43:12 +01001020 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
1021 "\n %p %08x stop message: %s",
1022 reinterpret_cast<int32_t*>(instr
1023 + Instruction::kInstrSize),
1024 *reinterpret_cast<char**>(instr
1025 + Instruction::kInstrSize),
1026 *reinterpret_cast<char**>(instr
1027 + Instruction::kInstrSize));
1028 // We have decoded 2 * Instruction::kInstrSize bytes.
1029 return 2 * Instruction::kInstrSize;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001030 } else {
1031 Format(instr, "svc'cond 'svc");
1032 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001033 } else {
Steve Blockd0582a62009-12-15 09:54:21 +00001034 DecodeTypeVFP(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001035 }
Steve Block1e0659c2011-05-24 12:43:12 +01001036 return Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001037}
1038
1039
Steve Block1e0659c2011-05-24 12:43:12 +01001040// void Decoder::DecodeTypeVFP(Instruction* instr)
Leon Clarkee46be812010-01-19 14:06:41 +00001041// vmov: Sn = Rt
1042// vmov: Rt = Sn
1043// vcvt: Dd = Sm
1044// vcvt: Sd = Dm
1045// Dd = vadd(Dn, Dm)
1046// Dd = vsub(Dn, Dm)
1047// Dd = vmul(Dn, Dm)
1048// Dd = vdiv(Dn, Dm)
Steve Blockd0582a62009-12-15 09:54:21 +00001049// vcmp(Dd, Dm)
Steve Block8defd9f2010-07-08 12:39:36 +01001050// vmrs
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001051// vmsr
Steve Block8defd9f2010-07-08 12:39:36 +01001052// Dd = vsqrt(Dm)
Steve Block1e0659c2011-05-24 12:43:12 +01001053void Decoder::DecodeTypeVFP(Instruction* instr) {
1054 ASSERT((instr->TypeValue() == 7) && (instr->Bit(24) == 0x0) );
Steve Block6ded16b2010-05-10 14:33:55 +01001055 ASSERT(instr->Bits(11, 9) == 0x5);
Steve Blockd0582a62009-12-15 09:54:21 +00001056
Steve Block6ded16b2010-05-10 14:33:55 +01001057 if (instr->Bit(4) == 0) {
Steve Block1e0659c2011-05-24 12:43:12 +01001058 if (instr->Opc1Value() == 0x7) {
Steve Block6ded16b2010-05-10 14:33:55 +01001059 // Other data processing instructions
Steve Block1e0659c2011-05-24 12:43:12 +01001060 if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x1)) {
Steve Block8defd9f2010-07-08 12:39:36 +01001061 // vmov register to register.
Steve Block1e0659c2011-05-24 12:43:12 +01001062 if (instr->SzValue() == 0x1) {
Steve Block8defd9f2010-07-08 12:39:36 +01001063 Format(instr, "vmov.f64'cond 'Dd, 'Dm");
1064 } else {
Ben Murdoch3bec4d22010-07-22 14:51:16 +01001065 Format(instr, "vmov.f32'cond 'Sd, 'Sm");
Steve Block8defd9f2010-07-08 12:39:36 +01001066 }
Steve Block1e0659c2011-05-24 12:43:12 +01001067 } else if ((instr->Opc2Value() == 0x0) && (instr->Opc3Value() == 0x3)) {
1068 // vabs
1069 Format(instr, "vabs'cond 'Dd, 'Dm");
1070 } else if ((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001071 DecodeVCVTBetweenDoubleAndSingle(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001072 } else if ((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001073 DecodeVCVTBetweenFloatingPointAndInteger(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001074 } else if (((instr->Opc2Value() >> 1) == 0x6) &&
1075 (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001076 DecodeVCVTBetweenFloatingPointAndInteger(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001077 } else if (((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
1078 (instr->Opc3Value() & 0x1)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001079 DecodeVCMP(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001080 } else if (((instr->Opc2Value() == 0x1)) && (instr->Opc3Value() == 0x3)) {
Steve Block8defd9f2010-07-08 12:39:36 +01001081 Format(instr, "vsqrt.f64'cond 'Dd, 'Dm");
Steve Block1e0659c2011-05-24 12:43:12 +01001082 } else if (instr->Opc3Value() == 0x0) {
1083 if (instr->SzValue() == 0x1) {
Ben Murdoch3bec4d22010-07-22 14:51:16 +01001084 Format(instr, "vmov.f64'cond 'Dd, 'd");
1085 } else {
1086 Unknown(instr); // Not used by V8.
1087 }
Steve Block6ded16b2010-05-10 14:33:55 +01001088 } else {
1089 Unknown(instr); // Not used by V8.
1090 }
Steve Block1e0659c2011-05-24 12:43:12 +01001091 } else if (instr->Opc1Value() == 0x3) {
1092 if (instr->SzValue() == 0x1) {
1093 if (instr->Opc3Value() & 0x1) {
Steve Block6ded16b2010-05-10 14:33:55 +01001094 Format(instr, "vsub.f64'cond 'Dd, 'Dn, 'Dm");
1095 } else {
1096 Format(instr, "vadd.f64'cond 'Dd, 'Dn, 'Dm");
1097 }
1098 } else {
1099 Unknown(instr); // Not used by V8.
1100 }
Steve Block1e0659c2011-05-24 12:43:12 +01001101 } else if ((instr->Opc1Value() == 0x2) && !(instr->Opc3Value() & 0x1)) {
1102 if (instr->SzValue() == 0x1) {
Steve Block6ded16b2010-05-10 14:33:55 +01001103 Format(instr, "vmul.f64'cond 'Dd, 'Dn, 'Dm");
1104 } else {
1105 Unknown(instr); // Not used by V8.
1106 }
Steve Block1e0659c2011-05-24 12:43:12 +01001107 } else if ((instr->Opc1Value() == 0x4) && !(instr->Opc3Value() & 0x1)) {
1108 if (instr->SzValue() == 0x1) {
Steve Blockd0582a62009-12-15 09:54:21 +00001109 Format(instr, "vdiv.f64'cond 'Dd, 'Dn, 'Dm");
Steve Block6ded16b2010-05-10 14:33:55 +01001110 } else {
1111 Unknown(instr); // Not used by V8.
1112 }
Steve Blockd0582a62009-12-15 09:54:21 +00001113 } else {
1114 Unknown(instr); // Not used by V8.
1115 }
1116 } else {
Steve Block1e0659c2011-05-24 12:43:12 +01001117 if ((instr->VCValue() == 0x0) &&
1118 (instr->VAValue() == 0x0)) {
Steve Block6ded16b2010-05-10 14:33:55 +01001119 DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(instr);
Steve Block1e0659c2011-05-24 12:43:12 +01001120 } else if ((instr->VCValue() == 0x0) &&
1121 (instr->VAValue() == 0x7) &&
Steve Block6ded16b2010-05-10 14:33:55 +01001122 (instr->Bits(19, 16) == 0x1)) {
Steve Block1e0659c2011-05-24 12:43:12 +01001123 if (instr->VLValue() == 0) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001124 if (instr->Bits(15, 12) == 0xF) {
1125 Format(instr, "vmsr'cond FPSCR, APSR");
1126 } else {
1127 Format(instr, "vmsr'cond FPSCR, 'rt");
1128 }
1129 } else {
1130 if (instr->Bits(15, 12) == 0xF) {
1131 Format(instr, "vmrs'cond APSR, FPSCR");
1132 } else {
1133 Format(instr, "vmrs'cond 'rt, FPSCR");
1134 }
1135 }
Steve Blockd0582a62009-12-15 09:54:21 +00001136 }
1137 }
1138}
1139
1140
Steve Block1e0659c2011-05-24 12:43:12 +01001141void Decoder::DecodeVMOVBetweenCoreAndSinglePrecisionRegisters(
1142 Instruction* instr) {
1143 ASSERT((instr->Bit(4) == 1) && (instr->VCValue() == 0x0) &&
1144 (instr->VAValue() == 0x0));
Steve Block6ded16b2010-05-10 14:33:55 +01001145
Steve Block1e0659c2011-05-24 12:43:12 +01001146 bool to_arm_register = (instr->VLValue() == 0x1);
Steve Block6ded16b2010-05-10 14:33:55 +01001147
1148 if (to_arm_register) {
1149 Format(instr, "vmov'cond 'rt, 'Sn");
1150 } else {
1151 Format(instr, "vmov'cond 'Sn, 'rt");
1152 }
1153}
1154
1155
Steve Block1e0659c2011-05-24 12:43:12 +01001156void Decoder::DecodeVCMP(Instruction* instr) {
1157 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1158 ASSERT(((instr->Opc2Value() == 0x4) || (instr->Opc2Value() == 0x5)) &&
1159 (instr->Opc3Value() & 0x1));
Steve Block6ded16b2010-05-10 14:33:55 +01001160
1161 // Comparison.
Steve Block1e0659c2011-05-24 12:43:12 +01001162 bool dp_operation = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001163 bool raise_exception_for_qnan = (instr->Bit(7) == 0x1);
1164
1165 if (dp_operation && !raise_exception_for_qnan) {
Steve Block1e0659c2011-05-24 12:43:12 +01001166 if (instr->Opc2Value() == 0x4) {
Iain Merrick75681382010-08-19 15:07:18 +01001167 Format(instr, "vcmp.f64'cond 'Dd, 'Dm");
Steve Block1e0659c2011-05-24 12:43:12 +01001168 } else if (instr->Opc2Value() == 0x5) {
Iain Merrick75681382010-08-19 15:07:18 +01001169 Format(instr, "vcmp.f64'cond 'Dd, #0.0");
1170 } else {
1171 Unknown(instr); // invalid
1172 }
Steve Block6ded16b2010-05-10 14:33:55 +01001173 } else {
1174 Unknown(instr); // Not used by V8.
1175 }
1176}
1177
1178
Steve Block1e0659c2011-05-24 12:43:12 +01001179void Decoder::DecodeVCVTBetweenDoubleAndSingle(Instruction* instr) {
1180 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1181 ASSERT((instr->Opc2Value() == 0x7) && (instr->Opc3Value() == 0x3));
Steve Block6ded16b2010-05-10 14:33:55 +01001182
Steve Block1e0659c2011-05-24 12:43:12 +01001183 bool double_to_single = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001184
1185 if (double_to_single) {
1186 Format(instr, "vcvt.f32.f64'cond 'Sd, 'Dm");
1187 } else {
1188 Format(instr, "vcvt.f64.f32'cond 'Dd, 'Sm");
1189 }
1190}
1191
1192
Steve Block1e0659c2011-05-24 12:43:12 +01001193void Decoder::DecodeVCVTBetweenFloatingPointAndInteger(Instruction* instr) {
1194 ASSERT((instr->Bit(4) == 0) && (instr->Opc1Value() == 0x7));
1195 ASSERT(((instr->Opc2Value() == 0x8) && (instr->Opc3Value() & 0x1)) ||
1196 (((instr->Opc2Value() >> 1) == 0x6) && (instr->Opc3Value() & 0x1)));
Steve Block6ded16b2010-05-10 14:33:55 +01001197
1198 bool to_integer = (instr->Bit(18) == 1);
Steve Block1e0659c2011-05-24 12:43:12 +01001199 bool dp_operation = (instr->SzValue() == 1);
Steve Block6ded16b2010-05-10 14:33:55 +01001200 if (to_integer) {
1201 bool unsigned_integer = (instr->Bit(16) == 0);
1202
1203 if (dp_operation) {
1204 if (unsigned_integer) {
1205 Format(instr, "vcvt.u32.f64'cond 'Sd, 'Dm");
1206 } else {
1207 Format(instr, "vcvt.s32.f64'cond 'Sd, 'Dm");
1208 }
1209 } else {
1210 if (unsigned_integer) {
1211 Format(instr, "vcvt.u32.f32'cond 'Sd, 'Sm");
1212 } else {
1213 Format(instr, "vcvt.s32.f32'cond 'Sd, 'Sm");
1214 }
1215 }
1216 } else {
1217 bool unsigned_integer = (instr->Bit(7) == 0);
1218
1219 if (dp_operation) {
1220 if (unsigned_integer) {
1221 Format(instr, "vcvt.f64.u32'cond 'Dd, 'Sm");
1222 } else {
1223 Format(instr, "vcvt.f64.s32'cond 'Dd, 'Sm");
1224 }
1225 } else {
1226 if (unsigned_integer) {
1227 Format(instr, "vcvt.f32.u32'cond 'Sd, 'Sm");
1228 } else {
1229 Format(instr, "vcvt.f32.s32'cond 'Sd, 'Sm");
1230 }
1231 }
1232 }
1233}
1234
1235
Steve Blockd0582a62009-12-15 09:54:21 +00001236// Decode Type 6 coprocessor instructions.
Leon Clarkee46be812010-01-19 14:06:41 +00001237// Dm = vmov(Rt, Rt2)
1238// <Rt, Rt2> = vmov(Dm)
Leon Clarked91b9f72010-01-27 17:25:45 +00001239// Ddst = MEM(Rbase + 4*offset).
1240// MEM(Rbase + 4*offset) = Dsrc.
Steve Block1e0659c2011-05-24 12:43:12 +01001241void Decoder::DecodeType6CoprocessorIns(Instruction* instr) {
1242 ASSERT(instr->TypeValue() == 6);
Steve Blockd0582a62009-12-15 09:54:21 +00001243
Steve Block1e0659c2011-05-24 12:43:12 +01001244 if (instr->CoprocessorValue() == 0xA) {
1245 switch (instr->OpcodeValue()) {
Steve Block6ded16b2010-05-10 14:33:55 +01001246 case 0x8:
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001247 case 0xA:
Steve Block6ded16b2010-05-10 14:33:55 +01001248 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001249 Format(instr, "vldr'cond 'Sd, ['rn - 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001250 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001251 Format(instr, "vstr'cond 'Sd, ['rn - 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001252 }
1253 break;
1254 case 0xC:
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001255 case 0xE:
Steve Block6ded16b2010-05-10 14:33:55 +01001256 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001257 Format(instr, "vldr'cond 'Sd, ['rn + 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001258 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001259 Format(instr, "vstr'cond 'Sd, ['rn + 4*'imm08@00]");
Steve Block6ded16b2010-05-10 14:33:55 +01001260 }
1261 break;
1262 default:
1263 Unknown(instr); // Not used by V8.
1264 break;
1265 }
Steve Block1e0659c2011-05-24 12:43:12 +01001266 } else if (instr->CoprocessorValue() == 0xB) {
1267 switch (instr->OpcodeValue()) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001268 case 0x2:
1269 // Load and store double to two GP registers
1270 if (instr->Bits(7, 4) != 0x1) {
1271 Unknown(instr); // Not used by V8.
1272 } else if (instr->HasL()) {
1273 Format(instr, "vmov'cond 'rt, 'rn, 'Dm");
1274 } else {
1275 Format(instr, "vmov'cond 'Dm, 'rt, 'rn");
1276 }
1277 break;
1278 case 0x8:
1279 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001280 Format(instr, "vldr'cond 'Dd, ['rn - 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001281 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001282 Format(instr, "vstr'cond 'Dd, ['rn - 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001283 }
1284 break;
1285 case 0xC:
1286 if (instr->HasL()) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001287 Format(instr, "vldr'cond 'Dd, ['rn + 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001288 } else {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001289 Format(instr, "vstr'cond 'Dd, ['rn + 4*'imm08@00]");
Leon Clarked91b9f72010-01-27 17:25:45 +00001290 }
1291 break;
1292 default:
1293 Unknown(instr); // Not used by V8.
1294 break;
1295 }
Steve Block6ded16b2010-05-10 14:33:55 +01001296 } else {
1297 UNIMPLEMENTED(); // Not used by V8.
Steve Blockd0582a62009-12-15 09:54:21 +00001298 }
1299}
1300
1301
Steve Blocka7e24c12009-10-30 11:49:00 +00001302// Disassemble the instruction at *instr_ptr into the output buffer.
1303int Decoder::InstructionDecode(byte* instr_ptr) {
Steve Block1e0659c2011-05-24 12:43:12 +01001304 Instruction* instr = Instruction::At(instr_ptr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001305 // Print raw instruction bytes.
Steve Block1e0659c2011-05-24 12:43:12 +01001306 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_,
1307 "%08x ",
1308 instr->InstructionBits());
1309 if (instr->ConditionField() == kSpecialCondition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001310 UNIMPLEMENTED();
Steve Block1e0659c2011-05-24 12:43:12 +01001311 return Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001312 }
Steve Block1e0659c2011-05-24 12:43:12 +01001313 switch (instr->TypeValue()) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001314 case 0:
1315 case 1: {
1316 DecodeType01(instr);
1317 break;
1318 }
1319 case 2: {
1320 DecodeType2(instr);
1321 break;
1322 }
1323 case 3: {
1324 DecodeType3(instr);
1325 break;
1326 }
1327 case 4: {
1328 DecodeType4(instr);
1329 break;
1330 }
1331 case 5: {
1332 DecodeType5(instr);
1333 break;
1334 }
1335 case 6: {
1336 DecodeType6(instr);
1337 break;
1338 }
1339 case 7: {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001340 return DecodeType7(instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001341 }
1342 default: {
1343 // The type field is 3-bits in the ARM encoding.
1344 UNREACHABLE();
1345 break;
1346 }
1347 }
Steve Block1e0659c2011-05-24 12:43:12 +01001348 return Instruction::kInstrSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001349}
1350
1351
Steve Block1e0659c2011-05-24 12:43:12 +01001352} } // namespace v8::internal
Steve Blocka7e24c12009-10-30 11:49:00 +00001353
1354
1355
1356//------------------------------------------------------------------------------
1357
1358namespace disasm {
1359
Steve Blocka7e24c12009-10-30 11:49:00 +00001360
1361const char* NameConverter::NameOfAddress(byte* addr) const {
1362 static v8::internal::EmbeddedVector<char, 32> tmp_buffer;
1363 v8::internal::OS::SNPrintF(tmp_buffer, "%p", addr);
1364 return tmp_buffer.start();
1365}
1366
1367
1368const char* NameConverter::NameOfConstant(byte* addr) const {
1369 return NameOfAddress(addr);
1370}
1371
1372
1373const char* NameConverter::NameOfCPURegister(int reg) const {
Steve Block1e0659c2011-05-24 12:43:12 +01001374 return v8::internal::Registers::Name(reg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001375}
1376
1377
1378const char* NameConverter::NameOfByteCPURegister(int reg) const {
1379 UNREACHABLE(); // ARM does not have the concept of a byte register
1380 return "nobytereg";
1381}
1382
1383
1384const char* NameConverter::NameOfXMMRegister(int reg) const {
1385 UNREACHABLE(); // ARM does not have any XMM registers
1386 return "noxmmreg";
1387}
1388
1389
1390const char* NameConverter::NameInCode(byte* addr) const {
1391 // The default name converter is called for unknown code. So we will not try
1392 // to access any memory.
1393 return "";
1394}
1395
1396
1397//------------------------------------------------------------------------------
1398
1399Disassembler::Disassembler(const NameConverter& converter)
1400 : converter_(converter) {}
1401
1402
1403Disassembler::~Disassembler() {}
1404
1405
1406int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
1407 byte* instruction) {
Steve Block1e0659c2011-05-24 12:43:12 +01001408 v8::internal::Decoder d(converter_, buffer);
Steve Blocka7e24c12009-10-30 11:49:00 +00001409 return d.InstructionDecode(instruction);
1410}
1411
1412
1413int Disassembler::ConstantPoolSizeAt(byte* instruction) {
1414 int instruction_bits = *(reinterpret_cast<int*>(instruction));
1415 if ((instruction_bits & 0xfff00000) == 0x03000000) {
1416 return instruction_bits & 0x0000ffff;
1417 } else {
1418 return -1;
1419 }
1420}
1421
1422
1423void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) {
1424 NameConverter converter;
1425 Disassembler d(converter);
1426 for (byte* pc = begin; pc < end;) {
1427 v8::internal::EmbeddedVector<char, 128> buffer;
1428 buffer[0] = '\0';
1429 byte* prev_pc = pc;
1430 pc += d.InstructionDecode(buffer, pc);
1431 fprintf(f, "%p %08x %s\n",
1432 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start());
1433 }
1434}
1435
1436
1437} // namespace disasm
Leon Clarkef7060e22010-06-03 12:02:55 +01001438
1439#endif // V8_TARGET_ARCH_ARM