crt0.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright (C) 1991, 1992, 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. In addition to the permissions in the GNU Lesser General Public
  12. License, the Free Software Foundation gives you unlimited
  13. permission to link the compiled version of this file with other
  14. programs, and to distribute those programs without any restriction
  15. coming from the use of this file. (The GNU Lesser General Public
  16. License restrictions do apply in other respects; for example, they
  17. cover modification of the file, and distribution when not linked
  18. into another program.)
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with the GNU C Library; see the file COPYING.LIB. If
  21. not, see <http://www.gnu.org/licenses/>. */
  22. /* Based on ../i386/crt0.S and newlib's libgloss/frv/crt0.S */
  23. /*
  24. When we enter this piece of code, the program stack looks like this:
  25. argc argument counter (integer)
  26. argv[0] program name (pointer)
  27. argv[1...N] program args (pointers)
  28. argv[argc-1] end of args (integer)
  29. NULL
  30. env[0...N] environment variables (pointers)
  31. NULL
  32. Also, GR16 holds a pointer to a memory map. */
  33. #include <features.h>
  34. .text
  35. .global _start
  36. .type _start,%function
  37. #if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__
  38. .type __uClibc_main,%function
  39. #else
  40. .weak _init
  41. .weak _fini
  42. .type __uClibc_start_main,%function
  43. #endif
  44. _start:
  45. /* Make sure the stack pointer is properly aligned. Save the
  46. original value in gr21 such that we can get to arguments and
  47. such from there. */
  48. mov.p sp, gr21
  49. andi sp, #-8, sp
  50. /* At program start-up, gr16 contains a pointer to a memory
  51. map, that we use to relocate addresses. */
  52. call .Lcall
  53. .Lcall:
  54. movsg lr, gr4
  55. sethi.p #gprelhi(.Lcall), gr5
  56. setlo #gprello(.Lcall), gr5
  57. sub.p gr4, gr5, gr4
  58. /* gr4 now holds the _gp address. */
  59. mov gr16, gr8
  60. sethi.p #gprelhi(__ROFIXUP_LIST__), gr9
  61. sethi #gprelhi(__ROFIXUP_END__), gr10
  62. setlo.p #gprello(__ROFIXUP_LIST__), gr9
  63. setlo #gprello(__ROFIXUP_END__), gr10
  64. add.p gr9, gr4, gr9
  65. add gr10, gr4, gr10
  66. call __self_reloc
  67. mov.p gr8, gr17
  68. mov gr8, gr15
  69. /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_
  70. address, because the linker added its unrelocated address as
  71. the last entry in the ROFIXUP list, and __self_reloc returns
  72. the last entry, relocated. */
  73. /* Prepare arguments for uClibc main. */
  74. ld @(gr21, gr0), gr8
  75. slli gr8, #2, gr10
  76. add gr21, gr10, gr10
  77. addi.p gr21, #4, gr9
  78. addi gr10, #8, gr10
  79. /* Set up an invalid (NULL return address, NULL frame pointer)
  80. callers stack frame so anybody unrolling the stack knows where
  81. to stop */
  82. mov gr0, fp
  83. movgs gr0, lr
  84. #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  85. /* Pass .init and .fini arguments to __uClibc_start_main(). */
  86. sethi.p #gotfuncdeschi(_init), gr11
  87. sethi #gotfuncdeschi(_fini), gr12
  88. setlo.p #gotfuncdesclo(_init), gr11
  89. setlo #gotfuncdesclo(_fini), gr12
  90. ld.p @(gr11, gr17), gr11
  91. mov gr17, gr15
  92. ld.p @(gr12, gr17), gr12
  93. call __uClibc_start_main
  94. #else
  95. mov.p gr17, gr15
  96. call __uClibc_main
  97. #endif
  98. /* Crash if somehow `exit' returns anyways. */
  99. jmpl @(gr0,gr0)
  100. .size _start,.-_start
  101. /* Define a symbol for the first piece of initialized data. */
  102. .data
  103. .globl __data_start
  104. __data_start:
  105. .long 0
  106. .weak data_start
  107. data_start = __data_start