clone.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define _ERRNO_H
  13. #include <bits/errno.h>
  14. #include <sys/syscall.h>
  15. #ifdef __NR_clone
  16. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  17. .text
  18. .global clone
  19. .type clone,%function
  20. .align 4
  21. clone:
  22. addi sp,sp,-8
  23. mov r8,r4
  24. stw ra,4(sp)
  25. stw r16,0(sp)
  26. mov r4,r6
  27. movi r2,-EINVAL
  28. /* sanity check */
  29. beq r8,zero,CLONE_ERROR_LABEL
  30. beq r5,zero,CLONE_ERROR_LABEL
  31. /* system call */
  32. movi r2,TRAP_ID_SYSCALL
  33. movi r3,__NR_clone
  34. trap
  35. /* child call the function */
  36. mov r4,r7
  37. bne r2,zero,CLONE_ERROR_LABEL
  38. callr r8
  39. /* exit if it returns */
  40. mov r4,r2
  41. movi r3,__NR_exit
  42. trap
  43. CLONE_ERROR_LABEL:
  44. movi r3,-4096
  45. sub r16,zero,r2
  46. bgeu r3,r2,CLONE_OK
  47. /* store errno */
  48. call __errno_location
  49. stw r16,0(r2)
  50. movi r2,-1
  51. CLONE_OK:
  52. ldw ra,4(sp)
  53. ldw r16,0(sp)
  54. addi sp,sp,8
  55. ret
  56. .size clone,.-clone
  57. #endif