clone.S 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2001, 2005 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public License as
  4. published by the Free Software Foundation; either version 2 of the
  5. License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with the GNU C Library; see the file COPYING.LIB. If not,
  12. see <http://www.gnu.org/licenses/>.  */
  13. /* clone is even more special than fork as it mucks with stacks
  14. and invokes a function in the right context after its all over. */
  15. #include <features.h>
  16. #include <sysdep.h>
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. #define __ASSEMBLY__
  20. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  21. a2 a3 a4 a5
  22. pid_t *ptid, struct user_desc *tls, pid_t *ctid)
  23. a6 a7 16(sp)
  24. */
  25. .text
  26. ENTRY (__clone)
  27. /* Sanity check arguments. */
  28. beqz a2, .Leinval /* no NULL function pointers */
  29. beqz a3, .Leinval /* no NULL stack pointers */
  30. /* a2 and a3 are candidates for destruction by system-call return
  31. parameters. We don't need the stack pointer after the system
  32. call. We trust that the kernel will preserve a6, a7 and a9. */
  33. mov a9, a5 /* save function argument */
  34. mov a5, a7
  35. mov a7, a2 /* save function pointer */
  36. mov a8, a6 /* use a8 as a temp */
  37. mov a6, a4
  38. mov a4, a8
  39. l32i a8, a1, FRAMESIZE /* child_tid */
  40. movi a2, SYS_ify(clone)
  41. /* syscall(NR_clone,clone_flags, usp, parent_tid, child_tls, child_tid)
  42. a2 a6 a3 a4 a5 a8
  43. */
  44. syscall
  45. bltz a2, SYSCALL_ERROR_LABEL
  46. beqz a2, .Lthread_start
  47. /* fall through for parent */
  48. .Lpseudo_end:
  49. abi_ret
  50. .Leinval:
  51. movi a2, -EINVAL
  52. j SYSCALL_ERROR_LABEL
  53. .Lthread_start:
  54. /* start child thread */
  55. movi a0, 0 /* terminate the stack frame */
  56. #if defined(__XTENSA_WINDOWED_ABI__)
  57. mov a6, a9 /* load up the 'arg' parameter */
  58. callx4 a7 /* call the user's function */
  59. /* Call _exit. Note that any return parameter from the user's
  60. function in a6 is seen as inputs to _exit. */
  61. movi a2, JUMPTARGET(_exit)
  62. callx4 a2
  63. #elif defined(__XTENSA_CALL0_ABI__)
  64. mov a2, a9 /* load up the 'arg' parameter */
  65. callx0 a7 /* call the user's function */
  66. /* Call _exit. Note that any return parameter from the user's
  67. function in a2 is seen as inputs to _exit. */
  68. movi a0, JUMPTARGET(_exit)
  69. callx0 a0
  70. #else
  71. #error Unsupported Xtensa ABI
  72. #endif
  73. PSEUDO_END (__clone)
  74. weak_alias (__clone, clone)