]> git.saurik.com Git - apple/libplatform.git/blob - src/setjmp/arm64/setjmp.s
libplatform-126.1.2.tar.gz
[apple/libplatform.git] / src / setjmp / arm64 / setjmp.s
1 /*
2 * Copyright (c) 2011 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 #define JMP_r19_20 #0x00
25 #define JMP_r21_22 #0x10
26 #define JMP_r23_24 #0x20
27 #define JMP_r25_26 #0x30
28 #define JMP_r27_28 #0x40
29 #define JMP_r29_lr #0x50
30 #define JMP_fp_sp #0x60
31
32 #define JMP_d8_d9 #0x70
33 #define JMP_d10_d11 #0x80
34 #define JMP_d12_d13 #0x90
35 #define JMP_d14_d15 #0xA0
36 #define JMP_sig #0xB0
37 #define JMP_sigflag #0xB8
38
39 #include <architecture/arm/asm_help.h>
40
41 /* int _setjmp(jmp_buf env); */
42 ENTRY_POINT(__setjmp)
43 add x1, sp, #0 /* can't STP from sp */
44 stp x19, x20, [x0, JMP_r19_20]
45 stp x21, x22, [x0, JMP_r21_22]
46 stp x23, x24, [x0, JMP_r23_24]
47 stp x25, x26, [x0, JMP_r25_26]
48 stp x27, x28, [x0, JMP_r27_28]
49 stp x29, lr, [x0, JMP_r29_lr]
50 stp fp, x1, [x0, JMP_fp_sp]
51 stp d8, d9, [x0, JMP_d8_d9]
52 stp d10, d11, [x0, JMP_d10_d11]
53 stp d12, d13, [x0, JMP_d12_d13]
54 stp d14, d15, [x0, JMP_d14_d15]
55 mov x0, #0
56 ret
57
58 /* void _longjmp(jmp_buf env, int val); */
59 ENTRY_POINT(__longjmp)
60 ldp x19, x20, [x0, JMP_r19_20]
61 ldp x21, x22, [x0, JMP_r21_22]
62 ldp x23, x24, [x0, JMP_r23_24]
63 ldp x25, x26, [x0, JMP_r25_26]
64 ldp x27, x28, [x0, JMP_r27_28]
65 ldp x29, lr, [x0, JMP_r29_lr]
66 ldp fp, x2, [x0, JMP_fp_sp]
67 ldp d8, d9, [x0, JMP_d8_d9]
68 ldp d10, d11, [x0, JMP_d10_d11]
69 ldp d12, d13, [x0, JMP_d12_d13]
70 ldp d14, d15, [x0, JMP_d14_d15]
71 add sp, x2, #0
72 mov x0, x1
73 cmp x0, #0 /* longjmp returns 1 if val is 0 */
74 b.ne 1f
75 add x0, x0, #1
76 1: ret
77
78 /* int sigsetjmp(sigjmp_buf env, int savemask); */
79 ENTRY_POINT(_sigsetjmp)
80 str x1, [x0, JMP_sigflag]
81 cmp x1, #0
82 b.ne 1f
83 b __setjmp
84 1:
85 /* else, fall through */
86
87 /* int setjmp(jmp_buf env); */
88 ENTRY_POINT(_setjmp)
89 stp x21, lr, [x0]
90 mov x21, x0
91
92 mov x0, #1
93 mov x1, #0
94 add x2, x21, JMP_sig
95 CALL_EXTERNAL(_sigprocmask)
96
97 mov x0, x21
98 ldp x21, lr, [x0]
99 b __setjmp
100
101 /* void siglongjmp(sigjmp_buf env, int val); */
102 ENTRY_POINT(_siglongjmp)
103 ldr x2, [x0, JMP_sigflag]
104 cmp x2, #0
105 b.ne 1f
106 b __longjmp
107 1:
108 /* else, fall through */
109
110 /* void longjmp(jmp_buf env, int val); */
111 ENTRY_POINT(_longjmp)
112 sub sp, sp, #16
113 mov x21, x0 // x21/x22 will be restored by __longjmp
114 mov x22, x1
115 ldr x0, [x21, JMP_sig] // restore the signal mask
116 str x0, [sp, #8]
117 add x1, sp, #8 // set
118 orr w0, wzr, #0x3 // SIG_SETMASK
119 movz x2, #0 // oset
120 CALL_EXTERNAL(_sigprocmask)
121 mov x0, x21
122 mov x1, x22
123 add sp, sp, #16
124 b __longjmp