OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / powerpc / clone.S
1 /* Wrapper around clone system call.
2    Copyright (C) 1997, 1998, 1999, 2000 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., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include "ppc_asm.h"
21 #define _ERRNO_H        1
22 #include <bits/errno.h>
23 #include <sys/syscall.h>
24
25 /* This is the only really unusual system call in PPC linux, but not
26    because of any weirdness in the system call itself; because of
27    all the freaky stuff we have to do to make the call useful.  */
28
29 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
30                   int flags [r5], void *arg [r6]); */
31
32 #ifdef __NR_clone
33         .globl clone
34         .type clone,@function
35         .align 2
36
37 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,.Lbadargs
43
44         /* Set up stack frame for parent.  */
45         stwu    r1,-32(r1)
46         stmw    r29,16(r1)
47         
48         /* Set up stack frame for child.  */
49         clrrwi  r4,r4,4
50         li      r0,0
51         stwu    r0,-16(r4)
52
53         /* Save fn, args, stack across syscall.  */
54         mr      r29,r3                  /* Function in r29.  */
55         mr      r30,r4                  /* Stack pointer in r30.  */
56         mr      r31,r6                  /* Argument in r31.  */
57
58         /* 'flags' argument is first parameter to clone syscall. (The other
59            argument is the stack pointer, already in r4.)  */
60         mr      r3,r5
61
62         /* Do the call.  */
63         li 0, __NR_clone
64         sc
65
66         /* Check for child process.  */
67         cmpwi   cr1,r3,0
68         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
69         bne-    cr1,.Lparent            /* The '-' is to minimise the race.  */
70
71         /* On at least mklinux DR3a5, clone() doesn't actually change
72            the stack pointer.  I'm pretty sure this is a bug, because
73            it adds a race condition if a signal is sent to a thread
74            just after it is created (in the previous three instructions).  */
75         mr      r1,r30
76         /* Call procedure.  */
77         mtctr   r29
78         mr      r3,r31
79         bctrl
80         /* Call _exit with result from procedure.  */
81         b       HIDDEN_JUMPTARGET(_exit)
82
83 .Lparent:
84         /* Parent.  Restore registers & return.  */
85         lmw     r29,16(r1)
86         addi    r1,r1,32
87         bnslr+
88
89         b       __syscall_error
90
91 .Lbadargs:
92         li      r3,EINVAL
93
94         b       __syscall_error
95
96         .size clone,.-clone
97 #endif