Skip to content

Commit

Permalink
Merge pull request #3915 from bylaws/winbase
Browse files Browse the repository at this point in the history
ARM64EC: Support the JIT API as is used by Windows
  • Loading branch information
Sonicadvance1 authored Aug 2, 2024
2 parents 201fe6e + 115fbb5 commit 7ffd3e5
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 93 deletions.
20 changes: 12 additions & 8 deletions Source/Windows/ARM64EC/BTInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
#include <winternl.h>

extern "C" {
void STDMETHODCALLTYPE ProcessInit();
void STDMETHODCALLTYPE ProcessTerm();
NTSTATUS STDMETHODCALLTYPE ProcessInit();
void STDMETHODCALLTYPE ProcessTerm(HANDLE Handle, BOOL After, NTSTATUS Status);
NTSTATUS STDMETHODCALLTYPE ThreadInit();
NTSTATUS STDMETHODCALLTYPE ThreadTerm(HANDLE Thread);
NTSTATUS STDMETHODCALLTYPE ResetToConsistentState(EXCEPTION_POINTERS* Ptrs, ARM64_NT_CONTEXT* Context, BOOLEAN* Continue);
NTSTATUS STDMETHODCALLTYPE ThreadTerm(HANDLE Thread, LONG ExitCode);
NTSTATUS STDMETHODCALLTYPE ResetToConsistentState(EXCEPTION_RECORD* Exception, CONTEXT* GuestContext, ARM64_NT_CONTEXT* NativeContext);
void STDMETHODCALLTYPE NotifyMemoryAlloc(void* Address, SIZE_T Size, ULONG Type, ULONG Prot, BOOL After, NTSTATUS Status);
void STDMETHODCALLTYPE NotifyMemoryFree(void* Address, SIZE_T Size, ULONG FreeType, BOOL After, NTSTATUS Status);
void STDMETHODCALLTYPE NotifyMemoryProtect(void* Address, SIZE_T Size, ULONG NewProt, BOOL After, NTSTATUS Status);
NTSTATUS STDMETHODCALLTYPE NotifyMapViewOfSection(void* Unk1, void* Address, void* Unk2, SIZE_T Size, ULONG AllocType, ULONG Prot);
void STDMETHODCALLTYPE NotifyUnmapViewOfSection(void* Address, BOOL After, NTSTATUS Status);
void STDMETHODCALLTYPE FlushInstructionCacheHeavy(const void* Address, SIZE_T Size);
void STDMETHODCALLTYPE BTCpu64FlushInstructionCache(const void* Address, SIZE_T Size);
void STDMETHODCALLTYPE NotifyMemoryAlloc(void* Address, SIZE_T Size, ULONG Type, ULONG Prot);
void STDMETHODCALLTYPE NotifyMemoryFree(void* Address, SIZE_T Size, ULONG FreeType);
void STDMETHODCALLTYPE NotifyMemoryProtect(void* Address, SIZE_T Size, ULONG NewProt);
void STDMETHODCALLTYPE NotifyUnmapViewOfSection(void* Address);
void STDMETHODCALLTYPE BTCpu64NotifyMemoryDirty(void* Address, SIZE_T Size);
void STDMETHODCALLTYPE BTCpu64NotifyReadFile(HANDLE Handle, void* Address, SIZE_T Size, BOOL After, NTSTATUS Status);
BOOLEAN STDMETHODCALLTYPE BTCpu64IsProcessorFeaturePresent(UINT Feature);
void STDMETHODCALLTYPE UpdateProcessorInformation(SYSTEM_CPU_INFORMATION* Info);
}
20 changes: 20 additions & 0 deletions Source/Windows/ARM64EC/Module.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ enter_jit:
// Expects a CONTEXT pointer in x0
.global BeginSimulation
BeginSimulation:
ldr x17, [x18, #0x1788] // TEB->ChpeV2CpuAreaInfo
ldr x16, [x17, #0x8] // ChpeV2CpuAreaInfo->EmulatorStackBase
mov sp, x16
bl "#SyncThreadContext"
ldr x17, [x18, #0x1788] // TEB->ChpeV2CpuAreaInfo
ldr x16, [x17, #0x48] // ChpeV2CpuAreaInfo->EmulatorData[3] - DispatcherLoopTopEnterECFillSRA
Expand Down Expand Up @@ -78,3 +81,20 @@ ret_sp_misaligned:
adrp lr, X64ReturnInstr
ldr lr, [lr, #:lo12:X64ReturnInstr]
br x17

// Calls NtContinue directly to allow continuing from a full native context, as the NTDLL NtContinue export takes in
// an x64 context with EC and the conversion to that loses the ARM64EC ABI-disallowed registers that FEX uses.
.global "#NtContinueNative"
"#NtContinueNative":
adrp x16, WineSyscallDispatcher
ldr x16, [x16, #:lo12:WineSyscallDispatcher]
cbz x16, direct_syscall
wine_syscall:
mov x9, x30
adrp x8, WineNtContinueSyscallId
ldr x8, [x8, #:lo12:WineNtContinueSyscallId]
blr x16
ret
direct_syscall:
svc #0x43
ret
Loading

0 comments on commit 7ffd3e5

Please sign in to comment.