2 Copyright (C) 2002, 2004, 2006 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., 51 Franklin Street, Fifth Floor, 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)
44 cfi_offset (lr, FRAME_LR_SAVE)
46 cfi_adjust_cfa_offset (128)
48 /* Get the ucontexts stack pointer and size. Compute the top of stack
49 and round down to a quadword boundary. Then stack a dummy frame
50 with a null back chain. We store the context pointer in the frames
51 "compiler double word" field so we can recover if is the function
52 returns. Finally save the callers link register and TOC pointer
53 into this frame so the debugger can display a backtrace.
55 ld r7,UCONTEXT_STACK_SP(r3)
56 ld r0,UCONTEXT_STACK_SIZE(r3)
61 std r3,FRAME_PARM1_SAVE(r7) /* Store context in dummy parm1. */
63 std r2,FRAME_TOC_SAVE(r7) /* Store the TOC pointer for later. */
64 std r0,FRAME_LR_SAVE(r7)
66 /* Now we need to stack another frame to hold the parameter save area
67 for the function. We need to allocate a frame with the minimum 48
68 byte header and 8 parameter register. However if there are more
69 than 8 parameters addition space is need to hold all the parameters.
70 The total size it rounded up to a quadword multiple then a frame is
71 stacked. This address is stored in the ucontext as GPR 1. */
78 addi r8,r8,FRAME_PARM_SAVE+8 /* Add header plus rounding factor. */
79 clrrdi r8,r8,4 /* Round down to quadword. */
82 std r7,0(r8) /* Stack the frame. */
83 std r8,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
85 /* Now we need to copy the target functions parameters. The functions
86 parameters are saved in the parameter save area. We skip over the
87 first three parameters and copy up to 8 double word into the
88 SIGCONTEXT_GP_REGS starting with R3. If there are more than 8
89 parameters then doublewords 8-N are copied into the parameter
90 save area of the context frame. */
99 addi r9,r3,(SIGCONTEXT_GP_REGS+(PT_R3*8)-8)
108 addi r9,r8,FRAME_PARM9_SAVE-8
116 /* Load the function address and TOC from the function descriptor
117 and store them in the ucontext as NIP and r2. Store the 3rd
118 field of the function descriptor into the ucontext as r11 in case
119 the calling language needs the "environment pointer". */
123 std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)
124 std r10,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3)
125 std r9,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
127 /* If the target function returns we need to do some cleanup. We use a
128 code trick to get the address of our cleanup function into the link
129 register. Do not add any code between here and L(exitcode). */
130 bl L(gotexitcodeaddr);
132 /* This is the helper code which gets called if a function which
133 is registered with 'makecontext' returns. In this case we
134 have to install the context listed in the uc_link element of
135 the context 'makecontext' manipulated at the time of the
136 'makecontext' call. If the pointer is NULL the process must
139 /* Recover the ucontext and TOC from the dummy frame. */
140 ld r1,FRAME_BACKCHAIN(r1) /* Unstack the parameter save area frame. */
141 ld r3,FRAME_PARM1_SAVE(r1)
142 ld r2,FRAME_TOC_SAVE(r1)
143 ld r3,UCONTEXT_LINK(r3) /* Load the resume context. */
146 bl JUMPTARGET(__setcontext)
150 /* If setcontext returns (which can happen if the syscall fails) we will
151 exit the program with error status (-1). */
154 b JUMPTARGET(__GI_exit);
159 /* The address of the exit code is in the link register. Store the lr
160 in the ucontext as LNK so the target function will return to our
164 std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
165 ld r0,128+FRAME_LR_SAVE(r1)
170 /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */
172 std r0,FRAME_LR_SAVE(r1)
173 cfi_offset (lr, FRAME_LR_SAVE)
175 cfi_adjust_cfa_offset (128)
177 bl JUMPTARGET(__syscall_error)
180 ld r0,128+FRAME_LR_SAVE(r1)
187 weak_alias (__makecontext, makecontext)