xref: /openbsd-src/lib/libc/arch/alpha/sys/tfork_thread.S (revision 13df69822c46036ceeeafb612b360459feebf6db)
1*13df6982Sderaadt/*	$OpenBSD: tfork_thread.S,v 1.3 2020/10/18 14:28:17 deraadt Exp $	*/
2c6f64c6fSguenther
3c6f64c6fSguenther/*
4c6f64c6fSguenther * Copyright (c) 2005, Miodrag Vallat
5c6f64c6fSguenther *
6c6f64c6fSguenther * Redistribution and use in source and binary forms, with or without
7c6f64c6fSguenther * modification, are permitted provided that the following conditions
8c6f64c6fSguenther * are met:
9c6f64c6fSguenther * 1. Redistributions of source code must retain the above copyright
10c6f64c6fSguenther *    notice, this list of conditions and the following disclaimer.
11c6f64c6fSguenther * 2. Redistributions in binary form must reproduce the above copyright
12c6f64c6fSguenther *    notice, this list of conditions and the following disclaimer in the
13c6f64c6fSguenther *    documentation and/or other materials provided with the distribution.
14c6f64c6fSguenther *
15c6f64c6fSguenther * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16c6f64c6fSguenther * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17c6f64c6fSguenther * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18c6f64c6fSguenther * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19c6f64c6fSguenther * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20c6f64c6fSguenther * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21c6f64c6fSguenther * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c6f64c6fSguenther * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23c6f64c6fSguenther * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24c6f64c6fSguenther * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25c6f64c6fSguenther * POSSIBILITY OF SUCH DAMAGE.
26c6f64c6fSguenther */
27c6f64c6fSguenther
28c6f64c6fSguenther#include  "SYS.h"
29c6f64c6fSguenther
30c6f64c6fSguenther/*
3116b62b6aSguenther * int __tfork_thread(const struct __tfork *param, size_t psize, void (*func)(void *), void *arg);
32c6f64c6fSguenther */
33c6f64c6fSguentherLEAF(__tfork_thread,0)
3416b62b6aSguenther	/* a0 = flags, a1 = psize, a2 = func, a3 = arg */
35c6f64c6fSguenther	mov	a3, a5
36c6f64c6fSguenther	CALLSYS_ERROR(__tfork)
37c6f64c6fSguenther
38c6f64c6fSguenther	beq	v0, 1f
39c6f64c6fSguenther
40c6f64c6fSguenther	/*
41c6f64c6fSguenther	 * In parent process: just return.
42c6f64c6fSguenther	 */
43c6f64c6fSguenther	RET
44c6f64c6fSguenther
45c6f64c6fSguenther1:
46c6f64c6fSguenther	/*
4716b62b6aSguenther	 * In child process: invoke function, then exit.
48c6f64c6fSguenther	 */
49c6f64c6fSguenther	mov	a5, a0		/* arg */
50c6f64c6fSguenther	mov	a2, pv		/* func */
51c6f64c6fSguenther	jsr	ra, (pv)
52c6f64c6fSguenther
53c6f64c6fSguenther	mov	zero, a0
54c6f64c6fSguenther	CALLSYS_NOERROR(__threxit)
55*13df6982Sderaadt	halt
56c6f64c6fSguenther
57c6f64c6fSguentherEND(__tfork_thread)
58