2013-11-27 12:11:31 +08:00
|
|
|
//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class prints an ARM MCInst to a .s file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-14 11:26:41 +08:00
|
|
|
/* Capstone Disassembly Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
|
|
|
|
|
|
|
|
#ifdef CAPSTONE_HAS_ARM
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
#include <stdio.h> // DEBUG
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "ARMInstPrinter.h"
|
|
|
|
#include "ARMAddressingModes.h"
|
|
|
|
#include "ARMBaseInfo.h"
|
2013-12-11 17:35:27 +08:00
|
|
|
#include "ARMDisassembler.h"
|
2013-11-27 12:11:31 +08:00
|
|
|
#include "../../MCInst.h"
|
|
|
|
#include "../../SStream.h"
|
|
|
|
#include "../../MCRegisterInfo.h"
|
|
|
|
#include "../../utils.h"
|
2014-01-20 09:47:21 +08:00
|
|
|
#include "ARMMapping.h"
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-11 17:35:27 +08:00
|
|
|
#define GET_SUBTARGETINFO_ENUM
|
|
|
|
#include "ARMGenSubtargetInfo.inc"
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
static void printRegName(cs_struct *h, SStream *OS, unsigned RegNo);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
// Autogenerated by tblgen.
|
|
|
|
static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI);
|
|
|
|
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
|
|
|
|
static void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
|
|
|
|
static void printAddrModeTBB(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrModeTBH(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode2Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode3Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0);
|
|
|
|
static void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAM3PostIndexOp(MCInst *MI, unsigned Op, SStream *O);
|
|
|
|
static void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O, bool AlwaysPrintImm0);
|
|
|
|
static void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPostIdxRegOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode5Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0);
|
|
|
|
static void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
|
|
|
|
static void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned);
|
|
|
|
static void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbAddrModeRROperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned Scale);
|
|
|
|
static void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printThumbAddrModeSPOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printAddrModeImm12Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0);
|
|
|
|
static void printT2AddrModeImm8Operand(MCInst *MI, unsigned OpNum, SStream *O, bool);
|
|
|
|
static void printT2AddrModeImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O, bool);
|
|
|
|
static void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printT2AddrModeImm8OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printT2AddrModeImm8s4OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printT2AddrModeSoRegOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printSBitModifierOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printNEONModImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printImmPlusOneOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O, MCRegisterInfo *MRI);
|
|
|
|
static void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printFBits16(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printFBits32(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O, MCRegisterInfo *MRI);
|
|
|
|
static void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum, SStream *O, MCRegisterInfo *RI);
|
|
|
|
static void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum, SStream *O, MCRegisterInfo *RI);
|
|
|
|
static void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListTwoSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O, MCRegisterInfo *MRI);
|
|
|
|
static void printVectorListThreeSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListFourSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
static void printVectorListFourSpaced(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
|
|
|
|
static void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O);
|
|
|
|
|
|
|
|
static void set_mem_access(MCInst *MI, bool status)
|
|
|
|
{
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail != CS_OPT_ON)
|
2013-12-14 00:23:41 +08:00
|
|
|
return;
|
|
|
|
|
2013-12-31 22:40:04 +08:00
|
|
|
MI->csh->doing_mem = status;
|
|
|
|
if (status) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = ARM_REG_INVALID;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = 0;
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
|
|
|
// done, create the next operand slot
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 13:56:01 +08:00
|
|
|
static void op_addImm(MCInst *MI, int v)
|
|
|
|
{
|
2014-06-17 18:08:29 +08:00
|
|
|
if (MI->csh->detail) {
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = v;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
|
|
|
}
|
2014-06-17 13:56:01 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
#define GET_INSTRINFO_ENUM
|
|
|
|
#include "ARMGenInstrInfo.inc"
|
|
|
|
|
|
|
|
//#define PRINT_ALIAS_INSTR
|
|
|
|
#include "ARMGenAsmWriter.inc"
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
void ARM_getRegName(cs_struct *handle, int value)
|
|
|
|
{
|
|
|
|
if (value == CS_OPT_SYNTAX_NOREGNAME)
|
|
|
|
handle->get_regname = getRegisterName2;
|
|
|
|
else
|
|
|
|
handle->get_regname = getRegisterName;
|
|
|
|
}
|
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
|
|
|
|
///
|
|
|
|
/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
|
|
|
|
static unsigned translateShiftImm(unsigned imm)
|
|
|
|
{
|
|
|
|
// lsr #32 and asr #32 exist, but should be encoded as a 0.
|
|
|
|
//assert((imm & ~0x1f) == 0 && "Invalid shift encoding");
|
|
|
|
if (imm == 0)
|
|
|
|
return 32;
|
|
|
|
return imm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prints the shift value with an immediate value.
|
2014-06-10 01:39:06 +08:00
|
|
|
static void printRegImmShift(MCInst *MI, SStream *O, ARM_AM_ShiftOpc ShOpc, unsigned ShImm)
|
2013-11-27 12:11:31 +08:00
|
|
|
{
|
|
|
|
if (ShOpc == ARM_AM_no_shift || (ShOpc == ARM_AM_lsl && !ShImm))
|
|
|
|
return;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
//assert (!(ShOpc == ARM_AM_ror && !ShImm) && "Cannot have ror #0");
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
|
2014-06-01 12:35:34 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-07-31 18:24:51 +08:00
|
|
|
if (MI->csh->doing_mem)
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (arm_shifter)ShOpc;
|
|
|
|
else
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = (arm_shifter)ShOpc;
|
2014-06-01 12:35:34 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (ShOpc != ARM_AM_rrx) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, " ");
|
2013-12-11 17:35:27 +08:00
|
|
|
SStream_concat(O, "#%u", translateShiftImm(ShImm));
|
2014-06-01 12:35:34 +08:00
|
|
|
if (MI->csh->detail) {
|
|
|
|
if (MI->csh->doing_mem)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = translateShiftImm(ShImm);
|
2014-06-01 12:35:34 +08:00
|
|
|
else
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = translateShiftImm(ShImm);
|
2014-06-01 12:35:34 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
static void printRegName(cs_struct *h, SStream *OS, unsigned RegNo)
|
2013-11-27 12:11:31 +08:00
|
|
|
{
|
2014-03-11 00:18:50 +08:00
|
|
|
#ifndef CAPSTONE_DIET
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(OS, h->get_regname(RegNo));
|
2014-03-11 00:18:50 +08:00
|
|
|
#endif
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static name_map insn_update_flgs[] = {
|
|
|
|
{ ARM_INS_CMN, "cmn" },
|
|
|
|
{ ARM_INS_CMP, "cmp" },
|
|
|
|
{ ARM_INS_TEQ, "teq" },
|
|
|
|
{ ARM_INS_TST, "tst" },
|
|
|
|
|
|
|
|
{ ARM_INS_ADC, "adcs" },
|
|
|
|
{ ARM_INS_ADD, "adds" },
|
|
|
|
{ ARM_INS_AND, "ands" },
|
|
|
|
{ ARM_INS_ASR, "asrs" },
|
|
|
|
{ ARM_INS_BIC, "bics" },
|
|
|
|
{ ARM_INS_EOR, "eors" },
|
|
|
|
{ ARM_INS_LSL, "lsls" },
|
|
|
|
{ ARM_INS_LSR, "lsrs" },
|
|
|
|
{ ARM_INS_MLA, "mlas" },
|
|
|
|
{ ARM_INS_MOV, "movs" },
|
|
|
|
{ ARM_INS_MUL, "muls" },
|
|
|
|
{ ARM_INS_MVN, "mvns" },
|
|
|
|
{ ARM_INS_ORN, "orns" },
|
|
|
|
{ ARM_INS_ORR, "orrs" },
|
|
|
|
{ ARM_INS_ROR, "rors" },
|
|
|
|
{ ARM_INS_RRX, "rrxs" },
|
|
|
|
{ ARM_INS_RSB, "rsbs" },
|
|
|
|
{ ARM_INS_RSC, "rscs" },
|
|
|
|
{ ARM_INS_SBC, "sbcs" },
|
|
|
|
{ ARM_INS_SMLAL, "smlals" },
|
|
|
|
{ ARM_INS_SMULL, "smulls" },
|
|
|
|
{ ARM_INS_SUB, "subs" },
|
|
|
|
{ ARM_INS_UMLAL, "umlals" },
|
|
|
|
{ ARM_INS_UMULL, "umulls" },
|
|
|
|
};
|
|
|
|
|
2014-05-19 16:46:31 +08:00
|
|
|
void ARM_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci)
|
2013-11-27 12:11:31 +08:00
|
|
|
{
|
2014-01-04 10:41:17 +08:00
|
|
|
if (((cs_struct *)ud)->detail != CS_OPT_ON)
|
|
|
|
return;
|
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
// check if this insn requests write-back
|
|
|
|
if (strrchr(insn_asm, '!') != NULL) {
|
2013-12-24 16:49:36 +08:00
|
|
|
insn->detail->arm.writeback = true;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if this insn requests update flags
|
2013-12-24 16:49:36 +08:00
|
|
|
if (insn->detail->arm.update_flags == false) {
|
2013-11-27 12:11:31 +08:00
|
|
|
// some insn still update flags, regardless of tabgen info
|
2014-03-12 12:50:54 +08:00
|
|
|
unsigned int i, j;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARR_SIZE(insn_update_flgs); i++) {
|
2013-12-24 16:49:36 +08:00
|
|
|
if (insn->id == insn_update_flgs[i].id &&
|
2013-11-27 12:11:31 +08:00
|
|
|
!strncmp(insn_asm, insn_update_flgs[i].name,
|
|
|
|
strlen(insn_update_flgs[i].name))) {
|
2013-12-24 16:49:36 +08:00
|
|
|
insn->detail->arm.update_flags = true;
|
2013-11-27 12:11:31 +08:00
|
|
|
// we have to update regs_write array as well
|
2013-12-24 16:49:36 +08:00
|
|
|
for (j = 0; j < ARR_SIZE(insn->detail->regs_write); j++) {
|
|
|
|
if (insn->detail->regs_write[j] == 0) {
|
|
|
|
insn->detail->regs_write[j] = ARM_REG_CPSR;
|
2013-11-27 12:11:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-01 10:45:19 +08:00
|
|
|
|
|
|
|
// instruction should not have invalid CC
|
|
|
|
if (insn->detail->arm.cc == ARM_CC_INVALID) {
|
|
|
|
insn->detail->arm.cc = ARM_CC_AL;
|
|
|
|
}
|
|
|
|
|
2014-06-01 11:03:14 +08:00
|
|
|
// manual fix for some special instructions
|
|
|
|
// printf(">>> id: %u, mcid: %u\n", insn->id, mci->Opcode);
|
|
|
|
switch(mci->Opcode) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case ARM_MOVPCLR:
|
|
|
|
insn->detail->arm.operands[0].type = ARM_OP_REG;
|
|
|
|
insn->detail->arm.operands[0].reg = ARM_REG_PC;
|
|
|
|
insn->detail->arm.operands[1].type = ARM_OP_REG;
|
|
|
|
insn->detail->arm.operands[1].reg = ARM_REG_LR;
|
|
|
|
insn->detail->arm.op_count = 2;
|
|
|
|
break;
|
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_printInst(MCInst *MI, SStream *O, void *Info)
|
|
|
|
{
|
|
|
|
MCRegisterInfo *MRI = (MCRegisterInfo *)Info;
|
|
|
|
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned Opcode = MCInst_getOpcode(MI), tmp, i;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
switch(Opcode) {
|
|
|
|
// Check for HINT instructions w/ canonical names.
|
|
|
|
case ARM_HINT:
|
|
|
|
case ARM_tHINT:
|
|
|
|
case ARM_t2HINT:
|
|
|
|
switch (MCOperand_getImm(MCInst_getOperand(MI, 0))) {
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0: SStream_concat0(O, "nop"); break;
|
|
|
|
case 1: SStream_concat0(O, "yield"); break;
|
|
|
|
case 2: SStream_concat0(O, "wfe"); break;
|
|
|
|
case 3: SStream_concat0(O, "wfi"); break;
|
|
|
|
case 4: SStream_concat0(O, "sev"); break;
|
2013-12-01 22:19:27 +08:00
|
|
|
case 5:
|
2013-12-31 18:15:12 +08:00
|
|
|
// FIXME: HasV80Ops becomes a mode
|
|
|
|
//if ((ARM_getFeatureBits(MI->csh->mode) & ARM_HasV8Ops)) {
|
2014-06-10 01:37:53 +08:00
|
|
|
// SStream_concat0(O, "sevl");
|
2013-12-31 18:15:12 +08:00
|
|
|
// break;
|
|
|
|
//}
|
2013-12-11 17:35:27 +08:00
|
|
|
// Fallthrough for non-v8
|
2013-12-31 18:15:12 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "sevl");
|
2013-12-31 18:15:12 +08:00
|
|
|
break;
|
2013-12-01 22:19:27 +08:00
|
|
|
default:
|
|
|
|
// Anything else should just print normally.
|
|
|
|
printInstruction(MI, O, MRI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printPredicateOperand(MI, 1, O);
|
|
|
|
if (Opcode == ARM_t2HINT)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ".w"); // FIXME: expose this in register-size of insn?
|
2013-11-27 12:11:31 +08:00
|
|
|
return;
|
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
// Check for MOVs and print canonical forms, instead.
|
|
|
|
case ARM_MOVsr: {
|
|
|
|
// FIXME: Thumb variants?
|
|
|
|
MCOperand *Dst = MCInst_getOperand(MI, 0);
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, 1);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, 2);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, 3);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO3))));
|
2013-12-01 22:19:27 +08:00
|
|
|
printSBitModifierOperand(MI, 6, O);
|
|
|
|
printPredicateOperand(MI, 4, O);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(Dst));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(Dst);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-14 00:23:41 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO2);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
//assert(ARM_AM_getSORegOffset(MO3.getImm()) == 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ARM_MOVsi: {
|
|
|
|
// FIXME: Thumb variants?
|
|
|
|
MCOperand *Dst = MCInst_getOperand(MI, 0);
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, 1);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, 2);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2))));
|
2013-12-01 22:19:27 +08:00
|
|
|
printSBitModifierOperand(MI, 5, O);
|
|
|
|
printPredicateOperand(MI, 3, O);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(Dst));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(Dst);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
if (ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)) == ARM_AM_rrx) {
|
2013-12-01 22:19:27 +08:00
|
|
|
//printAnnotation(O, Annot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = translateShiftImm(getSORegOffset((unsigned int)MCOperand_getImm(MO2)));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type =
|
2014-01-23 01:45:00 +08:00
|
|
|
(arm_shifter)ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2));
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = tmp;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A8.6.123 PUSH
|
|
|
|
case ARM_STMDB_UPD:
|
|
|
|
case ARM_t2STMDB_UPD:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP &&
|
|
|
|
MCInst_getNumOperands(MI) > 5) {
|
|
|
|
// Should only print PUSH if there are at least two registers in the list.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "push");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 2, O);
|
|
|
|
if (Opcode == ARM_t2STMDB_UPD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ".w");
|
|
|
|
SStream_concat0(O, "\t");
|
2013-12-01 22:19:27 +08:00
|
|
|
printRegisterList(MI, 4, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
case ARM_STR_PRE_IMM:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 2)) == ARM_SP &&
|
|
|
|
MCOperand_getImm(MCInst_getOperand(MI, 3)) == -4) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "push");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 4, O);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, 1)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 1));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-12-01 22:19:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
// A8.6.122 POP
|
|
|
|
case ARM_LDMIA_UPD:
|
|
|
|
case ARM_t2LDMIA_UPD:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP &&
|
|
|
|
MCInst_getNumOperands(MI) > 5) {
|
|
|
|
// Should only print POP if there are at least two registers in the list.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "pop");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 2, O);
|
|
|
|
if (Opcode == ARM_t2LDMIA_UPD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ".w");
|
|
|
|
SStream_concat0(O, "\t");
|
2013-12-01 22:19:27 +08:00
|
|
|
printRegisterList(MI, 4, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
case ARM_LDR_POST_IMM:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 2)) == ARM_SP &&
|
|
|
|
MCOperand_getImm(MCInst_getOperand(MI, 4)) == 4) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "pop");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 5, O);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, 0)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-12-01 22:19:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
// A8.6.355 VPUSH
|
|
|
|
case ARM_VSTMSDB_UPD:
|
|
|
|
case ARM_VSTMDDB_UPD:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "vpush");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 2, O);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t");
|
2013-12-01 22:19:27 +08:00
|
|
|
printRegisterList(MI, 4, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
// A8.6.354 VPOP
|
|
|
|
case ARM_VLDMSIA_UPD:
|
|
|
|
case ARM_VLDMDIA_UPD:
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "vpop");
|
2013-12-01 22:19:27 +08:00
|
|
|
printPredicateOperand(MI, 2, O);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t");
|
2013-12-01 22:19:27 +08:00
|
|
|
printRegisterList(MI, 4, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-01 22:19:27 +08:00
|
|
|
case ARM_tLDMIA: {
|
|
|
|
bool Writeback = true; // FIXME: expose this
|
|
|
|
unsigned BaseReg = MCOperand_getReg(MCInst_getOperand(MI, 0));
|
|
|
|
unsigned i;
|
|
|
|
for (i = 3; i < MCInst_getNumOperands(MI); ++i) {
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, i)) == BaseReg)
|
|
|
|
Writeback = false;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "ldm");
|
2013-12-01 22:19:27 +08:00
|
|
|
|
|
|
|
printPredicateOperand(MI, 1, O);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "\t");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, BaseReg);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = BaseReg;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-01 22:19:27 +08:00
|
|
|
if (Writeback)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "!");
|
|
|
|
SStream_concat0(O, ", ");
|
2013-12-01 22:19:27 +08:00
|
|
|
printRegisterList(MI, 3, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine 2 GPRs from disassember into a GPRPair to match with instr def.
|
|
|
|
// ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
|
|
|
|
// a single GPRPair reg operand is used in the .td file to replace the two
|
|
|
|
// GPRs. However, when decoding them, the two GRPs cannot be automatically
|
|
|
|
// expressed as a GPRPair, so we have to manually merge them.
|
|
|
|
// FIXME: We would really like to be able to tablegen'erate this.
|
|
|
|
case ARM_LDREXD:
|
|
|
|
case ARM_STREXD:
|
|
|
|
case ARM_LDAEXD:
|
|
|
|
case ARM_STLEXD: {
|
2014-07-31 18:24:51 +08:00
|
|
|
MCRegisterClass* MRC = MCRegisterInfo_getRegClass(MRI, ARM_GPRRegClassID);
|
|
|
|
bool isStore = Opcode == ARM_STREXD || Opcode == ARM_STLEXD;
|
2014-01-23 22:29:04 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, isStore ? 1 : 0));
|
|
|
|
if (MCRegisterClass_contains(MRC, Reg)) {
|
|
|
|
MCInst NewMI;
|
2014-06-10 14:59:55 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
MCInst_Init(&NewMI);
|
|
|
|
MCInst_setOpcode(&NewMI, Opcode);
|
2014-06-10 14:59:55 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
if (isStore)
|
|
|
|
MCInst_addOperand2(&NewMI, MCInst_getOperand(MI, 0));
|
2014-06-10 14:59:55 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
MCOperand_CreateReg0(&NewMI, MCRegisterInfo_getMatchingSuperReg(MRI, Reg, ARM_gsub_0,
|
|
|
|
MCRegisterInfo_getRegClass(MRI, ARM_GPRPairRegClassID)));
|
2014-06-10 14:59:55 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
// Copy the rest operands into NewMI.
|
|
|
|
for(i = isStore ? 3 : 2; i < MCInst_getNumOperands(MI); ++i)
|
|
|
|
MCInst_addOperand2(&NewMI, MCInst_getOperand(MI, i));
|
2014-06-10 14:59:55 +08:00
|
|
|
|
2014-07-31 18:24:51 +08:00
|
|
|
printInstruction(&NewMI, O, MRI);
|
|
|
|
return;
|
2013-12-01 22:19:27 +08:00
|
|
|
}
|
2014-07-31 18:24:51 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//if (printAliasInstr(MI, O, MRI))
|
|
|
|
// printInstruction(MI, O, MRI);
|
|
|
|
printInstruction(MI, O, MRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
|
|
|
|
{
|
2014-05-12 13:41:49 +08:00
|
|
|
int32_t imm;
|
2013-11-27 12:11:31 +08:00
|
|
|
MCOperand *Op = MCInst_getOperand(MI, OpNo);
|
|
|
|
if (MCOperand_isReg(Op)) {
|
|
|
|
unsigned Reg = MCOperand_getReg(Op);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2013-12-31 22:40:04 +08:00
|
|
|
if (MI->csh->doing_mem) {
|
2014-06-09 09:00:18 +08:00
|
|
|
if (MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base == ARM_REG_INVALID)
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = Reg;
|
2013-12-14 00:23:41 +08:00
|
|
|
else
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = Reg;
|
2013-12-14 00:23:41 +08:00
|
|
|
} else {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
} else if (MCOperand_isImm(Op)) {
|
2014-07-31 21:16:54 +08:00
|
|
|
unsigned int opc = MCInst_getOpcode(MI);
|
2014-06-30 13:45:40 +08:00
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
imm = (int32_t)MCOperand_getImm(Op);
|
2014-05-07 14:12:50 +08:00
|
|
|
|
|
|
|
// relative branch only has relative offset, so we have to update it
|
|
|
|
// to reflect absolute address.
|
|
|
|
// Note: in ARM, PC is always 2 instructions ahead, so we have to
|
|
|
|
// add 8 in ARM mode, or 4 in Thumb mode
|
2014-05-09 17:31:41 +08:00
|
|
|
// printf(">> opcode: %u\n", MCInst_getOpcode(MI));
|
2014-06-30 13:45:40 +08:00
|
|
|
if (ARM_rel_branch(MI->csh, opc)) {
|
2014-05-07 14:12:50 +08:00
|
|
|
// only do this for relative branch
|
2014-06-30 13:45:40 +08:00
|
|
|
if (MI->csh->mode & CS_MODE_THUMB) {
|
2014-05-07 14:12:50 +08:00
|
|
|
imm += (int32_t)MI->address + 4;
|
2014-07-31 18:24:51 +08:00
|
|
|
if (ARM_blx_to_arm_mode(MI->csh, opc)) {
|
2014-07-31 21:16:54 +08:00
|
|
|
// here need to align down to the nearest 4-byte address
|
2014-06-30 13:45:40 +08:00
|
|
|
#define _ALIGN_DOWN(v, align_width) ((v/align_width)*align_width)
|
2014-07-31 18:24:51 +08:00
|
|
|
imm = _ALIGN_DOWN(imm, 4);
|
2014-06-30 13:45:40 +08:00
|
|
|
#undef _ALIGN_DOWN
|
2014-07-31 18:24:51 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-05-07 14:12:50 +08:00
|
|
|
imm += (int32_t)MI->address + 8;
|
2014-07-31 18:24:51 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-05-07 14:12:50 +08:00
|
|
|
if (imm >= 0) {
|
|
|
|
if (imm > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", imm);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", imm);
|
|
|
|
} else {
|
|
|
|
if (imm < -HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#-0x%x", -imm);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#-%u", -imm);
|
|
|
|
}
|
|
|
|
} else if (imm >= 0) {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (imm > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", imm);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", imm);
|
2014-03-26 16:21:31 +08:00
|
|
|
} else {
|
|
|
|
if (imm < -HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#-0x%x", -imm);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#-%u", -imm);
|
|
|
|
}
|
2013-12-11 17:35:27 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2013-12-31 22:40:04 +08:00
|
|
|
if (MI->csh->doing_mem)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = imm;
|
2013-12-14 00:23:41 +08:00
|
|
|
else {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = imm;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
2014-05-12 13:41:49 +08:00
|
|
|
int32_t OffImm;
|
2014-05-09 07:33:35 +08:00
|
|
|
bool isSub;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[pc, ");
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
OffImm = (int32_t)MCOperand_getImm(MO1);
|
|
|
|
isSub = OffImm < 0;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
// Special value for #-0. All others are normal.
|
|
|
|
if (OffImm == INT32_MIN)
|
|
|
|
OffImm = 0;
|
|
|
|
if (isSub) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#-0x%x", -OffImm);
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", OffImm);
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2014-06-01 11:14:31 +08:00
|
|
|
|
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = ARM_REG_PC;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2014-06-01 11:14:31 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// so_reg is a 4-operand unit corresponding to register forms of the A5.1
|
|
|
|
// "Addressing Mode 1 - Data-processing operands" forms. This includes:
|
|
|
|
// REG 0 0 - e.g. R5
|
|
|
|
// REG REG 0,SH_OPC - e.g. R5, ROR R3
|
|
|
|
// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
|
|
|
|
static void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, OpNum+2);
|
2014-05-09 07:33:35 +08:00
|
|
|
ARM_AM_ShiftOpc ShOpc;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (MCOperand_getImm(MO3) & 7) + ARM_SFT_ASR_REG - 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
// Print the shift opc.
|
2014-05-09 06:44:49 +08:00
|
|
|
ShOpc = ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO3));
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
|
|
|
SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
|
2013-11-27 12:11:31 +08:00
|
|
|
if (ShOpc == ARM_AM_rrx)
|
|
|
|
return;
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, " ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = MCOperand_getReg(MO2);
|
2013-11-27 12:11:31 +08:00
|
|
|
//assert(ARM_AM_getSORegOffset(MO3.getImm()) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = MCOperand_getImm(MO2) & 7;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = (unsigned int)MCOperand_getImm(MO2) >> 3;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
// Print the shift opc.
|
2014-01-23 01:45:00 +08:00
|
|
|
printRegImmShift(MI, O, ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)),
|
2014-06-10 01:39:06 +08:00
|
|
|
getSORegOffset((unsigned int)MCOperand_getImm(MO2)));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #2
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op + 1);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, Op + 2);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (!MCOperand_getReg(MO2)) {
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned tmp = getAM2Offset((unsigned int)MCOperand_getImm(MO3));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp) { // Don't print +0.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
2014-01-23 01:45:00 +08:00
|
|
|
SStream_concat(O, "#%s0x%x", ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO3))), tmp);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-01-23 01:45:00 +08:00
|
|
|
SStream_concat(O, "#%s%u", ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO3))), tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (arm_shifter)getAM2Op((unsigned int)MCOperand_getImm(MO3));
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = tmp;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
|
|
|
SStream_concat0(O, ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO3))));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2);
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
printRegImmShift(MI, O, getAM2ShiftOpc((unsigned int)MCOperand_getImm(MO3)),
|
2014-06-10 01:39:06 +08:00
|
|
|
getAM2Offset((unsigned int)MCOperand_getImm(MO3)));
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrModeTBB(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op+1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrModeTBH(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op+1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", lsl #1]");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = ARM_SFT_LSL;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = 1;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode2Operand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
|
|
|
|
if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right.
|
|
|
|
printOperand(MI, Op, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printAM2PreOrOffsetIndexOp(MI, Op, O);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
|
|
|
|
if (!MCOperand_getReg(MO1)) {
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned ImmOffs = getAM2Offset((unsigned int)MCOperand_getImm(MO2));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (ImmOffs > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s0x%x",
|
|
|
|
ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO2))), ImmOffs);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s%u",
|
|
|
|
ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO2))), ImmOffs);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = ImmOffs;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_AM_getAddrOpcStr(getAM2Op((unsigned int)MCOperand_getImm(MO2))));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
printRegImmShift(MI, O, getAM2ShiftOpc((unsigned int)MCOperand_getImm(MO2)),
|
2014-06-10 01:39:06 +08:00
|
|
|
getAM2Offset((unsigned int)MCOperand_getImm(MO2)));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Addressing Mode #3
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static void printAM3PostIndexOp(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op+1);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, Op+2);
|
2014-01-23 01:45:00 +08:00
|
|
|
ARM_AM_AddrOpc op = getAM3Op((unsigned int)MCOperand_getImm(MO3));
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ImmOffs;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "], ");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
|
|
|
|
if (MCOperand_getReg(MO2)) {
|
2013-12-08 22:20:35 +08:00
|
|
|
SStream_concat(O, "%c", (char)op);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO2);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
ImmOffs = getAM3Offset((unsigned int)MCOperand_getImm(MO3));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (ImmOffs > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s0x%x", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s%u", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2013-12-14 00:23:41 +08:00
|
|
|
if (op)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = ImmOffs;
|
2013-12-14 00:23:41 +08:00
|
|
|
else
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = -(int)ImmOffs;
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O,
|
|
|
|
bool AlwaysPrintImm0)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op+1);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, Op+2);
|
2014-01-23 01:45:00 +08:00
|
|
|
ARM_AM_AddrOpc op = getAM3Op((unsigned int)MCOperand_getImm(MO3));
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ImmOffs;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (MCOperand_getReg(MO2)) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
|
|
|
SStream_concat0(O, ARM_AM_getAddrOpcStr(op));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2);
|
2013-12-14 00:23:41 +08:00
|
|
|
if (op)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = -1;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//If the op is sub we have to print the immediate even if it is 0
|
2014-05-09 06:44:49 +08:00
|
|
|
ImmOffs = getAM3Offset((unsigned int)MCOperand_getImm(MO3));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (AlwaysPrintImm0 || ImmOffs || (op == ARM_AM_sub)) {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (ImmOffs > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%s0x%x", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%s%u", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2013-12-14 00:23:41 +08:00
|
|
|
if (op)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = (int)MCOperand_getImm(MO3);
|
2013-12-14 00:23:41 +08:00
|
|
|
else
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = (int)-MCOperand_getImm(MO3);
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode3Operand(MCInst *MI, unsigned Op, SStream *O,
|
|
|
|
bool AlwaysPrintImm0)
|
|
|
|
{
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned IdxMode;
|
|
|
|
MCOperand *MO3;
|
2013-11-27 12:11:31 +08:00
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
if (!MCOperand_isReg(MO1)) { // For label symbolic references.
|
|
|
|
printOperand(MI, Op, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
MO3 = MCInst_getOperand(MI, Op+2);
|
|
|
|
IdxMode = getAM3IdxMode((unsigned int)MCOperand_getImm(MO3));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (IdxMode == ARMII_IndexModePost) {
|
|
|
|
printAM3PostIndexOp(MI, Op, O);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-01-23 01:45:00 +08:00
|
|
|
ARM_AM_AddrOpc op = getAM3Op((unsigned int)MCOperand_getImm(MO2));
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ImmOffs;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (MCOperand_getReg(MO1)) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_AM_getAddrOpcStr(op));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
2014-06-17 13:28:33 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
ImmOffs = getAM3Offset((unsigned int)MCOperand_getImm(MO2));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (ImmOffs > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s0x%x", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s%u", ARM_AM_getAddrOpcStr(op), ImmOffs);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2013-12-14 00:23:41 +08:00
|
|
|
if (op)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = ImmOffs;
|
2013-12-14 00:23:41 +08:00
|
|
|
else
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = -(int)ImmOffs;
|
2013-12-08 22:20:35 +08:00
|
|
|
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MO);
|
2013-12-11 17:35:27 +08:00
|
|
|
if ((Imm & 0xff) > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s0x%x", ((Imm & 256) ? "" : "-"), (Imm & 0xff));
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s%u", ((Imm & 256) ? "" : "-"), (Imm & 0xff));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Imm & 0xff;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printPostIdxRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, (MCOperand_getImm(MO2) ? "" : "-"));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MO);
|
2013-12-11 17:35:27 +08:00
|
|
|
if (((Imm & 0xff) << 2) > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s0x%x", ((Imm & 256) ? "" : "-"), ((Imm & 0xff) << 2));
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%s%u", ((Imm & 256) ? "" : "-"), ((Imm & 0xff) << 2));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode5Operand(MCInst *MI, unsigned OpNum, SStream *O,
|
|
|
|
bool AlwaysPrintImm0)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ImmOffs, Op;
|
2013-11-27 12:11:31 +08:00
|
|
|
if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right.
|
|
|
|
printOperand(MI, OpNum, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-01 11:48:55 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = 0;
|
2014-06-01 11:48:55 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
ImmOffs = ARM_AM_getAM5Offset((unsigned int)MCOperand_getImm(MO2));
|
|
|
|
Op = ARM_AM_getAM5Op((unsigned int)MCOperand_getImm(MO2));
|
2013-11-27 12:11:31 +08:00
|
|
|
if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (ImmOffs * 4 > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%s0x%x",
|
2014-01-23 01:45:00 +08:00
|
|
|
ARM_AM_getAddrOpcStr(ARM_AM_getAM5Op((unsigned int)MCOperand_getImm(MO2))),
|
2014-06-10 01:37:53 +08:00
|
|
|
ImmOffs * 4);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%s%u",
|
2014-01-23 01:45:00 +08:00
|
|
|
ARM_AM_getAddrOpcStr(ARM_AM_getAM5Op((unsigned int)MCOperand_getImm(MO2))),
|
2014-06-10 01:37:53 +08:00
|
|
|
ImmOffs * 4);
|
2014-06-01 11:52:01 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = ImmOffs * 4;
|
2014-06-01 11:52:01 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2014-06-01 11:48:55 +08:00
|
|
|
|
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2014-06-01 11:48:55 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned tmp;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = (unsigned int)MCOperand_getImm(MO2);
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp) {
|
|
|
|
if (tmp << 3 > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, ":0x%x", (tmp << 3));
|
|
|
|
else
|
|
|
|
SStream_concat(O, ":%u", (tmp << 3));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp << 3;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
|
|
|
if (MCOperand_getReg(MO) == 0)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "!");
|
2013-11-27 12:11:31 +08:00
|
|
|
else {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
2014-01-23 01:45:00 +08:00
|
|
|
uint32_t v = ~(uint32_t)MCOperand_getImm(MO);
|
2013-11-27 12:11:31 +08:00
|
|
|
int32_t lsb = CountTrailingZeros_32(v);
|
|
|
|
int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
|
2013-12-11 17:35:27 +08:00
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
//assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
|
2013-12-11 17:35:27 +08:00
|
|
|
if (lsb > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", lsb);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", lsb);
|
2013-12-11 17:35:27 +08:00
|
|
|
|
|
|
|
if (width > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #0x%x", width);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%u", width);
|
2013-12-11 17:35:27 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = lsb;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = width;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned val = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-31 18:15:12 +08:00
|
|
|
// FIXME: HasV80Ops becomes a mode
|
2014-06-10 01:37:53 +08:00
|
|
|
// SStream_concat0(O, ARM_MB_MemBOptToString(val,
|
2014-05-12 15:15:32 +08:00
|
|
|
// ARM_getFeatureBits(MI->csh->mode) & ARM_HasV8Ops));
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_MB_MemBOptToString(val, true));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned val = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_ISB_InstSyncBOptToString(val));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned ShiftOp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-11-27 12:11:31 +08:00
|
|
|
bool isASR = (ShiftOp & (1 << 5)) != 0;
|
|
|
|
unsigned Amt = ShiftOp & 0x1f;
|
|
|
|
if (isASR) {
|
2013-12-11 17:35:27 +08:00
|
|
|
unsigned tmp = Amt == 0 ? 32 : Amt;
|
|
|
|
if (tmp > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", asr #0x%x", tmp);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", asr #%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ASR;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = tmp;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
} else if (Amt) {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (Amt > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", lsl #0x%x", Amt);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", lsl #%u", Amt);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_LSL;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Amt;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-11-27 12:11:31 +08:00
|
|
|
if (Imm == 0)
|
|
|
|
return;
|
|
|
|
//assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
|
2013-12-11 17:35:27 +08:00
|
|
|
if (Imm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", lsl #0x%x", Imm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", lsl #%u", Imm);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_LSL;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-11-27 12:11:31 +08:00
|
|
|
// A shift amount of 32 is encoded as 0.
|
|
|
|
if (Imm == 0)
|
|
|
|
Imm = 32;
|
|
|
|
//assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
|
2013-12-11 17:35:27 +08:00
|
|
|
if (Imm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", asr #0x%x", Imm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", asr #%u", Imm);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ASR;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: push {r1, r2, r3, ...} can exceed the number of operands in MCInst struct
|
|
|
|
static void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-05-09 07:33:35 +08:00
|
|
|
unsigned i, e;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2013-11-27 12:11:31 +08:00
|
|
|
for (i = OpNum, e = MCInst_getNumOperands(MI); i != e; ++i) {
|
2014-06-10 01:37:53 +08:00
|
|
|
if (i != OpNum) SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, i)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, i));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O,
|
|
|
|
MCRegisterInfo *MRI)
|
|
|
|
{
|
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCRegisterInfo_getSubReg(MRI, Reg, ARM_gsub_0));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCRegisterInfo_getSubReg(MRI, Reg, ARM_gsub_0);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCRegisterInfo_getSubReg(MRI, Reg, ARM_gsub_1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCRegisterInfo_getSubReg(MRI, Reg, ARM_gsub_1);
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SETEND BE/LE
|
|
|
|
static void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *Op = MCInst_getOperand(MI, OpNum);
|
|
|
|
if (MCOperand_getImm(Op))
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "be");
|
2013-11-27 12:11:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "le");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *Op = MCInst_getOperand(MI, OpNum);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_PROC_IModToString((unsigned int)MCOperand_getImm(Op)));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *Op = MCInst_getOperand(MI, OpNum);
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned IFlags = (unsigned int)MCOperand_getImm(Op);
|
2013-11-27 12:11:31 +08:00
|
|
|
int i;
|
|
|
|
for (i=2; i >= 0; --i)
|
|
|
|
if (IFlags & (1 << i))
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARM_PROC_IFlagsToString(1 << i));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (IFlags == 0)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "none");
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = IFlags;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *Op = MCInst_getOperand(MI, OpNum);
|
2014-08-13 22:38:15 +08:00
|
|
|
unsigned SpecRegRBit = MCOperand_getImm(Op) >> 4;
|
|
|
|
unsigned Mask = MCOperand_getImm(Op) & 0xf;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-08-13 22:38:15 +08:00
|
|
|
if (ARM_getFeatureBits(MI->csh->mode) & ARM_FeatureMClass) {
|
|
|
|
unsigned SYSm = MCOperand_getImm(Op);
|
2013-11-27 12:11:31 +08:00
|
|
|
unsigned Opcode = MCInst_getOpcode(MI);
|
|
|
|
// For reads of the special registers ignore the "mask encoding" bits
|
|
|
|
// which are only for writes.
|
|
|
|
if (Opcode == ARM_t2MRS_M)
|
|
|
|
SYSm &= 0xff;
|
|
|
|
switch (SYSm) {
|
2014-08-13 22:38:15 +08:00
|
|
|
default: //llvm_unreachable("Unexpected mask value!");
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x800: SStream_concat0(O, "apsr"); return; // with _nzcvq bits is an alias for aspr
|
|
|
|
case 0x400: SStream_concat0(O, "apsr_g"); return;
|
|
|
|
case 0xc00: SStream_concat0(O, "apsr_nzcvqg"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 1:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x801: SStream_concat0(O, "iapsr"); return; // with _nzcvq bits is an alias for iapsr
|
|
|
|
case 0x401: SStream_concat0(O, "iapsr_g"); return;
|
|
|
|
case 0xc01: SStream_concat0(O, "iapsr_nzcvqg"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 2:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x802: SStream_concat0(O, "eapsr"); return; // with _nzcvq bits is an alias for eapsr
|
|
|
|
case 0x402: SStream_concat0(O, "eapsr_g"); return;
|
|
|
|
case 0xc02: SStream_concat0(O, "eapsr_nzcvqg"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 3:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x803: SStream_concat0(O, "xpsr"); return; // with _nzcvq bits is an alias for xpsr
|
|
|
|
case 0x403: SStream_concat0(O, "xpsr_g"); return;
|
|
|
|
case 0xc03: SStream_concat0(O, "xpsr_nzcvqg"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 5:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x805: SStream_concat0(O, "ipsr"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 6:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x806: SStream_concat0(O, "epsr"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 7:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x807: SStream_concat0(O, "iepsr"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 8:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x808: SStream_concat0(O, "msp"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 9:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x809: SStream_concat0(O, "psp"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0x10:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x810: SStream_concat0(O, "primask"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0x11:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x811: SStream_concat0(O, "basepri"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0x12:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x812: SStream_concat0(O, "basepri_max"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0x13:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x813: SStream_concat0(O, "faultmask"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
case 0x14:
|
2014-06-10 01:37:53 +08:00
|
|
|
case 0x814: SStream_concat0(O, "control"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-13 22:38:15 +08:00
|
|
|
|
2013-11-27 12:11:31 +08:00
|
|
|
// As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
|
|
|
|
// APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
|
|
|
|
if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
|
2014-08-13 22:38:15 +08:00
|
|
|
SStream_concat0(O, "APSR_");
|
2013-11-27 12:11:31 +08:00
|
|
|
switch (Mask) {
|
2014-08-13 22:38:15 +08:00
|
|
|
default: // llvm_unreachable("Unexpected mask value!");
|
2014-06-10 01:37:53 +08:00
|
|
|
case 4: SStream_concat0(O, "g"); return;
|
|
|
|
case 8: SStream_concat0(O, "nzcvq"); return;
|
|
|
|
case 12: SStream_concat0(O, "nzcvqg"); return;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SpecRegRBit)
|
2014-08-13 22:38:15 +08:00
|
|
|
SStream_concat0(O, "SPSR");
|
2013-11-27 12:11:31 +08:00
|
|
|
else
|
2014-08-13 22:38:15 +08:00
|
|
|
SStream_concat0(O, "CPSR");
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (Mask) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "_");
|
|
|
|
if (Mask & 8) SStream_concat0(O, "f");
|
|
|
|
if (Mask & 4) SStream_concat0(O, "s");
|
|
|
|
if (Mask & 2) SStream_concat0(O, "x");
|
|
|
|
if (Mask & 1) SStream_concat0(O, "c");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
|
|
|
// Handle the undefined 15 CC value here for printing so we don't abort().
|
|
|
|
if ((unsigned)CC == 15) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "<und>");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.cc = ARM_CC_INVALID;
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
|
|
|
if (CC != ARMCC_AL) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARMCC_ARMCondCodeToString(CC));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.cc = CC + 1;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: test this
|
|
|
|
static void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ARMCC_ARMCondCodeToString(CC));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.cc = CC + 1;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printSBitModifierOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
if (MCOperand_getReg(MCInst_getOperand(MI, OpNum))) {
|
|
|
|
//assert(MCOperand_getReg(MCInst_getOperand(MI, OpNum)) == ARM_CPSR &&
|
|
|
|
// "Expect ARM CPSR register!");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.update_flags = true;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "s");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2013-12-31 22:40:04 +08:00
|
|
|
if (MI->csh->doing_mem) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp;
|
2013-12-14 00:23:41 +08:00
|
|
|
} else {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2013-12-11 17:35:27 +08:00
|
|
|
SStream_concat(O, "p%u", MCOperand_getImm(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_PIMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2013-12-11 17:35:27 +08:00
|
|
|
SStream_concat(O, "c%u", MCOperand_getImm(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_CIMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "{0x%x}", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "{%u}", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned scale)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
|
|
|
|
|
|
|
int32_t OffImm = (int32_t)MCOperand_getImm(MO) << scale;
|
|
|
|
|
|
|
|
if (OffImm == INT32_MIN) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "#-0");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
|
|
|
if (OffImm < 0)
|
2013-11-28 16:02:08 +08:00
|
|
|
SStream_concat(O, "#-0x%x", -OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else {
|
|
|
|
if (OffImm > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", OffImm);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", OffImm);
|
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)) * 4;
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", tmp);
|
2014-01-23 22:29:04 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2014-01-23 22:29:04 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
unsigned tmp = Imm == 0 ? 32 : Imm;
|
|
|
|
if (tmp > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-11 17:35:27 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
static void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// (3 - the number of trailing zeros) is the number of then / else.
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Mask = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
|
|
|
unsigned Firstcond = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum-1));
|
2013-11-27 12:11:31 +08:00
|
|
|
unsigned CondBit0 = Firstcond & 1;
|
|
|
|
unsigned NumTZ = CountTrailingZeros_32(Mask);
|
|
|
|
//assert(NumTZ <= 3 && "Invalid IT mask!");
|
|
|
|
unsigned Pos, e;
|
|
|
|
for (Pos = 3, e = NumTZ; Pos > e; --Pos) {
|
|
|
|
bool T = ((Mask >> Pos) & 1) == CondBit0;
|
|
|
|
if (T)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "t");
|
2013-11-27 12:11:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "e");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeRROperand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op + 1);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned RegNum;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right.
|
|
|
|
printOperand(MI, Op, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-05-09 06:44:49 +08:00
|
|
|
RegNum = MCOperand_getReg(MO2);
|
2013-11-27 12:11:31 +08:00
|
|
|
if (RegNum) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, RegNum);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = RegNum;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned Op, SStream *O,
|
|
|
|
unsigned Scale)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, Op);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, Op + 1);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ImmOffs, tmp;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right.
|
|
|
|
printOperand(MI, Op, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2014-05-09 06:44:49 +08:00
|
|
|
ImmOffs = (unsigned int)MCOperand_getImm(MO2);
|
2013-11-27 12:11:31 +08:00
|
|
|
if (ImmOffs) {
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = ImmOffs * Scale;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
printThumbAddrModeImm5SOperand(MI, Op, O, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
printThumbAddrModeImm5SOperand(MI, Op, O, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
printThumbAddrModeImm5SOperand(MI, Op, O, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printThumbAddrModeSPOperand(MCInst *MI, unsigned Op, SStream *O)
|
|
|
|
{
|
|
|
|
printThumbAddrModeImm5SOperand(MI, Op, O, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
|
|
|
|
// register with shift forms.
|
|
|
|
// REG 0 0 - e.g. R5
|
|
|
|
// REG IMM, SH_OPC - e.g. R5, LSL #3
|
|
|
|
static void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
|
|
|
|
unsigned Reg = MCOperand_getReg(MO1);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
// Print the shift opc.
|
|
|
|
//assert(MO2.isImm() && "Not a valid t2_so_reg value!");
|
2014-01-23 01:45:00 +08:00
|
|
|
printRegImmShift(MI, O, ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)),
|
2014-06-10 01:39:06 +08:00
|
|
|
getSORegOffset((unsigned int)MCOperand_getImm(MO2)));
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAddrModeImm12Operand(MCInst *MI, unsigned OpNum,
|
|
|
|
SStream *O, bool AlwaysPrintImm0)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-01-23 22:29:04 +08:00
|
|
|
int32_t OffImm;
|
|
|
|
bool isSub;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right.
|
|
|
|
printOperand(MI, OpNum, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
OffImm = (int32_t)MCOperand_getImm(MO2);
|
|
|
|
isSub = OffImm < 0;
|
2013-11-27 12:11:31 +08:00
|
|
|
// Special value for #-0. All others are normal.
|
|
|
|
if (OffImm == INT32_MIN)
|
|
|
|
OffImm = 0;
|
|
|
|
if (isSub) {
|
2014-04-12 00:19:42 +08:00
|
|
|
if (OffImm < -HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-0x%x", -OffImm);
|
2014-04-12 00:19:42 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-%u", -OffImm);
|
2013-11-27 12:11:31 +08:00
|
|
|
} else if (AlwaysPrintImm0 || OffImm > 0) {
|
2014-03-26 16:21:31 +08:00
|
|
|
if (OffImm >= 0) {
|
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #0x%x", OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%u", OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
} else {
|
|
|
|
if (OffImm < -HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-0x%x", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-%u", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeImm8Operand(MCInst *MI, unsigned OpNum, SStream *O,
|
|
|
|
bool AlwaysPrintImm0)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-01-23 22:29:04 +08:00
|
|
|
int32_t OffImm;
|
|
|
|
bool isSub;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
|
|
|
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
OffImm = (int32_t)MCOperand_getImm(MO2);
|
|
|
|
isSub = OffImm < 0;
|
2013-11-27 12:11:31 +08:00
|
|
|
// Don't print +0.
|
|
|
|
if (OffImm == INT32_MIN)
|
|
|
|
OffImm = 0;
|
|
|
|
|
|
|
|
if (isSub)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-0x%x", -OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else if (AlwaysPrintImm0 || OffImm > 0) {
|
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #0x%x", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%u", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeImm8s4Operand(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O, bool AlwaysPrintImm0)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-01-23 22:29:04 +08:00
|
|
|
int32_t OffImm;
|
|
|
|
bool isSub;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
if (!MCOperand_isReg(MO1)) { // For label symbolic references.
|
|
|
|
printOperand(MI, OpNum, O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-01-23 01:45:00 +08:00
|
|
|
OffImm = (int32_t)MCOperand_getImm(MO2);
|
|
|
|
isSub = OffImm < 0;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
//assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
|
|
|
|
|
|
|
|
// Don't print +0.
|
|
|
|
if (OffImm == INT32_MIN)
|
|
|
|
OffImm = 0;
|
|
|
|
if (isSub) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #-0x%x", -OffImm);
|
2013-11-27 12:11:31 +08:00
|
|
|
} else if (AlwaysPrintImm0 || OffImm > 0) {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #0x%x", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, ", #%u", OffImm);
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned tmp;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
if (MCOperand_getImm(MO2)) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = (unsigned int)MCOperand_getImm(MO2) * 4;
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeImm8OffsetOperand(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2013-11-27 12:11:31 +08:00
|
|
|
if (OffImm == INT32_MIN) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "#-0");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
2014-03-26 16:21:31 +08:00
|
|
|
if (OffImm < 0) {
|
|
|
|
if (OffImm < -HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#-0x%x", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#-%u", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
} else {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeImm8s4OffsetOperand(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
|
|
|
|
|
|
|
|
//assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2013-11-27 12:11:31 +08:00
|
|
|
if (OffImm == INT32_MIN) {
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "#-0");
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
} else {
|
2014-03-26 16:21:31 +08:00
|
|
|
if (OffImm < 0) {
|
|
|
|
if (OffImm < -HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#-0x%x", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#-%u", -OffImm);
|
2014-03-26 16:21:31 +08:00
|
|
|
} else {
|
2013-12-11 17:35:27 +08:00
|
|
|
if (OffImm > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", OffImm);
|
2013-12-11 17:35:27 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printT2AddrModeSoRegOperand(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO1 = MCInst_getOperand(MI, OpNum);
|
|
|
|
MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1);
|
|
|
|
MCOperand *MO3 = MCInst_getOperand(MI, OpNum+2);
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned ShAmt;
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, true);
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO1));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
|
|
|
//assert(MCOperand_getReg(MO2.getReg() && "Invalid so_reg load / store address!");
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MO2));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail)
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2);
|
2013-11-27 12:11:31 +08:00
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
ShAmt = (unsigned int)MCOperand_getImm(MO3);
|
2013-11-27 12:11:31 +08:00
|
|
|
if (ShAmt) {
|
|
|
|
//assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", lsl ");
|
2013-11-27 12:11:31 +08:00
|
|
|
SStream_concat(O, "#%d", ShAmt);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_LSL;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = ShAmt;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "]");
|
2013-11-27 12:11:31 +08:00
|
|
|
set_mem_access(MI, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
MCOperand *MO = MCInst_getOperand(MI, OpNum);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%f", getFPImmFloat((unsigned int)MCOperand_getImm(MO)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_FP;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].fp = getFPImmFloat((unsigned int)MCOperand_getImm(MO));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printNEONModImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned EncodedImm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-11-27 12:11:31 +08:00
|
|
|
unsigned EltBits;
|
|
|
|
uint64_t Val = ARM_AM_decodeNEONModImm(EncodedImm, &EltBits);
|
2013-12-11 17:35:27 +08:00
|
|
|
if (Val > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%"PRIx64, Val);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%"PRIu64, Val);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = (unsigned int)Val;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printImmPlusOneOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (Imm + 1 > HEX_THRESHOLD)
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#0x%x", Imm + 1);
|
2013-12-11 17:35:27 +08:00
|
|
|
else
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat(O, "#%u", Imm + 1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Imm + 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-11-27 12:11:31 +08:00
|
|
|
if (Imm == 0)
|
|
|
|
return;
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ror #");
|
2013-11-27 12:11:31 +08:00
|
|
|
switch (Imm) {
|
|
|
|
default: //assert (0 && "illegal ror immediate!");
|
2014-06-10 01:37:53 +08:00
|
|
|
case 1: SStream_concat0(O, "8"); break;
|
|
|
|
case 2: SStream_concat0(O, "16"); break;
|
|
|
|
case 3: SStream_concat0(O, "24"); break;
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ROR;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm * 8;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printFBits16(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned tmp;
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = 16 - (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printFBits32(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-05-12 13:41:49 +08:00
|
|
|
unsigned tmp;
|
|
|
|
|
2014-05-09 06:44:49 +08:00
|
|
|
tmp = 32 - (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "#0x%x", tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "#%u", tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-01-23 01:45:00 +08:00
|
|
|
unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
|
2013-12-11 17:35:27 +08:00
|
|
|
if (tmp > HEX_THRESHOLD)
|
|
|
|
SStream_concat(O, "[0x%x]",tmp);
|
|
|
|
else
|
|
|
|
SStream_concat(O, "[%u]",tmp);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListTwo(MCInst *MI, unsigned OpNum,
|
|
|
|
SStream *O, MCRegisterInfo *MRI)
|
|
|
|
{
|
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
unsigned Reg0 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_0);
|
|
|
|
unsigned Reg1 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg0);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum,
|
|
|
|
SStream *O, MCRegisterInfo *MRI)
|
|
|
|
{
|
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
unsigned Reg0 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_0);
|
|
|
|
unsigned Reg1 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_2);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg0);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum,
|
|
|
|
SStream *O, MCRegisterInfo *MRI)
|
|
|
|
{
|
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
unsigned Reg0 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_0);
|
|
|
|
unsigned Reg1 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_1);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg0);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListTwoSpacedAllLanes(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O, MCRegisterInfo *MRI)
|
|
|
|
{
|
|
|
|
unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
unsigned Reg0 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_0);
|
|
|
|
unsigned Reg1 = MCRegisterInfo_getSubReg(MRI, Reg, ARM_dsub_2);
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg0);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, Reg1);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListThreeSpacedAllLanes(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListFourSpacedAllLanes(MCInst *MI,
|
|
|
|
unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[], ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "[]}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printVectorListFourSpaced(MCInst *MI, unsigned OpNum, SStream *O)
|
|
|
|
{
|
|
|
|
// Normally, it's not safe to use register enum values directly with
|
|
|
|
// addition to get the next register, but for VFP registers, the
|
|
|
|
// sort order is guaranteed because they're all of the form D<n>.
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "{");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)));
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, ", ");
|
2014-03-11 00:18:50 +08:00
|
|
|
printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6);
|
2013-12-30 00:15:25 +08:00
|
|
|
if (MI->csh->detail) {
|
2014-06-09 09:00:18 +08:00
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG;
|
|
|
|
MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6;
|
|
|
|
MI->flat_insn->detail->arm.op_count++;
|
2013-12-14 00:23:41 +08:00
|
|
|
}
|
2014-06-10 01:37:53 +08:00
|
|
|
SStream_concat0(O, "}");
|
2013-11-27 12:11:31 +08:00
|
|
|
}
|
2014-05-14 11:26:41 +08:00
|
|
|
|
|
|
|
#endif
|