clone.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * libc/sysdeps/linux/nios2/clone.S -- `clone' syscall for linux/nios2
  3. *
  4. * Copyright (C) 2004 Microtronix Datacom Ltd
  5. *
  6. * This file is subject to the terms and conditions of the GNU Lesser
  7. * General Public License. See the file COPYING.LIB in the main
  8. * directory of this archive for more details.
  9. *
  10. * Written by Wentao Xu <wentao@microtronix.com>
  11. */
  12. #include <asm/errno.h>
  13. #include <asm/unistd.h>
  14. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  15. .text
  16. .balign 4
  17. .type clone,@function
  18. .globl clone;
  19. clone:
  20. .type __clone,@function
  21. .globl __clone;
  22. __clone:
  23. addi sp,sp,-8
  24. mov r8,r4
  25. stw ra,4(sp)
  26. stw r16,0(sp)
  27. mov r4,r6
  28. movi r2,-EINVAL
  29. /* sanity check */
  30. beq r8,zero,CLONE_ERROR_LABEL
  31. beq r5,zero,CLONE_ERROR_LABEL
  32. /* system call */
  33. movi r2,TRAP_ID_SYSCALL
  34. movi r3,__NR_clone
  35. trap
  36. /* child call the function */
  37. mov r4,r7
  38. bne r2,zero,CLONE_ERROR_LABEL
  39. callr r8
  40. /* exit if it returns */
  41. mov r4,r2
  42. movi r3,__NR_exit
  43. trap
  44. CLONE_ERROR_LABEL:
  45. movi r3,-4096
  46. sub r16,zero,r2
  47. bgeu r3,r2,CLONE_OK
  48. /* store errno */
  49. call __errno_location
  50. stw r16,0(r2)
  51. movi r2,-1
  52. CLONE_OK:
  53. ldw ra,4(sp)
  54. ldw r16,0(sp)
  55. addi sp,sp,8
  56. ret