]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
1 /* Wrapper around clone system call. PowerPC64 version.
2 Copyright (C) 1997-2016 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, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <sysdep.h>
20 #define _ERRNO_H 1
21 #include <bits/errno.h>
22
23 #define CLONE_VM 0x00000100
24 #define CLONE_THREAD 0x00010000
25
26 /* This is the only really unusual system call in PPC linux, but not
27 because of any weirdness in the system call itself; because of
28 all the freaky stuff we have to do to make the call useful. */
29
30 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
31 int flags [r5], void *arg [r6], void *parent_tid [r7],
32 void *tls [r8], void *child_tid [r9]); */
33
34 ENTRY (__clone)
35 CALL_MCOUNT 7
36
37 /* Check for child_stack == NULL || fn == NULL. */
38 cmpdi cr0,r4,0
39 cmpdi cr1,r3,0
40 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
41 beq- cr0,L(badargs)
42
43 /* Save some regs in the "red zone". */
44 std r29,-24(r1)
45 std r30,-16(r1)
46 std r31,-8(r1)
47 cfi_offset(r29,-24)
48 cfi_offset(r30,-16)
49 cfi_offset(r31,-8)
50
51 /* Set up stack frame for child. */
52 clrrdi r4,r4,4
53 li r0,0
54 stdu r0,-FRAME_MIN_SIZE_PARM(r4)
55
56 /* Save fn, args, stack across syscall. */
57 mr r30,r3 /* Function in r30. */
58 mr r29,r5 /* Flags in r29. */
59 mr r31,r6 /* Argument in r31. */
60
61 /* 'flags' argument is first parameter to clone syscall.
62 Second is the stack pointer, already in r4. */
63 mr r3,r5
64 /* Move the parent_tid, child_tid and tls arguments. */
65 mr r5,r7
66 mr r6,r8
67 mr r7,r9
68
69 /* End FDE now, because in the child the unwind info will be
70 wrong. */
71 cfi_endproc
72
73 /* Do the call. */
74 DO_CALL(SYS_ify(clone))
75
76 /* Check for child process. */
77 cmpdi cr1,r3,0
78 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
79 bne- cr1,L(parent) /* The '-' is to minimise the race. */
80
81 andis. r0,r29,CLONE_THREAD>>16
82 bne+ cr0,L(oldpid)
83 andi. r0,r29,CLONE_VM
84 li r3,-1
85 bne- cr0,L(nomoregetpid)
86 DO_CALL(SYS_ify(getpid))
87 L(nomoregetpid):
88 stw r3,TID(r13)
89 stw r3,PID(r13)
90 L(oldpid):
91
92 std r2,FRAME_TOC_SAVE(r1)
93 /* Call procedure. */
94 PPC64_LOAD_FUNCPTR r30
95 mr r3,r31
96 bctrl
97 ld r2,FRAME_TOC_SAVE(r1)
98 /* Call _exit with result from procedure. */
99 #ifdef SHARED
100 b JUMPTARGET(__GI__exit)
101 #else
102 b JUMPTARGET(_exit)
103 /* We won't ever get here but provide a nop so that the linker
104 will insert a toc adjusting stub if necessary. */
105 nop
106 #endif
107
108 L(badargs):
109 cfi_startproc
110 li r3,EINVAL
111 TAIL_CALL_SYSCALL_ERROR
112
113 L(parent):
114 /* Parent. Restore registers & return. */
115 cfi_offset(r29,-24)
116 cfi_offset(r30,-16)
117 cfi_offset(r31,-8)
118 ld r29,-24(r1)
119 ld r30,-16(r1)
120 ld r31,-8(r1)
121 cfi_restore(r29)
122 cfi_restore(r30)
123 cfi_restore(r31)
124
125 PSEUDO_RET
126
127 END (__clone)
128
129 weak_alias (__clone, clone)