clone.S 2.2 KB

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