clone.S 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifdef __H8300H__
  10. .h8300h
  11. #endif
  12. #ifdef __H8300S__
  13. .h8300s
  14. #endif
  15. .text
  16. .globl _clone
  17. .globl ___clone
  18. _clone:
  19. ___clone:
  20. /* Sanity check arguments. */
  21. mov.l #-EINVAL,er3
  22. mov.l er0,er0 /* no NULL function pointers */
  23. beq __syscall_error
  24. mov.l er1,er1 /* no NULL stack pointers */
  25. beq __syscall_error
  26. /* Allocate space and copy the argument onto the new stack. */
  27. mov.l @(4:16,sp),er3
  28. mov.l er3,@-er1
  29. /* Do the system call */
  30. mov.l er0,er3 /* er3 = child entry */
  31. mov.l er1,er0
  32. mov.l er2,er1 /* er1 = flags */
  33. mov.l er0,er2 /* er2 = child sp */
  34. mov.l #__NR_clone,r0
  35. trapa #0
  36. mov.l er0,er0
  37. bmi __syscall_error
  38. beq thread_start
  39. rts
  40. __syscall_error:
  41. neg.l er0
  42. mov.l er0,@-sp
  43. #if !defined(__PIC__)
  44. jsr @__errno_location
  45. #else
  46. mov.l @(__errno_location@GOTOFF,er5),er1
  47. jsr @er1
  48. #endif
  49. mov.l @sp,er1
  50. mov.l er1,@er0
  51. sub.l er0,er0
  52. dec.l #1,er0
  53. rts
  54. thread_start:
  55. mov.l @sp+,er0 /* restore args */
  56. jsr @er3
  57. mov.l er0,er1
  58. mov.l #__NR_exit,er0
  59. trapa #0
  60. #if defined(__HAVE_ELF__)
  61. .weak clone
  62. clone = __clone
  63. #else
  64. .set clone,__clone
  65. #endif