clone.c 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <sched.h>
  9. #include <errno.h>
  10. #include <sys/syscall.h>
  11. int
  12. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
  13. {
  14. long rval = -1;
  15. if (fn && child_stack) {
  16. __asm__ __volatile__ (
  17. "excpt 0;" /* Call sys_clone */
  18. "cc = r0 == 0;"
  19. "if !cc jump 1f;" /* if (rval != 0) skip to parent */
  20. "r0 = %4;"
  21. "p0 = %5;"
  22. "fp = 0;"
  23. #ifdef __BFIN_FDPIC__
  24. "p1 = [p0];"
  25. "p3 = [p0 + 4];"
  26. "call (p1);" /* Call cloned function */
  27. #else
  28. "call (p0);" /* Call cloned function */
  29. #endif
  30. "p0 = %6;"
  31. "excpt 0;" /* Call sys_exit */
  32. "1: nop;"
  33. : "=q0" (rval)
  34. : "qA" (__NR_clone), "q1" (child_stack), "q0" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  35. : "CC");
  36. } else
  37. __set_errno(EINVAL);
  38. return rval;
  39. }