Skip to content

Commit 644bbd3

Browse files
committed
feat(darwin): Add support for arm64
1 parent e7934e9 commit 644bbd3

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

third_party/boost_context/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ if (WIN32)
6969
set(CONTEXT_ASM "gas.S")
7070
endif()
7171
elseif(APPLE)
72-
set(CONTEXT_OS "sysv")
72+
# arm requires aapcs. So we have to check if arm already set the calling convention
73+
if (NOT CONTEXT_OS)
74+
set(CONTEXT_OS "sysv")
75+
endif()
7376
set(CONTEXT_ABI "macho")
7477
set(CONTEXT_ASM "gas.S")
7578
elseif(UNIX)

third_party/boost_context/asm/not_modified_yet/jump_arm64_aapcs_macho_gas.S renamed to third_party/boost_context/asm/jump_arm64_aapcs_macho_gas.S

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright Edward Nevill + Oliver Kowalke 2015
3+
Copyright Adrian Astley 2025.
34
Distributed under the Boost Software License, Version 1.0.
45
(See accompanying file LICENSE_1_0.txt or copy at
56
http://www.boost.org/LICENSE_1_0.txt)
@@ -42,9 +43,9 @@
4243
* | x27 | x28 | FP | LR | *
4344
* ------------------------------------------------- *
4445
* ------------------------------------------------- *
45-
* | 40 | 41 | 42 | 43 | | | *
46+
* | 40 | 41 | 42 | 43 | 444| 45 | 46 | 47 | *
4647
* ------------------------------------------------- *
47-
* | 0xa0| 0xa4| 0xa8| 0xac| | | *
48+
* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
4849
* ------------------------------------------------- *
4950
* | PC | align | | | *
5051
* ------------------------------------------------- *
@@ -55,55 +56,55 @@
5556
.globl _jump_fcontext
5657
.balign 16
5758
_jump_fcontext:
58-
; prepare stack for GP + FPU
59+
# prepare stack for GP + FPU
5960
sub sp, sp, #0xb0
6061

61-
; save d8 - d15
62+
# save d8 - d15
6263
stp d8, d9, [sp, #0x00]
6364
stp d10, d11, [sp, #0x10]
6465
stp d12, d13, [sp, #0x20]
6566
stp d14, d15, [sp, #0x30]
6667

67-
; save x19-x30
68+
# save x19-x30
6869
stp x19, x20, [sp, #0x40]
6970
stp x21, x22, [sp, #0x50]
7071
stp x23, x24, [sp, #0x60]
7172
stp x25, x26, [sp, #0x70]
7273
stp x27, x28, [sp, #0x80]
73-
stp fp, lr, [sp, #0x90]
74+
stp x29, x30, [sp, #0x90]
7475

75-
; save LR as PC
76-
str lr, [sp, #0xa0]
76+
# save LR as PC
77+
str x30, [sp, #0xa0]
7778

78-
; store RSP (pointing to context-data) in X0
79-
mov x4, sp
79+
# store RSP (pointing to context-data) at address pointed at by X0
80+
# STR doesn't allow us to use sp as the base register, so we have to mov it to x4 first
81+
mov x4, sp
82+
str x4, [x0, 0]
8083

81-
; restore RSP (pointing to context-data) from X1
82-
mov sp, x0
84+
# restore RSP (pointing to context-data) from X1
85+
mov sp, x1
8386

84-
; load d8 - d15
87+
# load d8 - d15
8588
ldp d8, d9, [sp, #0x00]
8689
ldp d10, d11, [sp, #0x10]
8790
ldp d12, d13, [sp, #0x20]
8891
ldp d14, d15, [sp, #0x30]
8992

90-
; load x19-x30
93+
# load x19-x30
9194
ldp x19, x20, [sp, #0x40]
9295
ldp x21, x22, [sp, #0x50]
9396
ldp x23, x24, [sp, #0x60]
9497
ldp x25, x26, [sp, #0x70]
9598
ldp x27, x28, [sp, #0x80]
96-
ldp fp, lr, [sp, #0x90]
99+
ldp x29, x30, [sp, #0x90]
97100

98-
; return transfer_t from jump
99-
; pass transfer_t as first arg in context function
100-
; X0 == FCTX, X1 == DATA
101-
mov x0, x4
101+
# pass data (third arg passed to jump_fcontext) as first arg passed to context function
102+
mov x0, x2
102103

103-
; load pc
104+
# load pc
104105
ldr x4, [sp, #0xa0]
105106

106-
; restore stack from GP + FPU
107+
# restore stack from GP + FP
107108
add sp, sp, #0xb0
108109

109110
ret x4

third_party/boost_context/asm/not_modified_yet/make_arm64_aapcs_macho_gas.S renamed to third_party/boost_context/asm/make_arm64_aapcs_macho_gas.S

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Copyright Edward Nevill + Oliver Kowalke 2015
2+
Copyright Edward Nevill + Oliver Kowalke 2015
3+
Copyright Adrian Astley 2025.
34
Distributed under the Boost Software License, Version 1.0.
45
(See accompanying file LICENSE_1_0.txt or copy at
56
http://www.boost.org/LICENSE_1_0.txt)
@@ -56,33 +57,26 @@
5657
.balign 16
5758

5859
_make_fcontext:
59-
; shift address in x0 (allocated stack) to lower 16 byte boundary
60+
# shift address in x0 (allocated stack) to lower 16 byte boundary
6061
and x0, x0, ~0xF
6162

62-
; reserve space for context-data on context-stack
63+
# reserve space for context-data on context-stack
6364
sub x0, x0, #0xb0
6465

65-
; third arg of make_fcontext() == address of context-function
66-
; store address as a PC to jump in
66+
# third arg of make_fcontext() == address of context-function
67+
# store address as a PC to jump in
6768
str x2, [x0, #0xa0]
6869

69-
; compute abs address of label finish
70-
; 0x0c = 3 instructions * size (4) before label 'finish'
71-
72-
; TODO: Numeric offset since llvm still does not support labels in ADR. Fix:
73-
; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html
74-
adr x1, 0x0c
75-
76-
; save address of finish as return-address for context-function
77-
; will be entered after context-function returns (LR register)
70+
# save address of finish as return-address for context-function
71+
# will be entered after context-function returns (LR register)
72+
adr x1, finish
7873
str x1, [x0, #0x98]
7974

80-
ret lr ; return pointer to context-data (x0)
75+
ret x30 // return pointer to context-data (x0)
8176

8277
finish:
83-
; exit code is zero
78+
# exit code is zero
8479
mov x0, #0
85-
; exit application
86-
bl __exit
87-
80+
# exit application
81+
bl _exit
8882

0 commit comments

Comments
 (0)