clone.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * libc/sysdeps/linux/microblaze/clone.c -- `clone' syscall for linux/microblaze
  3. *
  4. * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au>
  5. * Copyright (C) 2002,03 NEC Electronics Corporation
  6. * Copyright (C) 2002,03 Miles Bader <miles@gnu.org>
  7. *
  8. * This file is subject to the terms and conditions of the GNU Lesser
  9. * General Public License. See the file COPYING.LIB in the main
  10. * directory of this archive for more details.
  11. *
  12. * Written by Miles Bader <miles@gnu.org>
  13. * Microblaze port by John Williams
  14. */
  15. #include <errno.h>
  16. #include <sys/syscall.h>
  17. int
  18. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
  19. {
  20. register unsigned long rval asm (SYSCALL_RET) = -EINVAL;
  21. if (fn && child_stack)
  22. {
  23. register unsigned long syscall asm (SYSCALL_NUM);
  24. register unsigned long arg0 asm (SYSCALL_ARG0);
  25. register unsigned long arg1 asm (SYSCALL_ARG1);
  26. /* Clone this thread. */
  27. arg0 = flags;
  28. arg1 = (unsigned long)child_stack;
  29. syscall = __NR_clone;
  30. asm volatile ("bralid r17, trap;nop;"
  31. : "=r" (rval), "=r" (syscall)
  32. : "1" (syscall), "r" (arg0), "r" (arg1)
  33. : SYSCALL_CLOBBERS);
  34. if (rval == 0)
  35. /* In child thread, call FN and exit. */
  36. {
  37. arg0 = (*fn) (arg);
  38. syscall = __NR_exit;
  39. asm volatile ("bralid r17, trap;nop;"
  40. : "=r" (rval), "=r" (syscall)
  41. : "1" (syscall), "r" (arg0)
  42. : SYSCALL_CLOBBERS);
  43. }
  44. }
  45. __syscall_return (int, rval);
  46. }