clone.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by David Huggins-Daines <dhd@debian.org>, 2000.
  4. Based on the Alpha version by Richard Henderson <rth@tamu.edu>, 1996.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. /* clone() is even more special than fork() as it mucks with stacks
  18. and invokes a function in the right context after its all over. */
  19. #include <asm/unistd.h>
  20. #define _ERRNO_H 1
  21. #include <bits/errno.h>
  22. #include <sys/syscall.h>
  23. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg) */
  24. .text
  25. .global __clone
  26. .type __clone,%function
  27. __clone:
  28. /* FIXME: I have no idea how profiling works on hppa. */
  29. /* Sanity check arguments. */
  30. comib,= 0,%arg0,.Lerror /* no NULL function pointers */
  31. ldi -EINVAL,%ret0
  32. comib,= 0,%arg1,.Lerror /* no NULL stack pointers */
  33. nop
  34. /* Save the fn ptr and arg on the new stack. */
  35. stwm %arg0,64(%arg1)
  36. stw %arg3,-60(%arg1)
  37. /* Save the PIC register. */
  38. #ifdef __PIC__
  39. stw %r19,-32(%sr0, %sp) /* parent */
  40. #endif
  41. /* Do the system call */
  42. copy %arg2,%arg0
  43. ble 0x100(%sr2,%r0)
  44. ldi __NR_clone,%r20
  45. ldi -4096,%r1
  46. comclr,>>= %r1,%ret0,%r0 /* Note: unsigned compare. */
  47. b,n .Lerror
  48. comib,=,n 0,%ret0,thread_start
  49. /* Successful return from the parent
  50. No need to restore the PIC register,
  51. since we return immediately. */
  52. bv %r0(%rp)
  53. nop
  54. /* Something bad happened -- no child created */
  55. .Lerror:
  56. /* Restore the PIC register on error */
  57. #ifdef __PIC__
  58. ldw -32(%sr0, %sp), %r19 /* parent */
  59. #endif
  60. b __syscall_error
  61. sub %r0,%ret0,%arg0
  62. thread_start:
  63. /* Load up the arguments. */
  64. ldw -60(%sr0, %sp),%arg0
  65. ldw -64(%sr0, %sp),%r22
  66. /* $$dyncall fixes childs PIC register */
  67. /* Call the user's function */
  68. bl $$dyncall,%r31
  69. copy %r31,%rp
  70. bl _exit_internal,%rp
  71. copy %ret0,%arg0
  72. /* Die horribly. */
  73. iitlbp %r0,(%r0)
  74. .size __clone,.-__clone
  75. .weak clone
  76. clone = __clone