1 /* Modify saved context.
2 Copyright (C) 2009 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, ...) */
34 LOCALSZ = 1 /* save gp */
36 #if _MIPS_SIM != _ABIO32
37 ARGSZ = 5 /* save a3-a7 */
42 FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
43 GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
44 #if _MIPS_SIM != _ABIO32
45 A3OFF = FRAMESZ - (5 * SZREG) /* callee-allocated */
46 A4OFF = FRAMESZ - (4 * SZREG)
47 A5OFF = FRAMESZ - (3 * SZREG)
48 A6OFF = FRAMESZ - (2 * SZREG)
49 A7OFF = FRAMESZ - (1 * SZREG)
52 A3OFF = FRAMESZ + (3 * SZREG) /* caller-allocated */
56 NESTED (__makecontext, FRAMESZ, ra)
57 .mask MASK, -(ARGSZ * SZREG)
65 PTR_ADDIU sp, -FRAMESZ
68 SETUP_GP64 (GPOFF, __makecontext)
79 /* Store args to be passed. */
81 #if _MIPS_SIM != _ABIO32
88 /* Store a magic flag. */
90 REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
92 /* Set up the stack. */
93 PTR_L t0, STACK_SP(a0)
94 PTR_L t2, STACK_SIZE(a0)
95 PTR_ADDIU t1, sp, A3OFF
98 blez a2, 2f /* no arguments */
100 /* Store register arguments. */
101 PTR_ADDIU t2, a0, MCONTEXT_GREGS + 4 * SZREG
109 bgeu t3, a2, 2f /* all done */
110 bltu t3, NARGREGS, 0b /* next */
112 /* Make room for stack arguments. */
118 /* Store stack arguments. */
126 bltu t3, a2, 1b /* next */
129 #if _MIPS_SIM == _ABIO32
130 /* Make room for a0-a3 storage. */
131 PTR_ADDIU t0, -(NARGSAVE * SZREG)
133 PTR_L v1, UCONTEXT_LINK(a0)
135 PTR_ADDIU t9, 99f - 98b
139 REG_S t0, (29 * SZREG + MCONTEXT_GREGS)(a0) /* sp */
140 REG_S v1, (16 * SZREG + MCONTEXT_GREGS)(a0) /* s0 */
142 REG_S gp, (17 * SZREG + MCONTEXT_GREGS)(a0) /* s1 */
144 REG_S t9, (31 * SZREG + MCONTEXT_GREGS)(a0) /* ra */
145 REG_S a1, MCONTEXT_PC(a0)
149 PTR_ADDIU sp, FRAMESZ
160 /* setcontext (ucp) */
163 PTR_LA t9, JUMPTARGET (__setcontext)
165 # if _MIPS_SIM == _ABIO32
169 jal JUMPTARGET (__setcontext)
176 PTR_LA t9, HIDDEN_JUMPTARGET (exit)
179 jal HIDDEN_JUMPTARGET (exit)
182 /* You don't exist, you won't feel anything. */
186 PSEUDO_END (__makecontext)
188 weak_alias (__makecontext, makecontext)