clone.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright (C) 1999, 2000, 2003, 2004, 2007 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* clone() is even more special than fork() as it mucks with stacks
  15. and invokes a function in the right context after its all over. */
  16. #include <features.h>
  17. #include <asm/unistd.h>
  18. #include <sysdep.h>
  19. #define _ERRNO_H 1
  20. #include <bits/errno.h>
  21. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  22. pid_t *ptid, void *tls, pid_t *ctid); */
  23. .text
  24. ENTRY(__clone)
  25. /* sanity check arguments. */
  26. tst r4, r4
  27. bt/s 0f
  28. tst r5, r5
  29. bf 1f
  30. 0:
  31. bra .Lsyscall_error
  32. mov #-EINVAL,r0
  33. 1:
  34. /* insert the args onto the new stack */
  35. mov.l r7, @-r5
  36. /* save the function pointer as the 0th element */
  37. mov.l r4, @-r5
  38. /* do the system call */
  39. mov r6, r4
  40. mov.l @r15, r6
  41. mov.l @(8,r15), r7
  42. mov.l @(4,r15), r0
  43. mov #+SYS_ify(clone), r3
  44. trapa #0x15
  45. mov r0, r1
  46. #ifdef __sh2__
  47. /* 12 arithmetic shifts for the sh2, because shad doesn't exist! */
  48. shar r1
  49. shar r1
  50. shar r1
  51. shar r1
  52. shar r1
  53. shar r1
  54. shar r1
  55. shar r1
  56. shar r1
  57. shar r1
  58. shar r1
  59. shar r1
  60. #else
  61. mov #-12, r2
  62. shad r2, r1
  63. #endif
  64. not r1, r1 // r1=0 means r0 = -1 to -4095
  65. tst r1, r1 // i.e. error in linux
  66. bf .Lclone_end
  67. .Lsyscall_error:
  68. SYSCALL_ERROR_HANDLER
  69. .Lclone_end:
  70. tst r0, r0
  71. bt 2f
  72. .Lpseudo_end:
  73. rts
  74. nop
  75. 2:
  76. /* terminate the stack frame */
  77. mov #0, r14
  78. /* thread starts */
  79. mov.l @r15, r1
  80. jsr @r1
  81. mov.l @(4,r15), r4
  82. /* we are done, passing the return value through r0 */
  83. mov.l .L3, r1
  84. #ifdef SHARED
  85. mov.l r12, @-r15
  86. sts.l pr, @-r15
  87. mov r0, r4
  88. mova .LG, r0
  89. mov.l .LG, r12
  90. add r0, r12
  91. mova .L3, r0
  92. add r0, r1
  93. jsr @r1
  94. nop
  95. lds.l @r15+, pr
  96. rts
  97. mov.l @r15+, r12
  98. #else
  99. jmp @r1
  100. mov r0, r4
  101. #endif
  102. .align 2
  103. .LG:
  104. .long _GLOBAL_OFFSET_TABLE_
  105. .L3:
  106. .long PLTJMP(C_SYMBOL_NAME(_exit))
  107. PSEUDO_END (__clone)
  108. weak_alias (__clone, clone)