crt1.S 1.7 KB

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