]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/microblaze/clone.c
a47ee8c6856fc1edf879763f3efbe336c5076536
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / microblaze / clone.c
1 /*
2  * libc/sysdeps/linux/microblaze/clone.c -- `clone' syscall for linux/microblaze
3  *
4  *  Copyright (C) 2003     John Williams <jwilliams@itee.uq.edu.au>
5  *  Copyright (C) 2002,03  NEC Electronics Corporation
6  *  Copyright (C) 2002,03  Miles Bader <miles@gnu.org>
7  *
8  * This file is subject to the terms and conditions of the GNU Lesser
9  * General Public License.  See the file COPYING.LIB in the main
10  * directory of this archive for more details.
11  *
12  * Written by Miles Bader <miles@gnu.org>
13  * Microblaze port by John Williams
14  */
15
16 #include <errno.h>
17 #include <sys/syscall.h>
18
19 int
20 clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
21 {
22   register unsigned long rval __asm__ (SYSCALL_RET) = -EINVAL;
23
24   if (fn && child_stack)
25     {
26       register unsigned long syscall __asm__ (SYSCALL_NUM);
27       register unsigned long arg0 __asm__ (SYSCALL_ARG0);
28       register unsigned long arg1 __asm__ (SYSCALL_ARG1);
29
30       /* Clone this thread.  */
31       arg0 = flags;
32       arg1 = (unsigned long)child_stack;
33       syscall = __NR_clone;
34       __asm__ __volatile__ ("bralid r17, trap;nop;"
35                     : "=r" (rval), "=r" (syscall)
36                     : "1" (syscall), "r" (arg0), "r" (arg1)
37                     : SYSCALL_CLOBBERS);
38
39       if (rval == 0)
40         /* In child thread, call FN and exit.  */
41         {
42           arg0 = (*fn) (arg);
43           syscall = __NR_exit;
44           __asm__ __volatile__ ("bralid r17, trap;nop;"
45                         : "=r" (rval), "=r" (syscall)
46                         : "1" (syscall), "r" (arg0)
47                         : SYSCALL_CLOBBERS);
48         }
49     }
50
51   __syscall_return (int, rval);
52 }