mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-12 05:00:39 +02:00
This allows for running x64 applications under wine without having to run all of wine under FEX. The JIT is invoked when ARM64EC code performs an indirect branch to x64 code, and left whenever the x64 code calls into ARM64EC code.
63 lines
2.0 KiB
ArmAsm
63 lines
2.0 KiB
ArmAsm
.text
|
|
.balign 16
|
|
|
|
// __os_arm64x_x64_jump in ARM64EC docs
|
|
// Expects target code address in x9
|
|
.globl DispatchJump
|
|
DispatchJump:
|
|
str lr, [sp, #-8]! // Push return address to stack, this will be popped by the x86 RET instr.
|
|
b check_target_ec
|
|
|
|
// __os_arm64x_dispatch_ret in ARM64EC docs
|
|
// Expects target code address in lr
|
|
.globl RetToEntryThunk
|
|
RetToEntryThunk:
|
|
mov x9, lr
|
|
|
|
check_target_ec:
|
|
// Check if target is in fact x86 code
|
|
ldr x16, [x18, #0x60] // TEB->PEB
|
|
ldr x16, [x16, #0x368] // PEB->EcCodeBitMap
|
|
lsr x17, x9, #15
|
|
and x17, x17, #0x1fffffffffff8
|
|
ldr x16, [x16, x17]
|
|
lsr x17, x9, #12
|
|
lsr x16, x16, x17
|
|
tbnz x16, #0, ExitFunctionEC
|
|
b enter_jit
|
|
|
|
// __os_arm64x_dispatch_call_no_redirect in ARM64EC docs
|
|
// Expects target code address in x9, and to be called using a 'blr x16' instruction.
|
|
.globl ExitToX64
|
|
ExitToX64:
|
|
str lr, [sp, #-8]! // Push return address to stack, this will be popped by the x86 RET instr.
|
|
|
|
enter_jit:
|
|
ldr x17, [x18, #0x1788] // TEB->ChpeV2CpuAreaInfo
|
|
ldr x16, [x17, #0x40] // ChpeV2CpuAreaInfo->EmulatorData[2] - DispatcherLoopTopEnterEC
|
|
br x16 // DispatcherLoopTopEnterEC(RIP:x9, CPUArea:x17)
|
|
|
|
// Called into by FEXCore
|
|
// Expects the target code address in x9
|
|
.global ExitFunctionEC
|
|
ExitFunctionEC:
|
|
// Either return to an exit thunk (return to ARM64EC function) or call an entry thunk (call to ARM64EC function).
|
|
// It is assumed that a 'blr x16' instruction is only ever used to call into x86 code from an exit thunk, and that all
|
|
// exported ARM64EC functions have a 4-byte offset to their entry thunk immediately before their first instruction.
|
|
mov x17, x9
|
|
mov w16, #0x200
|
|
movk w16, #0xd63f, lsl 16 // blr x16
|
|
ldursw x23, [x17, #-0x4] // Load either the entry thunk offset or the calling instruction.
|
|
cmp w23, w16
|
|
beq ret_sp_aligned
|
|
|
|
and x23, x23, #-0x4
|
|
add x17, x17, x23 // Resolve entry thunk address.
|
|
|
|
mov x4, sp
|
|
ldr lr, [x4], #0x8 // Pop the return address into lr.
|
|
mov sp, x4
|
|
|
|
ret_sp_aligned:
|
|
br x17
|