1 /* Set up a context to call a function.
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <shlib-compat.h>
24 #include <asm/ptrace.h>
25 #include "ucontext_i.h"
28 /* Set up the first 7 args to the function in its registers */
29 addi r11,r3,_UC_REG_SPACE+12
31 stw r11,_UC_REGS_PTR(r3)
32 stw r6,_UC_GREGS+(PT_R3*4)(r11)
33 stw r7,_UC_GREGS+(PT_R4*4)(r11)
34 stw r8,_UC_GREGS+(PT_R5*4)(r11)
35 stw r9,_UC_GREGS+(PT_R6*4)(r11)
36 stw r10,_UC_GREGS+(PT_R7*4)(r11)
39 stw r8,_UC_GREGS+(PT_R8*4)(r11)
40 stw r9,_UC_GREGS+(PT_R9*4)(r11)
42 /* Set the NIP to the start of the function */
43 stw r4,_UC_GREGS+(PT_NIP*4)(r11)
45 /* Set the function's r31 to ucp->uc_link for the exitcode below. */
47 stw r7,_UC_GREGS+(PT_R31*4)(r11)
49 /* Set the function's LR to point to the exitcode below. */
54 addi r6,r6,L(exitcode)-1b
58 addi r6,r6,L(exitcode)@l
60 stw r6,_UC_GREGS+(PT_LNK*4)(r11)
63 * Set up the stack frame for the function.
64 * If we have more than 5 args to the function (8 args to makecontext),
65 * there will be some arguments on the stack which have to end up
66 * in registers. If there are more than 8 args to the function,
67 * we have to copy (argc - 8) args from our stack to the functions'
68 * stack (and allow space for them in the frame).
70 lwz r4,_UC_STACK_SP(r3)
71 lwz r8,_UC_STACK_SIZE(r3)
73 rlwinm r4,r4,0,0,27 /* round down to 16-byte boundary */
74 addi r7,r4,-16 /* stack frame for fn's caller */
76 blt 2f /* less than 8 args is easy */
78 stw r10,_UC_GREGS+(PT_R10*4)(r11)
79 beq 2f /* if exactly 8 args */
84 mtctr r5 /* copy the 9th and following args */
90 2: stw r7,_UC_GREGS+(PT_R1*4)(r11)
97 * If the function returns, it comes here. We put ucp->uc_link in
98 * r31, which is a callee-saved register. We have to continue with
99 * the context that r31 points to, or exit if it is 0.
104 bl JUMPTARGET(__setcontext)
105 4: bl HIDDEN_JUMPTARGET(exit)
110 versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_4)
112 #if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
115 ENTRY(__novec_makecontext)
116 /* Set up the first 7 args to the function in its registers */
117 addi r11,r3,_UC_REG_SPACE
118 stw r11,_UC_REGS_PTR(r3)
119 stw r6,_UC_GREGS+(PT_R3*4)(r11)
120 stw r7,_UC_GREGS+(PT_R4*4)(r11)
121 stw r8,_UC_GREGS+(PT_R5*4)(r11)
122 stw r9,_UC_GREGS+(PT_R6*4)(r11)
123 stw r10,_UC_GREGS+(PT_R7*4)(r11)
126 stw r8,_UC_GREGS+(PT_R8*4)(r11)
127 stw r9,_UC_GREGS+(PT_R9*4)(r11)
129 /* Set the NIP to the start of the function */
130 stw r4,_UC_GREGS+(PT_NIP*4)(r11)
132 /* Set the function's r31 to ucp->uc_link for the exitcode below. */
134 stw r7,_UC_GREGS+(PT_R31*4)(r11)
136 /* Set the function's LR to point to the exitcode below. */
141 addi r6,r6,L(novec_exitcode)-1b
144 lis r6,L(novec_exitcode)@ha
145 addi r6,r6,L(novec_exitcode)@l
147 stw r6,_UC_GREGS+(PT_LNK*4)(r11)
150 * Set up the stack frame for the function.
151 * If we have more than 5 args to the function (8 args to makecontext),
152 * there will be some arguments on the stack which have to end up
153 * in registers. If there are more than 8 args to the function,
154 * we have to copy (argc - 8) args from our stack to the functions'
155 * stack (and allow space for them in the frame).
157 lwz r4,_UC_STACK_SP(r3)
158 lwz r8,_UC_STACK_SIZE(r3)
160 rlwinm r4,r4,0,0,27 /* round down to 16-byte boundary */
161 addi r7,r4,-16 /* stack frame for fn's caller */
163 blt 2f /* less than 8 args is easy */
165 stw r10,_UC_GREGS+(PT_R10*4)(r11)
166 beq 2f /* if exactly 8 args */
171 mtctr r5 /* copy the 9th and following args */
177 2: stw r7,_UC_GREGS+(PT_R1*4)(r11)
184 * If the function returns, it comes here. We put ucp->uc_link in
185 * r31, which is a callee-saved register. We have to continue with
186 * the context that r31 points to, or exit if it is 0.
191 bl JUMPTARGET(__novec_setcontext)
192 4: bl HIDDEN_JUMPTARGET(exit)
195 END(__novec_makecontext)
198 compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3)
201 #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
204 #include <bits/errno.h>
207 ENTRY (__makecontext_stub)
209 b JUMPTARGET(__syscall_error)
210 END (__makecontext_stub)
213 compat_symbol (libc, __makecontext_stub, makecontext, GLIBC_2_1)