clone.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "m68k_pic.S"
  10. /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  11. .text
  12. .align 4
  13. .type clone,@function
  14. .globl clone;
  15. clone:
  16. /* Sanity check arguments. */
  17. movel #-EINVAL, %d0
  18. movel 4(%sp), %d1 /* no NULL function pointers */
  19. movel %d1, %a0
  20. tstl %d1
  21. beq.w __syscall_error_trampoline
  22. movel 8(%sp), %d1 /* no NULL stack pointers */
  23. movel %d1, %a1
  24. tstl %d1
  25. beq.w __syscall_error_trampoline
  26. /* Allocate space and copy the argument onto the new stack. */
  27. movel 16(%sp), -(%a1)
  28. /* Do the system call */
  29. #if 1 /* defined (CONFIG_COLDFIRE) */
  30. movel %d2, %d1 /* save %d2 and get stack pointer */
  31. movel %a1, %d2
  32. movel %d1, %a1
  33. #else
  34. exg %d2, %a1 /* save %d2 and get stack pointer */
  35. #endif
  36. movel 12(%sp), %d1 /* get flags */
  37. movel #__NR_clone, %d0
  38. trap #0
  39. #if 1 /* defined (CONFIG_COLDFIRE) */
  40. movel %d2, %d1 /* restore %d2 */
  41. movel %a1, %d2
  42. movel %d1, %a1
  43. #else
  44. exg %d2, %a1 /* restore %d2 */
  45. #endif
  46. tstl %d0
  47. bmi.w __syscall_error_trampoline
  48. beq.w thread_start
  49. rts
  50. thread_start:
  51. /*subl %fp, %fp*/ /* terminate the stack frame */
  52. jsr (%a0)
  53. movel %d0, -(%sp)
  54. movel #__NR_exit, %d0
  55. trap #0
  56. /*jsr exit*/
  57. __syscall_error_trampoline:
  58. JUMP __syscall_error,%a0