xref: /minix3/lib/libc/arch/sh3/sys/__clone.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*	$NetBSD: __clone.S,v 1.7 2013/09/12 15:36:16 joerg 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	 */
432fe8fb19SBen Gras	tst	r4, r4
442fe8fb19SBen Gras	bt	inval
452fe8fb19SBen Gras	tst	r5, r5
462fe8fb19SBen Gras	bt	inval
472fe8fb19SBen Gras
482fe8fb19SBen Gras	mov	r4, r2		/* save entry point for later */
492fe8fb19SBen Gras
502fe8fb19SBen Gras	mov	r6, r4		/* r4 = flags, r5 = stack (already) */
512fe8fb19SBen Gras	mov.l	.L_SYS___clone, r0
522fe8fb19SBen Gras	trapa	#0x80
532fe8fb19SBen Gras	bf	err
542fe8fb19SBen Gras
552fe8fb19SBen Gras	tst	r0, r0
562fe8fb19SBen Gras	bf	3f		/* we're the parent, just return */
572fe8fb19SBen Gras
582fe8fb19SBen Gras	jsr	@r2		/* clone does _exit((*fn)(arg)); */
592fe8fb19SBen Gras	 mov	r7, r4
602fe8fb19SBen Gras
612fe8fb19SBen Gras	mov.l	.L__exit, r1
62*84d9c625SLionel Sambuc#ifdef __PIC__
632fe8fb19SBen Gras	mov	r0, r4
642fe8fb19SBen Gras	mov.l	.L_got, r12	/* PIC_PROLOGUE_NOSAVE(.L_got) */
652fe8fb19SBen Gras	mova	.L_got, r0	/*  expanded to fill the delay slot */
662fe8fb19SBen Gras1:	JUMP	r1
672fe8fb19SBen Gras	 add	r0, r12
682fe8fb19SBen Gras#else
692fe8fb19SBen Gras	JUMP	r1
702fe8fb19SBen Gras	 mov	r0, r4
712fe8fb19SBen Gras#endif
722fe8fb19SBen Gras	/* NOTREACHED */
732fe8fb19SBen Gras
742fe8fb19SBen Grasinval:
752fe8fb19SBen Gras	mov	#EINVAL, r0
762fe8fb19SBen Graserr:
772fe8fb19SBen Gras	JUMP_CERROR
782fe8fb19SBen Gras	/* NOTREACHED */
792fe8fb19SBen Gras
802fe8fb19SBen Gras3:	rts
812fe8fb19SBen Gras	 nop
822fe8fb19SBen Gras
832fe8fb19SBen Gras	.align	2
842fe8fb19SBen Gras.L_SYS___clone:	.long	SYS___clone
852fe8fb19SBen Gras
862fe8fb19SBen Gras.L_got:		PIC_GOT_DATUM
872fe8fb19SBen Gras.L__exit:	CALL_DATUM(_C_LABEL(_exit), 1b)
882fe8fb19SBen Gras	SET_ENTRY_SIZE(__clone)
89