* elf/tst-tls8.c (do_test): Use $ORIGIN in module names.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / makecontext.S
blob208a375ef3d1e54da347689f97c96b1606359fe2
1 /* Set up a context to call a function.
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
18    02110-1301 USA.  */
20 #include <sysdep.h>
21 #include <shlib-compat.h>
23 #define __ASSEMBLY__
24 #include <asm/ptrace.h>
25 #include "ucontext_i.h"
27 ENTRY(__makecontext)
28         /* Set up the first 7 args to the function in its registers */
29         addi    r11,r3,_UC_REG_SPACE+12
30         clrrwi  r11,r11,4
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)
37         lwz     r8,8(r1)
38         lwz     r9,12(r1)
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. */
46         lwz     r7,_UC_LINK(r3)
47         stw     r7,_UC_GREGS+(PT_R31*4)(r11)
49         /* Set the function's LR to point to the exitcode below. */
50 #ifdef PIC
51         mflr    r0
52         cfi_register(lr,r0)
53         bl      1f
54 1:      mflr    r6
55         addi    r6,r6,L(exitcode)-1b
56         mtlr    r0
57         cfi_same_value (lr)
58 #else
59         lis     r6,L(exitcode)@ha
60         addi    r6,r6,L(exitcode)@l
61 #endif
62         stw     r6,_UC_GREGS+(PT_LNK*4)(r11)
64         /*
65          * Set up the stack frame for the function.
66          * If we have more than 5 args to the function (8 args to makecontext),
67          * there will be some arguments on the stack which have to end up
68          * in registers.  If there are more than 8 args to the function,
69          * we have to copy (argc - 8) args from our stack to the functions'
70          * stack (and allow space for them in the frame).
71          */
72         lwz     r4,_UC_STACK_SP(r3)
73         lwz     r8,_UC_STACK_SIZE(r3)
74         add     r4,r4,r8
75         rlwinm  r4,r4,0,0,27    /* round down to 16-byte boundary */
76         addi    r7,r4,-16       /* stack frame for fn's caller */
77         cmpwi   r5,8
78         blt     2f              /* less than 8 args is easy */
79         lwz     r10,16(r1)
80         stw     r10,_UC_GREGS+(PT_R10*4)(r11)
81         beq     2f              /* if exactly 8 args */
82         subi    r9,r5,3
83         subi    r5,r5,8
84         rlwinm  r9,r9,2,0,27
85         subf    r7,r9,r4
86         mtctr   r5              /* copy the 9th and following args */
87         addi    r6,r1,16
88         addi    r8,r7,4
89 3:      lwzu    r10,4(r6)
90         stwu    r10,4(r8)
91         bdnz    3b
92 2:      stw     r7,_UC_GREGS+(PT_R1*4)(r11)
93         li      r6,0
94         stw     r6,0(r7)
96         blr
99  * If the function returns, it comes here.  We put ucp->uc_link in
100  * r31, which is a callee-saved register.  We have to continue with
101  * the context that r31 points to, or exit if it is 0.
102  */
103 L(exitcode):
104         mr.     r3,r31
105         beq     4f
106         bl      __setcontext@local
107 4:      bl      HIDDEN_JUMPTARGET(exit)
108         b       4b
110 END(__makecontext)
112 versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_4)
114 #if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
116         compat_text_section
117 ENTRY(__novec_makecontext)
118         /* Set up the first 7 args to the function in its registers */
119         addi    r11,r3,_UC_REG_SPACE
120         stw     r11,_UC_REGS_PTR(r3)
121         stw     r6,_UC_GREGS+(PT_R3*4)(r11)
122         stw     r7,_UC_GREGS+(PT_R4*4)(r11)
123         stw     r8,_UC_GREGS+(PT_R5*4)(r11)
124         stw     r9,_UC_GREGS+(PT_R6*4)(r11)
125         stw     r10,_UC_GREGS+(PT_R7*4)(r11)
126         lwz     r8,8(r1)
127         lwz     r9,12(r1)
128         stw     r8,_UC_GREGS+(PT_R8*4)(r11)
129         stw     r9,_UC_GREGS+(PT_R9*4)(r11)
131         /* Set the NIP to the start of the function */
132         stw     r4,_UC_GREGS+(PT_NIP*4)(r11)
134         /* Set the function's r31 to ucp->uc_link for the exitcode below. */
135         lwz     r7,_UC_LINK(r3)
136         stw     r7,_UC_GREGS+(PT_R31*4)(r11)
138         /* Set the function's LR to point to the exitcode below. */
139 #ifdef PIC
140         mflr    r0
141         cfi_register(lr,r0)
142         bl      1f
143 1:      mflr    r6
144         addi    r6,r6,L(novec_exitcode)-1b
145         mtlr    r0
146         cfi_same_value (lr)
147 #else
148         lis     r6,L(novec_exitcode)@ha
149         addi    r6,r6,L(novec_exitcode)@l
150 #endif
151         stw     r6,_UC_GREGS+(PT_LNK*4)(r11)
153         /*
154          * Set up the stack frame for the function.
155          * If we have more than 5 args to the function (8 args to makecontext),
156          * there will be some arguments on the stack which have to end up
157          * in registers.  If there are more than 8 args to the function,
158          * we have to copy (argc - 8) args from our stack to the functions'
159          * stack (and allow space for them in the frame).
160          */
161         lwz     r4,_UC_STACK_SP(r3)
162         lwz     r8,_UC_STACK_SIZE(r3)
163         add     r4,r4,r8
164         rlwinm  r4,r4,0,0,27    /* round down to 16-byte boundary */
165         addi    r7,r4,-16       /* stack frame for fn's caller */
166         cmpwi   r5,8
167         blt     2f              /* less than 8 args is easy */
168         lwz     r10,16(r1)
169         stw     r10,_UC_GREGS+(PT_R10*4)(r11)
170         beq     2f              /* if exactly 8 args */
171         subi    r9,r5,3
172         subi    r5,r5,8
173         rlwinm  r9,r9,2,0,27
174         subf    r7,r9,r4
175         mtctr   r5              /* copy the 9th and following args */
176         addi    r6,r1,16
177         addi    r8,r7,4
178 3:      lwzu    r10,4(r6)
179         stwu    r10,4(r8)
180         bdnz    3b
181 2:      stw     r7,_UC_GREGS+(PT_R1*4)(r11)
182         li      r6,0
183         stw     r6,0(r7)
185         blr
188  * If the function returns, it comes here.  We put ucp->uc_link in
189  * r31, which is a callee-saved register.  We have to continue with
190  * the context that r31 points to, or exit if it is 0.
191  */
192 L(novec_exitcode):
193         mr.     r3,r31
194         beq     4f
195         bl      __novec_setcontext@local
196 4:      bl      HIDDEN_JUMPTARGET(exit)
197         b       4b
199 END(__novec_makecontext)
200         .previous
202 compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3)
203 #endif
205 #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
207 #define _ERRNO_H        1
208 #include <bits/errno.h>
210         compat_text_section
211 ENTRY (__makecontext_stub)
212         li      r3,ENOSYS
213         b       __syscall_error@local
214 END (__makecontext_stub)
215         .previous
217 compat_symbol (libc, __makecontext_stub, makecontext, GLIBC_2_1)
219 #endif