clone.S 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 1996-2016 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 <sysdep.h>
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. #if defined __UCLIBC_HAS_THREADS__ && !defined __UCLIBC_HAS_LINUXTHREADS__
  20. #include <sysdep-cancel.h>
  21. #endif
  22. /* int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  23. pid_t *ptid, struct user_desc *tls, pid_t *ctid);
  24. INCOMING: r5 (fn), r6 (child_stack), r7 (flags), r8 (arg), r9 (ptid)
  25. r10 (tls), 28 (r1) ctid
  26. OUTGOING:
  27. linux: arch/microblaze/entry.S: sys_clone expects
  28. r5 (flags) r6 (child stack) r7 (stack_size) r8 (ptid)r9 (ctid)
  29. r10 (tls)
  30. */
  31. .text
  32. ENTRY (__clone)
  33. addik r3,r0,-EINVAL
  34. beqi r5,SYSCALL_ERROR_LABEL ; // Invalid func
  35. beqi r6,SYSCALL_ERROR_LABEL ; // Invalid stack
  36. addik r6,r6,-8
  37. swi r5,r6,0 ; // Push fn onto child's stack
  38. swi r8,r6,4 ; // Push arg for child
  39. addk r5,r0,r7 ; // flags for clone() syscall
  40. addk r7,r0,r0
  41. addk r8,r0,r9 ; // parent tid ptr
  42. lwi r9,r1,28 ; // child tid ptr
  43. addik r12,r0,SYS_ify(clone)
  44. brki r14,8
  45. addk r0,r0,r0
  46. addik r4,r0,-4095
  47. cmpu r4,r4,r3
  48. bgei r4,SYSCALL_ERROR_LABEL
  49. beqi r3,L(thread_start)
  50. rtsd r15,8
  51. nop
  52. L(thread_start):
  53. lwi r12,r1,0 ; // fn
  54. lwi r5,r1,4 ; // arg
  55. brald r15,r12
  56. nop
  57. addk r5,r0,r3
  58. addik r12,r0,SYS_ify(exit)
  59. brki r14,8
  60. nop
  61. PSEUDO_END(__clone)
  62. libc_hidden_def (__clone)
  63. weak_alias (__clone,clone)