xref: /netbsd-src/lib/libc/arch/powerpc/sys/__clone.S (revision 38dcdc34d982bf8ab9a66b4b5b2e99311457ea36)
1*38dcdc34Smatt/*	$NetBSD: __clone.S,v 1.6 2014/08/23 02:24:22 matt Exp $	*/
2193161b3Stsubai
3193161b3Stsubai/*-
4193161b3Stsubai * Copyright (c) 2001 Tsubai Masanari.  All rights reserved.
5193161b3Stsubai *
6193161b3Stsubai * Redistribution and use in source and binary forms, with or without
7193161b3Stsubai * modification, are permitted provided that the following conditions
8193161b3Stsubai * are met:
9193161b3Stsubai * 1. Redistributions of source code must retain the above copyright
10193161b3Stsubai *    notice, this list of conditions and the following disclaimer.
11193161b3Stsubai * 2. Redistributions in binary form must reproduce the above copyright
12193161b3Stsubai *    notice, this list of conditions and the following disclaimer in the
13193161b3Stsubai *    documentation and/or other materials provided with the distribution.
14193161b3Stsubai * 3. The name of the author may not be used to endorse or promote products
15193161b3Stsubai *    derived from this software without specific prior written permission.
16193161b3Stsubai *
17193161b3Stsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18193161b3Stsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19193161b3Stsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20193161b3Stsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21193161b3Stsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22193161b3Stsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23193161b3Stsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24193161b3Stsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25193161b3Stsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26193161b3Stsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27193161b3Stsubai */
28193161b3Stsubai
29193161b3Stsubai#include <sys/errno.h>
30193161b3Stsubai#include "SYS.h"
31193161b3Stsubai
32cf88c389Smatt#if defined(LIBC_SCCS) && !defined(lint)
33*38dcdc34Smatt__RCSID("$NetBSD: __clone.S,v 1.6 2014/08/23 02:24:22 matt Exp $")
34cf88c389Smatt#endif /* LIBC_SCCS && !lint */
35cf88c389Smatt
36193161b3Stsubai#ifdef WEAK_ALIAS
37193161b3StsubaiWEAK_ALIAS(clone, __clone)
38193161b3Stsubai#endif
39193161b3Stsubai
40193161b3Stsubai/*
41193161b3Stsubai * int __clone(int (*fn)(void *), void *stack, int flags, void *arg);
42193161b3Stsubai */
43193161b3StsubaiENTRY(__clone)
44193161b3Stsubai	/*
45193161b3Stsubai	 * Sanity checks: func and stack may not be NULL.
46193161b3Stsubai	 */
47*38dcdc34Smatt	cmpptri	%r3,0
48193161b3Stsubai	beq	1f
49*38dcdc34Smatt	cmpptri	%r4,0
50193161b3Stsubai	beq	1f
51193161b3Stsubai
521cddd41eSmatt	mr	%r7,%r3		/* Save fn in r7. */
531cddd41eSmatt	mr	%r3,%r5
54cf88c389Smatt	_DOSYSCALL(__clone)	/* (flags, stack) */
55193161b3Stsubai	bso	2f		/* error... */
56193161b3Stsubai
57*38dcdc34Smatt	cmpptri	%r3,0
58193161b3Stsubai	bnelr			/* We're the parent, just return. */
59193161b3Stsubai
601cddd41eSmatt	mtlr	%r7		/* fn */
611cddd41eSmatt	mr	%r3,%r6		/* arg */
62193161b3Stsubai	blrl			/* Call the clone's entry point. */
63193161b3Stsubai
644d12bfcdSjoerg#ifdef __PIC__
65b79441d4Smatt	PIC_TOCSETUP(__clone, %r30)	/* exit won't return so blow away r30 */
66b79441d4Smatt#endif
67193161b3Stsubai	bl	PIC_PLT(_C_LABEL(_exit))
68193161b3Stsubai
69193161b3Stsubai1:
701cddd41eSmatt	li	%r3,EINVAL
71193161b3Stsubai2:
72*38dcdc34Smatt	BRANCH_TO_CERROR()
73cf88c389SmattEND(__clone)
74