clone.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <bits/errno.h>
  7. #include <sys/syscall.h>
  8. /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  9. .text
  10. .align 4
  11. .type clone,@function
  12. .globl clone;
  13. clone:
  14. .type __clone,@function
  15. .globl __clone;
  16. __clone:
  17. /* Sanity check arguments. */
  18. movel #-EINVAL, %d0
  19. movel 4(%sp), %d1 /* no NULL function pointers */
  20. movel %d1, %a0
  21. tstl %d1
  22. beq.w __syscall_error
  23. movel 8(%sp), %d1 /* no NULL stack pointers */
  24. movel %d1, %a1
  25. tstl %d1
  26. beq.w __syscall_error
  27. /* Allocate space and copy the argument onto the new stack. */
  28. movel 16(%sp), -(%a1)
  29. /* Do the system call */
  30. #if 1 /* defined (CONFIG_COLDFIRE) */
  31. movel %d2, %d1 /* save %d2 and get stack pointer */
  32. movel %a1, %d2
  33. movel %d1, %a1
  34. #else
  35. exg %d2, %a1 /* save %d2 and get stack pointer */
  36. #endif
  37. movel 12(%sp), %d1 /* get flags */
  38. movel #__NR_clone, %d0
  39. trap #0
  40. #if 1 /* defined (CONFIG_COLDFIRE) */
  41. movel %d2, %d1 /* restore %d2 */
  42. movel %a1, %d2
  43. movel %d1, %a1
  44. #else
  45. exg %d2, %a1 /* restore %d2 */
  46. #endif
  47. tstl %d0
  48. bmi.w __syscall_error
  49. beq.w thread_start
  50. rts
  51. __syscall_error:
  52. negl %d0
  53. movel %d0, %sp@-
  54. lea __errno_location-.-8, %a0
  55. jsr %pc@(%a0)
  56. movel %d0, %a0
  57. movel %sp@+, %a0@
  58. moveq #-1, %d0
  59. rts
  60. thread_start:
  61. /*subl %fp, %fp*/ /* terminate the stack frame */
  62. jsr (%a0)
  63. movel %d0, -(%sp)
  64. movel #__NR_exit, %d0
  65. trap #0
  66. /*jsr exit*/
  67. #if defined(__HAVE_ELF__)
  68. .weak clone
  69. clone = __clone
  70. #else
  71. .set clone,__clone
  72. #endif