Skip to content

Commit

Permalink
v850: fix decode_formatIX
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jan 25, 2024
1 parent e9f8aee commit 41d4637
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 128 deletions.
122 changes: 0 additions & 122 deletions librz/analysis/arch/v850/v850_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,128 +80,6 @@ RzAnalysisILConfig *v850_il_config(RzAnalysis *a) {
return cfg;
}

static const char *SR_get(ut8 regID, ut8 selID) {
if (selID == 0) {
switch (regID) {
case 0: return "EIPC";
case 1: return "EIPSW";
case 2: return "FEPC";
case 3: return "FEPSW";
case 4: return "ECR";
case 5: return "PSW";
case 6: return "FPSR";
case 7: return "FPEPC";
case 8: return "FPST";
case 9: return "FPCC";
case 10: return "FPCFG";
case 11: return "FPEC";
case 13: return "EIIC";
case 14: return "FEIC";
case 16: return "CTPC";
case 17: return "CTPSW";
case 20: return "CTBP";
case 28: return "EIWR";
case 29: return "FEWR";
case 31: return "BSEL";
default: break;
}
} else if (selID == 1) {
switch (regID) {
case 0: return "MCFG0";
case 2: return "RBASE";
case 3: return "EBASE";
case 4: return "INTBP";
case 5: return "MCTL";
case 6: return "PID";
case 7: return "FPIPR";
case 11: return "SCCFG";
case 12: return "SCBP";
default: break;
}
} else if (selID == 2) {
switch (regID) {
case 0: return "HTCFG0";
case 6: return "MEA";
case 7: return "ASID";
case 8: return "MEI";
case 10: return "ISPR";
case 11: return "PMR";
case 12: return "ICSR";
case 13: return "INTCFG";
default: break;
}
} else if (selID == 5) {
switch (regID) {
case 0: return "MPM";
case 1: return "MPRC";
case 4: return "MPBRGN";
case 5: return "MPTRGN";
case 8: return "MCA";
case 9: return "MCS";
case 10: return "MCC";
case 11: return "MCR";
default: break;
}
} else if (selID == 6) {
switch (regID) {
case 0: return "MPLA0";
case 1: return "MPUA0";
case 2: return "MPAT0";
case 4: return "MPLA1";
case 5: return "MPUT1";
case 6: return "MPAT1";
case 8: return "MPLA2";
case 9: return "MPUA2";
case 10: return "MPAT2";
case 12: return "MPLA3";
case 13: return "MPUA3";
case 14: return "MPAT3";
case 16: return "MPLA4";
case 17: return "MPUA4";
case 18: return "MPAT4";
case 20: return "MPLA5";
case 21: return "MPUA5";
case 22: return "MPAT5";
case 24: return "MPLA6";
case 25: return "MPUA6";
case 26: return "MPAT6";
case 28: return "MPLA7";
case 29: return "MPUA7";
case 30: return "MPAT7";
default: break;
}
} else if (selID == 7) {
switch (regID) {
case 0: return "MPLA8";
case 1: return "MPUA8";
case 2: return "MPAT8";
case 4: return "MPLA9";
case 5: return "MPUT9";
case 6: return "MPAT9";
case 8: return "MPLA10";
case 9: return "MPUA10";
case 10: return "MPAT10";
case 12: return "MPLA11";
case 13: return "MPUA11";
case 14: return "MPAT11";
case 16: return "MPLA12";
case 17: return "MPUA12";
case 18: return "MPAT12";
case 20: return "MPLA13";
case 21: return "MPUA13";
case 22: return "MPAT13";
case 24: return "MPLA14";
case 25: return "MPUA14";
case 26: return "MPAT14";
case 28: return "MPLA15";
case 29: return "MPUA15";
case 30: return "MPAT15";
default: break;
}
}
return NULL;
}

typedef struct {
const char *p;
const char *x;
Expand Down
6 changes: 4 additions & 2 deletions librz/asm/arch/v850/v850_disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ static bool decode_formatIX(V850_Inst *inst) {
inst->reg1 = get_reg1(inst);
inst->reg2 = get_reg2(inst);
inst->sub_opcode = get_imm16(inst) & ~1;
ut8 selID = -1;

if (inst->opcode == 0x3f) {
switch (inst->w2) {
Expand Down Expand Up @@ -558,6 +559,7 @@ static bool decode_formatIX(V850_Inst *inst) {
} else {
return false;
}
selID = inst->sub_opcode >> 11;
break;
}
} else if (inst->opcode == 0x3e) {
Expand All @@ -573,10 +575,10 @@ static bool decode_formatIX(V850_Inst *inst) {
PRINT_INSTR;
switch (inst->id) {
case V850_STSR:
OPERANDS("%d, %s, %d", inst->reg1, R2, get_reg3(inst));
OPERANDS("%s, %s, %d", SR_get(inst->reg1, selID), R2, get_reg3(inst));
break;
case V850_LDSR:
OPERANDS("%s, %d, %d", R1, inst->reg2, get_reg3(inst));
OPERANDS("%s, %s, %d", R1, SR_get(inst->reg2, selID), get_reg3(inst));
break;
case V850_SHL: OPERANDS("%s, %s", R1, R2); break;
default: break;
Expand Down
122 changes: 122 additions & 0 deletions librz/asm/arch/v850/v850_disas.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,128 @@ static inline const char *GR_get(ut8 i) {
return GR[i];
}

static inline const char *SR_get(ut8 regID, ut8 selID) {
if (selID == 0) {
switch (regID) {
case 0: return "EIPC";
case 1: return "EIPSW";
case 2: return "FEPC";
case 3: return "FEPSW";
case 4: return "ECR";
case 5: return "PSW";
case 6: return "FPSR";
case 7: return "FPEPC";
case 8: return "FPST";
case 9: return "FPCC";
case 10: return "FPCFG";
case 11: return "FPEC";
case 13: return "EIIC";
case 14: return "FEIC";
case 16: return "CTPC";
case 17: return "CTPSW";
case 20: return "CTBP";
case 28: return "EIWR";
case 29: return "FEWR";
case 31: return "BSEL";
default: break;
}
} else if (selID == 1) {
switch (regID) {
case 0: return "MCFG0";
case 2: return "RBASE";
case 3: return "EBASE";
case 4: return "INTBP";
case 5: return "MCTL";
case 6: return "PID";
case 7: return "FPIPR";
case 11: return "SCCFG";
case 12: return "SCBP";
default: break;
}
} else if (selID == 2) {
switch (regID) {
case 0: return "HTCFG0";
case 6: return "MEA";
case 7: return "ASID";
case 8: return "MEI";
case 10: return "ISPR";
case 11: return "PMR";
case 12: return "ICSR";
case 13: return "INTCFG";
default: break;
}
} else if (selID == 5) {
switch (regID) {
case 0: return "MPM";
case 1: return "MPRC";
case 4: return "MPBRGN";
case 5: return "MPTRGN";
case 8: return "MCA";
case 9: return "MCS";
case 10: return "MCC";
case 11: return "MCR";
default: break;
}
} else if (selID == 6) {
switch (regID) {
case 0: return "MPLA0";
case 1: return "MPUA0";
case 2: return "MPAT0";
case 4: return "MPLA1";
case 5: return "MPUT1";
case 6: return "MPAT1";
case 8: return "MPLA2";
case 9: return "MPUA2";
case 10: return "MPAT2";
case 12: return "MPLA3";
case 13: return "MPUA3";
case 14: return "MPAT3";
case 16: return "MPLA4";
case 17: return "MPUA4";
case 18: return "MPAT4";
case 20: return "MPLA5";
case 21: return "MPUA5";
case 22: return "MPAT5";
case 24: return "MPLA6";
case 25: return "MPUA6";
case 26: return "MPAT6";
case 28: return "MPLA7";
case 29: return "MPUA7";
case 30: return "MPAT7";
default: break;
}
} else if (selID == 7) {
switch (regID) {
case 0: return "MPLA8";
case 1: return "MPUA8";
case 2: return "MPAT8";
case 4: return "MPLA9";
case 5: return "MPUT9";
case 6: return "MPAT9";
case 8: return "MPLA10";
case 9: return "MPUA10";
case 10: return "MPAT10";
case 12: return "MPLA11";
case 13: return "MPUA11";
case 14: return "MPAT11";
case 16: return "MPLA12";
case 17: return "MPUA12";
case 18: return "MPAT12";
case 20: return "MPLA13";
case 21: return "MPUA13";
case 22: return "MPAT13";
case 24: return "MPLA14";
case 25: return "MPUA14";
case 26: return "MPAT14";
case 28: return "MPLA15";
case 29: return "MPUA15";
case 30: return "MPAT15";
default: break;
}
}
return NULL;
}

enum v850_sysregs {
V850_SREG_EIPC = 0x0,
V850_SREG_EIPCW = 0x1,
Expand Down
8 changes: 4 additions & 4 deletions test/db/asm/v850
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ d "mov 0x200000, sp" 230600002000 0x10000a
d "mov 0x10073c, ep" 3e063c071000 0x100010
d "mov 0x10873c, gp" 24063c871000 0x100016
d "mov 0x1002e4, r6" 2606e4021000 0x10001c
d "ldsr r6, ctbp/dpa0l, 0" e6a72000 0x100022
d "stsr psw/vmtid, r6, 0" e5374000 0x100026
d "ldsr r6, CTBP, 0" e6a72000 0x100022
d "stsr PSW, r6, 0" e5374000 0x100026
d "movhi 1, r0, r7" 403e0100 0x10002a
d "or r7, r6" 0731 0x10002e
d "ldsr r6, psw/vmtid, 0" e62f2000 0x100030
d "ldsr r6, PSW, 0" e62f2000 0x100030
d "movhi 2, r0, r6" 40360200 0x100034
d "ldsr r6, sr6/fpsr/vmadr/dcc, 0" e6372000 0x100038
d "ldsr r6, FPSR, 0" e6372000 0x100038
d "mov 0x100744, r6" 260644071000 0x10003c
d "mov 0x10074c, r7" 27064c071000 0x100042
d "st.w r0, 0[r6]" 66070100 0x100048
Expand Down

0 comments on commit 41d4637

Please sign in to comment.