xref: /minix3/lib/libc/arch/powerpc64/sys/__clone.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: __clone.S,v 1.2 2014/08/23 02:24:22 matt Exp $	*/
22fe8fb19SBen Gras
32fe8fb19SBen Gras/*-
42fe8fb19SBen Gras * Copyright (c) 2001 Tsubai Masanari.  All rights reserved.
52fe8fb19SBen Gras *
62fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras * modification, are permitted provided that the following conditions
82fe8fb19SBen Gras * are met:
92fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras *    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras * 3. The name of the author may not be used to endorse or promote products
152fe8fb19SBen Gras *    derived from this software without specific prior written permission.
162fe8fb19SBen Gras *
172fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
182fe8fb19SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
192fe8fb19SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
202fe8fb19SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
212fe8fb19SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
222fe8fb19SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232fe8fb19SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242fe8fb19SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252fe8fb19SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262fe8fb19SBen Gras * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272fe8fb19SBen Gras */
282fe8fb19SBen Gras
292fe8fb19SBen Gras#include <sys/errno.h>
302fe8fb19SBen Gras#include "SYS.h"
312fe8fb19SBen Gras
322fe8fb19SBen Gras#ifdef WEAK_ALIAS
332fe8fb19SBen GrasWEAK_ALIAS(clone, __clone)
342fe8fb19SBen Gras#endif
352fe8fb19SBen Gras
362fe8fb19SBen Gras/*
372fe8fb19SBen Gras * int __clone(int (*fn)(void *), void *stack, int flags, void *arg);
382fe8fb19SBen Gras */
392fe8fb19SBen GrasENTRY(__clone)
402fe8fb19SBen Gras	/*
412fe8fb19SBen Gras	 * Sanity checks: func and stack may not be NULL.
422fe8fb19SBen Gras	 */
43*0a6a1f1dSLionel Sambuc	cmpptri	%r3,0
442fe8fb19SBen Gras	beq	1f
45*0a6a1f1dSLionel Sambuc	cmpptri	%r4,0
462fe8fb19SBen Gras	beq	1f
472fe8fb19SBen Gras
482fe8fb19SBen Gras	mr	%r7,%r3		/* Save fn in r7. */
492fe8fb19SBen Gras	mr	%r3,%r5
50*0a6a1f1dSLionel Sambuc	_DOSYSCALL(__clone)	/* (flags, stack) */
512fe8fb19SBen Gras	bso	2f		/* error... */
522fe8fb19SBen Gras
53*0a6a1f1dSLionel Sambuc	cmpptri	%r3,0
542fe8fb19SBen Gras	bnelr			/* We're the parent, just return. */
552fe8fb19SBen Gras
562fe8fb19SBen Gras	mtlr	%r7		/* fn */
572fe8fb19SBen Gras	mr	%r3,%r6		/* arg */
582fe8fb19SBen Gras	blrl			/* Call the clone's entry point. */
592fe8fb19SBen Gras
602fe8fb19SBen Gras	bl	PIC_PLT(_C_LABEL(_exit))
61*0a6a1f1dSLionel Sambuc	nop
622fe8fb19SBen Gras
632fe8fb19SBen Gras1:
642fe8fb19SBen Gras	li	%r3,EINVAL
652fe8fb19SBen Gras2:
66*0a6a1f1dSLionel Sambuc	BRANCH_TO_CERROR()
67*0a6a1f1dSLionel SambucEND(__clone)
68