diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-01-05 10:05:27 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-01-05 10:05:27 +0000 |
commit | 124ec188720b6bdea85ade49e7ea195161b12fce (patch) | |
tree | 2bce39bc1e51bd587e010a61419b47d122be3165 /libc/sysdeps/linux/xtensa/clone.S | |
parent | 9c95d5d28d8d40f7b826c9399f5ce781bbc61567 (diff) |
Chris Zankel writes:
The following patches add support for the Xtensa processor architecture
to uClibc. They are based on a recent SVN checkout (12/05/2007).
The first patch (attached to this post) adds Xtensa support to various
shared configuration and make files. The following patches then include
the Xtensa specific files and directories.
I welcome any feedback and would appreciate it if you could include the
patches into the mainline tree. I am certainly committed to maintain the port.
Bob Wilson was kind enough to review the patches.
Some notes about the architecture: Xtensa is a configurable and
extensible processor architecture developed by Tensilica. For more
information, please visit: www.linux-xtensa.org.
Diffstat (limited to 'libc/sysdeps/linux/xtensa/clone.S')
-rw-r--r-- | libc/sysdeps/linux/xtensa/clone.S | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/xtensa/clone.S b/libc/sysdeps/linux/xtensa/clone.S new file mode 100644 index 000000000..31921ea47 --- /dev/null +++ b/libc/sysdeps/linux/xtensa/clone.S @@ -0,0 +1,103 @@ +/* Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street - Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* clone is even more special than fork as it mucks with stacks + and invokes a function in the right context after it's all over. */ + +#include "sysdep.h" +#include <sys/syscall.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* int clone (a2 = int (*fn)(void *arg), + a3 = void *child_stack, + a4 = int flags, + a5 = void *arg, + a6 = pid_t *ptid, + a7 = struct user_desc *tls, + 16(sp) = pid_t *ctid) */ + + .text +ENTRY (__clone) + + /* Sanity check arguments. */ + beqz a2, .Leinval /* no NULL function pointers */ + beqz a3, .Leinval /* no NULL stack pointers */ + + /* a2 and a3 are candidates for destruction by system-call return + parameters. We don't need the stack pointer after the system + call. We trust that the kernel will preserve a7, a9, and a6. */ + + mov a9, a5 /* save function argument */ + mov a5, a7 + mov a7, a2 /* save function pointer */ + mov a8, a6 /* use a8 as a temp */ + mov a6, a4 + mov a4, a8 + l32i a8, a1, 16 /* child_tid */ + movi a2, SYS_ify (clone) + + /* syscall (a2 = NR_clone, + a6 = clone_flags, + a3 = usp, + a4 = parent_tid, + a5 = child_tls, + a8 = child_tid) */ + syscall + bltz a2, SYSCALL_ERROR_LABEL + beqz a2, .Lthread_start + + /* Fall through for parent. */ +.Lpseudo_end: + retw + +.Leinval: + movi a2, -EINVAL + j SYSCALL_ERROR_LABEL + +.Lthread_start: + /* Start child thread. */ + movi a0, 0 /* terminate the stack frame */ + +#ifdef RESET_PID + /* Check and see if we need to reset the PID. */ + bbsi.l a6, 16, 1f /* CLONE_THREAD = 0x00010000 */ + movi a2, -1 + bbsi.l a6, 8, 2f /* CLONE_VM = 0x00000100 */ + movi a2, SYS_ify (getpid) + syscall +2: rur a3, THREADPTR + movi a4, PID_OFFSET + add a4, a4, a3 + s32i a2, a4, 0 + movi a4, TID_OFFSET + add a4, a4, a3 + s32i a2, a3, 0 +1: +#endif /* RESET_PID */ + + mov a6, a9 /* load up the 'arg' parameter */ + callx4 a7 /* call the user's function */ + + /* Call _exit. Note that any return parameter from the user's + function in a6 is seen as inputs to _exit. */ + movi a2, JUMPTARGET(_exit) + callx4 a2 + +PSEUDO_END (__clone) + +weak_alias (__clone, clone) |