]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
PowerPC64 ELFv2 ABI 4/6: Stack frame layout changes
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc64 / clone.S
CommitLineData
cfc91acd 1/* Wrapper around clone system call. PowerPC64 version.
568035b7 2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
cfc91acd
RM
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
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
cfc91acd
RM
18
19#include <sysdep.h>
20#define _ERRNO_H 1
21#include <bits/errno.h>
cfc91acd 22
1f9d7c27
UD
23#define CLONE_VM 0x00000100
24#define CLONE_THREAD 0x00010000
25
cfc91acd
RM
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],
4fba8a3b
RM
31 int flags [r5], void *arg [r6], void *parent_tid [r7],
32 void *tls [r8], void *child_tid [r9]); */
cfc91acd 33
2d67d91a 34ENTRY (__clone)
865d953f 35 CALL_MCOUNT 7
cfc91acd
RM
36
37 /* Check for child_stack == NULL || fn == NULL. */
38 cmpdi cr0,r4,0
a2eae4cc 39 cmpdi cr1,r3,0
cfc91acd
RM
40 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
41 beq- cr0,L(badargs)
42
8b8a692c 43 /* Save some regs in the "red zone". */
1f9d7c27 44#ifdef RESET_PID
8b8a692c 45 std r29,-24(r1)
1f9d7c27 46#endif
8b8a692c
UW
47 std r30,-16(r1)
48 std r31,-8(r1)
bebff237 49#ifdef RESET_PID
8b8a692c 50 cfi_offset(r29,-24)
bebff237 51#endif
8b8a692c
UW
52 cfi_offset(r30,-16)
53 cfi_offset(r31,-8)
cfc91acd
RM
54
55 /* Set up stack frame for child. */
56 clrrdi r4,r4,4
57 li r0,0
8b8a692c 58 stdu r0,-FRAME_MIN_SIZE_PARM(r4)
cfc91acd
RM
59
60 /* Save fn, args, stack across syscall. */
bebff237 61 mr r30,r3 /* Function in r30. */
1f9d7c27 62#ifdef RESET_PID
bebff237 63 mr r29,r5 /* Flags in r29. */
1f9d7c27 64#endif
cfc91acd
RM
65 mr r31,r6 /* Argument in r31. */
66
bebff237
AM
67 /* 'flags' argument is first parameter to clone syscall.
68 Second is the stack pointer, already in r4. */
cfc91acd 69 mr r3,r5
4fba8a3b
RM
70 /* Move the parent_tid, child_tid and tls arguments. */
71 mr r5,r7
72 mr r6,r8
73 mr r7,r9
cfc91acd 74
97d901a6
RM
75 /* End FDE now, because in the child the unwind info will be
76 wrong. */
77 cfi_endproc
78
cfc91acd
RM
79 /* Do the call. */
80 DO_CALL(SYS_ify(clone))
81
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. */
86
1f9d7c27 87#ifdef RESET_PID
bebff237 88 andis. r0,r29,CLONE_THREAD>>16
a2eae4cc 89 bne+ cr0,L(oldpid)
bebff237 90 andi. r0,r29,CLONE_VM
1f9d7c27 91 li r3,-1
a2eae4cc 92 bne- cr0,L(nomoregetpid)
1f9d7c27
UD
93 DO_CALL(SYS_ify(getpid))
94L(nomoregetpid):
95 stw r3,TID(r13)
96 stw r3,PID(r13)
97L(oldpid):
98#endif
99
8b8a692c 100 std r2,FRAME_TOC_SAVE(r1)
cfc91acd 101 /* Call procedure. */
d31beafa 102 PPC64_LOAD_FUNCPTR r30
cfc91acd
RM
103 mr r3,r31
104 bctrl
8b8a692c 105 ld r2,FRAME_TOC_SAVE(r1)
cfc91acd 106 /* Call _exit with result from procedure. */
7062ca8f
UD
107#ifdef SHARED
108 b JUMPTARGET(__GI__exit)
109#else
cfc91acd 110 b JUMPTARGET(_exit)
bebff237
AM
111 /* We won't ever get here but provide a nop so that the linker
112 will insert a toc adjusting stub if necessary. */
113 nop
7062ca8f 114#endif
cfc91acd 115
bebff237
AM
116L(badargs):
117 cfi_startproc
118 li r3,EINVAL
119 TAIL_CALL_SYSCALL_ERROR
120
cfc91acd
RM
121L(parent):
122 /* Parent. Restore registers & return. */
1f9d7c27 123#ifdef RESET_PID
8b8a692c 124 cfi_offset(r29,-24)
1f9d7c27 125#endif
8b8a692c
UW
126 cfi_offset(r30,-16)
127 cfi_offset(r31,-8)
bebff237 128#ifdef RESET_PID
8b8a692c 129 ld r29,-24(r1)
bebff237 130#endif
8b8a692c
UW
131 ld r30,-16(r1)
132 ld r31,-8(r1)
bebff237
AM
133#ifdef RESET_PID
134 cfi_restore(r29)
135#endif
136 cfi_restore(r30)
137 cfi_restore(r31)
138 PSEUDO_RET
97d901a6 139
2d67d91a 140END (__clone)
cfc91acd 141
2d67d91a 142weak_alias (__clone, clone)