librz/arch/c166: fix behavior on big-endian hosts

This commit is contained in:
SSharshunov 2026-05-13 01:28:29 +05:00 committed by GitHub
parent 93eeefc399
commit 75ad6e9a51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 38 deletions

View file

@ -1510,15 +1510,10 @@ RZ_IPI st32 c166_decode_command(RZ_NONNULL C166State *state, RZ_NONNULL C166_Ins
return -1;
}
for (size_t i = 0; i < RZ_MIN(8, len) / 2; ++i) {
ut16 tmp;
if (!rz_buf_read_le16(b, &tmp)) {
goto err;
}
instr->d |= (ut64)(tmp) << (i * 16);
if (!rz_buf_read(b, (ut8 *)&instr->d, RZ_MIN(8, len))) {
goto err;
}
ut8 opcode = get_opcode(instr, 0, 8);
const ut8 opcode = rz_read_le8(&instr->d);
instr->id = opcode;
instr->ext = state->ext; // Copy state
c166_maybe_deactivate_ext(state, instr->addr);

View file

@ -775,38 +775,9 @@ typedef struct {
C166ExtState ext;
} C166_Inst;
static inline ut32 extract(const ut64 x, const ut8 i, const ut8 n) {
return (x >> i) & ((1 << n) - 1);
}
static inline ut16 C166_word(const C166_Inst *i, const unsigned index) {
rz_warn_if_fail(index >= 1 && index <= 4);
return extract(i->d, (index - 1) * 16, 16);
}
static inline ut16 get_opcode(const C166_Inst *i, unsigned l, unsigned r) {
return extract(i->d, l, r - l + 1);
}
static inline ut16 get_byte(const C166_Inst *i, const ut8 index) {
rz_warn_if_fail(index <= 3);
ut16 ret = 0;
switch (index) {
case 0:
ret = get_opcode(i, 0, 8);
break;
case 1:
ret = (C166_word(i, 1) & 0xFF00) >> 8;
break;
case 2:
ret = C166_word(i, 2) & 0x00FF;
break;
case 3:
ret = (C166_word(i, 2) & 0xFF00) >> 8;
break;
default: break;
}
return ret;
return rz_read_at_le8(&i->d, index);
}
static inline ut16 get_operand(const C166_Inst *i, const ut8 index) {