crt1.S 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * libc/sysdeps/linux/nios2/crt0.S -- entry point for linux/nios2
  3. *
  4. * Copyright (C) 2004,05,06 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. * Updated by Thomas Chou <thomas@wytron.com.tw> for crt1.S
  12. *
  13. */
  14. #include <features.h>
  15. #include <asm/unistd.h>
  16. #define TRAP_ID_SYSCALL 0
  17. .global _start
  18. .type _start,@function
  19. .type _init,%function
  20. .type _fini,%function
  21. #ifndef __UCLIBC_CTOR_DTOR__
  22. .weak _init
  23. .weak _fini
  24. #endif
  25. .type main,@function
  26. .type __uClibc_main,@function
  27. .text
  28. .balign 4
  29. _start:
  30. nop
  31. br 0f
  32. 0:
  33. /* load gp */
  34. movhi gp, %hiadj(_gp)
  35. addi gp, gp, %lo(_gp)
  36. /* load main, argc, argv from stack */
  37. movhi r4, %hi(main)
  38. ori r4, r4, %lo(main) /* main */
  39. ldw r5, 0(sp) /* argc */
  40. ldw r6, 4(sp) /* argv */
  41. /* load the 4th arg */
  42. movhi r7, %hi(_init)
  43. ori r7, r7, %lo(_init)
  44. /* Allocate space on the stack for 6-7th arg, reuse 5th space */
  45. addi sp,sp,-8
  46. /* push 5-7th args on stack */
  47. movhi r8, %hi(_fini)
  48. ori r8, r8, %lo(_fini)
  49. stw r8, 0(sp)
  50. stw r2, 4(sp) /* rtld_fini */
  51. stw sp, 8(sp) /* stack_end */
  52. /* call uClibc_main, shouldn't return */
  53. #ifdef __PIC__
  54. /* just pray 16 bit offset is enough */
  55. br __uClibc_main
  56. #else
  57. call __uClibc_main
  58. #endif
  59. /* crash in the event of return */
  60. __exit:
  61. movui r2, TRAP_ID_SYSCALL
  62. movui r3, __NR_exit
  63. trap