cleanup unused defines and includes from clone.S
[uclibc-ng.git] / libc / sysdeps / linux / mips / clone.S
blobf95adaf0df8fd4d7b2d98e54dace79841497c3ef
1 /* Copyright (C) 1996, 1997, 2000, 2003, 2005 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ralf Baechle <ralf@linux-mips.org>, 1996.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 /* clone() is even more special than fork() as it mucks with stacks
20    and invokes a function in the right context after its all over.  */
22 #include <features.h>
23 #include <sys/asm.h>
24 #include <sysdep.h>
25 #define _ERRNO_H        1
26 #include <bits/errno.h>
28 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
29              void *parent_tidptr, void *tls, void *child_tidptr) */
31         .text
32 #if _MIPS_SIM == _ABIO32
33 # define EXTRA_LOCALS 1
34 #else
35 # define EXTRA_LOCALS 0
36 #endif
37 LOCALSZ= 4
38 FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
39 GPOFF= FRAMESZ-(1*SZREG)
40 NESTED(clone,4*SZREG,sp)
41 #ifdef __PIC__
42         SETUP_GP
43 #endif
44         PTR_SUBU sp, FRAMESZ
45         SETUP_GP64 (GPOFF, clone)
46 #ifdef __PIC__
47         SAVE_GP (GPOFF)
48 #endif
50         /* Sanity check arguments.  */
51         li              v0,EINVAL
52         beqz            a0,L(error)     /* No NULL function pointers.  */
53         beqz            a1,L(error)     /* No NULL stack pointers.  */
55         PTR_SUBU        a1,32           /* Reserve argument save space.  */
56         PTR_S           a0,0(a1)        /* Save function pointer.  */
57         PTR_S           a3,PTRSIZE(a1)  /* Save argument pointer.  */
59         move            a0,a2
61         /* Shuffle in the last three arguments - arguments 5, 6, and 7 to
62            this function, but arguments 3, 4, and 5 to the syscall.  */
63 #if _MIPS_SIM == _ABIO32
64         PTR_L           a2,(FRAMESZ+PTRSIZE+PTRSIZE+16)(sp)
65         PTR_S           a2,16(sp)
66         PTR_L           a2,(FRAMESZ+16)(sp)
67         PTR_L           a3,(FRAMESZ+PTRSIZE+16)(sp)
68 #else
69         move            a2,a4
70         move            a3,a5
71         move            a4,a6
72 #endif
74         /* Do the system call */
75         li              v0,__NR_clone
76         syscall
78         bnez            a3,L(error)
79         beqz            v0,L(thread_start)
81         /* Successful return from the parent */
82         RESTORE_GP64
83         PTR_ADDU        sp, FRAMESZ
84         j $31  ; nop
86         /* Something bad happened -- no child created */
87 L(error):
88 #ifdef __PIC__
89         PTR_LA          t9,__syscall_error
90         RESTORE_GP64
91         PTR_ADDU        sp, FRAMESZ
92         /* uClibc change -- start */
93         move            a0,v0           /* Pass return val to C function. */
94         /* uClibc change -- stop */
95         jr              t9
96 #else
97         RESTORE_GP64
98         PTR_ADDU        sp, FRAMESZ
99         /* uClibc change -- start */
100         move            a0,v0           /* Pass return val to C function. */
101         /* uClibc change -- stop */
102         j               __syscall_error
103 #endif
104         END(clone)
106 /* Load up the arguments to the function.  Put this block of code in
107    its own function so that we can terminate the stack trace with our
108    debug info.  */
110 ENTRY(__thread_start)
111 L(thread_start):
112         /* cp is already loaded.  */
113         SAVE_GP (GPOFF)
114         /* The stackframe has been created on entry of clone().  */
116         /* Restore the arg for user's function.  */
117         PTR_L           t9,0(sp)        /* Function pointer.  */
118         PTR_L           a0,PTRSIZE(sp)  /* Argument pointer.  */
120         /* Call the user's function.  */
121         jal             t9
123         /* Call _exit rather than doing it inline for breakpoint purposes.  */
124         move            a0,v0
125 #ifdef __PIC__
126         PTR_LA          t9,_exit
127         jalr            t9
128 #else
129         jal             _exit
130 #endif
132         END(__thread_start)
134 weak_alias(clone, __clone)