crt1.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. .weak _init
  38. .weak _fini
  39. .type __uClibc_main,%function
  40. _start:
  41. /* Make sure the stack pointer is properly aligned. Save the
  42. original value in gr21 such that we can get to arguments and
  43. such from there. */
  44. mov.p sp, gr21
  45. andi sp, #-8, sp
  46. /* At program start-up, gr16 contains a pointer to a memory
  47. map, that we use to relocate addresses. */
  48. call .Lcall
  49. .Lcall:
  50. movsg lr, gr4
  51. sethi.p #gprelhi(.Lcall), gr5
  52. setlo #gprello(.Lcall), gr5
  53. sub.p gr4, gr5, gr4
  54. /* gr4 now holds the _gp address. */
  55. mov gr16, gr8
  56. sethi.p #gprelhi(__ROFIXUP_LIST__), gr9
  57. sethi #gprelhi(__ROFIXUP_END__), gr10
  58. setlo.p #gprello(__ROFIXUP_LIST__), gr9
  59. setlo #gprello(__ROFIXUP_END__), gr10
  60. add.p gr9, gr4, gr9
  61. add gr10, gr4, gr10
  62. call __self_reloc
  63. mov.p gr8, gr17
  64. mov gr8, gr15
  65. /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_
  66. address, because the linker added its unrelocated address as
  67. the last entry in the ROFIXUP list, and __self_reloc returns
  68. the last entry, relocated. */
  69. /* Prepare arguments for uClibc main. */
  70. ld @(gr21, gr0), gr8
  71. slli gr8, #2, gr10
  72. add gr21, gr10, gr10
  73. addi.p gr21, #4, gr9
  74. addi gr10, #8, gr10
  75. /* Set up an invalid (NULL return address, NULL frame pointer)
  76. callers stack frame so anybody unrolling the stack knows where
  77. to stop */
  78. mov gr0, fp
  79. movgs gr0, lr
  80. #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  81. /* Pass .init and .fini arguments to __uClibc_start_main(). */
  82. sethi.p #gotfuncdeschi(_init), gr11
  83. sethi #gotfuncdeschi(_fini), gr12
  84. setlo.p #gotfuncdesclo(_init), gr11
  85. setlo #gotfuncdesclo(_fini), gr12
  86. ld.p @(gr11, gr17), gr11
  87. mov gr17, gr15
  88. ld.p @(gr12, gr17), gr12
  89. call __uClibc_main
  90. #else
  91. mov.p gr17, gr15
  92. call __uClibc_main
  93. #endif
  94. /* Crash if somehow `exit' returns anyways. */
  95. jmpl @(gr0,gr0)
  96. .size _start,.-_start
  97. /* Define a symbol for the first piece of initialized data. */
  98. .data
  99. .globl __data_start
  100. __data_start:
  101. .long 0
  102. .weak data_start
  103. data_start = __data_start