xref: /openbsd/lib/libc/arch/sh/sys/tfork_thread.S (revision 8529ddd3)
1/*	$OpenBSD: tfork_thread.S,v 1.2 2012/06/21 00:56:59 guenther Exp $	*/
2
3/*
4 * Copyright (c) 2007 Miodrag Vallat.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice, this permission notice, and the disclaimer below
9 * appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "SYS.h"
21
22/*
23 * int __tfork_thread(const struct __tfork *param, size_t psize, void (*func)(void *), void *arg);
24 *			r4			r5		   r6		r7
25 */
26ENTRY(__tfork_thread)
27	mov.l	.LSYS___tfork, r0
28	.word	0xc380		/* trapa #0x80 */
29	bf	9f
30
31	tst	r0, r0
32	bt	1f
33
34	/*
35	 * In parent process: just return.
36	 */
37	rts
38	 nop
39
401:
41	/*
42	 * In child process: invoke function, then exit.
43	 */
44	jsr	@r6
45	 mov	r7, r4
46
47	mov.l	.LSYS___threxit, r0
48	.word	0xc380		/* trapa #0x80 */
49
509:
51	/*
52	 * System call failure.
53	 */
54	JUMP_CERROR
55
56	.align 2
57.LSYS___tfork:	.long SYS___tfork
58.LSYS___threxit:	.long SYS___threxit
59
60	SET_ENTRY_SIZE(__tfork_thread)
61