summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/xtensa/clone.S
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/xtensa/clone.S')
-rw-r--r--libc/sysdeps/linux/xtensa/clone.S101
1 files changed, 55 insertions, 46 deletions
diff --git a/libc/sysdeps/linux/xtensa/clone.S b/libc/sysdeps/linux/xtensa/clone.S
index aa79aa736..34d68a875 100644
--- a/libc/sysdeps/linux/xtensa/clone.S
+++ b/libc/sysdeps/linux/xtensa/clone.S
@@ -1,34 +1,38 @@
-/* Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2005 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.
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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.
+ Library 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, see
- <http://www.gnu.org/licenses/>. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, 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. */
+ and invokes a function in the right context after its all over. */
-#include "sysdep.h"
-#include <sys/syscall.h>
+#include <features.h>
+#include <sysdep.h>
#define _ERRNO_H 1
#include <bits/errno.h>
+#ifdef RESET_PID
+#include <tls.h>
+#endif
+#define __ASSEMBLY__
+#include <linux/sched.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) */
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ a2 a3 a4 a5
+ pid_t *ptid, struct user_desc *tls, pid_t *ctid)
+ a6 a7 16(sp)
+*/
.text
ENTRY (__clone)
@@ -39,7 +43,7 @@ ENTRY (__clone)
/* 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. */
+ call. We trust that the kernel will preserve a6, a7 and a9. */
mov a9, a5 /* save function argument */
mov a5, a7
@@ -48,19 +52,18 @@ ENTRY (__clone)
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) */
+ movi a2, SYS_ify(clone)
+
+ /* syscall(NR_clone,clone_flags, usp, parent_tid, child_tls, child_tid)
+ a2 a6 a3 a4 a5 a8
+ */
+
syscall
bltz a2, SYSCALL_ERROR_LABEL
beqz a2, .Lthread_start
- /* Fall through for parent. */
+ /* fall through for parent */
+
.Lpseudo_end:
retw
@@ -69,32 +72,38 @@ ENTRY (__clone)
j SYSCALL_ERROR_LABEL
.Lthread_start:
- /* Start child thread. */
- movi a0, 0 /* terminate the stack frame */
+
+#if CLONE_THREAD != 0x00010000 || CLONE_VM != 0x00000100
+# error invalid values for CLONE_THREAD or CLONE_VM
+#endif
#ifdef RESET_PID
- /* Check and see if we need to reset the PID. */
- bbsi.l a6, 16, 1f /* CLONE_THREAD = 0x00010000 */
+ bbsi.l a6, 16, .Lskip_restore_pid /* CLONE_THREAD = 0x00010000 */
movi a2, -1
- bbsi.l a6, 8, 2f /* CLONE_VM = 0x00000100 */
- movi a2, SYS_ify (getpid)
+ bbsi a6, 8, .Lgotpid /* 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 */
-
+.Lgotpid:
+ rur a3, threadptr
+ movi a0, TLS_PRE_TCB_SIZE
+ sub a3, a3, a0
+ s32i a2, a3, PID
+ s32i a2, a3, TID
+.Lskip_restore_pid:
+#endif
+
+ /* start child thread */
+ movi a0, 0 /* terminate the stack frame */
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)
+ function in a6 is seen as inputs to _exit. */
+#ifdef PIC
+ movi a2, _exit@PLT
+#else
+ movi a2, _exit
+#endif
callx4 a2
PSEUDO_END (__clone)