Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / clone.S
blobbb1510dff19fd6075c780d0495085de3796f5414
1 /* Wrapper around clone system call.
2    Copyright (C) 1997-2014 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 <kernel-features.h>
24 #define CLONE_VM        0x00000100
25 #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 (__clone)
38         /* Check for child_stack == NULL || fn == NULL.  */
39         cmpwi   cr0,r4,0
40         cmpwi   cr1,r3,0
41         cror    cr0*4+eq,cr1*4+eq,cr0*4+eq
42         beq-    cr0,L(badargs)
44         /* Set up stack frame for parent.  */
45         stwu    r1,-32(r1)
46         cfi_adjust_cfa_offset (32)
47 #ifdef RESET_PID
48         stmw    r28,16(r1)
49 #else
50         stmw    r30,16(r1)
51 #endif
53         /* Set up stack frame for child.  */
54         clrrwi  r4,r4,4
55         li      r0,0
56         stwu    r0,-16(r4)
58         /* Save fn, args, stack across syscall.  */
59         mr      r30,r3                  /* Function in r30.  */
60 #ifdef RESET_PID
61         mr      r28,r5
62 #endif
63         mr      r31,r6                  /* Argument in r31.  */
65         /* 'flags' argument is first parameter to clone syscall. (The other
66            argument is the stack pointer, already in r4.)  */
67         mr      r3,r5
69         /* Move the parent_tid, child_tid and tls arguments. */
70         mr      r5,r7
71         mr      r6,r8
72         mr      r7,r9
74         /* End FDE now, because in the child the unwind info will be
75            wrong.  */
76         cfi_endproc
78         /* Do the call.  */
79         DO_CALL(SYS_ify(clone))
81         /* Check for child process.  */
82         cmpwi   cr1,r3,0
83         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
84         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
86 #ifdef RESET_PID
87         andis.  r0,r28,CLONE_THREAD>>16
88         bne+    r0,L(oldpid)
89         andi.   r0,r28,CLONE_VM
90         li      r3,-1
91         bne-    r0,L(nomoregetpid)
92         DO_CALL(SYS_ify(getpid))
93 L(nomoregetpid):
94         stw     r3,TID(r2)
95         stw     r3,PID(r2)
96 L(oldpid):
97 #endif
99         /* Call procedure.  */
100         mtctr   r30
101         mr      r3,r31
102         bctrl
103         /* Call _exit with result from procedure.  */
104         b       HIDDEN_JUMPTARGET(_exit)
106 L(parent):
107         /* Parent.  Restore registers & return.  */
108 #ifdef RESET_PID
109         lmw     r28,16(r1)
110 #else
111         lmw     r30,16(r1)
112 #endif
113         addi    r1,r1,32
114         bnslr+
115         b       __syscall_error@local
117 L(badargs):
118         li      r3,EINVAL
119         b       __syscall_error@local
121         cfi_startproc
122 END (__clone)
124 weak_alias (__clone, clone)