(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
blob287597c4802b1454dc3ce3f0321d57355cf4eeef
1 /* Wrapper around clone system call.  PowerPC64 version.
2    Copyright (C) 1997,98,99,2000,02, 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
18    02111-1307 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         std     r29,56(r1)
52         std     r30,64(r1)
53         std     r31,72(r1)
54 #ifdef RESET_PID
55         std     r28,48(r1)
56 #endif
58         /* Set up stack frame for child.  */
59         clrrdi  r4,r4,4
60         li      r0,0
61         stdu    r0,-48(r4) /* min stack frame is 48 bytes per ABI */
63         /* Save fn, args, stack across syscall.  */
64         mr      r29,r3                  /* Function in r29.  */
65         mr      r30,r4                  /* Stack pointer in r30.  */
66 #ifdef RESET_PID
67         mr      r28,r5                  /* Flags in r28.  */
68 #endif
69         mr      r31,r6                  /* Argument in r31.  */
71         /* 'flags' argument is first parameter to clone syscall. (The other
72            argument is the stack pointer, already in r4.)  */
73         mr      r3,r5
74   /* Move the parent_tid, child_tid and tls arguments. */
75         mr      r5,r7
76         mr      r6,r8
77         mr      r7,r9
79         /* Do the call.  */
80         DO_CALL(SYS_ify(clone))
82         /* Check for child process.  */
83         cmpdi   cr1,r3,0
84         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
85         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
87 #ifdef RESET_PID
88         andis.  r0,r28,CLONE_THREAD>>16
89         bne+    cr0,L(oldpid)
90         andi.   r0,r28,CLONE_VM
91         li      r3,-1
92         bne-    cr0,L(nomoregetpid)
93         DO_CALL(SYS_ify(getpid))
94 L(nomoregetpid):
95         stw     r3,TID(r13)
96         stw     r3,PID(r13)
97 L(oldpid):
98 #endif
100         std     r2,40(r1)
101         /* Call procedure.  */
102         ld      r0,0(r29)
103         ld      r2,8(r29)
104         mtctr   r0
105         mr      r3,r31
106         bctrl
107         ld      r2,40(r1)
108         /* Call _exit with result from procedure.  */
109 #ifdef SHARED
110         b       JUMPTARGET(__GI__exit)
111 #else
112         b       JUMPTARGET(_exit)
113 #endif
115 L(parent):
116         /* Parent.  Restore registers & return.  */
117 #ifdef RESET_PID
118         ld      r28,48(r1)
119 #endif
120         ld      r31,72(r1)
121         ld      r30,64(r1)
122         ld      r29,56(r1)
123         addi    r1,r1,80
124         bnslr+
125         b       JUMPTARGET(__syscall_error)
127 L(badargs):
128         li      r3,EINVAL
129         b       JUMPTARGET(__syscall_error)
130 END (BP_SYM (__clone))
132 weak_alias (BP_SYM (__clone), BP_SYM (clone))