Skip to content

Commit

Permalink
PIC: pic18 fix disasm
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Mar 27, 2024
1 parent 527f23b commit d0fd53b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions librz/arch/isa/pic/pic_pic18.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool pic18_disasm_op(Pic18Op *op, ut64 addr, const ut8 *buff, ut64 len) {
break;
case FA_T:
op->f = word & 0xff;
op->d = (word >> 8) & 1;
op->a = (word >> 8) & 1;
break;
case BAF_T:
op->f = word & 0xff;
Expand All @@ -158,7 +158,7 @@ bool pic18_disasm_op(Pic18Op *op, ut64 addr, const ut8 *buff, ut64 len) {
}
case K20S_T: {
check_dword_inst;
op->k = (dword & 0xff) | (dword >> 16 & 0xfff);
op->k = (dword & 0xff) | ((dword >> 16 & 0xfff) << 8);
op->s = (dword >> 8) & 0x1;
break;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ int pic_pic18_disassemble(RzAsm *a, RzAsmOp *asm_op, const ut8 *b, int blen) {
Pic18Op op = { 0 };
if (!pic18_disasm_op(&op, a->pc, b, blen) ||
op.code == PIC18_OPCODE_INVALID) {
rz_asm_op_set_asm(asm_op, op.mnemonic);
rz_asm_op_set_asm(asm_op, "invalid");
return -1;
}
asm_op->size = op.size;
Expand All @@ -217,10 +217,10 @@ int pic_pic18_disassemble(RzAsm *a, RzAsmOp *asm_op, const ut8 *b, int blen) {
rz_asm_op_setf_asm(asm_op, "%s 0x%x", op.mnemonic, op.n);
break;
case K20S_T:
rz_asm_op_setf_asm(asm_op, "%s 0x%x, %d", op.mnemonic, op.k, op.s);
rz_asm_op_setf_asm(asm_op, "%s 0x%x, %d", op.mnemonic, op.k << 1, op.s);
break;
case K20_T:
rz_asm_op_setf_asm(asm_op, "%s 0x%x", op.mnemonic, op.k);
rz_asm_op_setf_asm(asm_op, "%s 0x%x", op.mnemonic, op.k << 1);
break;
case SD_T:
rz_asm_op_setf_asm(asm_op, "%s 0x%x, 0x%x", op.mnemonic, op.s, op.d);
Expand All @@ -232,7 +232,7 @@ int pic_pic18_disassemble(RzAsm *a, RzAsmOp *asm_op, const ut8 *b, int blen) {
rz_asm_op_setf_asm(asm_op, "%s %d", op.mnemonic, op.s);
break;
case FK_T: {
rz_asm_op_setf_asm(asm_op, "%s %s, %d", op.mnemonic, fsr[op.n], op.k);
rz_asm_op_setf_asm(asm_op, "%s %s, %d", op.mnemonic, fsr[op.f], op.k);
break;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions librz/arch/isa/pic/pic_pic18.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ typedef struct {
struct {
ut32 k : 20;
ut16 n : 11;
ut16 d;
ut16 s;
ut8 f;
ut8 d : 1;
ut8 a : 1;
ut8 s : 1;
ut8 b : 3;
};
} Pic18Op;
Expand Down
2 changes: 1 addition & 1 deletion test/db/asm/pic_pic18_8
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ d "andwf 0x85, 1, 1" 8517
d "bcf 0x42, 7, 1" 429f
d "bnn 0xfa" fae7
d "bra 0x51e" 1ed5
d "call 0x612a1, 1" a1ed12f6
d "call 0xc2542, 1" a1ed12f6
d "clrf 0x15, 0" 156a
d "comf 0x48, 0, 0" 481c
d "cpfseq 0x71, 1" 7163
Expand Down

0 comments on commit d0fd53b

Please sign in to comment.