clone.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # clone.S, part of the i960 support for the uClibc library.
  3. #
  4. # Copyright (C) 2002 by Okiok Data Ltd. http://www.okiok.com/
  5. #
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU Library General Public License as published by the Free
  8. # Software Foundation; either version 2 of the License, or (at your option) any
  9. # later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. # FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  14. # details.
  15. #
  16. # You should have received a copy of the GNU Library General Public License
  17. # along with this program; if not, write to the Free Software Foundation, Inc.,
  18. # at 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # Derived from an old port of uC-libc to the i960 by Keith Adams (kma@cse.ogi.edu).
  21. #
  22. #include <sys/syscall.h>
  23. #include <bits/errno.h>
  24. /* clone is even more special than fork as it mucks with stacks
  25. and invokes a function in the right context after its all over. */
  26. /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  27. .globl __clone
  28. __clone:
  29. /* set up new stack image in regs r4-r7; argument will be in r3 in child. */
  30. ldconst 0, r4 /* pfp == 0 */
  31. addo 16, g1, r5 /* sp == newfp + 16 */
  32. mov g0, r6 /* rip == fnc */
  33. mov g2, r7
  34. stq r4, (g1)
  35. addo sp, 4, sp
  36. st g10, -4(sp)
  37. mov sp, g10
  38. ldconst __NR_clone, g13
  39. calls 0
  40. /* Do the system call */
  41. cmpibg 0, g0, syscall_error /* if < 0, error */
  42. be thread_start /* if == 0, we're the child */
  43. ret /* we're the parent */
  44. syscall_error:
  45. not g0, r3
  46. callx ___errno_location
  47. st r3, (g0)
  48. ret
  49. thread_start:
  50. # our new pfp is in g1; here we go
  51. flushreg
  52. mov g1, pfp
  53. flushreg
  54. ret