* elf/tst-tls8.c (do_test): Use $ORIGIN in module names.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
bloba0f018ba41b7d7f57488a0be85bbdfad299db5d8
1 /* Wrapper around clone system call.  PowerPC64 version.
2    Copyright (C) 1997,98,99,2000,02,04, 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 #define _ERRNO_H        1
22 #include <bits/errno.h>
23 #include <bp-sym.h>
24 #include <bp-asm.h>
26 #define CLONE_VM        0x00000100
27 #define CLONE_THREAD    0x00010000
29 /* This is the only really unusual system call in PPC linux, but not
30    because of any weirdness in the system call itself; because of
31    all the freaky stuff we have to do to make the call useful.  */
33 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
34                   int flags [r5], void *arg [r6], void *parent_tid [r7],
35                   void *tls [r8], void *child_tid [r9]); */
37 ENTRY (BP_SYM (__clone))
38         CALL_MCOUNT 7
39         /* GKM FIXME: add bounds checks, where sensible.  */
40         DISCARD_BOUNDS (r4)
41         DISCARD_BOUNDS (r6)
43         /* Check for child_stack == NULL || fn == NULL.  */
44         cmpdi   cr0,r4,0
45         cmpdi   cr1,r3,0
46         cror    cr0*4+eq,cr1*4+eq,cr0*4+eq
47         beq-    cr0,L(badargs)
49         /* Set up stack frame for parent.  */
50         stdu    r1,-80(r1)
51         cfi_adjust_cfa_offset (80)
52         std     r29,56(r1)
53         std     r30,64(r1)
54         std     r31,72(r1)
55 #ifdef RESET_PID
56         std     r28,48(r1)
57 #endif
59         /* Set up stack frame for child.  */
60         clrrdi  r4,r4,4
61         li      r0,0
62         stdu    r0,-48(r4) /* min stack frame is 48 bytes per ABI */
64         /* Save fn, args, stack across syscall.  */
65         mr      r29,r3                  /* Function in r29.  */
66         mr      r30,r4                  /* Stack pointer in r30.  */
67 #ifdef RESET_PID
68         mr      r28,r5                  /* Flags in r28.  */
69 #endif
70         mr      r31,r6                  /* Argument in r31.  */
72         /* 'flags' argument is first parameter to clone syscall. (The other
73            argument is the stack pointer, already in r4.)  */
74         mr      r3,r5
75   /* Move the parent_tid, child_tid and tls arguments. */
76         mr      r5,r7
77         mr      r6,r8
78         mr      r7,r9
80         /* Do the call.  */
81         DO_CALL(SYS_ify(clone))
83         /* Check for child process.  */
84         cmpdi   cr1,r3,0
85         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
86         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
88 #ifdef RESET_PID
89         andis.  r0,r28,CLONE_THREAD>>16
90         bne+    cr0,L(oldpid)
91         andi.   r0,r28,CLONE_VM
92         li      r3,-1
93         bne-    cr0,L(nomoregetpid)
94         DO_CALL(SYS_ify(getpid))
95 L(nomoregetpid):
96         stw     r3,TID(r13)
97         stw     r3,PID(r13)
98 L(oldpid):
99 #endif
101         std     r2,40(r1)
102         /* Call procedure.  */
103         ld      r0,0(r29)
104         ld      r2,8(r29)
105         mtctr   r0
106         mr      r3,r31
107         bctrl
108         ld      r2,40(r1)
109         /* Call _exit with result from procedure.  */
110 #ifdef SHARED
111         b       JUMPTARGET(__GI__exit)
112 #else
113         b       JUMPTARGET(_exit)
114 #endif
116 L(parent):
117         /* Parent.  Restore registers & return.  */
118 #ifdef RESET_PID
119         ld      r28,48(r1)
120 #endif
121         ld      r31,72(r1)
122         ld      r30,64(r1)
123         ld      r29,56(r1)
124         addi    r1,r1,80
125         bnslr+
126         b       JUMPTARGET(__syscall_error)
128 L(badargs):
129         li      r3,EINVAL
130         b       JUMPTARGET(__syscall_error)
131 END (BP_SYM (__clone))
133 weak_alias (BP_SYM (__clone), BP_SYM (clone))