17 #ifdef CAPSTONE_HAS_MIPS
19 #include <capstone/platform.h>
25 #include "../../MCInst.h"
26 #include "../../utils.h"
27 #include "../../SStream.h"
28 #include "../../MCRegisterInfo.h"
42 typedef enum Mips_CondCode {
82 #define GET_INSTRINFO_ENUM
85 static const char *getRegisterName(
unsigned RegNo);
98 MI->
flat_insn->detail->mips.operands[MI->
flat_insn->detail->mips.op_count].mem.disp = 0;
105 static bool isReg(
MCInst *MI,
unsigned OpNo,
unsigned R)
111 static const char* MipsFCCToString(Mips_CondCode CC)
116 case Mips_FCOND_T:
return "f";
118 case Mips_FCOND_OR:
return "un";
120 case Mips_FCOND_UNE:
return "eq";
122 case Mips_FCOND_ONE:
return "ueq";
124 case Mips_FCOND_UGE:
return "olt";
126 case Mips_FCOND_OGE:
return "ult";
128 case Mips_FCOND_UGT:
return "ole";
130 case Mips_FCOND_OGT:
return "ule";
132 case Mips_FCOND_ST:
return "sf";
133 case Mips_FCOND_NGLE:
134 case Mips_FCOND_GLE:
return "ngle";
136 case Mips_FCOND_SNE:
return "seq";
138 case Mips_FCOND_GL:
return "ngl";
140 case Mips_FCOND_NLT:
return "lt";
142 case Mips_FCOND_GE:
return "nge";
144 case Mips_FCOND_NLE:
return "le";
146 case Mips_FCOND_GT:
return "ngt";
150 static void printRegName(
SStream *
OS,
unsigned RegNo)
164 case Mips_RestoreX16:
171 mnem = printAlias(MI,
O);
173 printInstruction(MI,
O,
NULL);
188 if (OpNo >= MI->
size)
194 printRegName(
O,
reg);
238 printOperand(MI, opNum,
O);
256 printOperand(MI, opNum,
O);
278 set_mem_access(MI,
true);
279 printOperand(MI, opNum + 1,
O);
281 printOperand(MI, opNum,
O);
283 set_mem_access(MI,
false);
291 printOperand(MI, opNum,
O);
293 printOperand(MI, opNum + 1,
O);
308 static char *printAlias1(
const char *Str,
MCInst *MI,
unsigned OpNo,
SStream *
OS)
311 printOperand(MI, OpNo,
OS);
315 static char *printAlias2(
const char *Str,
MCInst *MI,
316 unsigned OpNo0,
unsigned OpNo1,
SStream *
OS)
320 tmp = printAlias1(Str, MI, OpNo0,
OS);
322 printOperand(MI, OpNo1,
OS);
327 #define GET_REGINFO_ENUM
337 if (isReg(MI, 0, Mips_ZERO) && isReg(MI, 1, Mips_ZERO))
338 return printAlias1(
"b", MI, 2,
OS);
339 if (isReg(MI, 1, Mips_ZERO))
340 return printAlias2(
"beqz", MI, 0, 2,
OS);
344 if (isReg(MI, 1, Mips_ZERO_64))
345 return printAlias2(
"beqz", MI, 0, 2,
OS);
349 if (isReg(MI, 1, Mips_ZERO))
350 return printAlias2(
"bnez", MI, 0, 2,
OS);
354 if (isReg(MI, 1, Mips_ZERO_64))
355 return printAlias2(
"bnez", MI, 0, 2,
OS);
359 if (isReg(MI, 0, Mips_ZERO))
360 return printAlias1(
"bal", MI, 1,
OS);
364 if (isReg(MI, 0, Mips_FCC0))
365 return printAlias1(
"bc1t", MI, 1,
OS);
369 if (isReg(MI, 0, Mips_FCC0))
370 return printAlias1(
"bc1f", MI, 1,
OS);
374 if (isReg(MI, 0, Mips_RA))
375 return printAlias1(
"jalr", MI, 1,
OS);
379 if (isReg(MI, 0, Mips_RA_64))
380 return printAlias1(
"jalr", MI, 1,
OS);
385 if (isReg(MI, 2, Mips_ZERO))
386 return printAlias2(
"not", MI, 0, 1,
OS);
390 if (isReg(MI, 2, Mips_ZERO_64))
391 return printAlias2(
"not", MI, 0, 1,
OS);
395 if (isReg(MI, 2, Mips_ZERO))
396 return printAlias2(
"move", MI, 0, 1,
OS);
398 default:
return NULL;
412 printRegName(
O,
reg);
421 #define PRINT_ALIAS_INSTR
unsigned MCInst_getOpcode(const MCInst *inst)
unsigned MCInst_getNumOperands(const MCInst *inst)
MCOperand * MCInst_getOperand(MCInst *inst, unsigned i)
bool MCOperand_isReg(const MCOperand *op)
void MCInst_setOpcodePub(MCInst *inst, unsigned Op)
int64_t MCOperand_getImm(MCOperand *op)
unsigned MCOperand_getReg(const MCOperand *op)
getReg - Returns the register number.
bool MCOperand_isImm(const MCOperand *op)
void Mips_printInst(MCInst *MI, SStream *O, void *info)
mips_reg Mips_map_register(unsigned int r)
mips_reg Mips_map_insn(const char *name)
void printInt64(SStream *O, int64_t val)
void SStream_concat(SStream *ss, const char *fmt,...)
void SStream_concat0(SStream *ss, const char *s)
RzBinInfo * info(RzBinFile *bf)
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
static const char struct stat static buf struct stat static buf static vhangup int status
@ MIPS_OP_REG
= CS_OP_REG (Register operand).
@ MIPS_OP_IMM
= CS_OP_IMM (Immediate operand).
@ MIPS_OP_MEM
= CS_OP_MEM (Memory operand).
char * cs_strdup(const char *str)