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