Skip to content

Commit

Permalink
v850: fix disas
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jan 25, 2024
1 parent 41d4637 commit b27f3ad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
46 changes: 34 additions & 12 deletions librz/asm/arch/v850/v850_disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,21 @@ static bool decode_formatI(V850_Inst *inst) {
static bool decode_formatII(V850_Inst *inst) {
inst->opcode = get_opcode(inst, 5, 10);
inst->reg2 = get_reg2(inst);
st32 imm = get_reg1(inst);
switch (inst->opcode) {
case V850_ADD_IMM5:
case V850_CMP_IMM5:
case V850_MOV_IMM5:
case V850_MULH_IMM5:
case V850_SAR_IMM5:
case V850_SATADD_IMM5:
inst->imm = sext32(imm, 5);
inst->id = inst->opcode;
break;
case V850_SAR_IMM5:
case V850_SHL_IMM5:
case V850_SHR_IMM5:
inst->id = inst->opcode;
inst->imm = get_reg1(inst);
inst->imm = imm;
break;
default:
// CALLT
Expand Down Expand Up @@ -366,21 +370,38 @@ static bool decode_formatVI(V850_Inst *inst, RzBuffer *b) {
switch (inst->opcode) {
case V850_ADDI:
case V850_MOVEA:
case V850_MOVHI:
case V850_SATSUBI:
inst->id = inst->opcode;
inst->imm = sext32(inst->imm, 16);
break;
case V850_ANDI:
case V850_MULHI:
case V850_MOVHI:
case V850_ORI:
case V850_SATSUBI:
case V850_XORI:
case V850_ANDI: inst->id = inst->opcode; break;
inst->id = inst->opcode;
break;
default: return false;
}
}

PRINT_INSTR;
if (inst->id == V850_MOV) {
switch (inst->id) {
case V850_MOV:
OPERANDS("0x%x, %s", inst->imm, R1);
} else {
break;
case V850_ANDI:
case V850_ADDI:
case V850_MOVHI:
case V850_MULHI:
case V850_ORI:
case V850_SATSUBI:
case V850_XORI:
OPERANDS("%d, %s, %s", inst->imm, R1, R2);
break;
default:
OPERANDS("0x%x, %s, %s", inst->imm, R1, R2);
break;
}
return true;
}
Expand Down Expand Up @@ -470,6 +491,7 @@ static bool decode_formatVII(V850_Inst *inst) {
case V850_LDH:
case V850_LDHU:
case V850_LDW:
inst->disp = sext32(inst->disp, 16);
OPERANDS("%d[%s], %s", inst->disp, R1, R2);
break;
case V850_STB:
Expand Down Expand Up @@ -848,34 +870,34 @@ static bool decode_formatXIII(V850_Inst *inst, RzBuffer *b) {
if (inst->reg2 == 1) {
inst->id = V850_PREPARE;
list_str = fmt_list(inst->list);
OPERANDS("%s, %x", list_str, inst->imm);
OPERANDS("%s, %d", list_str, inst->imm);
} else if ((inst->reg2 & 0x7) == 0x3) {
inst->id = V850_PREPARE;
ut8 ff = inst->reg2 >> 3;
switch (ff) {
case 0b00: OPERANDS("%s, %x, sp", list_str, inst->imm); break;
case 0b00: OPERANDS("%s, %d, sp", list_str, inst->imm); break;
case 0b01: {
ut16 imm = 0;
if (!rz_buf_read_le16(b, &imm)) {
return false;
}
OPERANDS("%s, %x, %d", list_str, inst->imm, sext32(imm, 16));
OPERANDS("%s, %d, %d", list_str, inst->imm, sext32(imm, 16));
break;
}
case 0b10: {
ut16 imm = 0;
if (!rz_buf_read_le16(b, &imm)) {
return false;
}
OPERANDS("%s, %x, %d", list_str, inst->imm, (ut32)(imm) << 16);
OPERANDS("%s, %d, %d", list_str, inst->imm, (ut32)(imm) << 16);
break;
}
case 0b11: {
ut32 imm = 0;
if (!rz_buf_read_le32(b, &imm)) {
return false;
}
OPERANDS("%s, %x, %d", list_str, inst->imm, imm);
OPERANDS("%s, %d, %d", list_str, inst->imm, imm);
break;
}
default: break;
Expand Down
4 changes: 2 additions & 2 deletions test/db/asm/v850
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
d "movea 255, r0, r20" 20a6ff00 0x100000
d "movea 0xff, r0, r20" 20a6ff00 0x100000
d "mov 0xffff, r21" 3506ffff0000 0x100004
d "mov 0x200000, sp" 230600002000 0x10000a
d "mov 0x10073c, ep" 3e063c071000 0x100010
Expand Down Expand Up @@ -74,7 +74,7 @@ d "st.w r10, 4[r29]" 7d570500 0x1000f4
d "ld.w 4[r29], r10" 3d570500 0x1000f8
d "cmp 15, r10" 6f52 0x1000fc
d "ble 100080" 97c5 0x1000fe
d "movea 88, r0, r10" 20565800 0x100100
d "movea 0x58, r0, r10" 20565800 0x100100
d "ld.bu 11[r29], r11" bd5f0b00 0x100104
d "cmp r10, r11" ea59 0x100108
d "bne 10015c" 9a2d 0x10010a
Expand Down

0 comments on commit b27f3ad

Please sign in to comment.