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 "kernel-features.h"
24 #include <asm/ptrace.h>
25 #include "ucontext_i.h"
26 #include <asm/errno.h>
30 #ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL
31 /* Save parameters into the parameter save area of callers frame. */
32 std r3,FRAME_PARM1_SAVE(r1) /* ucontext_t *ucp */
33 std r4,FRAME_PARM2_SAVE(r1) /* void (*func)(void) */
34 std r5,FRAME_PARM3_SAVE(r1) /* int argc */
35 std r6,FRAME_PARM4_SAVE(r1) /* ... */
36 std r7,FRAME_PARM5_SAVE(r1)
37 std r8,FRAME_PARM6_SAVE(r1)
38 std r9,FRAME_PARM7_SAVE(r1)
39 std r10,FRAME_PARM8_SAVE(r1)
41 /* Get the address of the target functions first parameter. */
42 addi r6,r1,FRAME_PARM4_SAVE
43 std r0,FRAME_LR_SAVE(r1)
46 /* Get the ucontexts stack pointer and size. Compute the top of stack
47 and round down to a quadword boundary. Then stack a dummy frame
48 with a null back chain. We store the context pointer in the frames
49 "compiler double word" field so we can recover if is the function
50 returns. Finally save the callers link register and TOC pointer
51 into this frame so the debugger can display a backtrace.
53 ld r7,UCONTEXT_STACK_SP(r3)
54 ld r0,UCONTEXT_STACK_SIZE(r3)
59 std r3,FRAME_PARM1_SAVE(r7) /* Store context in dummy parm1. */
61 std r2,FRAME_TOC_SAVE(r7) /* Store the TOC pointer for later. */
62 std r0,FRAME_LR_SAVE(r7)
64 /* Now we need to stack another frame to hold the parameter save area
65 for the function. We need to allocate a frame with the minimum 48
66 byte header and 8 parameter register. However if there are more
67 than 8 parameters addition space is need to hold all the parameters.
68 The total size it rounded up to a quadword multiple then a frame is
69 stacked. This address is stored in the ucontext as GPR 1. */
76 addi r8,r8,FRAME_PARM_SAVE+8 /* Add header plus rounding factor. */
77 clrrdi r8,r8,4 /* Round down to quadword. */
80 std r7,0(r8) /* Stack the frame. */
81 std r8,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
83 /* Now we need to copy the target functions parameters. The functions
84 parameters are saved in the parameter save area. We skip over the
85 first three parameters and copy up to 8 double word into the
86 SIGCONTEXT_GP_REGS starting with R3. If there are more than 8
87 parameters then doublewords 8-N are copied into the parameter
88 save area of the context frame. */
97 addi r9,r3,(SIGCONTEXT_GP_REGS+(PT_R3*8)-8)
106 addi r9,r8,FRAME_PARM9_SAVE-8
114 /* Load the function address and TOC from the function descriptor
115 and store them in the ucontext as NIP and r2. Store the 3rd
116 field of the function descriptor into the ucontext as r11 in case
117 the calling language needs the "environment pointer". */
121 std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
122 std r10,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
123 std r9,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
125 /* If the target function returns we need to do some cleanup. We use a
126 code trick to get the address of our cleanup function into the link
127 register. Do not add any code between here and L(exitcode). */
128 bl L(gotexitcodeaddr);
130 /* This is the helper code which gets called if a function which
131 is registered with 'makecontext' returns. In this case we
132 have to install the context listed in the uc_link element of
133 the context 'makecontext' manipulated at the time of the
134 'makecontext' call. If the pointer is NULL the process must
137 /* Recover the ucontext and TOC from the dummy frame. */
138 ld r1,FRAME_BACKCHAIN(r1) /* Unstack the parameter save area frame. */
139 ld r3,FRAME_PARM1_SAVE(r1)
140 ld r2,FRAME_TOC_SAVE(r1)
141 ld r3,UCONTEXT_LINK(r3) /* Load the resume context. */
144 bl JUMPTARGET(__setcontext)
148 /* If setcontext returns (which can happen if the syscall fails) we will
149 exit the program with error status (-1). */
152 b JUMPTARGET(__GI_exit);
157 /* The address of the exit code is in the link register. Store the lr
158 in the ucontext as LNK so the target function will return to our
162 std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
163 ld r0,128+FRAME_LR_SAVE(r1)
168 /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
170 std r0,FRAME_LR_SAVE(r1)
173 bl JUMPTARGET(__syscall_error)
176 ld r0,128+FRAME_LR_SAVE(r1)
183 weak_alias(__makecontext, makecontext)