]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
d14da54fd781c7cbf3d73b315a44606581b9ea19
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
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.
4
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.
9
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.
14
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. */
19
20 #include <sysdep.h>
21 #define _ERRNO_H 1
22 #include <bits/errno.h>
23 #include <bp-sym.h>
24 #include <bp-asm.h>
25
26 #define CLONE_VM 0x00000100
27 #define CLONE_THREAD 0x00010000
28
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. */
32
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]); */
36
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)
42
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)
48
49 /* Save some regs in parm save area. */
50 #ifdef RESET_PID
51 std r29,48(r1)
52 #endif
53 std r30,56(r1)
54 std r31,64(r1)
55 #ifdef RESET_PID
56 cfi_offset(r29,48)
57 #endif
58 cfi_offset(r30,56)
59 cfi_offset(r31,64)
60
61 /* Set up stack frame for child. */
62 clrrdi r4,r4,4
63 li r0,0
64 stdu r0,-112(r4) /* min stack frame is 112 bytes per ABI */
65
66 /* Save fn, args, stack across syscall. */
67 mr r30,r3 /* Function in r30. */
68 #ifdef RESET_PID
69 mr r29,r5 /* Flags in r29. */
70 #endif
71 mr r31,r6 /* Argument in r31. */
72
73 /* 'flags' argument is first parameter to clone syscall.
74 Second is the stack pointer, already in r4. */
75 mr r3,r5
76 /* Move the parent_tid, child_tid and tls arguments. */
77 mr r5,r7
78 mr r6,r8
79 mr r7,r9
80
81 /* End FDE now, because in the child the unwind info will be
82 wrong. */
83 cfi_endproc
84
85 /* Do the call. */
86 DO_CALL(SYS_ify(clone))
87
88 /* Check for child process. */
89 cmpdi cr1,r3,0
90 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
91 bne- cr1,L(parent) /* The '-' is to minimise the race. */
92
93 #ifdef RESET_PID
94 andis. r0,r29,CLONE_THREAD>>16
95 bne+ cr0,L(oldpid)
96 andi. r0,r29,CLONE_VM
97 li r3,-1
98 bne- cr0,L(nomoregetpid)
99 DO_CALL(SYS_ify(getpid))
100 L(nomoregetpid):
101 stw r3,TID(r13)
102 stw r3,PID(r13)
103 L(oldpid):
104 #endif
105
106 std r2,40(r1)
107 /* Call procedure. */
108 ld r0,0(r30)
109 ld r2,8(r30)
110 mtctr r0
111 mr r3,r31
112 bctrl
113 ld r2,40(r1)
114 /* Call _exit with result from procedure. */
115 #ifdef SHARED
116 b JUMPTARGET(__GI__exit)
117 #else
118 b JUMPTARGET(_exit)
119 /* We won't ever get here but provide a nop so that the linker
120 will insert a toc adjusting stub if necessary. */
121 nop
122 #endif
123
124 L(badargs):
125 cfi_startproc
126 li r3,EINVAL
127 TAIL_CALL_SYSCALL_ERROR
128
129 L(parent):
130 /* Parent. Restore registers & return. */
131 #ifdef RESET_PID
132 cfi_offset(r29,48)
133 #endif
134 cfi_offset(r30,56)
135 cfi_offset(r31,64)
136 #ifdef RESET_PID
137 ld r29,48(r1)
138 #endif
139 ld r30,56(r1)
140 ld r31,64(r1)
141 #ifdef RESET_PID
142 cfi_restore(r29)
143 #endif
144 cfi_restore(r30)
145 cfi_restore(r31)
146 PSEUDO_RET
147
148 END (BP_SYM (__clone))
149
150 weak_alias (BP_SYM (__clone), BP_SYM (clone))