Update.
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / powerpc / clone.S
1 /* Wrapper around clone system call.
2    Copyright (C) 1997 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 Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    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    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #include <sysdep.h>
21 #define _ERRNO_H        1
22 #include <bits/errno.h>
23
24 /* This is the only really unusual system call in PPC linux, but not
25    because of any weirdness in the system call itself; because of
26    all the freaky stuff we have to do to make the call useful.  */
27
28 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
29
30 ENTRY(__clone)
31         /* Set up stack frame, save registers.  */
32         stwu  %r1,-32(%r1)
33         /* Check for child_stack == NULL || fn == NULL.  */
34         cmpwi %cr0,%r4,0
35         stw   %r31,16(%r1)
36         cmpwi %cr1,%r3,0
37         stw   %r30,20(%r1)
38         beq-  %cr0,badargs
39         beq-  %cr1,badargs
40
41         /* Set up stack frame for child.  */
42         addi  %r4,%r4,-16
43         clrrwi %r4,%r4,4
44         li    %r0,0
45         stw   %r0,0(%r4)
46
47         /* Save fn, args across syscall.  */
48         mr    %r30,%r3          /* Function in r30.  */
49         mr    %r31,%r6          /* Arguments in r31.  */
50
51         /* 'flags' argument is first parameter to clone syscall. (The other
52            argument is the stack pointer, already in r4.)  */
53         mr    %r3,%r5
54
55         /* Do the call.  */
56         DO_CALL(SYS_ify(clone))
57         bso-  error
58         beq   child
59
60         /* Parent.  Restore registers & return.  */
61         lwz   %r31,16(%r1)
62         lwz   %r30,20(%r1)
63         addi  %r1,%r1,32
64         blr
65
66 child:
67         /* Call procedure.  */
68         mtlr  %r30
69         mr    %r3,%r31
70         blrl
71         /* Call _exit with result from procedure.  */
72         b JUMPTARGET(_exit)
73
74 badargs:
75         li    %r3,EINVAL
76 error:
77         lwz   %r31,16(%r1)
78         lwz   %r30,20(%r1)
79         addi  %r1,%r1,32
80         b JUMPTARGET(__syscall_error)
81 END (__clone)
82
83 weak_alias (__clone, clone)