mips: properly map alias instruction back to public id. this fixes the crash reported by Pancake

This commit is contained in:
Nguyen Anh Quynh 2013-12-06 13:49:23 +08:00
parent fe8030bdf0
commit 9f523d1699
3 changed files with 17 additions and 12 deletions

View File

@ -153,8 +153,8 @@ void Mips_printInst(MCInst *MI, SStream *O, void *info)
default: break;
case Mips_RDHWR:
case Mips_RDHWR64:
SStream_concat(O, "\t.set\tpush\n");
SStream_concat(O, "\t.set\tmips32r2\n");
SStream_concat(O, ".set\tpush\n");
SStream_concat(O, ".set\tmips32r2\n");
break;
}
@ -168,7 +168,6 @@ void Mips_printInst(MCInst *MI, SStream *O, void *info)
if (tab)
*tab = '\0';
// printf(">>> mnem = '%s': %u\n", mnem, Mips_map_insn(mnem));
// reflect the new insn name (alias) in the opcode
MCInst_setOpcode(MI, Mips_get_insn_id2(Mips_map_insn(mnem)));
free(mnem);
@ -178,7 +177,7 @@ void Mips_printInst(MCInst *MI, SStream *O, void *info)
default: break;
case Mips_RDHWR:
case Mips_RDHWR64:
SStream_concat(O, "\n\t.set\tpop");
SStream_concat(O, "\n.set\tpop");
break;
}
}
@ -270,7 +269,7 @@ static void printFCCOperand(MCInst *MI, int opNum, SStream *O)
static bool printAlias1(char *Str, MCInst *MI, unsigned OpNo, SStream *OS)
{
SStream_concat(OS, "\t%s\t", Str);
SStream_concat(OS, "%s\t", Str);
printOperand(MI, OpNo, OS);
return true;
}

View File

@ -1899,8 +1899,13 @@ static name_map insn_name_maps[] = {
};
// special alias insn
static name_map insn_name_maps2[] = {
static name_map alias_insn_names[] = {
{ MIPS_INS_NOP, "NOP" },
{ MIPS_INS_BEQ, "BEQZ" },
{ MIPS_INS_BNE, "BNEZ" },
{ MIPS_INS_BGEZAL, "BAL" },
{ MIPS_INS_BC1T, "BC1T" },
{ MIPS_INS_BC1F, "BC1F" },
};
char *Mips_insn_name(unsigned int id)
@ -1910,9 +1915,9 @@ char *Mips_insn_name(unsigned int id)
// handle special alias first
int i;
for (i = 0; i < ARR_SIZE(insn_name_maps2); i++) {
if (insn_name_maps2[i].id == id)
return insn_name_maps2[i].name;
for (i = 0; i < ARR_SIZE(alias_insn_names); i++) {
if (alias_insn_names[i].id == id)
return alias_insn_names[i].name;
}
return insn_name_maps[id].name;
@ -1923,9 +1928,9 @@ mips_reg Mips_map_insn(char *name)
// handle special alias first
int i;
for (i = 0; i < ARR_SIZE(insn_name_maps2); i++) {
if (!strcasecmp(insn_name_maps2[i].name, name))
return insn_name_maps2[i].id;
for (i = 0; i < ARR_SIZE(alias_insn_names); i++) {
if (!strcasecmp(alias_insn_names[i].name, name))
return alias_insn_names[i].id;
}
// NOTE: skip first NULL name in insn_name_maps

View File

@ -73,6 +73,7 @@ static void test()
//#define MIPS_CODE "\xc6\x23\xe9\xe4" // swc1 $f9, 0x23c6($7)
//#define MIPS_CODE "\x21\x38\x00\x01" // move $7, $8
#define MIPS_CODE "\x0C\x10\x00\x97\x00\x00\x00\x00\x24\x02\x00\x0c\x8f\xa2\x00\x00\x34\x21\x34\x56"
//#define MIPS_CODE "\x04\x11\x00\x01" // bal 0x8
#define MIPS_CODE2 "\x56\x34\x21\x34\xc2\x17\x01\x00"
struct platform platforms[] = {