]>
Commit | Line | Data |
---|---|---|
554066b8 MS |
1 | /* Set current context. |
2 | ||
b168057a | 3 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
554066b8 MS |
4 | |
5 | This file is part of the GNU C Library. | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Lesser General Public License as | |
9 | published by the Free Software Foundation; either version 2.1 of the | |
10 | License, or (at your option) any later version. | |
11 | ||
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public | |
18 | License along with the GNU C Library; if not, see | |
19 | <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include <sysdep.h> | |
22 | #include "ucontext_i.h" | |
23 | #include "ucontext-internal.h" | |
24 | ||
37d35007 | 25 | /* int __setcontext (const ucontext_t *ucp) |
554066b8 | 26 | |
37d35007 WN |
27 | Restores the machine context in UCP and thereby resumes execution |
28 | in that context. | |
554066b8 | 29 | |
37d35007 WN |
30 | This implementation is intended to be used for *synchronous* context |
31 | switches only. Therefore, it does not have to restore anything | |
32 | other than the PRESERVED state. */ | |
554066b8 | 33 | |
37d35007 | 34 | .text |
554066b8 | 35 | |
37d35007 WN |
36 | ENTRY (__setcontext) |
37 | /* Save a copy of UCP. */ | |
38 | mov x9, x0 | |
39 | ||
40 | /* Set the signal mask with | |
41 | rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8). */ | |
42 | mov x0, #SIG_SETMASK | |
43 | add x1, x9, #UCONTEXT_SIGMASK | |
44 | mov x2, #0 | |
45 | mov x3, #_NSIG8 | |
46 | mov x8, SYS_ify (rt_sigprocmask) | |
554066b8 | 47 | svc 0 |
37d35007 WN |
48 | cbz x0, 1f |
49 | b C_SYMBOL_NAME (__syscall_error) | |
50 | 1: | |
51 | /* Restore the general purpose registers. */ | |
52 | mov x0, x9 | |
53 | cfi_def_cfa (x0, 0) | |
54 | cfi_offset (x18, oX0 + 18 * SZREG) | |
55 | cfi_offset (x19, oX0 + 19 * SZREG) | |
56 | cfi_offset (x20, oX0 + 20 * SZREG) | |
57 | cfi_offset (x21, oX0 + 21 * SZREG) | |
58 | cfi_offset (x22, oX0 + 22 * SZREG) | |
59 | cfi_offset (x23, oX0 + 23 * SZREG) | |
60 | cfi_offset (x24, oX0 + 24 * SZREG) | |
61 | cfi_offset (x25, oX0 + 25 * SZREG) | |
62 | cfi_offset (x26, oX0 + 26 * SZREG) | |
63 | cfi_offset (x27, oX0 + 27 * SZREG) | |
64 | cfi_offset (x28, oX0 + 28 * SZREG) | |
65 | cfi_offset (x29, oX0 + 29 * SZREG) | |
66 | cfi_offset (x30, oX0 + 30 * SZREG) | |
67 | ||
68 | cfi_offset ( d8, oV0 + 8 * SZVREG) | |
69 | cfi_offset ( d9, oV0 + 9 * SZVREG) | |
70 | cfi_offset (d10, oV0 + 10 * SZVREG) | |
71 | cfi_offset (d11, oV0 + 11 * SZVREG) | |
72 | cfi_offset (d12, oV0 + 12 * SZVREG) | |
73 | cfi_offset (d13, oV0 + 13 * SZVREG) | |
74 | cfi_offset (d14, oV0 + 14 * SZVREG) | |
75 | cfi_offset (d15, oV0 + 15 * SZVREG) | |
76 | ldp x18, x19, [x0, oX0 + 18 * SZREG] | |
77 | ldp x20, x21, [x0, oX0 + 20 * SZREG] | |
78 | ldp x22, x23, [x0, oX0 + 22 * SZREG] | |
79 | ldp x24, x25, [x0, oX0 + 24 * SZREG] | |
80 | ldp x26, x27, [x0, oX0 + 26 * SZREG] | |
81 | ldp x28, x29, [x0, oX0 + 28 * SZREG] | |
82 | ldr x30, [x0, oX0 + 30 * SZREG] | |
83 | ldr x2, [x0, oSP] | |
84 | mov sp, x2 | |
85 | ||
86 | /* Check for FP SIMD context. We don't support restoring | |
87 | contexts created by the kernel, so this context must have | |
88 | been created by getcontext. Hence we can rely on the | |
89 | first extension block being the FP SIMD context. */ | |
90 | add x2, x0, #oEXTENSION | |
91 | ||
92 | mov w3, #(FPSIMD_MAGIC & 0xffff) | |
93 | movk w3, #(FPSIMD_MAGIC >> 16), lsl #16 | |
94 | ldr w1, [x2, #oHEAD + oMAGIC] | |
95 | cmp w1, w3 | |
96 | b.ne 2f | |
97 | ||
98 | /* Restore the FP SIMD context. */ | |
99 | add x3, x2, #oV0 + 8 * SZVREG | |
100 | ldp d8, d9, [x3], #2 * SZVREG | |
101 | ldp d10, d11, [x3], #2 * SZVREG | |
102 | ldp d12, d13, [x3], #2 * SZVREG | |
103 | ldp d14, d15, [x3], #2 * SZVREG | |
104 | ||
105 | add x3, x2, oFPSR | |
106 | ||
107 | ldr w4, [x3] | |
108 | msr fpsr, x4 | |
109 | ||
110 | ldr w4, [x3, oFPCR - oFPSR] | |
111 | msr fpcr, x4 | |
112 | ||
113 | 2: | |
114 | ldr x16, [x0, oPC] | |
115 | /* Restore arg registers. */ | |
116 | ldp x2, x3, [x0, oX0 + 2 * SZREG] | |
117 | ldp x4, x5, [x0, oX0 + 4 * SZREG] | |
118 | ldp x6, x7, [x0, oX0 + 6 * SZREG] | |
119 | ldp x0, x1, [x0, oX0 + 0 * SZREG] | |
120 | /* Jump to the new pc value. */ | |
121 | br x16 | |
554066b8 MS |
122 | PSEUDO_END (__setcontext) |
123 | weak_alias (__setcontext, setcontext) | |
124 | ||
37d35007 | 125 | ENTRY (__startcontext) |
554066b8 MS |
126 | mov x0, x19 |
127 | cbnz x0, __setcontext | |
c92d40c0 | 128 | 1: b HIDDEN_JUMPTARGET (exit) |
37d35007 | 129 | END (__startcontext) |