2013-11-27 04:11:31 +00:00
|
|
|
//===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the MCInst and MCOperand classes, which
|
|
|
|
// is the basic representation used to represent low-level machine code
|
|
|
|
// instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-04-29 03:21:04 +00:00
|
|
|
/* Capstone Disassembly Engine */
|
2019-02-26 07:19:51 +00:00
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2014-01-02 05:15:07 +00:00
|
|
|
#ifndef CS_MCINST_H
|
|
|
|
#define CS_MCINST_H
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2015-02-24 03:55:55 +00:00
|
|
|
#include "include/capstone/capstone.h"
|
2024-09-14 08:57:54 +00:00
|
|
|
#include "MCAsmInfo.h"
|
2023-05-30 03:08:18 +00:00
|
|
|
#include "MCInstrDesc.h"
|
2019-03-16 07:22:15 +00:00
|
|
|
#include "MCRegisterInfo.h"
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
typedef struct MCInst MCInst;
|
2013-12-29 16:15:25 +00:00
|
|
|
typedef struct cs_struct cs_struct;
|
2013-11-27 04:11:31 +00:00
|
|
|
typedef struct MCOperand MCOperand;
|
2024-09-30 03:35:51 +00:00
|
|
|
typedef void MCExpr;
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
/// MCOperand - Instances of this class represent operands of the MCInst class.
|
|
|
|
/// This is a simple discriminated union.
|
|
|
|
struct MCOperand {
|
|
|
|
enum {
|
2023-05-30 03:09:37 +00:00
|
|
|
kInvalid = 0, ///< Uninitialized.
|
|
|
|
kRegister, ///< Register operand.
|
|
|
|
kImmediate, ///< Immediate operand.
|
|
|
|
kFPImmediate, ///< Floating-point immediate operand.
|
|
|
|
kDFPImmediate, ///< Double-Floating-point immediate operand.
|
|
|
|
kExpr, ///< Relocatable immediate operand.
|
|
|
|
kInst ///< Sub-instruction operand.
|
2013-11-27 04:11:31 +00:00
|
|
|
} MachineOperandType;
|
|
|
|
unsigned char Kind;
|
|
|
|
|
|
|
|
union {
|
2023-10-25 04:09:08 +00:00
|
|
|
uint64_t RegVal;
|
2013-11-27 04:11:31 +00:00
|
|
|
int64_t ImmVal;
|
|
|
|
double FPImmVal;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
bool MCOperand_isValid(const MCOperand *op);
|
|
|
|
|
|
|
|
bool MCOperand_isReg(const MCOperand *op);
|
|
|
|
|
|
|
|
bool MCOperand_isImm(const MCOperand *op);
|
|
|
|
|
|
|
|
bool MCOperand_isFPImm(const MCOperand *op);
|
|
|
|
|
2023-05-30 03:08:18 +00:00
|
|
|
bool MCOperand_isDFPImm(const MCOperand *op);
|
|
|
|
|
|
|
|
bool MCOperand_isExpr(const MCOperand *op);
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
bool MCOperand_isInst(const MCOperand *op);
|
|
|
|
|
|
|
|
/// getReg - Returns the register number.
|
|
|
|
unsigned MCOperand_getReg(const MCOperand *op);
|
|
|
|
|
|
|
|
/// setReg - Set the register number.
|
|
|
|
void MCOperand_setReg(MCOperand *op, unsigned Reg);
|
|
|
|
|
2023-11-15 04:12:14 +00:00
|
|
|
int64_t MCOperand_getImm(const MCOperand *op);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
void MCOperand_setImm(MCOperand *op, int64_t Val);
|
|
|
|
|
2024-09-14 08:57:54 +00:00
|
|
|
int64_t MCOperand_getExpr(const MCOperand *op);
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
double MCOperand_getFPImm(const MCOperand *op);
|
|
|
|
|
|
|
|
void MCOperand_setFPImm(MCOperand *op, double Val);
|
|
|
|
|
|
|
|
const MCInst *MCOperand_getInst(const MCOperand *op);
|
|
|
|
|
|
|
|
void MCOperand_setInst(MCOperand *op, const MCInst *Val);
|
|
|
|
|
2014-06-09 18:01:23 +00:00
|
|
|
// create Reg operand in the next slot
|
2014-06-05 16:56:46 +00:00
|
|
|
void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);
|
2014-06-04 15:51:51 +00:00
|
|
|
|
2014-06-09 18:01:23 +00:00
|
|
|
// create Reg operand use the last-unused slot
|
|
|
|
MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);
|
|
|
|
|
|
|
|
// create Imm operand in the next slot
|
2014-06-05 16:56:46 +00:00
|
|
|
void MCOperand_CreateImm0(MCInst *inst, int64_t Val);
|
2014-06-04 15:51:51 +00:00
|
|
|
|
2014-06-09 18:01:23 +00:00
|
|
|
// create Imm operand in the last-unused slot
|
|
|
|
MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);
|
|
|
|
|
2023-05-30 03:08:18 +00:00
|
|
|
#define MAX_MC_OPS 48
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
/// MCInst - Instances of this class represent a single low-level machine
|
|
|
|
/// instruction.
|
|
|
|
struct MCInst {
|
2019-06-08 17:58:03 +00:00
|
|
|
unsigned OpcodePub; // public opcode (<arch>_INS_yyy in header files <arch>.h)
|
2014-11-03 08:32:06 +00:00
|
|
|
uint8_t size; // number of operands
|
|
|
|
bool has_imm; // indicate this instruction has an X86_OP_IMM operand - used for ATT syntax
|
|
|
|
uint8_t op1_size; // size of 1st operand - for X86 Intel syntax
|
2019-06-08 17:58:03 +00:00
|
|
|
unsigned Opcode; // private opcode
|
2023-05-30 03:08:18 +00:00
|
|
|
MCOperand Operands[MAX_MC_OPS];
|
2014-06-08 16:35:52 +00:00
|
|
|
cs_insn *flat_insn; // insn to be exposed to public
|
2013-12-13 16:23:41 +00:00
|
|
|
uint64_t address; // address of this insn
|
2013-12-29 16:15:25 +00:00
|
|
|
cs_struct *csh; // save the main csh
|
2014-06-18 04:16:24 +00:00
|
|
|
uint8_t x86opsize; // opsize for [mem] operand
|
2014-05-07 00:25:24 +00:00
|
|
|
|
2019-02-26 07:19:51 +00:00
|
|
|
// These flags could be used to pass some info from one target subcomponent
|
|
|
|
// to another, for example, from disassembler to asm printer. The values of
|
|
|
|
// the flags have any sense on target level only (e.g. prefixes on x86).
|
|
|
|
unsigned flags;
|
|
|
|
|
2014-06-18 04:16:24 +00:00
|
|
|
// (Optional) instruction prefix, which can be up to 4 bytes.
|
2014-05-07 00:25:24 +00:00
|
|
|
// A prefix byte gets value 0 when irrelevant.
|
|
|
|
// This is copied from cs_x86 struct
|
2014-06-04 11:04:46 +00:00
|
|
|
uint8_t x86_prefix[4];
|
2014-06-25 14:03:18 +00:00
|
|
|
uint8_t imm_size; // immediate size for X86_OP_IMM operand
|
2023-05-30 03:09:37 +00:00
|
|
|
bool writeback; // writeback for ARM
|
|
|
|
int8_t tied_op_idx
|
|
|
|
[MAX_MC_OPS]; ///< Tied operand indices. Index = Src op; Value: Dest op
|
2015-04-07 03:59:26 +00:00
|
|
|
// operand access index for list of registers sharing the same access right (for ARM)
|
|
|
|
uint8_t ac_idx;
|
2016-07-15 12:37:19 +00:00
|
|
|
uint8_t popcode_adjust; // Pseudo X86 instruction adjust
|
2024-05-12 13:17:20 +00:00
|
|
|
char assembly[8]; // for special instruction, so that we don't need printer
|
2018-03-31 09:29:22 +00:00
|
|
|
unsigned char evm_data[32]; // for EVM PUSH operand
|
2019-02-01 15:03:47 +00:00
|
|
|
cs_wasm_op wasm_data; // for WASM operand
|
2019-03-16 07:22:15 +00:00
|
|
|
MCRegisterInfo *MRI;
|
2019-05-14 01:59:23 +00:00
|
|
|
uint8_t xAcquireRelease; // X86 xacquire/xrelease
|
2023-09-05 04:24:59 +00:00
|
|
|
bool isAliasInstr; // Flag if this MCInst is an alias.
|
|
|
|
bool fillDetailOps; // If set, detail->operands gets filled.
|
2024-03-26 05:58:56 +00:00
|
|
|
hppa_ext hppa_ext; ///< for HPPA operand. Contains info about modifiers and their effect on the instruction
|
2024-09-14 08:57:54 +00:00
|
|
|
MCAsmInfo MAI; ///< The equivalent to MCAsmInfo in LLVM. It holds flags relevant for the asm style to print.
|
2013-11-27 04:11:31 +00:00
|
|
|
};
|
|
|
|
|
2024-09-14 08:57:54 +00:00
|
|
|
void MCInst_Init(MCInst *inst, cs_arch arch);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
|
|
|
void MCInst_clear(MCInst *inst);
|
|
|
|
|
2014-06-09 18:01:23 +00:00
|
|
|
// do not free operand after inserting
|
|
|
|
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
void MCInst_setOpcode(MCInst *inst, unsigned Op);
|
|
|
|
|
|
|
|
unsigned MCInst_getOpcode(const MCInst*);
|
|
|
|
|
2013-11-29 16:54:24 +00:00
|
|
|
void MCInst_setOpcodePub(MCInst *inst, unsigned Op);
|
|
|
|
|
|
|
|
unsigned MCInst_getOpcodePub(const MCInst*);
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
MCOperand *MCInst_getOperand(MCInst *inst, unsigned i);
|
|
|
|
|
|
|
|
unsigned MCInst_getNumOperands(const MCInst *inst);
|
|
|
|
|
2024-04-30 02:37:53 +00:00
|
|
|
// This addOperand2 function doesn't free Op
|
2014-06-16 06:52:09 +00:00
|
|
|
void MCInst_addOperand2(MCInst *inst, MCOperand *Op);
|
2013-11-27 04:11:31 +00:00
|
|
|
|
2023-05-30 03:08:18 +00:00
|
|
|
bool MCInst_isPredicable(const MCInstrDesc *MIDesc);
|
|
|
|
|
2024-07-08 02:28:54 +00:00
|
|
|
void MCInst_handleWriteback(MCInst *MI, const MCInstrDesc *InstDescTable, unsigned tbl_size);
|
2023-05-30 03:08:18 +00:00
|
|
|
|
|
|
|
bool MCInst_opIsTied(const MCInst *MI, unsigned OpNum);
|
|
|
|
|
|
|
|
bool MCInst_opIsTying(const MCInst *MI, unsigned OpNum);
|
|
|
|
|
2023-07-19 09:56:27 +00:00
|
|
|
uint64_t MCInst_getOpVal(MCInst *MI, unsigned OpNum);
|
|
|
|
|
2023-09-05 04:24:59 +00:00
|
|
|
void MCInst_setIsAlias(MCInst *MI, bool Flag);
|
|
|
|
|
|
|
|
static inline bool MCInst_isAlias(const MCInst *MI) {
|
|
|
|
return MI->isAliasInstr;
|
|
|
|
}
|
|
|
|
|
2023-11-15 04:12:14 +00:00
|
|
|
void MCInst_updateWithTmpMI(MCInst *MI, MCInst *TmpMI);
|
|
|
|
|
2013-11-27 04:11:31 +00:00
|
|
|
#endif
|