1 /* Save and set current context.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Maciej W. Rozycki <macro@codesourcery.com>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
22 #include <sys/fpregdef.h>
23 #include <sys/regdef.h>
25 #include "ucontext_i.h"
27 /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
35 LOCALSZ = 1 /* save gp */
37 #if _MIPS_SIM != _ABIO32
38 ARGSZ = 1 /* save a1 */
43 FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
44 GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
45 #if _MIPS_SIM != _ABIO32
46 A1OFF = FRAMESZ - (1 * SZREG) /* callee-allocated */
48 A1OFF = FRAMESZ + (1 * SZREG) /* caller-allocated */
51 #if _MIPS_SIM == _ABIO32 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
57 NESTED (__swapcontext, FRAMESZ, ra)
58 .mask MASK, -(ARGSZ * SZREG)
67 # if _MIPS_SIM != _ABIO32
72 PTR_ADDIU sp, -FRAMESZ
73 cfi_adjust_cfa_offset (FRAMESZ)
74 SETUP_GP64_STACK (GPOFF, __swapcontext)
81 #endif /* ! __PIC__ */
90 /* Store a magic flag. */
93 REG_S v1, (MCONTEXT_GREGOFF + 0 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
95 REG_S s0, (MCONTEXT_GREGOFF + 16 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
96 REG_S s1, (MCONTEXT_GREGOFF + 17 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
97 REG_S s2, (MCONTEXT_GREGOFF + 18 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
98 REG_S s3, (MCONTEXT_GREGOFF + 19 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
99 REG_S s4, (MCONTEXT_GREGOFF + 20 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
100 REG_S s5, (MCONTEXT_GREGOFF + 21 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
101 REG_S s6, (MCONTEXT_GREGOFF + 22 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
102 REG_S s7, (MCONTEXT_GREGOFF + 23 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
103 #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
104 REG_S _GP, (MCONTEXT_GREGOFF + 28 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
106 REG_S _SP, (MCONTEXT_GREGOFF + 29 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
107 REG_S fp, (MCONTEXT_GREGOFF + 30 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
108 REG_S ra, (MCONTEXT_GREGOFF + 31 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
109 REG_S ra, (MCONTEXT_GREGOFF + MCONTEXT_PC)(a0)
111 #ifdef __mips_hard_float
112 # if _MIPS_SIM == _ABI64
113 s.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
114 s.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
115 s.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
116 s.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
117 s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
118 s.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
119 s.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
120 s.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
122 # else /* _MIPS_SIM != _ABI64 */
123 s.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
124 s.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
125 s.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
126 s.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
127 s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
128 s.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
130 # endif /* _MIPS_SIM != _ABI64 */
133 sw v1, MCONTEXT_FPC_CSR(a0)
134 #endif /* __mips_hard_float */
138 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
140 PTR_ADDU a2, a0, UCONTEXT_SIGMASK
141 PTR_ADDU a1, a1, UCONTEXT_SIGMASK
144 li v0, SYS_ify (rt_sigprocmask)
150 #ifdef __mips_hard_float
151 # if _MIPS_SIM == _ABI64
152 l.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(v0)
153 l.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(v0)
154 l.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(v0)
155 l.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(v0)
156 l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
157 l.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(v0)
158 l.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(v0)
159 l.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(v0)
161 # else /* _MIPS_SIM != _ABI64 */
162 l.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(v0)
163 l.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(v0)
164 l.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(v0)
165 l.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(v0)
166 l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
167 l.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(v0)
169 # endif /* _MIPS_SIM != _ABI64 */
171 lw v1, MCONTEXT_FPC_CSR(v0)
173 #endif /* __mips_hard_float */
175 /* Note the contents of argument registers will be random
176 unless makecontext() has been called. */
177 REG_L a0, (MCONTEXT_GREGOFF + 4 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
178 REG_L a1, (MCONTEXT_GREGOFF + 5 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
179 REG_L a2, (MCONTEXT_GREGOFF + 6 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
180 REG_L a3, (MCONTEXT_GREGOFF + 7 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
181 #if _MIPS_SIM != _ABIO32
182 REG_L a4, (MCONTEXT_GREGOFF + 8 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
183 REG_L a5, (MCONTEXT_GREGOFF + 9 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
184 REG_L a6, (MCONTEXT_GREGOFF + 10 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
185 REG_L a7, (MCONTEXT_GREGOFF + 11 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
188 REG_L s0, (MCONTEXT_GREGOFF + 16 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
189 REG_L s1, (MCONTEXT_GREGOFF + 17 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
190 REG_L s2, (MCONTEXT_GREGOFF + 18 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
191 REG_L s3, (MCONTEXT_GREGOFF + 19 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
192 REG_L s4, (MCONTEXT_GREGOFF + 20 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
193 REG_L s5, (MCONTEXT_GREGOFF + 21 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
194 REG_L s6, (MCONTEXT_GREGOFF + 22 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
195 REG_L s7, (MCONTEXT_GREGOFF + 23 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
196 #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
197 REG_L gp, (MCONTEXT_GREGOFF + 28 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
199 REG_L sp, (MCONTEXT_GREGOFF + 29 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
200 REG_L fp, (MCONTEXT_GREGOFF + 30 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
201 REG_L ra, (MCONTEXT_GREGOFF + 31 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
202 REG_L t9, (MCONTEXT_GREGOFF + MCONTEXT_PC)(v0)
209 PTR_LA t9, JUMPTARGET (__syscall_error)
211 PTR_ADDIU sp, FRAMESZ
212 cfi_adjust_cfa_offset (-FRAMESZ)
215 #else /* ! __PIC__ */
217 j JUMPTARGET (__syscall_error)
218 #endif /* ! __PIC__ */
219 PSEUDO_END (__swapcontext)
221 weak_alias (__swapcontext, swapcontext)