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