clone.S 2.1 KB

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