clone.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. __syscall_error:
  50. negl %d0
  51. movel %d0, %sp@-
  52. lea __errno_location-.-8, %a0
  53. jsr %pc@(%a0)
  54. movel %d0, %a0
  55. movel %sp@+, %a0@
  56. moveq #-1, %d0
  57. rts
  58. thread_start:
  59. /*subl %fp, %fp*/ /* terminate the stack frame */
  60. jsr (%a0)
  61. movel %d0, -(%sp)
  62. movel #__NR_exit, %d0
  63. trap #0
  64. /*jsr exit*/
  65. #if defined(__HAVE_ELF__)
  66. .weak clone
  67. clone = __clone
  68. #else
  69. .set clone,__clone
  70. #endif