clone.S 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2001, 2003 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. see <http://www.gnu.org/licenses/>. */
  14. #include <features.h>
  15. #include <sys/syscall.h>
  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. .syntax no_register_prefix
  21. .text
  22. ENTRY (clone)
  23. /* Sanity check arguments: No NULL function pointers. Allow a NULL
  24. stack pointer though; it makes the kernel allocate stack. */
  25. cmpq 0,r10
  26. beq 1f
  27. nop
  28. /* We need to muck with a few registers. */
  29. subq 8,sp
  30. movem r1,[sp]
  31. /* Save the function pointer and argument. We can't save them
  32. onto the new stack since it can be NULL. */
  33. move.d r10,r0
  34. move.d r13,r1
  35. /* Move the other arguments into place for the system call. */
  36. move.d r11,r10
  37. move.d r12,r11
  38. /* Do the system call. */
  39. movu.w SYS_ify (clone),r9
  40. break 13
  41. cmpq 0,r10
  42. beq .Lthread_start
  43. nop
  44. /* Jump to error handler if we get (unsigned) -4096 .. 0xffffffff. */
  45. cmps.w -4096,r10
  46. bhs 0f
  47. movem [sp+],r1
  48. /* In parent, successful return. (Avoid using "ret" - it's a macro.) */
  49. Ret
  50. nop
  51. .Lthread_start:
  52. /* Terminate frame pointers here. */
  53. moveq 0,r8
  54. #ifdef __arch_v32
  55. /* Is this the right place for an argument? */
  56. jsr r0
  57. move.d r1,r10
  58. #else
  59. /* I've told you once. */
  60. move.d r1,r10
  61. jsr r0
  62. #endif
  63. SETUP_PIC
  64. PLTCALL (HIDDEN_JUMPTARGET(_exit))
  65. /* Die horribly. */
  66. move.d 6809,r13
  67. test.d [r13]
  68. /* Stop the unstoppable. */
  69. 9:
  70. ba 9b
  71. nop
  72. /* Local error handler. */
  73. 1:
  74. movs.w -EINVAL,r10
  75. /* Drop through into the ordinary error handler. */
  76. PSEUDO_END (clone)