crt1.S 1.7 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. .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. .long _stext /* start address of .text + 4 */
  31. .long _etext /* start address of .data */
  32. .long _edata /* start address of .bss */
  33. 0:
  34. /* load gp */
  35. movhi gp, %hiadj(_gp)
  36. addi gp, gp, %lo(_gp)
  37. /* load main, argc, argv from stack */
  38. movhi r4, %hi(main)
  39. ori r4, r4, %lo(main) /* main */
  40. ldw r5, 0(sp) /* argc */
  41. ldw r6, 4(sp) /* argv */
  42. /* load the 4th arg */
  43. movhi r7, %hi(_init)
  44. ori r7, r7, %lo(_init)
  45. /* reuse the argc stack slot for the 5th arg */
  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