crt0.S 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. *
  12. */
  13. #include <features.h>
  14. #include <asm/unistd.h>
  15. .global _start
  16. .type __start,@function
  17. .weak _init
  18. .weak _fini
  19. .type __uClibc_start_main,@function
  20. .type __h_errno_location, @function
  21. .type _stdio_init, @function
  22. .type _stdio_term, @function
  23. .text
  24. .balign 4
  25. _start:
  26. nop
  27. br 0f
  28. .long _stext /* start address of .text + 4 */
  29. .long _etext /* start address of .data */
  30. .long _edata /* start address of .bss */
  31. 0:
  32. /* load gp */
  33. movhi gp, %hiadj(_gp)
  34. addi gp, gp, %lo(_gp)
  35. /* load argc, argv, envp from stack */
  36. ldw r4, 0(sp)
  37. ldw r5, 4(sp)
  38. ldw r6, 8(sp)
  39. /* load the 4th arg */
  40. movhi r7, %hi(_init)
  41. ori r7, r7, %lo(_init)
  42. /* reuse the argc stack slot for the 5th arg */
  43. movhi r8, %hi(_fini)
  44. ori r8, r8, %lo(_fini)
  45. stw r8, 0(sp)
  46. /* call uClibc_main, shouldn't return */
  47. #ifdef __PIC__
  48. /* just pray 16 bit offset is enough */
  49. br __uClibc_start_main
  50. #else
  51. call __uClibc_start_main
  52. #endif
  53. /* crash in the event of return */
  54. __exit:
  55. movui r2, TRAP_ID_SYSCALL
  56. movui r3, __NR_exit
  57. trap