__clone.S revision 1.1.2.4 1 1.1.2.4 nathanw /* $NetBSD: __clone.S,v 1.1.2.4 2002/09/17 21:32:43 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*
4 1.1.2.2 nathanw * Copyright (c) 2001 Christopher Gilbert
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
8 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
9 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
10 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
11 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
12 1.1.2.2 nathanw * 3. The name of the company nor the name of the author may be used to
13 1.1.2.2 nathanw * endorse or promote products derived from this software without specific
14 1.1.2.2 nathanw * prior written permission.
15 1.1.2.2 nathanw *
16 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 1.1.2.2 nathanw * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 1.1.2.2 nathanw * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 1.1.2.2 nathanw * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1.2.2 nathanw * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1.2.2 nathanw * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.2.2 nathanw * SUCH DAMAGE.
27 1.1.2.2 nathanw */
28 1.1.2.2 nathanw
29 1.1.2.2 nathanw #include <machine/asm.h>
30 1.1.2.2 nathanw #include <sys/errno.h>
31 1.1.2.2 nathanw #include "SYS.h"
32 1.1.2.2 nathanw
33 1.1.2.2 nathanw #ifdef WEAK_ALIAS
34 1.1.2.2 nathanw WEAK_ALIAS(clone, __clone)
35 1.1.2.2 nathanw #endif
36 1.1.2.2 nathanw
37 1.1.2.2 nathanw /*
38 1.1.2.2 nathanw * int __clone(int (*fn)(void *), void *stack, int flags, void *arg);
39 1.1.2.2 nathanw */
40 1.1.2.2 nathanw ENTRY(__clone)
41 1.1.2.2 nathanw
42 1.1.2.2 nathanw /* test stack and function are not null */
43 1.1.2.2 nathanw teq r0, #0x00
44 1.1.2.2 nathanw teqne r1, #0x00
45 1.1.2.3 nathanw beq .Leinval
46 1.1.2.2 nathanw
47 1.1.2.2 nathanw /* place the func and it's arg onto the child's stack */
48 1.1.2.2 nathanw stmfd r1!, {r0, r3}
49 1.1.2.2 nathanw
50 1.1.2.2 nathanw /* syscall expects (flags, stack) */
51 1.1.2.2 nathanw mov r0, r2
52 1.1.2.2 nathanw
53 1.1.2.2 nathanw SYSTRAP(__clone)
54 1.1.2.2 nathanw bcs PIC_SYM(CERROR, PLT)
55 1.1.2.2 nathanw
56 1.1.2.2 nathanw /*
57 1.1.2.2 nathanw * r1 and r0 are the same as from fork:
58 1.1.2.2 nathanw * r1 == 0 in parent process, r1 == 1 in child process.
59 1.1.2.2 nathanw * r0 == pid of child in parent, r0 == pid of parent in child.
60 1.1.2.2 nathanw */
61 1.1.2.2 nathanw teq r1, #0x00
62 1.1.2.2 nathanw
63 1.1.2.2 nathanw /* if this is the parent then just return the pid */
64 1.1.2.2 nathanw #ifdef __APCS_26__
65 1.1.2.2 nathanw moveqs r15, r14
66 1.1.2.2 nathanw #else
67 1.1.2.2 nathanw moveq r15, r14
68 1.1.2.2 nathanw #endif
69 1.1.2.2 nathanw /*
70 1.1.2.2 nathanw * This is the child
71 1.1.2.2 nathanw * load the function and arg off the stack
72 1.1.2.2 nathanw */
73 1.1.2.2 nathanw ldmfd sp!, {r1, r2}
74 1.1.2.2 nathanw
75 1.1.2.2 nathanw /* setup return address */
76 1.1.2.3 nathanw add lr, pc, #.Lreturnhere - . - 8
77 1.1.2.2 nathanw
78 1.1.2.2 nathanw /* place arg in r0 */
79 1.1.2.2 nathanw mov r0, r2
80 1.1.2.2 nathanw
81 1.1.2.2 nathanw /* call the function */
82 1.1.2.2 nathanw mov pc, r1
83 1.1.2.2 nathanw
84 1.1.2.3 nathanw .Lreturnhere:
85 1.1.2.2 nathanw /* call _exit with the returned value */
86 1.1.2.4 nathanw b PIC_SYM(_C_LABEL(_exit), PLT)
87 1.1.2.2 nathanw
88 1.1.2.2 nathanw /* NOTREACHED */
89 1.1.2.2 nathanw
90 1.1.2.2 nathanw /* error handler if func or stack is NULL */
91 1.1.2.3 nathanw .Leinval:
92 1.1.2.2 nathanw mov R0, #EINVAL
93 1.1.2.2 nathanw b PIC_SYM(CERROR, PLT)
94