Skip to content

Commit f340d2c

Browse files
GulinSSTerrorJack
authored andcommitted
Add support for Windows ARM
Co-authored-by: Cheng Shao <terrorjack@type.dance>
1 parent 427e76a commit f340d2c

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ dist-newstyle/
1212
.stack-work/
1313
stack.yaml
1414
stack.yaml.lock
15+
16+
# IDEs
17+
.vscode

Graphics/Win32/Window.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Until a better solution is presented each version is provided explicitly here.
238238
-}
239239
#if defined(i386_HOST_ARCH)
240240
foreign import WINDOWS_CCONV unsafe "windows.h SetWindowLongW"
241-
#elif defined(x86_64_HOST_ARCH)
241+
#elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH)
242242
foreign import WINDOWS_CCONV unsafe "windows.h SetWindowLongPtrW"
243243
#else
244244
# error Unknown mingw32 arch
@@ -247,7 +247,7 @@ foreign import WINDOWS_CCONV unsafe "windows.h SetWindowLongPtrW"
247247

248248
#if defined(i386_HOST_ARCH)
249249
foreign import WINDOWS_CCONV unsafe "windows.h GetWindowLongW"
250-
#elif defined(x86_64_HOST_ARCH)
250+
#elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH)
251251
foreign import WINDOWS_CCONV unsafe "windows.h GetWindowLongPtrW"
252252
#else
253253
# error Unknown mingw32 arch

System/Win32/DebugApi.hsc

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,22 @@ module System.Win32.DebugApi
5454
, useAllRegs
5555
, withThreadContext
5656

57-
#if __i386__
57+
#if defined(i386_HOST_ARCH)
5858
, eax, ebx, ecx, edx, esi, edi, ebp, eip, esp
59-
#elif __x86_64__
59+
#elif defined(x86_64_HOST_ARCH)
6060
, rax, rbx, rcx, rdx, rsi, rdi, rbp, rip, rsp
6161
#endif
62+
#if defined(x86_64_HOST_ARCH) || defined(i386_HOST_ARCH)
6263
, segCs, segDs, segEs, segFs, segGs
6364
, eFlags
6465
, dr
66+
#endif
67+
#if defined(aarch64_HOST_ARCH)
68+
, x0, x1, x2, x3, x4, x5, x6, x7, x8
69+
, x9, x10, x11, x12, x13, x14, x15, x16, x17
70+
, x18, x19, x20, x21, x22, x23, x24, x25, x26
71+
, x27, x28, fp, lr, sp, pc
72+
#endif
6573
, setReg, getReg, modReg
6674
, makeModThreadContext
6775
, modifyThreadContext
@@ -331,7 +339,7 @@ withThreadContext t act =
331339
(act buf)
332340

333341

334-
#if __i386__
342+
#if defined(i386_HOST_ARCH)
335343
eax, ebx, ecx, edx :: Int
336344
esi, edi :: Int
337345
ebp, eip, esp :: Int
@@ -344,7 +352,7 @@ edi = (#offset CONTEXT, Edi)
344352
ebp = (#offset CONTEXT, Ebp)
345353
eip = (#offset CONTEXT, Eip)
346354
esp = (#offset CONTEXT, Esp)
347-
#elif __x86_64__
355+
#elif defined(x86_64_HOST_ARCH)
348356
rax, rbx, rcx, rdx :: Int
349357
rsi, rdi :: Int
350358
rbp, rip, rsp :: Int
@@ -357,10 +365,49 @@ rdi = (#offset CONTEXT, Rdi)
357365
rbp = (#offset CONTEXT, Rbp)
358366
rip = (#offset CONTEXT, Rip)
359367
rsp = (#offset CONTEXT, Rsp)
368+
#elif defined(aarch64_HOST_ARCH)
369+
x0, x1, x2, x3, x4, x5, x6, x7, x8 :: Int
370+
x9, x10, x11, x12, x13, x14, x15, x16, x17 :: Int
371+
x18, x19, x20, x21, x22, x23, x24, x25, x26 :: Int
372+
x27, x28, fp, lr, sp, pc :: Int
373+
x0 = (#offset CONTEXT, X0 )
374+
x1 = (#offset CONTEXT, X1 )
375+
x2 = (#offset CONTEXT, X2 )
376+
x3 = (#offset CONTEXT, X3 )
377+
x4 = (#offset CONTEXT, X4 )
378+
x5 = (#offset CONTEXT, X5 )
379+
x6 = (#offset CONTEXT, X6 )
380+
x7 = (#offset CONTEXT, X7 )
381+
x8 = (#offset CONTEXT, X8 )
382+
x9 = (#offset CONTEXT, X9 )
383+
x10 = (#offset CONTEXT, X10)
384+
x11 = (#offset CONTEXT, X11)
385+
x12 = (#offset CONTEXT, X12)
386+
x13 = (#offset CONTEXT, X13)
387+
x14 = (#offset CONTEXT, X14)
388+
x15 = (#offset CONTEXT, X15)
389+
x16 = (#offset CONTEXT, X16)
390+
x17 = (#offset CONTEXT, X17)
391+
x18 = (#offset CONTEXT, X18)
392+
x19 = (#offset CONTEXT, X19)
393+
x20 = (#offset CONTEXT, X20)
394+
x21 = (#offset CONTEXT, X21)
395+
x22 = (#offset CONTEXT, X22)
396+
x23 = (#offset CONTEXT, X23)
397+
x24 = (#offset CONTEXT, X24)
398+
x25 = (#offset CONTEXT, X25)
399+
x26 = (#offset CONTEXT, X26)
400+
x27 = (#offset CONTEXT, X27)
401+
x28 = (#offset CONTEXT, X28)
402+
fp = (#offset CONTEXT, Fp)
403+
lr = (#offset CONTEXT, Lr)
404+
sp = (#offset CONTEXT, Sp)
405+
pc = (#offset CONTEXT, Pc)
360406
#else
361-
#error Unsupported architecture
407+
#error Unknown mingw32 arch
362408
#endif
363409

410+
#if defined(x86_64_HOST_ARCH) || defined(i386_HOST_ARCH)
364411
segCs, segDs, segEs, segFs, segGs :: Int
365412
segCs = (#offset CONTEXT, SegCs)
366413
segDs = (#offset CONTEXT, SegDs)
@@ -380,6 +427,7 @@ dr n = case n of
380427
6 -> (#offset CONTEXT, Dr6)
381428
7 -> (#offset CONTEXT, Dr7)
382429
_ -> undefined
430+
#endif
383431

384432
setReg :: Ptr a -> Int -> DWORD -> IO ()
385433
setReg = pokeByteOff

include/windows_cconv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#if defined(i386_HOST_ARCH)
55
# define WINDOWS_CCONV stdcall
6-
#elif defined(x86_64_HOST_ARCH)
6+
#elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH)
77
# define WINDOWS_CCONV ccall
88
#else
99
# error Unknown mingw32 arch

0 commit comments

Comments
 (0)