clone.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "r1 = %2;"
  19. "r0 = %3;"
  20. "P0 = %1;"
  21. "excpt 0;" /*Call sys_clone*/
  22. "%0 = r0;"
  23. "cc = r0 == 0;"
  24. "if !cc jump .Lxxx;" /* if (rval != 0) skip to parent */
  25. "r0 = %4;"
  26. "p0 = %5;"
  27. "fp = 0;"
  28. "p1 = [p0];"
  29. "p3 = [p0 + 4];"
  30. "call (p1);" /* Call cloned function */
  31. "p0 = %6;"
  32. "excpt 0;" /* Call sys_exit */
  33. ".Lxxx: nop;"
  34. : "=d" (rval)
  35. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  36. : "CC", "R0", "R1", "P0");
  37. #else
  38. __asm__ __volatile__ (
  39. "r1 = %2;"
  40. "r0 = %3;"
  41. "P0 = %1;"
  42. "excpt 0;" /*Call sys_clone*/
  43. "%0 = r0;"
  44. "cc = r0 == 0;"
  45. "if !cc jump .Lxxx;" /* if (rval != 0) skip to parent */
  46. "r0 = %4;"
  47. "p0 = %5;"
  48. "fp = 0;"
  49. "call (p0);" /* Call cloned function */
  50. "p0 = %6;"
  51. "excpt 0;" /* Call sys_exit */
  52. ".Lxxx: nop;"
  53. : "=d" (rval)
  54. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  55. : "CC", "R0", "R1", "P0");
  56. #endif
  57. } else {
  58. __set_errno(EINVAL);
  59. }
  60. return rval;
  61. }