OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A Disassembler object is used to disassemble a block of code instruction by | 5 // A Disassembler object is used to disassemble a block of code instruction by |
6 // instruction. The default implementation of the NameConverter object can be | 6 // instruction. The default implementation of the NameConverter object can be |
7 // overriden to modify register names or to do symbol lookup on addresses. | 7 // overriden to modify register names or to do symbol lookup on addresses. |
8 // | 8 // |
9 // The example below will disassemble a block of code and print it to stdout. | 9 // The example below will disassemble a block of code and print it to stdout. |
10 // | 10 // |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 void Decoder::PrintFd(Instruction* instr) { | 178 void Decoder::PrintFd(Instruction* instr) { |
179 int freg = instr->RdValue(); | 179 int freg = instr->RdValue(); |
180 PrintFPURegister(freg); | 180 PrintFPURegister(freg); |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 // Print the integer value of the sa field. | 184 // Print the integer value of the sa field. |
185 void Decoder::PrintSa(Instruction* instr) { | 185 void Decoder::PrintSa(Instruction* instr) { |
186 int sa = instr->SaValue(); | 186 int sa = instr->SaValue(); |
187 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", sa); | 187 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", sa); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 // Print the integer value of the rd field, when it is not used as reg. | 191 // Print the integer value of the rd field, when it is not used as reg. |
192 void Decoder::PrintSd(Instruction* instr) { | 192 void Decoder::PrintSd(Instruction* instr) { |
193 int sd = instr->RdValue(); | 193 int sd = instr->RdValue(); |
194 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", sd); | 194 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", sd); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 // Print the integer value of the rd field, when used as 'ext' size. | 198 // Print the integer value of the rd field, when used as 'ext' size. |
199 void Decoder::PrintSs1(Instruction* instr) { | 199 void Decoder::PrintSs1(Instruction* instr) { |
200 int ss = instr->RdValue(); | 200 int ss = instr->RdValue(); |
201 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", ss + 1); | 201 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", ss + 1); |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 // Print the integer value of the rd field, when used as 'ins' size. | 205 // Print the integer value of the rd field, when used as 'ins' size. |
206 void Decoder::PrintSs2(Instruction* instr) { | 206 void Decoder::PrintSs2(Instruction* instr) { |
207 int ss = instr->RdValue(); | 207 int ss = instr->RdValue(); |
208 int pos = instr->SaValue(); | 208 int pos = instr->SaValue(); |
209 out_buffer_pos_ += | 209 out_buffer_pos_ += |
210 OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", ss - pos + 1); | 210 SNPrintF(out_buffer_ + out_buffer_pos_, "%d", ss - pos + 1); |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 // Print the integer value of the cc field for the bc1t/f instructions. | 214 // Print the integer value of the cc field for the bc1t/f instructions. |
215 void Decoder::PrintBc(Instruction* instr) { | 215 void Decoder::PrintBc(Instruction* instr) { |
216 int cc = instr->FBccValue(); | 216 int cc = instr->FBccValue(); |
217 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", cc); | 217 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", cc); |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 // Print the integer value of the cc field for the FP compare instructions. | 221 // Print the integer value of the cc field for the FP compare instructions. |
222 void Decoder::PrintCc(Instruction* instr) { | 222 void Decoder::PrintCc(Instruction* instr) { |
223 int cc = instr->FCccValue(); | 223 int cc = instr->FCccValue(); |
224 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "cc(%d)", cc); | 224 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "cc(%d)", cc); |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 // Print 16-bit unsigned immediate value. | 228 // Print 16-bit unsigned immediate value. |
229 void Decoder::PrintUImm16(Instruction* instr) { | 229 void Decoder::PrintUImm16(Instruction* instr) { |
230 int32_t imm = instr->Imm16Value(); | 230 int32_t imm = instr->Imm16Value(); |
231 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%u", imm); | 231 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%u", imm); |
232 } | 232 } |
233 | 233 |
234 | 234 |
235 // Print 16-bit signed immediate value. | 235 // Print 16-bit signed immediate value. |
236 void Decoder::PrintSImm16(Instruction* instr) { | 236 void Decoder::PrintSImm16(Instruction* instr) { |
237 int32_t imm = ((instr->Imm16Value()) << 16) >> 16; | 237 int32_t imm = ((instr->Imm16Value()) << 16) >> 16; |
238 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "%d", imm); | 238 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", imm); |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 // Print 16-bit hexa immediate value. | 242 // Print 16-bit hexa immediate value. |
243 void Decoder::PrintXImm16(Instruction* instr) { | 243 void Decoder::PrintXImm16(Instruction* instr) { |
244 int32_t imm = instr->Imm16Value(); | 244 int32_t imm = instr->Imm16Value(); |
245 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", imm); | 245 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", imm); |
246 } | 246 } |
247 | 247 |
248 | 248 |
249 // Print 26-bit immediate value. | 249 // Print 26-bit immediate value. |
250 void Decoder::PrintXImm26(Instruction* instr) { | 250 void Decoder::PrintXImm26(Instruction* instr) { |
251 uint32_t imm = instr->Imm26Value() << kImmFieldShift; | 251 uint32_t imm = instr->Imm26Value() << kImmFieldShift; |
252 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", imm); | 252 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", imm); |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 // Print 26-bit immediate value. | 256 // Print 26-bit immediate value. |
257 void Decoder::PrintCode(Instruction* instr) { | 257 void Decoder::PrintCode(Instruction* instr) { |
258 if (instr->OpcodeFieldRaw() != SPECIAL) | 258 if (instr->OpcodeFieldRaw() != SPECIAL) |
259 return; // Not a break or trap instruction. | 259 return; // Not a break or trap instruction. |
260 switch (instr->FunctionFieldRaw()) { | 260 switch (instr->FunctionFieldRaw()) { |
261 case BREAK: { | 261 case BREAK: { |
262 int32_t code = instr->Bits(25, 6); | 262 int32_t code = instr->Bits(25, 6); |
263 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, | 263 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
264 "0x%05x (%d)", code, code); | 264 "0x%05x (%d)", code, code); |
265 break; | 265 break; |
266 } | 266 } |
267 case TGE: | 267 case TGE: |
268 case TGEU: | 268 case TGEU: |
269 case TLT: | 269 case TLT: |
270 case TLTU: | 270 case TLTU: |
271 case TEQ: | 271 case TEQ: |
272 case TNE: { | 272 case TNE: { |
273 int32_t code = instr->Bits(15, 6); | 273 int32_t code = instr->Bits(15, 6); |
274 out_buffer_pos_ += | 274 out_buffer_pos_ += |
275 OS::SNPrintF(out_buffer_ + out_buffer_pos_, "0x%03x", code); | 275 SNPrintF(out_buffer_ + out_buffer_pos_, "0x%03x", code); |
276 break; | 276 break; |
277 } | 277 } |
278 default: // Not a break or trap instruction. | 278 default: // Not a break or trap instruction. |
279 break; | 279 break; |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 | 283 |
284 // Printing of instruction name. | 284 // Printing of instruction name. |
285 void Decoder::PrintInstructionName(Instruction* instr) { | 285 void Decoder::PrintInstructionName(Instruction* instr) { |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 default: | 924 default: |
925 UNREACHABLE(); | 925 UNREACHABLE(); |
926 } | 926 } |
927 } | 927 } |
928 | 928 |
929 | 929 |
930 // Disassemble the instruction at *instr_ptr into the output buffer. | 930 // Disassemble the instruction at *instr_ptr into the output buffer. |
931 int Decoder::InstructionDecode(byte* instr_ptr) { | 931 int Decoder::InstructionDecode(byte* instr_ptr) { |
932 Instruction* instr = Instruction::At(instr_ptr); | 932 Instruction* instr = Instruction::At(instr_ptr); |
933 // Print raw instruction bytes. | 933 // Print raw instruction bytes. |
934 out_buffer_pos_ += OS::SNPrintF(out_buffer_ + out_buffer_pos_, | 934 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, |
935 "%08x ", | 935 "%08x ", |
936 instr->InstructionBits()); | 936 instr->InstructionBits()); |
937 switch (instr->InstructionType()) { | 937 switch (instr->InstructionType()) { |
938 case Instruction::kRegisterType: { | 938 case Instruction::kRegisterType: { |
939 DecodeTypeRegister(instr); | 939 DecodeTypeRegister(instr); |
940 break; | 940 break; |
941 } | 941 } |
942 case Instruction::kImmediateType: { | 942 case Instruction::kImmediateType: { |
943 DecodeTypeImmediate(instr); | 943 DecodeTypeImmediate(instr); |
944 break; | 944 break; |
945 } | 945 } |
946 case Instruction::kJumpType: { | 946 case Instruction::kJumpType: { |
(...skipping 11 matching lines...) Expand all Loading... |
958 | 958 |
959 } } // namespace v8::internal | 959 } } // namespace v8::internal |
960 | 960 |
961 | 961 |
962 | 962 |
963 //------------------------------------------------------------------------------ | 963 //------------------------------------------------------------------------------ |
964 | 964 |
965 namespace disasm { | 965 namespace disasm { |
966 | 966 |
967 const char* NameConverter::NameOfAddress(byte* addr) const { | 967 const char* NameConverter::NameOfAddress(byte* addr) const { |
968 v8::internal::OS::SNPrintF(tmp_buffer_, "%p", addr); | 968 v8::internal::SNPrintF(tmp_buffer_, "%p", addr); |
969 return tmp_buffer_.start(); | 969 return tmp_buffer_.start(); |
970 } | 970 } |
971 | 971 |
972 | 972 |
973 const char* NameConverter::NameOfConstant(byte* addr) const { | 973 const char* NameConverter::NameOfConstant(byte* addr) const { |
974 return NameOfAddress(addr); | 974 return NameOfAddress(addr); |
975 } | 975 } |
976 | 976 |
977 | 977 |
978 const char* NameConverter::NameOfCPURegister(int reg) const { | 978 const char* NameConverter::NameOfCPURegister(int reg) const { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); | 1032 prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); |
1033 } | 1033 } |
1034 } | 1034 } |
1035 | 1035 |
1036 | 1036 |
1037 #undef UNSUPPORTED | 1037 #undef UNSUPPORTED |
1038 | 1038 |
1039 } // namespace disasm | 1039 } // namespace disasm |
1040 | 1040 |
1041 #endif // V8_TARGET_ARCH_MIPS | 1041 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |