Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
blobaa8420135f3fed7a4372c016c09153cf02d5b104
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, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #define _ERRNO_H        1
21 #include <bits/errno.h>
22 #include <bp-sym.h>
23 #include <bp-asm.h>
25 #define CLONE_VM        0x00000100
26 #define CLONE_THREAD    0x00010000
28 /* This is the only really unusual system call in PPC linux, but not
29    because of any weirdness in the system call itself; because of
30    all the freaky stuff we have to do to make the call useful.  */
32 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
33                   int flags [r5], void *arg [r6], void *parent_tid [r7],
34                   void *tls [r8], void *child_tid [r9]); */
36 ENTRY (BP_SYM (__clone))
37         CALL_MCOUNT 7
38         /* GKM FIXME: add bounds checks, where sensible.  */
39         DISCARD_BOUNDS (r4)
40         DISCARD_BOUNDS (r6)
42         /* Check for child_stack == NULL || fn == NULL.  */
43         cmpdi   cr0,r4,0
44         cmpdi   cr1,r3,0
45         cror    cr0*4+eq,cr1*4+eq,cr0*4+eq
46         beq-    cr0,L(badargs)
48         /* Save some regs in parm save area.  */
49 #ifdef RESET_PID
50         std     r29,48(r1)
51 #endif
52         std     r30,56(r1)
53         std     r31,64(r1)
54 #ifdef RESET_PID
55         cfi_offset(r29,48)
56 #endif
57         cfi_offset(r30,56)
58         cfi_offset(r31,64)
60         /* Set up stack frame for child.  */
61         clrrdi  r4,r4,4
62         li      r0,0
63         stdu    r0,-112(r4) /* min stack frame is 112 bytes per ABI */
65         /* Save fn, args, stack across syscall.  */
66         mr      r30,r3                  /* Function in r30.  */
67 #ifdef RESET_PID
68         mr      r29,r5                  /* Flags in r29.  */
69 #endif
70         mr      r31,r6                  /* Argument in r31.  */
72         /* 'flags' argument is first parameter to clone syscall.
73            Second 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         /* End FDE now, because in the child the unwind info will be
81            wrong.  */
82         cfi_endproc
84         /* Do the call.  */
85         DO_CALL(SYS_ify(clone))
87         /* Check for child process.  */
88         cmpdi   cr1,r3,0
89         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
90         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
92 #ifdef RESET_PID
93         andis.  r0,r29,CLONE_THREAD>>16
94         bne+    cr0,L(oldpid)
95         andi.   r0,r29,CLONE_VM
96         li      r3,-1
97         bne-    cr0,L(nomoregetpid)
98         DO_CALL(SYS_ify(getpid))
99 L(nomoregetpid):
100         stw     r3,TID(r13)
101         stw     r3,PID(r13)
102 L(oldpid):
103 #endif
105         std     r2,40(r1)
106         /* Call procedure.  */
107         ld      r0,0(r30)
108         ld      r2,8(r30)
109         mtctr   r0
110         mr      r3,r31
111         bctrl
112         ld      r2,40(r1)
113         /* Call _exit with result from procedure.  */
114 #ifdef SHARED
115         b       JUMPTARGET(__GI__exit)
116 #else
117         b       JUMPTARGET(_exit)
118         /* We won't ever get here but provide a nop so that the linker
119            will insert a toc adjusting stub if necessary.  */
120         nop
121 #endif
123 L(badargs):
124         cfi_startproc
125         li      r3,EINVAL
126         TAIL_CALL_SYSCALL_ERROR
128 L(parent):
129         /* Parent.  Restore registers & return.  */
130 #ifdef RESET_PID
131         cfi_offset(r29,48)
132 #endif
133         cfi_offset(r30,56)
134         cfi_offset(r31,64)
135 #ifdef RESET_PID
136         ld      r29,48(r1)
137 #endif
138         ld      r30,56(r1)
139         ld      r31,64(r1)
140 #ifdef RESET_PID
141         cfi_restore(r29)
142 #endif
143         cfi_restore(r30)
144         cfi_restore(r31)
145         PSEUDO_RET
147 END (BP_SYM (__clone))
149 weak_alias (BP_SYM (__clone), BP_SYM (clone))