encode: Fix erroneous encoding of SREG push/pop
This commit is contained in:
6
encode.c
6
encode.c
@@ -348,6 +348,10 @@ fe_enc64_impl(uint8_t** restrict buf, uint64_t mnem, FeOp op0, FeOp op1,
|
|||||||
opc |= OPC_67;
|
opc |= OPC_67;
|
||||||
if (UNLIKELY(mnem & FE_SEG_MASK))
|
if (UNLIKELY(mnem & FE_SEG_MASK))
|
||||||
opc |= (mnem & FE_SEG_MASK) << (OPC_SEG_IDX - 16);
|
opc |= (mnem & FE_SEG_MASK) << (OPC_SEG_IDX - 16);
|
||||||
|
if (UNLIKELY(desc->enc == ENC_S)) {
|
||||||
|
if ((op_reg_idx(op0) << 3 & 0x20) != (opc & 0x20)) goto next;
|
||||||
|
opc |= op_reg_idx(op0) << 3;
|
||||||
|
}
|
||||||
|
|
||||||
if (ei->immctl > 0) {
|
if (ei->immctl > 0) {
|
||||||
imm = ops[ei->immidx];
|
imm = ops[ei->immidx];
|
||||||
@@ -372,8 +376,6 @@ fe_enc64_impl(uint8_t** restrict buf, uint64_t mnem, FeOp op0, FeOp op1,
|
|||||||
if (enc_mr(buf, opc, ops[ei->modrm^3], modreg, desc->immsz)) goto fail;
|
if (enc_mr(buf, opc, ops[ei->modrm^3], modreg, desc->immsz)) goto fail;
|
||||||
} else if (ei->modreg) {
|
} else if (ei->modreg) {
|
||||||
if (enc_o(buf, opc, ops[ei->modreg^3])) goto fail;
|
if (enc_o(buf, opc, ops[ei->modreg^3])) goto fail;
|
||||||
} else if (UNLIKELY(desc->enc == ENC_S)) {
|
|
||||||
if (enc_opc(buf, opc | (op_reg_idx(op0) << 3))) goto fail;
|
|
||||||
} else {
|
} else {
|
||||||
if (enc_opc(buf, opc)) goto fail;
|
if (enc_opc(buf, opc)) goto fail;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,14 @@ main(int argc, char** argv)
|
|||||||
TEST("\x54", FE_PUSHr, FE_SP);
|
TEST("\x54", FE_PUSHr, FE_SP);
|
||||||
TEST("\x41\x57", FE_PUSHr, FE_R15);
|
TEST("\x41\x57", FE_PUSHr, FE_R15);
|
||||||
TEST("\x41\x50", FE_PUSHr, FE_R8);
|
TEST("\x41\x50", FE_PUSHr, FE_R8);
|
||||||
|
TEST("", FE_PUSHr, FE_ES);
|
||||||
|
TEST("", FE_PUSH16r, FE_ES);
|
||||||
|
TEST("", FE_PUSHr, FE_CS);
|
||||||
|
TEST("", FE_PUSH16r, FE_CS);
|
||||||
|
TEST("", FE_PUSHr, FE_SS);
|
||||||
|
TEST("", FE_PUSH16r, FE_SS);
|
||||||
|
TEST("", FE_PUSHr, FE_DS);
|
||||||
|
TEST("", FE_PUSH16r, FE_DS);
|
||||||
TEST("\x0f\xa0", FE_PUSHr, FE_FS);
|
TEST("\x0f\xa0", FE_PUSHr, FE_FS);
|
||||||
TEST("\x66\x0f\xa0", FE_PUSH16r, FE_FS);
|
TEST("\x66\x0f\xa0", FE_PUSH16r, FE_FS);
|
||||||
TEST("\x0f\xa8", FE_PUSHr, FE_GS);
|
TEST("\x0f\xa8", FE_PUSHr, FE_GS);
|
||||||
|
|||||||
Reference in New Issue
Block a user