summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/sparc/clone.S
blob: fd8d1d126715315e3e9c5b644e25a1bf375c788b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <errno.h>
#include "syscalls.h"

.text
.align 4
.weak clone
clone:
.type __clone,#function
.global __clone
__clone:
	save	%sp, -96, %sp

	tst	%i0		/* check for function pointer */
	be	.Lerror
	tst	%i1		/* check for stack pointer */
	be	.Lerror
	nop

	mov	%i1, %o1	/* child-stack */
	mov	%i2, %o0	/* clone-flags */
	mov	__NR_clone, %g1
	ta	0x10		/* syscall: clone */
	bcs	.Lerror

	tst	%o1
	bne	.Lstart		/* we are the child :) */
	nop
	mov	%o0, %i0	/* return child pid */
	ret
	restore

.Lerror:
	call	__errno_location
	nop
	mov	EINVAL, %l0
	st	%l0, [%o0]
	ret
	restore	%g0, -1, %o0

.Lstart:
	call	%i0		/* call child-function */
	mov	%i3, %o0	/* put arg in the right place for the child */

	call	_exit		/* child returned */
	nop