1/* Copyright (C) 2001, 2003 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
4   The GNU C Library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Library General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   The GNU C Library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Library General Public License for more details.
13
14   You should have received a copy of the GNU Library General Public
15   License along with the GNU C Library; see the file COPYING.LIB.  If not,
16   see <http://www.gnu.org/licenses/>.  */
17
18#include <features.h>
19#include <sys/syscall.h>
20#include "sysdep.h"
21#define _ERRNO_H	1
22#include <bits/errno.h>
23
24/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
25
26	.syntax no_register_prefix
27
28        .text
29ENTRY (clone)
30	/* Sanity check arguments: No NULL function pointers.  Allow a NULL
31	   stack pointer though; it makes the kernel allocate stack.  */
32	cmpq	0,r10
33	beq	1f
34	nop
35
36	/* We need to muck with a few registers.  */
37	subq	8,sp
38	movem	r1,[sp]
39
40	/* Save the function pointer and argument.  We can't save them
41	   onto the new stack since it can be NULL.  */
42	move.d	r10,r0
43	move.d	r13,r1
44
45        /* Move the other arguments into place for the system call.  */
46	move.d	r11,r10
47	move.d	r12,r11
48
49	/* Do the system call.  */
50	movu.w	SYS_ify (clone),r9
51	break	13
52	cmpq	0,r10
53	beq	.Lthread_start
54	nop
55
56	/* Jump to error handler if we get (unsigned) -4096 .. 0xffffffff.  */
57	cmps.w	-4096,r10
58	bhs	0f
59	movem	[sp+],r1
60
61	/* In parent, successful return.  (Avoid using "ret" - it's a macro.)  */
62	Ret
63	nop
64
65.Lthread_start:
66	/* Terminate frame pointers here.  */
67	moveq	0,r8
68
69#ifdef __arch_v32
70	/* Is this the right place for an argument?  */
71	jsr	r0
72	move.d	r1,r10
73#else
74	/* I've told you once.  */
75	move.d	r1,r10
76	jsr	r0
77#endif
78
79	SETUP_PIC
80	PLTCALL	(HIDDEN_JUMPTARGET(_exit))
81
82	/* Die horribly.  */
83	move.d 6809,r13
84	test.d	[r13]
85
86	/* Stop the unstoppable.  */
879:
88	ba	9b
89	nop
90
91/* Local error handler.  */
921:
93	movs.w	-EINVAL,r10
94	/* Drop through into the ordinary error handler.  */
95PSEUDO_END (clone)
96