clone.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 2003, 2004 Free Software Foudnation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Alexandre Oliva <aoliva@redhat.com>, 2003.
  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 <asm/unistd.h>
  19. #define _ERRNO_H 1
  20. #include <bits/errno.h>
  21. .text
  22. .globl __clone
  23. .type __clone,@function
  24. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg) */
  25. __clone:
  26. /* Sanity check arguments. */
  27. cmp.p gr8, gr0, icc0
  28. cmp gr9, gr0, icc1
  29. mov.p gr8, gr4
  30. beq icc0, #0, .Lerror
  31. mov.p gr11, gr5
  32. beq icc1, #0, .Lerror
  33. mov.p gr10, gr8
  34. setlos #__NR_clone, gr7
  35. tra gr0,gr0
  36. cmp.p gr8, gr0, icc0
  37. setlos #-4096, gr6
  38. cmp.p gr8, gr6, icc1
  39. beq icc0, #0, .Lthread_start
  40. blslr icc1, #2
  41. .Lsys_error:
  42. sethi.p #gotofffuncdeschi(__syscall_error), gr14
  43. setlo #gotofffuncdesclo(__syscall_error), gr14
  44. ldd @(gr14, gr15), gr14
  45. jmpl @(gr14, gr0)
  46. .Lerror:
  47. setlos.p #-EINVAL, gr8
  48. bra .Lsys_error
  49. ###############################################################################
  50. #
  51. # come here as the new thread [GR4 is fn, GR5 is arg]
  52. #
  53. ###############################################################################
  54. .Lthread_start:
  55. /* Save the PIC register. */
  56. mov gr15, gr17
  57. /* Call the user's function. */
  58. ldd.p @(gr4, gr0), gr14
  59. mov gr5, gr8
  60. calll @(gr14, gr0)
  61. /* Call _exit, rather simply inlining the syscall, such that
  62. breakpoints work.*/
  63. mov.p gr17, gr15
  64. call _exit_internal
  65. /* Should never get here. */
  66. jmpl @(gr0, gr0)
  67. .size __clone,.-__clone
  68. .weak clone
  69. clone = __clone