| 405 | } |
| 406 | |
| 407 | static DecodeStatus MipsDisassembler_getInstruction(int mode, MCInst *instr, |
| 408 | const uint8_t *code, size_t code_len, |
| 409 | uint16_t *Size, |
| 410 | uint64_t Address, bool isBigEndian, MCRegisterInfo *MRI) |
| 411 | { |
| 412 | uint32_t Insn; |
| 413 | DecodeStatus Result; |
| 414 | |
| 415 | if (instr->flat_insn->detail) { |
| 416 | memset(instr->flat_insn->detail, 0, offsetof(cs_detail, mips)+sizeof(cs_mips)); |
| 417 | } |
| 418 | |
| 419 | if (mode & CS_MODE_MICRO) { |
| 420 | if (code_len < 2) |
| 421 | // not enough data |
| 422 | return MCDisassembler_Fail; |
| 423 | |
| 424 | readInstruction16((unsigned char*)code, &Insn, isBigEndian); |
| 425 | |
| 426 | // Calling the auto-generated decoder function. |
| 427 | Result = decodeInstruction(DecoderTableMicroMips16, instr, Insn, Address, MRI, mode); |
| 428 | if (Result != MCDisassembler_Fail) { |
| 429 | *Size = 2; |
| 430 | return Result; |
| 431 | } |
| 432 | |
| 433 | if (code_len < 4) |
| 434 | // not enough data |
| 435 | return MCDisassembler_Fail; |
| 436 | |
| 437 | readInstruction32((unsigned char*)code, &Insn, isBigEndian, true); |
| 438 | |
| 439 | //DEBUG(dbgs() << "Trying MicroMips32 table (32-bit instructions):\n"); |
| 440 | // Calling the auto-generated decoder function. |
| 441 | Result = decodeInstruction(DecoderTableMicroMips32, instr, Insn, Address, MRI, mode); |
| 442 | if (Result != MCDisassembler_Fail) { |
| 443 | *Size = 4; |
| 444 | return Result; |
| 445 | } |
| 446 | return MCDisassembler_Fail; |
| 447 | } |
| 448 | |
| 449 | if (code_len < 4) |
| 450 | // not enough data |
| 451 | return MCDisassembler_Fail; |
| 452 | |
| 453 | readInstruction32((unsigned char*)code, &Insn, isBigEndian, false); |
| 454 | |
| 455 | if ((mode & CS_MODE_MIPS2) && ((mode & CS_MODE_MIPS3) == 0)) { |
| 456 | // DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n"); |
| 457 | Result = decodeInstruction(DecoderTableCOP3_32, instr, Insn, Address, MRI, mode); |
| 458 | if (Result != MCDisassembler_Fail) { |
| 459 | *Size = 4; |
| 460 | return Result; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if ((mode & CS_MODE_MIPS32R6) && (mode & CS_MODE_MIPS64)) { |
no test coverage detected
searching dependent graphs…