OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / arm / clone.S
1 /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Pat Beirne <patb@corelcomputer.com>
4
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.
9
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.
14
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/>.  */
18
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.  */
21
22 #define _ERRNO_H
23 #include <features.h>
24 #include <bits/errno.h>
25 #include <sys/syscall.h>
26 #include <bits/arm_asm.h>
27
28 #if defined(__NR_clone)
29 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
30
31 .text
32 .global __clone
33 .type __clone,%function
34 .align 2
35 #if defined(THUMB1_ONLY)
36 .thumb_func
37 __clone:
38         @ sanity check args
39         cmp     r0, #0
40         beq     __einval
41         cmp     r1, #0
42         beq     __einval
43
44         @ insert the args onto the new stack
45         sub     r1, r1, #8
46         str     r3, [r1, #4]
47         @ save the function pointer as the 0th element
48         str     r0, [r1]
49
50         @ do the system call
51         @ get flags
52         mov     r0, r2
53         @ new sp is already in r1
54         @ load remaining arguments off the stack
55         stmfd   sp!, {r4}
56         ldr     r2, [sp, #4]
57         ldr     r3, [sp, #8]
58         ldr     r4, [sp, #12]
59         DO_CALL (clone)
60         movs    a1, a1
61         blt     __error
62         ldmnefd sp!, {r4}
63         beq     1f
64         bx      lr
65 1:
66
67         @ pick the function arg and call address off the stack and execute
68         ldr     r0, [sp, #4]
69         ldr     r1, [sp]
70         bl      2f      @ blx r1
71
72         @ and we are done, passing the return value through r0
73         bl      HIDDEN_JUMPTARGET(_exit)
74         @ Should never return
75         b       .
76
77 2:
78         bx      r1
79
80 __einval:
81         ldr     r0, =-EINVAL
82 __error:
83         push    {r3, lr}
84         bl      __syscall_error
85         POP_RET
86 .pool
87 #else
88 __clone:
89         @ sanity check args
90         cmp     r0, #0
91         IT(te, ne)
92         cmpne   r1, #0
93         moveq   r0, #-EINVAL
94         beq     __error
95
96         @ insert the args onto the new stack
97         sub     r1, r1, #8
98         str     r3, [r1, #4]
99         @ save the function pointer as the 0th element
100         str     r0, [r1]
101
102         @ do the system call
103         @ get flags
104         mov     r0, r2
105         @ new sp is already in r1
106         @ load remaining arguments off the stack
107         stmfd   sp!, {r4}
108         ldr     r2, [sp, #4]
109         ldr     r3, [sp, #8]
110         ldr     r4, [sp, #12]
111         DO_CALL (clone)
112         movs    a1, a1
113         blt     __error
114         ldmnefd sp!, {r4}
115         IT(t, ne)
116 #if defined(__USE_BX__)
117         bxne    lr
118 #else
119         movne   pc, lr
120 #endif
121
122         @ pick the function arg and call address off the stack and execute
123         ldr     r0, [sp, #4]
124         mov     lr, pc
125         ldr     pc, [sp]
126
127         @ and we are done, passing the return value through r0
128         b       HIDDEN_JUMPTARGET(_exit)
129
130 __error:
131         b       __syscall_error
132 #endif
133
134 .size __clone,.-__clone
135 weak_alias(__clone, clone)
136
137 #endif