| 349 | } |
| 350 | |
| 351 | uint32_t get_shifted_immediate(const InstructionOperand *instructionOperand, char *outBuffer, uint32_t outBufferSize, uint32_t type) |
| 352 | { |
| 353 | char shiftBuff[48] = {0}; |
| 354 | char immBuff[32] = {0}; |
| 355 | const char *sign = ""; |
| 356 | if (instructionOperand == NULL) |
| 357 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 358 | |
| 359 | uint64_t imm = instructionOperand->immediate; |
| 360 | if (instructionOperand->signedImm == 1 && ((int64_t)imm) < 0) |
| 361 | { |
| 362 | sign = "-"; |
| 363 | imm = -(int64_t)imm; |
| 364 | } |
| 365 | if (instructionOperand->shiftType != ShiftType_NONE) |
| 366 | { |
| 367 | if (instructionOperand->shiftValueUsed != 0) |
| 368 | { |
| 369 | if (snprintf(immBuff, sizeof(immBuff), " #%#x", instructionOperand->shiftValue) >= sizeof(immBuff)) |
| 370 | { |
| 371 | return FAILED_TO_DISASSEMBLE_REGISTER; |
| 372 | } |
| 373 | } |
| 374 | const char *shiftStr = get_shift(instructionOperand->shiftType); |
| 375 | if (shiftStr == NULL) |
| 376 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 377 | snprintf( |
| 378 | shiftBuff, |
| 379 | sizeof(shiftBuff), |
| 380 | ", %s%s", |
| 381 | shiftStr, |
| 382 | immBuff); |
| 383 | } |
| 384 | if (type == FIMM32) |
| 385 | { |
| 386 | float f = *(const float*)&instructionOperand->immediate; |
| 387 | if (snprintf(outBuffer, outBufferSize, "#%.08f%s", f, shiftBuff) >= outBufferSize) |
| 388 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 389 | } |
| 390 | else if (type == IMM32) |
| 391 | { |
| 392 | if (snprintf(outBuffer, outBufferSize, "#%s%#x%s", sign, (uint32_t)imm, shiftBuff) >= outBufferSize) |
| 393 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 394 | } |
| 395 | else if (type == LABEL) |
| 396 | { |
| 397 | if (snprintf(outBuffer, outBufferSize, "0x%" PRIx64, (uint64_t)imm) >= outBufferSize) |
| 398 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 399 | } |
| 400 | else if (type == STR_IMM) |
| 401 | { |
| 402 | if (snprintf(outBuffer, outBufferSize, "%s #0x%" PRIx64, instructionOperand->name, (uint64_t)imm) >= outBufferSize) |
| 403 | return FAILED_TO_DISASSEMBLE_OPERAND; |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | if (snprintf(outBuffer, outBufferSize, "#%s%#" PRIx64 "%s", |
| 408 | sign, |
no test coverage detected