xref: /minix3/lib/libc/arch/powerpc/sys/__clone.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: __clone.S,v 1.6 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#if defined(LIBC_SCCS) && !defined(lint)
33*0a6a1f1dSLionel Sambuc__RCSID("$NetBSD: __clone.S,v 1.6 2014/08/23 02:24:22 matt Exp $")
342fe8fb19SBen Gras#endif /* LIBC_SCCS && !lint */
352fe8fb19SBen Gras
362fe8fb19SBen Gras#ifdef WEAK_ALIAS
372fe8fb19SBen GrasWEAK_ALIAS(clone, __clone)
382fe8fb19SBen Gras#endif
392fe8fb19SBen Gras
402fe8fb19SBen Gras/*
412fe8fb19SBen Gras * int __clone(int (*fn)(void *), void *stack, int flags, void *arg);
422fe8fb19SBen Gras */
432fe8fb19SBen GrasENTRY(__clone)
442fe8fb19SBen Gras	/*
452fe8fb19SBen Gras	 * Sanity checks: func and stack may not be NULL.
462fe8fb19SBen Gras	 */
47*0a6a1f1dSLionel Sambuc	cmpptri	%r3,0
482fe8fb19SBen Gras	beq	1f
49*0a6a1f1dSLionel Sambuc	cmpptri	%r4,0
502fe8fb19SBen Gras	beq	1f
512fe8fb19SBen Gras
522fe8fb19SBen Gras	mr	%r7,%r3		/* Save fn in r7. */
532fe8fb19SBen Gras	mr	%r3,%r5
542fe8fb19SBen Gras	_DOSYSCALL(__clone)	/* (flags, stack) */
552fe8fb19SBen Gras	bso	2f		/* error... */
562fe8fb19SBen Gras
57*0a6a1f1dSLionel Sambuc	cmpptri	%r3,0
582fe8fb19SBen Gras	bnelr			/* We're the parent, just return. */
592fe8fb19SBen Gras
602fe8fb19SBen Gras	mtlr	%r7		/* fn */
612fe8fb19SBen Gras	mr	%r3,%r6		/* arg */
622fe8fb19SBen Gras	blrl			/* Call the clone's entry point. */
632fe8fb19SBen Gras
6484d9c625SLionel Sambuc#ifdef __PIC__
652fe8fb19SBen Gras	PIC_TOCSETUP(__clone, %r30)	/* exit won't return so blow away r30 */
662fe8fb19SBen Gras#endif
672fe8fb19SBen Gras	bl	PIC_PLT(_C_LABEL(_exit))
682fe8fb19SBen Gras
692fe8fb19SBen Gras1:
702fe8fb19SBen Gras	li	%r3,EINVAL
712fe8fb19SBen Gras2:
72*0a6a1f1dSLionel Sambuc	BRANCH_TO_CERROR()
732fe8fb19SBen GrasEND(__clone)
74