17 #ifdef CAPSTONE_HAS_MIPS
25 #include "../../MCInst.h"
26 #include "../../utils.h"
27 #include "../../SStream.h"
28 #include "../../MCRegisterInfo.h"
33 static void printUnsignedImm(
MCInst *MI,
int opNum,
SStream *O);
34 static char *printAliasInstr(
MCInst *MI,
SStream *O,
void *info);
42 typedef enum Mips_CondCode {
82 #define GET_INSTRINFO_ENUM
83 #include "MipsGenInstrInfo.inc"
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:
169 mnem = printAliasInstr(MI, O, info);
171 mnem = printAlias(MI, O);
173 printInstruction(MI, O, NULL);
184 static void printOperand(
MCInst *MI,
unsigned OpNo,
SStream *O)
188 if (OpNo >= MI->
size)
194 printRegName(O, reg);
198 MI->
flat_insn->detail->mips.operands[MI->
flat_insn->detail->mips.op_count].mem.base = reg;
212 MI->
flat_insn->detail->mips.operands[MI->
flat_insn->detail->mips.op_count].mem.disp = imm;
225 static void printUnsignedImm(
MCInst *MI,
int opNum,
SStream *O)
234 MI->
flat_insn->detail->mips.operands[MI->
flat_insn->detail->mips.op_count].imm = (
unsigned short int)imm;
238 printOperand(MI, opNum, O);
241 static void printUnsignedImm8(
MCInst *MI,
int opNum,
SStream *O)
256 printOperand(MI, opNum, O);
259 static void printMemOperand(
MCInst *MI,
int opNum,
SStream *O)
278 set_mem_access(MI,
true);
279 printOperand(MI, opNum + 1, O);
281 printOperand(MI, opNum, O);
283 set_mem_access(MI,
false);
287 static void printMemOperandEA(
MCInst *MI,
int opNum,
SStream *O)
291 printOperand(MI, opNum, O);
293 printOperand(MI, opNum + 1, O);
297 static void printFCCOperand(
MCInst *MI,
int opNum,
SStream *O)
303 static void printRegisterPair(
MCInst *MI,
int opNum,
SStream *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
328 #include "MipsGenRegisterInfo.inc"
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;
402 static void printRegisterList(
MCInst *MI,
int opNum,
SStream *O)
412 printRegName(O, reg);
421 #define PRINT_ALIAS_INSTR
422 #include "MipsGenAsmWriter.inc"