xref: /csrg-svn/lib/libc/vax/sys/Ovfork.s (revision 61222)
19426Smckusick/*
2*61222Sbostic * Copyright (c) 1983, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
434391Sbostic *
542642Sbostic * %sccs.include.redist.c%
621542Sdist */
721542Sdist
834391Sbostic#if defined(SYSLIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)Ovfork.s	8.1 (Berkeley) 06/04/93"
1034391Sbostic#endif /* SYSLIBC_SCCS and not lint */
1121542Sdist
1221542Sdist/*
139426Smckusick * @(#)vfork.s	4.1 (Berkeley) 12/21/80
149426Smckusick * C library -- vfork
159426Smckusick */
169426Smckusick
1747640Storek#include "SYS.h"
1847640Storek
199426Smckusick/*
209426Smckusick * pid = vfork();
219426Smckusick *
229426Smckusick * r1 == 0 in parent process, r1 == 1 in child process.
239426Smckusick * r0 == pid of child in parent, r0 == pid of parent in child.
249426Smckusick *
259426Smckusick * trickery here, due to keith sklower, uses ret to clear the stack,
269426Smckusick * and then returns with a jump indirect, since only one person can return
279426Smckusick * with a ret off this stack... we do the ret before we vfork!
289426Smckusick */
299426Smckusick
3047640StorekENTRY(vfork)
3147640Storek	movl	16(fp),r2	# save return address before we smash it
329426Smckusick	movab	here,16(fp)
339426Smckusick	ret
349426Smckusickhere:
3547640Storek	chmk	$SYS_vfork
3647640Storek	bcs	err		# if failed, set errno and return -1
3747640Storek	/* this next trick is Chris Torek's fault */
3847640Storek	mnegl	r1,r1		# r1 = 0xffffffff if child, 0 if parent
3947640Storek	bicl2	r1,r0		# r0 &= ~r1, i.e., 0 if child, else unchanged
4047640Storek	jmp	(r2)
4147640Storek
4247640Storekerr:
439426Smckusick	movl	r0,_errno
449426Smckusick	mnegl	$1,r0
459426Smckusick	jmp	(r2)
46