clone.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <sys/syscall.h>
  10. int
  11. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...)
  12. {
  13. register long rval = -1;
  14. if (fn && child_stack) {
  15. #ifdef __BFIN_FDPIC__
  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. "fp = 0;"
  27. "p1 = [p0];"
  28. "p3 = [p0 + 4];"
  29. "call (p1);" /* Call cloned function */
  30. "p0 = %6;"
  31. "excpt 0;" /* Call sys_exit */
  32. "xxx: nop;"
  33. : "=d" (rval)
  34. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  35. : "CC", "R0", "R1", "P0");
  36. #else
  37. __asm__ __volatile__ (
  38. "r1 = %2;"
  39. "r0 = %3;"
  40. "P0 = %1;"
  41. "excpt 0;" /*Call sys_clone*/
  42. "%0 = r0;"
  43. "cc = r0 == 0;"
  44. "if !cc jump xxx;" /* if (rval != 0) skip to parent */
  45. "r0 = %4;"
  46. "p0 = %5;"
  47. "fp = 0;"
  48. "call (p0);" /* Call cloned function */
  49. "p0 = %6;"
  50. "excpt 0;" /* Call sys_exit */
  51. "xxx: nop;"
  52. : "=d" (rval)
  53. : "i" (__NR_clone), "a" (child_stack), "a" (flags), "a" (arg), "a" (fn), "i" (__NR_exit)
  54. : "CC", "R0", "R1", "P0");
  55. #endif
  56. }
  57. return rval;
  58. }