__clone.S revision 1.1 1 1.1 matt /* $NetBSD: __clone.S,v 1.1 2014/09/03 19:34:26 matt Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2001 Tsubai Masanari. All rights reserved.
5 1.1 matt *
6 1.1 matt * Redistribution and use in source and binary forms, with or without
7 1.1 matt * modification, are permitted provided that the following conditions
8 1.1 matt * are met:
9 1.1 matt * 1. Redistributions of source code must retain the above copyright
10 1.1 matt * notice, this list of conditions and the following disclaimer.
11 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer in the
13 1.1 matt * documentation and/or other materials provided with the distribution.
14 1.1 matt * 3. The name of the author may not be used to endorse or promote products
15 1.1 matt * derived from this software without specific prior written permission.
16 1.1 matt *
17 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 matt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 matt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 matt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 matt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 matt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 matt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 matt */
28 1.1 matt
29 1.1 matt #include <sys/errno.h>
30 1.1 matt #include "SYS.h"
31 1.1 matt
32 1.1 matt #if defined(LIBC_SCCS) && !defined(lint)
33 1.1 matt __RCSID("$NetBSD: __clone.S,v 1.1 2014/09/03 19:34:26 matt Exp $")
34 1.1 matt #endif /* LIBC_SCCS && !lint */
35 1.1 matt
36 1.1 matt #ifdef WEAK_ALIAS
37 1.1 matt WEAK_ALIAS(clone, __clone)
38 1.1 matt #endif
39 1.1 matt
40 1.1 matt /*
41 1.1 matt * int __clone(int (*fn)(void *), void *stack, int flags, void *arg);
42 1.1 matt */
43 1.1 matt ENTRY(__clone)
44 1.1 matt /*
45 1.1 matt * Sanity checks: func and stack may not be NULL.
46 1.1 matt */
47 1.1 matt l.sfeqi r3,0
48 1.1 matt l.bf 2f
49 1.1 matt l.sfeqi r4,0
50 1.1 matt l.bf 2f
51 1.1 matt
52 1.1 matt l.or r7,r3,r0 /* Save fn in r7. */
53 1.1 matt l.or r3,r5,r0
54 1.1 matt _DOSYSCALL(__clone) /* (flags, stack) */
55 1.1 matt l.bf _C_LABEL(__cerror) /* error... */
56 1.1 matt l.nop
57 1.1 matt
58 1.1 matt l.sfeqi r11,0
59 1.1 matt l.bf 1f /* We're the parent, just return. */
60 1.1 matt l.nop
61 1.1 matt l.jr lr
62 1.1 matt l.nop
63 1.1 matt
64 1.1 matt 1: l.or r3,r6,r0 /* arg */
65 1.1 matt l.jalr r7 /* Call the clone's entry point. */
66 1.1 matt l.nop
67 1.1 matt
68 1.1 matt #ifdef __PIC__
69 1.1 matt // We don't need to save r9 or r16 since we aren't ever coming back
70 1.1 matt PIC_GOTSETUP(r16)
71 1.1 matt #endif
72 1.1 matt l.jal plt(_C_LABEL(_exit))
73 1.1 matt l.nop
74 1.1 matt
75 1.1 matt 2:
76 1.1 matt l.addi r11,r0,EINVAL
77 1.1 matt l.j _C_LABEL(__cerror)
78 1.1 matt l.nop
79 1.1 matt END(__clone)
80