From c3d50a69839f8d80fc7244fde6e4a57e5e39dd36 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 16 Jul 2004 11:09:34 +0000 Subject: Pete Popov writes: Hi Erik, I'm not sure why the NIOS support is not in uClibc -- perhaps the patch was rejected or never submitted? In any case, I'm playing with some NIOS stuff and created this patch against 0.9.26. The work was done by Microtronix. I'm not sure who else contributed to it. It would be great to have the NIOS support available in uClibc so developers don't have to go searching for these bits. Pete --- libc/sysdeps/linux/nios2/clone.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 libc/sysdeps/linux/nios2/clone.c (limited to 'libc/sysdeps/linux/nios2/clone.c') diff --git a/libc/sysdeps/linux/nios2/clone.c b/libc/sysdeps/linux/nios2/clone.c new file mode 100644 index 000000000..0555658b4 --- /dev/null +++ b/libc/sysdeps/linux/nios2/clone.c @@ -0,0 +1,49 @@ +/* + * libc/sysdeps/linux/nios2/clone.c -- `clone' syscall for linux/nios2 + * + * Copyright (C) 2004,05 Microtronix Datacom Ltd + * Copyright (C) 2002,03 NEC Electronics Corporation + * Copyright (C) 2002,03 Miles Bader + * + * 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 + * Nios2 port by Wentao Xu + */ + +#include +#include + +int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg) +{ + register unsigned long rval asm ("r2") = -EINVAL; + + if (fn && child_stack) { + register unsigned long syscall asm ("r3"); + register unsigned long arg0 asm ("r4"); + register unsigned long arg1 asm ("r5"); + + /* Clone this thread. */ + rval = TRAP_ID_SYSCALL; + syscall = __NR_clone; + arg0 = flags; + arg1 = (unsigned long)child_stack; + asm volatile ("trap " + : "=r" (rval), "=r" (syscall) + : "0" (rval),"1" (syscall), "r" (arg0), "r" (arg1) + ); + + if (rval == 0) { + /* In child thread, call fn and exit. */ + arg0 = (*fn) (arg); + syscall = __NR_exit; + asm volatile ("trap " + : "=r" (rval), "=r" (syscall) + : "1" (syscall), "r" (arg0)); + } + } + + __syscall_return (int, rval); +} -- cgit v1.2.3