1 /* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by David Huggins-Daines <dhd@debian.org>, 2000.
4 Based on the Alpha version by Richard Henderson <rth@tamu.edu>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 /* clone() is even more special than fork() as it mucks with stacks
21 and invokes a function in the right context after its all over. */
23 #include <asm/unistd.h>
25 #include <bits/errno.h>
26 #include <sys/syscall.h>
28 /* Non-thread code calls __clone with the following parameters:
29 int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
31 NPTL Code will call __clone with the following parameters:
32 int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
33 int *parent_tidptr, struct user_desc *newtls, int *child_pidptr)
35 The code should not mangle the extra input registers.
36 Syscall expects: Input to __clone:
37 4(r25) - function pointer (r26, arg0)
38 0(r25) - argument (r23, arg3)
39 r26 - clone flags. (r24, arg2)
40 r25+64 - user stack pointer. (r25, arg1)
41 r24 - parent tid pointer. (stack - 52)
42 r23 - struct user_desc newtls pointer. (stack - 56)
43 r22 - child tid pointer. (stack - 60)
44 r20 - clone syscall number (constant)
49 .type __clone,%function
52 /* Sanity check arguments. */
54 comib,=,n 0,%arg0,.Lerror /* no NULL function pointers */
55 comib,=,n 0,%arg1,.Lerror /* no NULL stack pointers */
57 /* Save the fn ptr and arg on the new stack. */
60 /* Clone arguments are (int flags, void * child_stack) */
61 copy %r24,%r26 /* flags are first */
62 /* User stack pointer is in the correct register already */
64 /* Load args from stack... */
65 ldw -52(%sp), %r24 /* Load parent_tidptr */
66 ldw -56(%sp), %r23 /* Load newtls */
67 ldw -60(%sp), %r22 /* Load child_tidptr */
69 /* Create frame to get r3 free */
74 /* Save the PIC register. */
76 copy %r19, %r3 /* parent */
79 /* Do the system call */
84 comclr,>>= %r1,%ret0,%r0 /* Note: unsigned compare. */
87 comib,=,n 0,%ret0,thread_start
89 /* Successful return from the parent
90 No need to restore the PIC register,
91 since we return immediately. */
97 /* Restore the PIC register on error */
99 copy %r3, %r19 /* parent */
102 /* Something bad happened -- no child created */
105 /* Set errno, save ret0 so we return with that value. */
110 /* Return after setting errno, and restoring ret0 */
116 /* Load up the arguments. */
117 ldw -60(%sr0, %sp),%arg0
118 ldw -64(%sr0, %sp),%r22
120 /* $$dyncall fixes childs PIC register */
122 /* Call the user's function */
126 bl HIDDEN_JUMPTARGET(_exit),%rp
130 iitlbp %r0,(%sr0,%r0)
134 weak_alias (__clone, clone)