1 /* Modify saved context.
2 Copyright (C) 2009-2018 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 makecontext (ucontext_t *ucp, (void *func) (), int argc, ...) */
35 LOCALSZ = 1 /* save gp */
37 #if _MIPS_SIM != _ABIO32
38 ARGSZ = 5 /* save a3-a7 */
43 FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
44 GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
45 #if _MIPS_SIM != _ABIO32
46 A3OFF = FRAMESZ - (5 * SZREG) /* callee-allocated */
47 A4OFF = FRAMESZ - (4 * SZREG)
48 A5OFF = FRAMESZ - (3 * SZREG)
49 A6OFF = FRAMESZ - (2 * SZREG)
50 A7OFF = FRAMESZ - (1 * SZREG)
53 A3OFF = FRAMESZ + (3 * SZREG) /* caller-allocated */
57 #if _MIPS_SIM == _ABIO32 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
63 NESTED (__makecontext, FRAMESZ, ra)
64 .mask MASK, -(ARGSZ * SZREG)
72 PTR_ADDIU sp, -FRAMESZ
73 cfi_adjust_cfa_offset (FRAMESZ)
76 SETUP_GP64_STACK (GPOFF, __makecontext)
87 /* Store args to be passed. */
89 #if _MIPS_SIM != _ABIO32
96 /* Store a magic flag. */
99 REG_S v1, (MCONTEXT_GREGOFF + 0 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
101 /* Set up the stack. */
102 PTR_L t0, STACK_SP(a0)
103 PTR_L t2, STACK_SIZE(a0)
104 PTR_ADDIU t1, sp, A3OFF
107 blez a2, 2f /* no arguments */
109 /* Store register arguments. */
110 PTR_ADDIU t2, a0, MCONTEXT_GREGS + 4 * MCONTEXT_GREGSZ + MCONTEXT_GREGOFF
117 PTR_ADDIU t2, MCONTEXT_GREGSZ
118 bgeu t3, a2, 2f /* all done */
119 bltu t3, NARGREGS, 0b /* next */
121 /* Make room for stack arguments. */
127 /* Store stack arguments. */
135 bltu t3, a2, 1b /* next */
138 #if _MIPS_SIM == _ABIO32
139 /* Make room for a0-a3 storage. */
140 PTR_ADDIU t0, -(NARGSAVE * SZREG)
142 PTR_L v1, UCONTEXT_LINK(a0)
144 PTR_ADDIU t9, 99f - 98b
149 REG_S t0, (MCONTEXT_GREGOFF + 29 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
151 REG_S v1, (MCONTEXT_GREGOFF + 16 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
154 REG_S gp, (MCONTEXT_GREGOFF + 17 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
157 REG_S t9, (MCONTEXT_GREGOFF + 31 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
158 REG_S a1, (MCONTEXT_GREGOFF + MCONTEXT_PC)(a0)
162 PTR_ADDIU sp, FRAMESZ
163 cfi_adjust_cfa_offset (-FRAMESZ)
167 /* We need to terminate the FDE to stop unwinding if backtrace was
168 called within a context created by makecontext. */
179 /* setcontext (ucp) */
182 PTR_LA t9, JUMPTARGET (__setcontext)
184 # if _MIPS_SIM == _ABIO32
188 jal JUMPTARGET (__setcontext)
195 PTR_LA t9, HIDDEN_JUMPTARGET (exit)
198 jal HIDDEN_JUMPTARGET (exit)
201 /* You don't exist, you won't feel anything. */
207 PSEUDO_END (__makecontext)
209 weak_alias (__makecontext, makecontext)