clone.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 2001 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 <asm/errno.h>
  17. #include <sys/syscall.h>
  18. #include "sysdep.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. test.d r10
  26. beq 1f
  27. nop
  28. /* We need to muck with a few registers. */
  29. movem r1,[sp=sp-8]
  30. /* Save the function pointer and argument. We can't save them
  31. onto the new stack since it can be NULL. */
  32. move.d r10,r0
  33. move.d r13,r1
  34. /* Move the other arguments into place for the system call. */
  35. move.d r11,r10
  36. move.d r12,r11
  37. /* Do the system call. */
  38. movu.w SYS_ify (clone),r9
  39. break 13
  40. test.d r10
  41. beq .Lthread_start
  42. nop
  43. /* Jump to error handler if we get (unsigned) -4096 .. 0xffffffff. */
  44. cmps.w -4096,r10
  45. bhs 0f
  46. movem [sp+],r1
  47. /* In parent, successful return. (Avoid using "ret" - it's a macro.) */
  48. Ret
  49. nop
  50. .Lthread_start:
  51. /* Terminate frame pointers here. */
  52. moveq 0,r8
  53. /* I've told you once. */
  54. move.d r1,r10
  55. jsr r0
  56. SETUP_PIC
  57. PLTCALL (HIDDEN_JUMPTARGET(_exit))
  58. /* Die horribly. */
  59. test.d [6809]
  60. /* Stop the unstoppable. */
  61. 9:
  62. ba 9b
  63. nop
  64. /* Local error handler. */
  65. 1:
  66. movs.w -EINVAL,r10
  67. /* Drop through into the ordinary error handler. */
  68. PSEUDO_END (clone)