crt1.S 1.6 KB

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