]> git.saurik.com Git - apple/libplatform.git/blob - src/ucontext/arm64/_ctx_start.s
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / src / ucontext / arm64 / _ctx_start.s
1 /*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include "asm_help.h"
25 #include <os/tsd.h>
26 #include <TargetConditionals.h>
27
28 .text
29
30 #if TARGET_OS_OSX || TARGET_OS_DRIVERKIT
31
32 /* Helper macro for unmunging pointers in place */
33 .macro PTR_UNMUNGE addr
34 #if defined(__LP64__)
35 _OS_PTR_MUNGE_TOKEN(x16, x16)
36 #else
37 _OS_PTR_MUNGE_TOKEN(x16, w16)
38 #endif
39 _OS_PTR_UNMUNGE(\addr, \addr, x16)
40 .endmacro
41
42 .macro CALL_USER_FUNC func
43 // Populate the first 8 arguments in registers from the stack. Coordinated
44 // with makecontext which populates the arguments on the stack
45 ldp w0, w1, [sp], #32
46 ldp w2, w3, [sp, #-24]
47 ldp w4, w5, [sp, #-16]
48 ldp w6, w7, [sp, #-8]
49
50 PTR_UNMUNGE \func
51
52 #if defined(__arm64e__)
53 blraaz \func
54 #else
55 blr \func
56 #endif
57 .endmacro
58
59 .private_extern __ctx_start
60 .align 2
61 __ctx_start:
62 /* x20 = munged signed user func,
63 * x19 = uctx,
64 * fp = top of stack,
65 * sp = where args end */
66 CALL_USER_FUNC x20
67
68 /* user function returned, set up stack for _ctx_done */
69
70 /* Reset to top of stack */
71 mov sp, fp
72
73 mov x0, x19 /* x0 = uctx */
74 bl __ctx_done
75
76 brk #666 /* Should not get here */
77
78 #endif