xref: /netbsd-src/lib/libc/arch/m68k/sys/__vfork14.S (revision 4d12bfcd155352508213ace5ccc59ce930ea2974)
1*4d12bfcdSjoerg/*	$NetBSD: __vfork14.S,v 1.12 2013/09/12 15:36:15 joerg Exp $	*/
2bedc7b48Sthorpej
3bedc7b48Sthorpej/*-
4bedc7b48Sthorpej * Copyright (c) 1990 The Regents of the University of California.
5bedc7b48Sthorpej * All rights reserved.
6bedc7b48Sthorpej *
7bedc7b48Sthorpej * This code is derived from software contributed to Berkeley by
8bedc7b48Sthorpej * the Systems Programming Group of the University of Utah Computer
9bedc7b48Sthorpej * Science Department.
10bedc7b48Sthorpej *
11bedc7b48Sthorpej * Redistribution and use in source and binary forms, with or without
12bedc7b48Sthorpej * modification, are permitted provided that the following conditions
13bedc7b48Sthorpej * are met:
14bedc7b48Sthorpej * 1. Redistributions of source code must retain the above copyright
15bedc7b48Sthorpej *    notice, this list of conditions and the following disclaimer.
16bedc7b48Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
17bedc7b48Sthorpej *    notice, this list of conditions and the following disclaimer in the
18bedc7b48Sthorpej *    documentation and/or other materials provided with the distribution.
19eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
20bedc7b48Sthorpej *    may be used to endorse or promote products derived from this software
21bedc7b48Sthorpej *    without specific prior written permission.
22bedc7b48Sthorpej *
23bedc7b48Sthorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24bedc7b48Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25bedc7b48Sthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26bedc7b48Sthorpej * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27bedc7b48Sthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28bedc7b48Sthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29bedc7b48Sthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30bedc7b48Sthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31bedc7b48Sthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32bedc7b48Sthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33bedc7b48Sthorpej * SUCH DAMAGE.
34bedc7b48Sthorpej */
35bedc7b48Sthorpej
36bedc7b48Sthorpej#include "SYS.h"
37bedc7b48Sthorpej
38bedc7b48Sthorpej#if defined(LIBC_SCCS) && !defined(lint)
39bedc7b48Sthorpej#if 0
40bedc7b48Sthorpej	RCSID("from: @(#)Ovfork.s	5.1 (Berkeley) 5/12/90")
41bedc7b48Sthorpej#else
42*4d12bfcdSjoerg	RCSID("$NetBSD: __vfork14.S,v 1.12 2013/09/12 15:36:15 joerg Exp $")
43bedc7b48Sthorpej#endif
44bedc7b48Sthorpej#endif /* LIBC_SCCS and not lint */
45bedc7b48Sthorpej
46bedc7b48Sthorpej/*
47bedc7b48Sthorpej * @(#)vfork.s	4.1 (Berkeley) 12/21/80
48bedc7b48Sthorpej * C library -- vfork
49bedc7b48Sthorpej */
50bedc7b48Sthorpej
51bedc7b48Sthorpej/*
52bedc7b48Sthorpej * pid = vfork();
53bedc7b48Sthorpej *
54bedc7b48Sthorpej * d1 == 0 in parent process, d1 == 1 in child process.
55bedc7b48Sthorpej * d0 == pid of child in parent, d0 == pid of parent in child.
56bedc7b48Sthorpej *
57bedc7b48Sthorpej * trickery here, due to keith sklower, uses ret to clear the stack,
58bedc7b48Sthorpej * and then returns with a jump indirect, since only one person can return
59bedc7b48Sthorpej * with a ret off this stack... we do the ret before we vfork!
60bedc7b48Sthorpej */
61bedc7b48Sthorpej
62bedc7b48SthorpejENTRY(__vfork14)
6307a0a325Smatt	movl	(%sp)+,%a1
642d913a7cSmatt	SYSTRAP(__vfork14)
65bedc7b48Sthorpej	jcs	err
663b435a73Sthorpej	subql	#1,%d1	/* from 1 to 0 in child, 0 to -1 in parent */
673b435a73Sthorpej	andl	%d1,%d0
6807a0a325Smatt	jmp	(%a1)
69bedc7b48Sthorpejerr:
70ad0a7279Skleink#ifdef	_REENTRANT
71ad0a7279Skleink	.globl	_C_LABEL(__errno)
7207a0a325Smatt	movl	%a1,-(%sp)
7307a0a325Smatt	movl	%d0,-(%sp)
741d0a4330Sitohy	jbsr	PIC_PLT(_C_LABEL(__errno))
7518d5ba61Skleink#ifdef	__SVR4_ABI__
7607a0a325Smatt	movl	(%sp)+,(%a0)
7718d5ba61Skleink#else
783b435a73Sthorpej	movl	%d0,%a1
7907a0a325Smatt	movl	(%sp)+,(%a1)
8018d5ba61Skleink#endif
8107a0a325Smatt	movl	(%sp)+,%a1
82ad0a7279Skleink#else
83*4d12bfcdSjoerg#ifdef __PIC__
842d913a7cSmatt	GOT_SETUP(%a0)
8507a0a325Smatt	movl	_C_LABEL(errno)@GOT:w(%a0),%a0
8607a0a325Smatt	movl	%d0,(%a0)
87bedc7b48Sthorpej#else
882d913a7cSmatt	.globl	_C_LABEL(errno)
893b435a73Sthorpej	movl	%d0,_C_LABEL(errno)
90*4d12bfcdSjoerg#endif	/* __PIC__ */
91ad0a7279Skleink#endif	/* _REENTRANT */
923b435a73Sthorpej	moveq	#-1,%d0
9307a0a325Smatt	jmp	(%a1)
942d913a7cSmattEND(__vfork14)
95