clone.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. _clone:
  18. /* Sanity check arguments. */
  19. mov.l #-EINVAL,er3
  20. mov.l er0,er0 /* no NULL function pointers */
  21. beq __syscall_error
  22. mov.l er1,er1 /* no NULL stack pointers */
  23. beq __syscall_error
  24. /* Allocate space and copy the argument onto the new stack. */
  25. mov.l @(4:16,sp),er3
  26. mov.l er3,@-er1
  27. /* Do the system call */
  28. mov.l er0,er3 /* er3 = child entry */
  29. mov.l er1,er0
  30. mov.l er2,er1 /* er1 = flags */
  31. mov.l er0,er2 /* er2 = child sp */
  32. mov.l #__NR_clone,r0
  33. trapa #0
  34. mov.l er0,er0
  35. bmi __syscall_error
  36. beq thread_start
  37. rts
  38. __syscall_error:
  39. neg.l er0
  40. mov.l er0,@-sp
  41. #if !defined(__PIC__)
  42. jsr @__errno_location
  43. #else
  44. mov.l @(__errno_location@GOTOFF,er5),er1
  45. jsr @er1
  46. #endif
  47. mov.l @sp,er1
  48. mov.l er1,@er0
  49. sub.l er0,er0
  50. dec.l #1,er0
  51. rts
  52. thread_start:
  53. mov.l @sp+,er0 /* restore args */
  54. jsr @er3
  55. mov.l er0,er1
  56. mov.l #__NR_exit,er0
  57. trapa #0