clone.c 911 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * libc/sysdeps/linux/bfin/clone.c -- `clone' syscall for linux/blackfin
  3. *
  4. *
  5. * This file is subject to the terms and conditions of the GNU Lesser
  6. * General Public License. See the file COPYING.LIB in the main
  7. * directory of this archive for more details.
  8. *
  9. */
  10. #include <asm/unistd.h>
  11. int
  12. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
  13. {
  14. register long rval = -1;
  15. if (fn && child_stack) {
  16. __asm__ __volatile__ (
  17. "r1 = %2;"
  18. "r0 = %3;"
  19. "P0 = %1;"
  20. "excpt 0;" /*Call sys_clone*/
  21. "%0 = r0;"
  22. "cc = r0 == 0;"
  23. "if !cc jump xxx;" /* if (rval != 0) skip to parent */
  24. "r0 = %4;"
  25. "p0 = %5;"
  26. "call (p0);" /* Call cloned function */
  27. "p0 = %6;"
  28. "excpt 0;" /* Call sys_exit */
  29. "xxx: nop;"
  30. : "=d" (rval)
  31. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  32. : "CC", "R0", "R1", "P0");
  33. }
  34. return rval;
  35. }