]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/hppa/clone.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / hppa / clone.S
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
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.
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
14    Lesser General Public License for more details.
15
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/>.  */
19
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.  */
22
23 #include <asm/unistd.h>
24 #define _ERRNO_H        1
25 #include <bits/errno.h>
26 #include <sys/syscall.h>
27
28 /* Non-thread code calls __clone with the following parameters:
29    int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg)
30    
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)
34         
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)
45  */
46
47 .text
48 .global __clone
49 .type   __clone,%function
50 __clone:
51
52         /* Sanity check arguments.  */
53         ldi     -EINVAL,%ret0
54         comib,=,n  0,%arg0,.Lerror        /* no NULL function pointers */
55         comib,=,n  0,%arg1,.Lerror        /* no NULL stack pointers */
56
57         /* Save the fn ptr and arg on the new stack.  */
58         stwm    %r26,64(%r25)
59         stw     %r23,-60(%r25)
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 */
63
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 */
68
69         /* Create frame to get r3 free */
70         copy    %sp, %r21
71         stwm    %r3, 64(%sp)
72         stw     %r21, -4(%sp)
73
74         /* Save the PIC register. */
75 #ifdef __PIC__
76         copy    %r19, %r3               /* parent */
77 #endif
78
79         /* Do the system call */
80         ble     0x100(%sr2,%r0)
81         ldi     __NR_clone,%r20
82
83         ldi     -4096,%r1
84         comclr,>>= %r1,%ret0,%r0        /* Note: unsigned compare. */
85         b,n     .LerrorRest
86
87         comib,=,n 0,%ret0,thread_start
88
89         /* Successful return from the parent
90            No need to restore the PIC register, 
91            since we return immediately. */
92
93         bv      %r0(%rp)
94         ldwm    -64(%sp), %r3
95
96 .LerrorRest:
97         /* Restore the PIC register on error */
98 #ifdef __PIC__
99         copy    %r3, %r19               /* parent */ 
100 #endif
101
102         /* Something bad happened -- no child created */
103 .Lerror:
104
105         /* Set errno, save ret0 so we return with that value. */
106         copy    %ret0, %r3
107         b       __syscall_error
108         sub     %r0,%ret0,%arg0
109         copy    %r3, %ret0
110         /* Return after setting errno, and restoring ret0 */
111         bv      %r0(%rp)
112         ldwm    -64(%sp), %r3
113
114 thread_start:
115
116         /* Load up the arguments.  */
117         ldw     -60(%sr0, %sp),%arg0
118         ldw     -64(%sr0, %sp),%r22
119
120         /* $$dyncall fixes childs PIC register */
121
122         /* Call the user's function */
123         bl      $$dyncall,%r31
124         copy    %r31,%rp
125
126         bl      HIDDEN_JUMPTARGET(_exit),%rp
127         copy    %ret0,%arg0
128
129         /* Die horribly.  */
130         iitlbp  %r0,(%sr0,%r0)
131
132 .size clone,.-clone
133
134 weak_alias (__clone, clone)