clone.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #include <features.h>
  16. #include <sys/syscall.h>
  17. #include "sysdep.h"
  18. #define _ERRNO_H 1
  19. #include <bits/errno.h>
  20. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  21. .syntax no_register_prefix
  22. .text
  23. ENTRY (clone)
  24. /* Sanity check arguments: No NULL function pointers. Allow a NULL
  25. stack pointer though; it makes the kernel allocate stack. */
  26. cmpq 0,r10
  27. beq 1f
  28. nop
  29. /* We need to muck with a few registers. */
  30. subq 8,sp
  31. movem r1,[sp]
  32. /* Save the function pointer and argument. We can't save them
  33. onto the new stack since it can be NULL. */
  34. move.d r10,r0
  35. move.d r13,r1
  36. /* Move the other arguments into place for the system call. */
  37. move.d r11,r10
  38. move.d r12,r11
  39. /* Do the system call. */
  40. movu.w SYS_ify (clone),r9
  41. break 13
  42. cmpq 0,r10
  43. beq .Lthread_start
  44. nop
  45. /* Jump to error handler if we get (unsigned) -4096 .. 0xffffffff. */
  46. cmps.w -4096,r10
  47. bhs 0f
  48. movem [sp+],r1
  49. /* In parent, successful return. (Avoid using "ret" - it's a macro.) */
  50. Ret
  51. nop
  52. .Lthread_start:
  53. /* Terminate frame pointers here. */
  54. moveq 0,r8
  55. #ifdef __arch_v32
  56. /* Is this the right place for an argument? */
  57. jsr r0
  58. move.d r1,r10
  59. #else
  60. /* I've told you once. */
  61. move.d r1,r10
  62. jsr r0
  63. #endif
  64. SETUP_PIC
  65. PLTCALL (HIDDEN_JUMPTARGET(_exit))
  66. /* Die horribly. */
  67. move.d 6809,r13
  68. test.d [r13]
  69. /* Stop the unstoppable. */
  70. 9:
  71. ba 9b
  72. nop
  73. /* Local error handler. */
  74. 1:
  75. movs.w -EINVAL,r10
  76. /* Drop through into the ordinary error handler. */
  77. PSEUDO_END (clone)