crt1.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Startup code for Nios II
  2. Copyright (C) 1995-2016 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library. If not, see
  29. <http://www.gnu.org/licenses/>. */
  30. #include <features.h>
  31. #include <asm/unistd.h>
  32. .global _start
  33. .type _start,@function
  34. .type _init,%function
  35. .type _fini,%function
  36. #ifndef __UCLIBC_CTOR_DTOR__
  37. .weak _init
  38. .weak _fini
  39. #endif
  40. .type main,@function
  41. .type __uClibc_main,@function
  42. .text
  43. _start:
  44. /* Set up the global pointer. */
  45. movhi gp, %hiadj(_gp)
  46. addi gp, gp, %lo(_gp)
  47. /* Save the stack pointer. */
  48. mov r2, sp
  49. /* Create room on the stack for the fini, rtld_fini and stack_end args
  50. to __uClibc_main. */
  51. subi sp, sp, 12
  52. /* Push stack_end */
  53. stw r2, 8(sp)
  54. /* Push rtld_fini */
  55. stw r4, 4(sp)
  56. /* Set up the GOT pointer. */
  57. nextpc r22
  58. 1: movhi r2, %hiadj(_gp_got - 1b)
  59. addi r2, r2, %lo(_gp_got - 1b)
  60. add r22, r22, r2
  61. /* r6 == argv */
  62. addi r6, sp, 16
  63. /* r5 == argc */
  64. ldw r5, 12(sp)
  65. /* r4 == main */
  66. movhi r4, %call_hiadj(main)
  67. addi r4, r4, %call_lo(main)
  68. add r4, r4, r22
  69. ldw r4, 0(r4)
  70. /* fp == 0 */
  71. mov fp, zero
  72. /* Let the libc call main and exit with its return code. */
  73. movhi r2, %call_hiadj(__uClibc_main)
  74. addi r2, r2, %call_lo(__uClibc_main)
  75. add r2, r2, r22
  76. ldw r2, 0(r2)
  77. callr r2
  78. /* should never get here....*/
  79. movhi r2, %call_hiadj(abort)
  80. addi r2, r2, %call_lo(abort)
  81. add r2, r2, r22
  82. ldw r2, 0(r2)
  83. callr r2
  84. /* Define a symbol for the first piece of initialized data. */
  85. .data
  86. .globl __data_start
  87. __data_start:
  88. .long 0
  89. .weak data_start
  90. data_start = __data_start