OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/disassembler.h" | 5 #include "vm/disassembler.h" |
6 | 6 |
7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
8 #if defined(TARGET_ARCH_IA32) | 8 #if defined(TARGET_ARCH_IA32) |
9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 case 0x31: return "rdtsc"; | 230 case 0x31: return "rdtsc"; |
231 case 0xBE: return "movsx_b"; | 231 case 0xBE: return "movsx_b"; |
232 case 0xBF: return "movsx_w"; | 232 case 0xBF: return "movsx_w"; |
233 case 0xB6: return "movzx_b"; | 233 case 0xB6: return "movzx_b"; |
234 case 0xB7: return "movzx_w"; | 234 case 0xB7: return "movzx_w"; |
235 case 0xAF: return "imul"; | 235 case 0xAF: return "imul"; |
236 case 0xA5: return "shld"; | 236 case 0xA5: return "shld"; |
237 case 0xAD: return "shrd"; | 237 case 0xAD: return "shrd"; |
238 case 0xAB: return "bts"; | 238 case 0xAB: return "bts"; |
239 case 0xB1: return "cmpxchg"; | 239 case 0xB1: return "cmpxchg"; |
240 case 0x50: return "movmskps"; | |
241 case 0x51: return "sqrtps"; | |
242 case 0x52: return "rqstps"; | |
243 case 0x53: return "rcpps"; | |
244 case 0x54: return "andps"; | |
245 case 0x56: return "orps"; | |
246 case 0x57: return "xorps"; | 240 case 0x57: return "xorps"; |
247 case 0x58: return "addps"; | |
248 case 0x59: return "mulps"; | |
249 case 0x5C: return "subps"; | |
250 case 0x5D: return "minps"; | |
251 case 0x5E: return "divps"; | |
252 case 0x5F: return "maxps"; | |
253 case 0x28: return "movaps"; | 241 case 0x28: return "movaps"; |
254 case 0x10: return "movups"; | |
255 case 0x11: return "movups"; | |
256 default: return NULL; | 242 default: return NULL; |
257 } | 243 } |
258 } | 244 } |
259 | 245 |
260 | 246 |
261 // The implementation of x86 decoding based on the above tables. | 247 // The implementation of x86 decoding based on the above tables. |
262 class X86Decoder : public ValueObject { | 248 class X86Decoder : public ValueObject { |
263 public: | 249 public: |
264 X86Decoder(char* buffer, intptr_t buffer_size) | 250 X86Decoder(char* buffer, intptr_t buffer_size) |
265 : buffer_(buffer), | 251 : buffer_(buffer), |
(...skipping 27 matching lines...) Expand all Loading... |
293 const char* GetBranchPrefix(uint8_t** data); | 279 const char* GetBranchPrefix(uint8_t** data); |
294 | 280 |
295 bool DecodeInstructionType(const InstructionDesc& idesc, | 281 bool DecodeInstructionType(const InstructionDesc& idesc, |
296 const char* branch_hint, | 282 const char* branch_hint, |
297 uint8_t** data); | 283 uint8_t** data); |
298 | 284 |
299 // Printing of common values. | 285 // Printing of common values. |
300 void PrintCPURegister(int reg); | 286 void PrintCPURegister(int reg); |
301 void PrintCPUByteRegister(int reg); | 287 void PrintCPUByteRegister(int reg); |
302 void PrintXmmRegister(int reg); | 288 void PrintXmmRegister(int reg); |
303 void PrintXmmComparison(int comparison); | |
304 void PrintAddress(uword addr); | 289 void PrintAddress(uword addr); |
305 | 290 |
306 typedef void (X86Decoder::*RegisterNamePrinter)(int reg); | 291 typedef void (X86Decoder::*RegisterNamePrinter)(int reg); |
307 | 292 |
308 int PrintRightOperandHelper(uint8_t* modrmp, | 293 int PrintRightOperandHelper(uint8_t* modrmp, |
309 RegisterNamePrinter register_printer); | 294 RegisterNamePrinter register_printer); |
310 int PrintRightOperand(uint8_t* modrmp); | 295 int PrintRightOperand(uint8_t* modrmp); |
311 int PrintRightXmmOperand(uint8_t* modrmp); | 296 int PrintRightXmmOperand(uint8_t* modrmp); |
312 int PrintRightByteOperand(uint8_t* modrmp); | 297 int PrintRightByteOperand(uint8_t* modrmp); |
313 int PrintOperands(const char* mnem, OperandOrder op_order, uint8_t* data); | 298 int PrintOperands(const char* mnem, OperandOrder op_order, uint8_t* data); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 UNIMPLEMENTED(); | 388 UNIMPLEMENTED(); |
404 } | 389 } |
405 | 390 |
406 | 391 |
407 void X86Decoder::PrintXmmRegister(int reg) { | 392 void X86Decoder::PrintXmmRegister(int reg) { |
408 ASSERT(0 <= reg); | 393 ASSERT(0 <= reg); |
409 ASSERT(reg < kMaxXmmRegisters); | 394 ASSERT(reg < kMaxXmmRegisters); |
410 Print(xmm_regs[reg]); | 395 Print(xmm_regs[reg]); |
411 } | 396 } |
412 | 397 |
413 void X86Decoder::PrintXmmComparison(int comparison) { | |
414 ASSERT(0 <= comparison); | |
415 ASSERT(comparison < 8); | |
416 static const char* comparisons[8] = { | |
417 "eq", "lt", "le", "unordered", "not eq", "not lt", "not le", "ordered" | |
418 }; | |
419 Print(comparisons[comparison]); | |
420 } | |
421 | |
422 | 398 |
423 static const char* ObjectToCStringNoGC(const Object& obj) { | 399 static const char* ObjectToCStringNoGC(const Object& obj) { |
424 if (obj.IsSmi() || | 400 if (obj.IsSmi() || |
425 obj.IsMint() || | 401 obj.IsMint() || |
426 obj.IsDouble() || | 402 obj.IsDouble() || |
427 obj.IsString() || | 403 obj.IsString() || |
428 obj.IsNull() || | 404 obj.IsNull() || |
429 obj.IsBool() || | 405 obj.IsBool() || |
430 obj.IsClass() || | 406 obj.IsClass() || |
431 obj.IsFunction() || | 407 obj.IsFunction() || |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 } | 1330 } |
1355 } else if (f0byte == 0x28) { | 1331 } else if (f0byte == 0x28) { |
1356 // movaps | 1332 // movaps |
1357 Print(f0mnem); | 1333 Print(f0mnem); |
1358 int mod, regop, rm; | 1334 int mod, regop, rm; |
1359 GetModRm(*data, &mod, ®op, &rm); | 1335 GetModRm(*data, &mod, ®op, &rm); |
1360 Print(" "); | 1336 Print(" "); |
1361 PrintXmmRegister(regop); | 1337 PrintXmmRegister(regop); |
1362 Print(","); | 1338 Print(","); |
1363 data += PrintRightXmmOperand(data); | 1339 data += PrintRightXmmOperand(data); |
1364 } else if (f0byte == 0x11) { | |
1365 Print("movups "); | |
1366 int mod, regop, rm; | |
1367 GetModRm(*data, &mod, ®op, &rm); | |
1368 data += PrintRightXmmOperand(data); | |
1369 Print(","); | |
1370 PrintXmmRegister(regop); | |
1371 } else if (f0byte == 0x10) { | |
1372 int mod, regop, rm; | |
1373 GetModRm(*data, &mod, ®op, &rm); | |
1374 Print("movups "); | |
1375 PrintXmmRegister(regop); | |
1376 Print(","); | |
1377 data += PrintRightOperand(data); | |
1378 } else if (f0byte == 0x51 || f0byte == 0x52 || f0byte == 0x53 || | |
1379 f0byte == 0x54 || f0byte == 0x56 || f0byte == 0x58 || | |
1380 f0byte == 0x59 || f0byte == 0x5C || f0byte == 0x5D || | |
1381 f0byte == 0x5E || f0byte == 0x5F) { | |
1382 int mod, regop, rm; | |
1383 GetModRm(*data, &mod, ®op, &rm); | |
1384 Print(f0mnem); | |
1385 Print(" "); | |
1386 PrintXmmRegister(regop); | |
1387 Print(","); | |
1388 data += PrintRightXmmOperand(data); | |
1389 } else if (f0byte == 0x50) { | |
1390 Print("movmskpd "); | |
1391 int mod, regop, rm; | |
1392 GetModRm(*data, &mod, ®op, &rm); | |
1393 PrintCPURegister(regop); | |
1394 Print(","); | |
1395 data += PrintRightXmmOperand(data); | |
1396 } else if (f0byte == 0xC2 || f0byte == 0xC6) { | |
1397 if (f0byte == 0xC2) | |
1398 Print("cmpps "); | |
1399 else | |
1400 Print("shufps "); | |
1401 int mod, regop, rm; | |
1402 GetModRm(*data, &mod, ®op, &rm); | |
1403 Print(" "); | |
1404 PrintXmmRegister(regop); | |
1405 Print(","); | |
1406 data += PrintRightXmmOperand(data); | |
1407 int comparison = *data; | |
1408 Print(" ["); | |
1409 PrintHex(comparison); | |
1410 Print("]"); | |
1411 data++; | |
1412 } else { | 1340 } else { |
1413 UNIMPLEMENTED(); | 1341 UNIMPLEMENTED(); |
1414 } | 1342 } |
1415 } | 1343 } |
1416 } | 1344 } |
1417 break; | 1345 break; |
1418 | 1346 |
1419 case 0x8F: | 1347 case 0x8F: |
1420 { data++; | 1348 { data++; |
1421 int mod, regop, rm; | 1349 int mod, regop, rm; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 human_buffer, | 1720 human_buffer, |
1793 sizeof(human_buffer), | 1721 sizeof(human_buffer), |
1794 pc); | 1722 pc); |
1795 pc += instruction_length; | 1723 pc += instruction_length; |
1796 } | 1724 } |
1797 } | 1725 } |
1798 | 1726 |
1799 } // namespace dart | 1727 } // namespace dart |
1800 | 1728 |
1801 #endif // defined TARGET_ARCH_IA32 | 1729 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |