crt1.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. .global _start
  17. .type _start,@function
  18. .type _init,%function
  19. .type _fini,%function
  20. #ifndef __UCLIBC_CTOR_DTOR__
  21. .weak _init
  22. .weak _fini
  23. #endif
  24. .type main,@function
  25. .type __uClibc_main,@function
  26. .text
  27. .balign 4
  28. _start:
  29. nop
  30. br 0f
  31. 0:
  32. /* load gp */
  33. movhi gp, %hiadj(_gp)
  34. addi gp, gp, %lo(_gp)
  35. /* load main, argc, argv from stack */
  36. movhi r4, %hi(main)
  37. ori r4, r4, %lo(main) /* main */
  38. ldw r5, 0(sp) /* argc */
  39. ldw r6, 4(sp) /* argv */
  40. /* load the 4th arg */
  41. movhi r7, %hi(_init)
  42. ori r7, r7, %lo(_init)
  43. /* Allocate space on the stack for 6-7th arg, reuse 5th space */
  44. addi sp,sp,-8
  45. /* push 5-7th args on stack */
  46. movhi r8, %hi(_fini)
  47. ori r8, r8, %lo(_fini)
  48. stw r8, 0(sp)
  49. stw r2, 4(sp) /* rtld_fini */
  50. stw sp, 8(sp) /* stack_end */
  51. /* call uClibc_main, shouldn't return */
  52. #ifdef __PIC__
  53. /* just pray 16 bit offset is enough */
  54. br __uClibc_main
  55. #else
  56. call __uClibc_main
  57. #endif
  58. /* crash in the event of return */
  59. __exit:
  60. movui r2, TRAP_ID_SYSCALL
  61. movui r3, __NR_exit
  62. trap