]>
Commit | Line | Data |
---|---|---|
ada7c492 | 1 | /* |
438624e0 | 2 | * Copyright (c) 2011-2018 Apple Inc. All rights reserved. |
ada7c492 A |
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 | |
438624e0 A |
29 | #define JMP_fp_lr #0x50 |
30 | #define JMP_sp_rsvd #0x60 /* second field is reserved/unused */ | |
ada7c492 A |
31 | #define JMP_d8_d9 #0x70 |
32 | #define JMP_d10_d11 #0x80 | |
33 | #define JMP_d12_d13 #0x90 | |
34 | #define JMP_d14_d15 #0xA0 | |
35 | #define JMP_sig #0xB0 | |
36 | #define JMP_sigflag #0xB8 | |
37 | ||
38 | #include <architecture/arm/asm_help.h> | |
438624e0 A |
39 | #include <os/tsd.h> |
40 | ||
ada7c492 A |
41 | |
42 | /* int _setjmp(jmp_buf env); */ | |
43 | ENTRY_POINT(__setjmp) | |
438624e0 A |
44 | _OS_PTR_MUNGE_TOKEN(x16, x16) |
45 | _OS_PTR_MUNGE(x10, fp, x16) | |
46 | _OS_PTR_MUNGE(x11, lr, x16) | |
47 | mov x12, sp | |
48 | _OS_PTR_MUNGE(x12, x12, x16) | |
ada7c492 A |
49 | stp x19, x20, [x0, JMP_r19_20] |
50 | stp x21, x22, [x0, JMP_r21_22] | |
51 | stp x23, x24, [x0, JMP_r23_24] | |
52 | stp x25, x26, [x0, JMP_r25_26] | |
53 | stp x27, x28, [x0, JMP_r27_28] | |
438624e0 A |
54 | stp x10, x11, [x0, JMP_fp_lr] |
55 | str x12, [x0, JMP_sp_rsvd] | |
ada7c492 A |
56 | stp d8, d9, [x0, JMP_d8_d9] |
57 | stp d10, d11, [x0, JMP_d10_d11] | |
58 | stp d12, d13, [x0, JMP_d12_d13] | |
59 | stp d14, d15, [x0, JMP_d14_d15] | |
438624e0 | 60 | mov w0, #0 |
ada7c492 A |
61 | ret |
62 | ||
63 | /* void _longjmp(jmp_buf env, int val); */ | |
64 | ENTRY_POINT(__longjmp) | |
438624e0 | 65 | _OS_PTR_MUNGE_TOKEN(x16, x16) |
ada7c492 A |
66 | ldp x19, x20, [x0, JMP_r19_20] |
67 | ldp x21, x22, [x0, JMP_r21_22] | |
68 | ldp x23, x24, [x0, JMP_r23_24] | |
69 | ldp x25, x26, [x0, JMP_r25_26] | |
70 | ldp x27, x28, [x0, JMP_r27_28] | |
438624e0 A |
71 | ldp x10, x11, [x0, JMP_fp_lr] |
72 | ldr x12, [x0, JMP_sp_rsvd] | |
ada7c492 A |
73 | ldp d8, d9, [x0, JMP_d8_d9] |
74 | ldp d10, d11, [x0, JMP_d10_d11] | |
75 | ldp d12, d13, [x0, JMP_d12_d13] | |
76 | ldp d14, d15, [x0, JMP_d14_d15] | |
438624e0 A |
77 | _OS_PTR_UNMUNGE(fp, x10, x16) |
78 | _OS_PTR_UNMUNGE(lr, x11, x16) | |
79 | _OS_PTR_UNMUNGE(x12, x12, x16) | |
80 | mov sp, x12 | |
81 | cmp w1, #0 | |
82 | csinc w0, w1, wzr, ne | |
83 | ret | |
ada7c492 A |
84 | |
85 | /* int sigsetjmp(sigjmp_buf env, int savemask); */ | |
86 | ENTRY_POINT(_sigsetjmp) | |
438624e0 A |
87 | str w1, [x0, JMP_sigflag] |
88 | cbnz w1, 1f | |
ada7c492 A |
89 | b __setjmp |
90 | 1: | |
91 | /* else, fall through */ | |
92 | ||
93 | /* int setjmp(jmp_buf env); */ | |
94 | ENTRY_POINT(_setjmp) | |
95 | stp x21, lr, [x0] | |
96 | mov x21, x0 | |
438624e0 A |
97 | |
98 | orr w0, wzr, #0x1 | |
ada7c492 A |
99 | mov x1, #0 |
100 | add x2, x21, JMP_sig | |
101 | CALL_EXTERNAL(_sigprocmask) | |
102 | ||
103 | mov x0, x21 | |
104 | ldp x21, lr, [x0] | |
105 | b __setjmp | |
106 | ||
438624e0 | 107 | |
ada7c492 A |
108 | /* void siglongjmp(sigjmp_buf env, int val); */ |
109 | ENTRY_POINT(_siglongjmp) | |
438624e0 A |
110 | ldr w8, [x0, JMP_sigflag] |
111 | cbnz w8, 1f | |
ada7c492 A |
112 | b __longjmp |
113 | 1: | |
114 | /* else, fall through */ | |
115 | ||
116 | /* void longjmp(jmp_buf env, int val); */ | |
117 | ENTRY_POINT(_longjmp) | |
118 | sub sp, sp, #16 | |
119 | mov x21, x0 // x21/x22 will be restored by __longjmp | |
120 | mov x22, x1 | |
438624e0 A |
121 | ldr x8, [x21, JMP_sig] // restore the signal mask |
122 | str x8, [sp, #8] | |
ada7c492 | 123 | orr w0, wzr, #0x3 // SIG_SETMASK |
438624e0 A |
124 | add x1, sp, #8 // set |
125 | mov x2, #0 // oset | |
ada7c492 A |
126 | CALL_EXTERNAL(_sigprocmask) |
127 | mov x0, x21 | |
128 | mov x1, x22 | |
129 | add sp, sp, #16 | |
130 | b __longjmp |