1 /* Modify saved context.
2 Copyright (C) 2009-2014 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 NESTED (__makecontext, FRAMESZ, ra)
58 .mask MASK, -(ARGSZ * SZREG)
66 PTR_ADDIU sp, -FRAMESZ
67 cfi_adjust_cfa_offset (FRAMESZ)
70 SETUP_GP64_STACK (GPOFF, __makecontext)
81 /* Store args to be passed. */
83 #if _MIPS_SIM != _ABIO32
90 /* Store a magic flag. */
92 REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
94 /* Set up the stack. */
95 PTR_L t0, STACK_SP(a0)
96 PTR_L t2, STACK_SIZE(a0)
97 PTR_ADDIU t1, sp, A3OFF
100 blez a2, 2f /* no arguments */
102 /* Store register arguments. */
103 PTR_ADDIU t2, a0, MCONTEXT_GREGS + 4 * SZREG
111 bgeu t3, a2, 2f /* all done */
112 bltu t3, NARGREGS, 0b /* next */
114 /* Make room for stack arguments. */
120 /* Store stack arguments. */
128 bltu t3, a2, 1b /* next */
131 #if _MIPS_SIM == _ABIO32
132 /* Make room for a0-a3 storage. */
133 PTR_ADDIU t0, -(NARGSAVE * SZREG)
135 PTR_L v1, UCONTEXT_LINK(a0)
137 PTR_ADDIU t9, 99f - 98b
141 REG_S t0, (29 * SZREG + MCONTEXT_GREGS)(a0) /* sp */
142 REG_S v1, (16 * SZREG + MCONTEXT_GREGS)(a0) /* s0 */
144 REG_S gp, (17 * SZREG + MCONTEXT_GREGS)(a0) /* s1 */
146 REG_S t9, (31 * SZREG + MCONTEXT_GREGS)(a0) /* ra */
147 REG_S a1, MCONTEXT_PC(a0)
151 PTR_ADDIU sp, FRAMESZ
152 cfi_adjust_cfa_offset (-FRAMESZ)
163 /* setcontext (ucp) */
166 PTR_LA t9, JUMPTARGET (__setcontext)
168 # if _MIPS_SIM == _ABIO32
172 jal JUMPTARGET (__setcontext)
179 PTR_LA t9, HIDDEN_JUMPTARGET (exit)
182 jal HIDDEN_JUMPTARGET (exit)
185 /* You don't exist, you won't feel anything. */
189 PSEUDO_END (__makecontext)
191 weak_alias (__makecontext, makecontext)