about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--wow64/compiler.h2
-rw-r--r--wow64/wowbox64.c34
2 files changed, 35 insertions, 1 deletions
diff --git a/wow64/compiler.h b/wow64/compiler.h
index 1fff78b3..a656609d 100644
--- a/wow64/compiler.h
+++ b/wow64/compiler.h
@@ -4,4 +4,6 @@
 /* Things missing from mingw64 right now */
 #define ThreadWow64Context (29)
 
+NTSTATUS WINAPI RtlWow64GetCurrentCpuArea(USHORT *, void **, void **);
+
 #endif //__COMPILER_H_
diff --git a/wow64/wowbox64.c b/wow64/wowbox64.c
index 86a5fdfd..a137cf43 100644
--- a/wow64/wowbox64.c
+++ b/wow64/wowbox64.c
@@ -1,3 +1,7 @@
+/*
+ * Copyright 2022-2025 André Zwing
+ * Copyright 2023 Alexandre Julliard
+ */
 #include <stdio.h>
 #include <windows.h>
 #include <ntstatus.h>
@@ -8,6 +12,8 @@
 #include "os.h"
 #include "custommem.h"
 #include "env.h"
+#include "emu/x64emu_private.h"
+#include "emu/x87emu_private.h"
 #include "box64context.h"
 #include "wine/debug.h"
 
@@ -21,6 +27,17 @@ uint8_t box64_rdtsc_shift = 0;
 int box64_is32bits = 0;
 int box64_wine = 0; // this is for the emulated x86 Wine.
 
+static uint32_t x86emu_parity_tab[8] =
+{
+    0x96696996,
+    0x69969669,
+    0x69969669,
+    0x96696996,
+    0x69969669,
+    0x96696996,
+    0x96696996,
+    0x69969669,
+};
 
 int is_addr_unaligned(uintptr_t addr)
 {
@@ -121,7 +138,22 @@ void WINAPI BTCpuSimulate(void)
 
 NTSTATUS WINAPI BTCpuThreadInit(void)
 {
-    // NYI
+    WOW64_CONTEXT *ctx;
+    x64emu_t *emu = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*emu) );
+    __wine_dbg_output("[BOX64] BTCpuThreadInit\n");
+
+    RtlWow64GetCurrentCpuArea( NULL, (void **)&ctx, NULL );
+    emu->context = &box64_context;
+
+    // setup cpu helpers
+    for (int i=0; i<16; ++i)
+        emu->sbiidx[i] = &emu->regs[i];
+    emu->sbiidx[4] = &emu->zero;
+    emu->x64emu_parity_tab = x86emu_parity_tab;
+
+    reset_fpu(emu);
+
+    NtCurrentTeb()->TlsSlots[0] = emu;  // FIXME
     return STATUS_SUCCESS;
 }