clone.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. register long rval = -1;
  15. if (fn && child_stack) {
  16. #ifdef __BFIN_FDPIC__
  17. __asm__ __volatile__ (
  18. "excpt 0;" /*Call sys_clone*/
  19. "cc = r0 == 0;"
  20. "if !cc jump .Lxxx;" /* if (rval != 0) skip to parent */
  21. "r0 = %4;"
  22. "p0 = %5;"
  23. "fp = 0;"
  24. "p1 = [p0];"
  25. "p3 = [p0 + 4];"
  26. "call (p1);" /* Call cloned function */
  27. "p0 = %6;"
  28. "excpt 0;" /* Call sys_exit */
  29. ".Lxxx: nop;"
  30. : "=q0" (rval)
  31. : "qA" (__NR_clone), "q1" (child_stack), "q0" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  32. : "CC");
  33. #else
  34. __asm__ __volatile__ (
  35. "excpt 0;" /*Call sys_clone*/
  36. "cc = r0 == 0;"
  37. "if !cc jump .Lxxx;" /* if (rval != 0) skip to parent */
  38. "r0 = %4;"
  39. "p0 = %5;"
  40. "fp = 0;"
  41. "call (p0);" /* Call cloned function */
  42. "p0 = %6;"
  43. "excpt 0;" /* Call sys_exit */
  44. ".Lxxx: nop;"
  45. : "=q0" (rval)
  46. : "qA" (__NR_clone), "q1" (child_stack), "q0" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  47. : "CC");
  48. #endif
  49. } else {
  50. __set_errno(EINVAL);
  51. }
  52. return rval;
  53. }