]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/hppa/clone.S
2006-05-24 Carlos O'Donell <carlos@systemhalted.org>
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / hppa / clone.S
CommitLineData
b35e2407
UD
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.
5
6 The GNU C Library is free software; you can redistribute it and/or
3214b89b
AJ
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.
b35e2407
UD
10
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
3214b89b 14 Lesser General Public License for more details.
b35e2407 15
3214b89b
AJ
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
b35e2407
UD
20
21/* clone() is even more special than fork() as it mucks with stacks
22 and invokes a function in the right context after its all over. */
23
24#include <asm/unistd.h>
25#include <sysdep.h>
26#define _ERRNO_H 1
27#include <bits/errno.h>
28
a29e6e84
CD
29/* Non-thread code calls __clone with the following parameters:
30 int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
31
32 NPTL Code will call __clone with the following parameters:
33 int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
34 int *parent_tidptr, struct user_desc *newtls, int *child_pidptr)
35
36 The code should not mangle the extra input registers.
37 Syscall expects: Input to __clone:
38 4(r25) - function pointer (r26, arg0)
39 0(r25) - argument (r23, arg3)
40 r26 - clone flags. (r24, arg2)
41 r25+64 - user stack pointer. (r25, arg1)
42 r24 - parent tid pointer. (stack - 52)
43 r23 - struct user_desc newtls pointer. (stack - 56)
44 r22 - child tid pointer. (stack - 60)
45 r20 - clone syscall number (constant)
46 */
b35e2407
UD
47
48 .text
49ENTRY(__clone)
b35e2407
UD
50
51 /* Sanity check arguments. */
15a25bb6 52 ldi -EINVAL,%ret0
a29e6e84
CD
53 comib,=,n 0,%arg0,.Lerror /* no NULL function pointers */
54 comib,=,n 0,%arg1,.Lerror /* no NULL stack pointers */
b35e2407
UD
55
56 /* Save the fn ptr and arg on the new stack. */
a29e6e84
CD
57 stwm %r26,64(%r25)
58 stw %r23,-60(%r25)
59 /* Clone arguments are (int flags, void * child_stack) */
60 copy %r24,%r26 /* flags are first */
61 /* User stack pointer is in the correct register already */
62
63 /* Load args from stack... */
64 ldw -52(%sp), %r24 /* Load parent_tidptr */
65 ldw -56(%sp), %r23 /* Load newtls */
66 ldw -60(%sp), %r22 /* Load child_tidptr */
67
68 /* Create frame to get r3 free */
69 copy %sp, %r21
70 stwm %r3, 64(%sp)
71 stw %r21, -4(%sp)
b35e2407 72
46bf1d81
UD
73 /* Save the PIC register. */
74#ifdef PIC
a29e6e84 75 copy %r19, %r3 /* parent */
46bf1d81
UD
76#endif
77
b35e2407 78 /* Do the system call */
15a25bb6 79 ble 0x100(%sr2,%r0)
b35e2407
UD
80 ldi __NR_clone,%r20
81
82 ldi -4096,%r1
83 comclr,>>= %r1,%ret0,%r0 /* Note: unsigned compare. */
a29e6e84 84 b,n .LerrorRest
b35e2407
UD
85
86 comib,=,n 0,%ret0,thread_start
87
46bf1d81
UD
88 /* Successful return from the parent
89 No need to restore the PIC register,
90 since we return immediately. */
91
b35e2407 92 bv %r0(%rp)
a29e6e84 93 ldwm -64(%sp), %r3
46bf1d81 94
a29e6e84 95.LerrorRest
46bf1d81
UD
96 /* Restore the PIC register on error */
97#ifdef PIC
a29e6e84 98 copy %r3, %r19 /* parent */
46bf1d81
UD
99#endif
100
a29e6e84
CD
101 /* Something bad happened -- no child created */
102.Lerror:
103
104 /* Set errno, save ret0 so we return with that value. */
105 copy %ret0, %r3
b35e2407 106 b __syscall_error
15a25bb6 107 sub %r0,%ret0,%arg0
a29e6e84
CD
108 copy %r3, %ret0
109 /* Return after setting errno, and restoring ret0 */
110 bv %r0(%rp)
111 ldwm -64(%sp), %r3
b35e2407
UD
112
113thread_start:
46bf1d81 114
b35e2407 115 /* Load up the arguments. */
46bf1d81
UD
116 ldw -60(%sr0, %sp),%arg0
117 ldw -64(%sr0, %sp),%r22
118
119 /* $$dyncall fixes childs PIC register */
b35e2407
UD
120
121 /* Call the user's function */
122 bl $$dyncall,%r31
123 copy %r31,%rp
124
125 bl _exit,%rp
126 copy %ret0,%arg0
127
128 /* Die horribly. */
a29e6e84 129 iitlbp %r0,(%sr0,%r0)
b35e2407
UD
130
131PSEUDO_END(__clone)
132
8796ce21 133weak_alias (__clone, clone)