1 /* 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 setcontext (const ucontext_t *ucp) */
35 LOCALSZ = 1 /* save gp */
37 #if _MIPS_SIM != _ABIO32
38 ARGSZ = 1 /* save a0 */
43 FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
44 GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
45 #if _MIPS_SIM != _ABIO32
46 A0OFF = FRAMESZ - (1 * SZREG) /* callee-allocated */
48 A0OFF = FRAMESZ + (0 * SZREG) /* caller-allocated */
51 #if _MIPS_SIM == _ABIO32 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
57 NESTED (__setcontext, FRAMESZ, ra)
58 .mask MASK, -(ARGSZ * SZREG)
65 PTR_ADDIU sp, -FRAMESZ
66 cfi_adjust_cfa_offset (FRAMESZ)
69 SETUP_GP64_STACK (GPOFF, __setcontext)
80 /* Check for the magic flag. */
83 REG_L v1, (MCONTEXT_GREGOFF + 0 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
88 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
91 PTR_ADDU a1, a0, UCONTEXT_SIGMASK
94 li v0, SYS_ify (rt_sigprocmask)
100 #ifdef __mips_hard_float
101 # if _MIPS_SIM == _ABI64
102 l.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(v0)
103 l.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(v0)
104 l.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(v0)
105 l.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(v0)
106 l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
107 l.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(v0)
108 l.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(v0)
109 l.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(v0)
111 # else /* _MIPS_SIM != _ABI64 */
112 l.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(v0)
113 l.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(v0)
114 l.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(v0)
115 l.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(v0)
116 l.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
117 l.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(v0)
119 # endif /* _MIPS_SIM != _ABI64 */
121 lw v1, MCONTEXT_FPC_CSR(v0)
123 #endif /* __mips_hard_float */
125 /* Note the contents of argument registers will be random
126 unless makecontext() has been called. */
127 REG_L a0, (MCONTEXT_GREGOFF + 4 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
128 REG_L a1, (MCONTEXT_GREGOFF + 5 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
129 REG_L a2, (MCONTEXT_GREGOFF + 6 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
130 REG_L a3, (MCONTEXT_GREGOFF + 7 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
131 #if _MIPS_SIM != _ABIO32
132 REG_L a4, (MCONTEXT_GREGOFF + 8 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
133 REG_L a5, (MCONTEXT_GREGOFF + 9 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
134 REG_L a6, (MCONTEXT_GREGOFF + 10 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
135 REG_L a7, (MCONTEXT_GREGOFF + 11 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
138 REG_L s0, (MCONTEXT_GREGOFF + 16 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
139 REG_L s1, (MCONTEXT_GREGOFF + 17 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
140 REG_L s2, (MCONTEXT_GREGOFF + 18 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
141 REG_L s3, (MCONTEXT_GREGOFF + 19 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
142 REG_L s4, (MCONTEXT_GREGOFF + 20 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
143 REG_L s5, (MCONTEXT_GREGOFF + 21 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
144 REG_L s6, (MCONTEXT_GREGOFF + 22 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
145 REG_L s7, (MCONTEXT_GREGOFF + 23 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
146 #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
147 REG_L gp, (MCONTEXT_GREGOFF + 28 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
149 REG_L sp, (MCONTEXT_GREGOFF + 29 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
150 REG_L fp, (MCONTEXT_GREGOFF + 30 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
151 REG_L ra, (MCONTEXT_GREGOFF + 31 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(v0)
152 REG_L t9, (MCONTEXT_GREGOFF + MCONTEXT_PC)(v0)
158 /* This is a context obtained from a signal handler.
159 Perform a full restore by pushing the context
160 passed onto a simulated signal frame on the stack
161 and call the signal return syscall as if a signal
162 handler exited normally. */
163 PTR_ADDIU sp, -((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
164 cfi_adjust_cfa_offset ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
166 /* Only ucontext is referred to from rt_sigreturn,
168 PTR_ADDIU t1, sp, RT_SIGFRAME_UCONTEXT
169 li t3, ((UCONTEXT_SIZE + SZREG - 1) / SZREG) - 1
180 /* rt_sigreturn () -- no arguments, sp points to struct rt_sigframe. */
181 li v0, SYS_ify (rt_sigreturn)
184 /* Restore the stack and fall through to the error
185 path. Successful rt_sigreturn never returns to
186 its calling place. */
187 PTR_ADDIU sp, ((RT_SIGFRAME_SIZE + ALSZ) & ALMASK)
188 cfi_adjust_cfa_offset (-((RT_SIGFRAME_SIZE + ALSZ) & ALMASK))
191 PTR_LA t9, JUMPTARGET (__syscall_error)
193 PTR_ADDIU sp, FRAMESZ
194 cfi_adjust_cfa_offset (-FRAMESZ)
197 #else /* ! __PIC__ */
199 j JUMPTARGET (__syscall_error)
200 #endif /* ! __PIC__ */
201 PSEUDO_END (__setcontext)
203 weak_alias (__setcontext, setcontext)