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