feat(asm): encode indirect JMP and CALL on all four architectures
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -575,6 +575,24 @@ func (e *enc) encodeJmpRel(ops []Operand, opcode []byte) error {
|
||||
return e.emit(&instr{opcode: opcode, modrm: -1, sib: -1, imm: le32(int64(imm))})
|
||||
}
|
||||
|
||||
// encodeIndirectBranch encodes JMP/CALL through a register or memory operand:
|
||||
// FF /4 for JMP, FF /2 for CALL. The operand size is fixed at 64 bits in
|
||||
// 64-bit mode, so no REX.W is emitted; a REX appears only for R8-R15 bases.
|
||||
func (e *enc) encodeIndirectBranch(mnem string, ops []Operand) error {
|
||||
if len(ops) != 1 {
|
||||
return fmt.Errorf("%s expects 1 operand, got %d", mnem, len(ops))
|
||||
}
|
||||
digit := 4 // JMP r/m64
|
||||
if mnem == "CALL" {
|
||||
digit = 2 // CALL r/m64
|
||||
}
|
||||
i := &instr{opcode: []byte{0xFF}, modrm: -1, sib: -1}
|
||||
if err := setRMDigit(i, digit, ops[0], 8); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.emit(i)
|
||||
}
|
||||
|
||||
// condCode maps a Plan 9 conditional-jump mnemonic to its x86 condition code.
|
||||
func condCode(upper string) (int, bool) {
|
||||
if len(upper) < 2 || upper[0] != 'J' || upper == "JMP" {
|
||||
|
||||
Reference in New Issue
Block a user