clone.S 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Richard Henderson <rth@tamu.edu>, 1996.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* clone() is even more special than fork() as it mucks with stacks
  17. and invokes a function in the right context after its all over. */
  18. #include <features.h>
  19. #define _ERRNO_H 1
  20. #include <bits/errno.h>
  21. #include <sys/syscall.h>
  22. #include <asm/regdef.h>
  23. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg) */
  24. .text
  25. .globl clone;
  26. .align 3;
  27. .ent clone , 0;
  28. clone:
  29. .frame $30 , 0, $26
  30. .prologue 0
  31. /* Sanity check arguments. */
  32. ldiq v0,EINVAL
  33. beq a0,$error /* no NULL function pointers */
  34. beq a1,$error /* no NULL stack pointers */
  35. /* Save the fn ptr and arg on the new stack. */
  36. subq a1,16,a1
  37. stq a0,0(a1)
  38. stq a3,8(a1)
  39. /* Do the system call */
  40. mov a2,a0
  41. ldiq v0,__NR_clone
  42. call_pal 131
  43. bne a3,$error
  44. beq v0,thread_start
  45. /* Successful return from the parent */
  46. ret
  47. /* Something bad happened -- no child created */
  48. $error:
  49. br gp,1f
  50. 1: ldgp gp,0(gp)
  51. jmp zero,__syscall_error
  52. .end clone
  53. /* Load up the arguments to the function. Put this block of code in
  54. its own function so that we can terminate the stack trace with our
  55. debug info. */
  56. .ent thread_start
  57. thread_start:
  58. .frame fp,0,zero,0
  59. mov zero,fp
  60. .prologue 0
  61. /* Load up the arguments. */
  62. ldq pv,0($30)
  63. ldq a0,8($30)
  64. addq $30,16,$30
  65. /* Call the user's function */
  66. jsr ra,(pv)
  67. ldgp gp,0(ra)
  68. /* Call _exit rather than doing it inline for breakpoint purposes */
  69. mov v0,a0
  70. jsr ra,HIDDEN_JUMPTARGET(_exit)
  71. /* Die horribly. */
  72. halt
  73. .end thread_start