1 /*
2  * libc/sysdeps/linux/bfin/clone.c -- `clone' syscall for linux/blackfin
3  *
4  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7  */
8 
9 #include <sched.h>
10 #include <errno.h>
11 #include <sys/syscall.h>
12 
13 int
clone(int (* fn)(void * arg),void * child_stack,int flags,void * arg,...)14 clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
15 {
16 	long rval = -1;
17 
18 	if (fn && child_stack) {
19 
20 		__asm__ __volatile__ (
21 			"excpt 0;"	/* Call sys_clone */
22 			"cc = r0 == 0;"
23 			"if !cc jump 1f;"	/* if (rval != 0) skip to parent */
24 			"r0 = %4;"
25 			"p0 = %5;"
26 			"fp = 0;"
27 #ifdef __BFIN_FDPIC__
28 			"p1 = [p0];"
29 			"p3 = [p0 + 4];"
30 			"call (p1);"	/* Call cloned function */
31 #else
32 			"call (p0);"	/* Call cloned function */
33 #endif
34 			"p0 = %6;"
35 			"excpt 0;"	/* Call sys_exit */
36 			"1: nop;"
37 			: "=q0" (rval)
38 			: "qA" (__NR_clone), "q1" (child_stack), "q0" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
39 			: "CC");
40 
41 	} else
42 		__set_errno(EINVAL);
43 
44 	return rval;
45 }
46