xref: /netbsd-src/lib/libc/arch/sh3/sys/fork.S (revision 026eb7b69e29274c7f3c5a0040c34575439f33e4)
1*026eb7b6Suwe/*	$NetBSD: fork.S,v 1.10 2006/01/06 05:11:29 uwe Exp $	*/
295d875fbSmsaitoh
395d875fbSmsaitoh/*-
495d875fbSmsaitoh * Copyright (c) 1990 The Regents of the University of California.
595d875fbSmsaitoh * All rights reserved.
695d875fbSmsaitoh *
795d875fbSmsaitoh * This code is derived from software contributed to Berkeley by
895d875fbSmsaitoh * William Jolitz.
995d875fbSmsaitoh *
1095d875fbSmsaitoh * Redistribution and use in source and binary forms, with or without
1195d875fbSmsaitoh * modification, are permitted provided that the following conditions
1295d875fbSmsaitoh * are met:
1395d875fbSmsaitoh * 1. Redistributions of source code must retain the above copyright
1495d875fbSmsaitoh *    notice, this list of conditions and the following disclaimer.
1595d875fbSmsaitoh * 2. Redistributions in binary form must reproduce the above copyright
1695d875fbSmsaitoh *    notice, this list of conditions and the following disclaimer in the
1795d875fbSmsaitoh *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
1995d875fbSmsaitoh *    may be used to endorse or promote products derived from this software
2095d875fbSmsaitoh *    without specific prior written permission.
2195d875fbSmsaitoh *
2295d875fbSmsaitoh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2395d875fbSmsaitoh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2495d875fbSmsaitoh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2595d875fbSmsaitoh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2695d875fbSmsaitoh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2795d875fbSmsaitoh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2895d875fbSmsaitoh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2995d875fbSmsaitoh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3095d875fbSmsaitoh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3195d875fbSmsaitoh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3295d875fbSmsaitoh * SUCH DAMAGE.
3395d875fbSmsaitoh *
3495d875fbSmsaitoh *	from: @(#)fork.s	5.1 (Berkeley) 4/23/90
3595d875fbSmsaitoh */
3695d875fbSmsaitoh
3795d875fbSmsaitoh#include <machine/asm.h>
3895d875fbSmsaitoh#if defined(SYSLIBC_SCCS) && !defined(lint)
39*026eb7b6Suwe	RCSID("$NetBSD: fork.S,v 1.10 2006/01/06 05:11:29 uwe Exp $")
4095d875fbSmsaitoh#endif /* SYSLIBC_SCCS and not lint */
4195d875fbSmsaitoh
4295d875fbSmsaitoh#include "SYS.h"
4395d875fbSmsaitoh
44*026eb7b6Suwe/*
45*026eb7b6Suwe * pid = fork();
46*026eb7b6Suwe *
47*026eb7b6Suwe * r1 == 0 in parent process, r1 == 1 in child process.
48*026eb7b6Suwe * r0 == pid of child in parent, r0 == pid of parent in child.
49*026eb7b6Suwe *
50*026eb7b6Suwe */
51*026eb7b6SuweENTRY(__fork)
52*026eb7b6Suwe	mov	#SYS_fork, r0
53*026eb7b6Suwe	trapa	#0x80
54*026eb7b6Suwe	bf	err
55b46734f0Suwe
5695d875fbSmsaitoh	add	#0xff, r1	/* from 1 to 0 in child, 0 to -1 in parent */
57*026eb7b6Suwe	rts
58*026eb7b6Suwe	 and	r1, r0		/* 0 in child, child pid in parent */
59*026eb7b6Suwe
60*026eb7b6Suweerr:
61*026eb7b6Suwe	JUMP_CERROR
62*026eb7b6Suwe
63*026eb7b6Suwe	SET_ENTRY_SIZE(__fork)
64