clone.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #include <linux/sched.h>
  21. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  22. a2 a3 a4 a5
  23. pid_t *ptid, struct user_desc *tls, pid_t *ctid)
  24. a6 a7 16(sp)
  25. */
  26. .text
  27. ENTRY (__clone)
  28. /* Sanity check arguments. */
  29. beqz a2, .Leinval /* no NULL function pointers */
  30. beqz a3, .Leinval /* no NULL stack pointers */
  31. /* a2 and a3 are candidates for destruction by system-call return
  32. parameters. We don't need the stack pointer after the system
  33. call. We trust that the kernel will preserve a6, a7 and a9. */
  34. mov a9, a5 /* save function argument */
  35. mov a5, a7
  36. mov a7, a2 /* save function pointer */
  37. mov a8, a6 /* use a8 as a temp */
  38. mov a6, a4
  39. mov a4, a8
  40. l32i a8, a1, FRAMESIZE /* child_tid */
  41. movi a2, SYS_ify(clone)
  42. /* syscall(NR_clone,clone_flags, usp, parent_tid, child_tls, child_tid)
  43. a2 a6 a3 a4 a5 a8
  44. */
  45. syscall
  46. bltz a2, SYSCALL_ERROR_LABEL
  47. beqz a2, .Lthread_start
  48. /* fall through for parent */
  49. .Lpseudo_end:
  50. abi_ret
  51. .Leinval:
  52. movi a2, -EINVAL
  53. j SYSCALL_ERROR_LABEL
  54. .Lthread_start:
  55. #if CLONE_THREAD != 0x00010000 || CLONE_VM != 0x00000100
  56. # error invalid values for CLONE_THREAD or CLONE_VM
  57. #endif
  58. /* start child thread */
  59. movi a0, 0 /* terminate the stack frame */
  60. #if defined(__XTENSA_WINDOWED_ABI__)
  61. mov a6, a9 /* load up the 'arg' parameter */
  62. callx4 a7 /* call the user's function */
  63. /* Call _exit. Note that any return parameter from the user's
  64. function in a6 is seen as inputs to _exit. */
  65. movi a2, JUMPTARGET(_exit)
  66. callx4 a2
  67. #elif defined(__XTENSA_CALL0_ABI__)
  68. mov a2, a9 /* load up the 'arg' parameter */
  69. callx0 a7 /* call the user's function */
  70. /* Call _exit. Note that any return parameter from the user's
  71. function in a2 is seen as inputs to _exit. */
  72. movi a0, JUMPTARGET(_exit)
  73. callx0 a0
  74. #else
  75. #error Unsupported Xtensa ABI
  76. #endif
  77. PSEUDO_END (__clone)
  78. weak_alias (__clone, clone)