clone.c 864 B

12345678910111213141516171819202122232425262728293031323334353637
  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. #include <asm/unistd.h>
  9. int
  10. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
  11. {
  12. register long rval = -1;
  13. if (fn && child_stack) {
  14. __asm__ __volatile__ (
  15. "r1 = %2;"
  16. "r0 = %3;"
  17. "P0 = %1;"
  18. "excpt 0;" /*Call sys_clone*/
  19. "%0 = r0;"
  20. "cc = r0 == 0;"
  21. "if !cc jump xxx;" /* if (rval != 0) skip to parent */
  22. "r0 = %4;"
  23. "p0 = %5;"
  24. "call (p0);" /* Call cloned function */
  25. "p0 = %6;"
  26. "excpt 0;" /* Call sys_exit */
  27. "xxx: nop;"
  28. : "=d" (rval)
  29. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  30. : "CC", "R0", "R1", "P0");
  31. }
  32. return rval;
  33. }