clone.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Adapted from glibc */
  2. /* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */
  3. /* clone is even more special than fork as it mucks with stacks
  4. and invokes a function in the right context after its all over. */
  5. #define _ERRNO_H
  6. #include <features.h>
  7. #include <bits/errno.h>
  8. #include <sys/syscall.h>
  9. /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  10. .text
  11. .align 4
  12. .type clone,@function
  13. .globl clone;
  14. clone:
  15. /* Sanity check arguments. */
  16. movel #-EINVAL, %d0
  17. movel 4(%sp), %d1 /* no NULL function pointers */
  18. movel %d1, %a0
  19. tstl %d1
  20. beq.w __syscall_error
  21. movel 8(%sp), %d1 /* no NULL stack pointers */
  22. movel %d1, %a1
  23. tstl %d1
  24. beq.w __syscall_error
  25. /* Allocate space and copy the argument onto the new stack. */
  26. movel 16(%sp), -(%a1)
  27. /* Do the system call */
  28. #if 1 /* defined (CONFIG_COLDFIRE) */
  29. movel %d2, %d1 /* save %d2 and get stack pointer */
  30. movel %a1, %d2
  31. movel %d1, %a1
  32. #else
  33. exg %d2, %a1 /* save %d2 and get stack pointer */
  34. #endif
  35. movel 12(%sp), %d1 /* get flags */
  36. movel #__NR_clone, %d0
  37. trap #0
  38. #if 1 /* defined (CONFIG_COLDFIRE) */
  39. movel %d2, %d1 /* restore %d2 */
  40. movel %a1, %d2
  41. movel %d1, %a1
  42. #else
  43. exg %d2, %a1 /* restore %d2 */
  44. #endif
  45. tstl %d0
  46. bmi.w __syscall_error
  47. beq.w thread_start
  48. rts
  49. thread_start:
  50. /*subl %fp, %fp*/ /* terminate the stack frame */
  51. jsr (%a0)
  52. movel %d0, -(%sp)
  53. movel #__NR_exit, %d0
  54. trap #0
  55. /*jsr exit*/