crt0.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright (C) 1991, 1992, 2003 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. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. /* Based on ../i386/crt0.S and newlib's libgloss/frv/crt0.S */
  16. /*
  17. When we enter this piece of code, the program stack looks like this:
  18. argc argument counter (integer)
  19. argv[0] program name (pointer)
  20. argv[1...N] program args (pointers)
  21. argv[argc-1] end of args (integer)
  22. NULL
  23. env[0...N] environment variables (pointers)
  24. NULL
  25. Also, GR16 holds a pointer to a memory map. */
  26. #include <features.h>
  27. .text
  28. .global _start
  29. .type _start,%function
  30. #if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__
  31. .type __uClibc_main,%function
  32. #else
  33. .weak _init
  34. .weak _fini
  35. .type __uClibc_start_main,%function
  36. #endif
  37. /* Stick in a dummy reference to main(), so that if an application
  38. * is linking when the main() function is in a static library (.a)
  39. * we can be sure that main() actually gets linked in */
  40. .type main,%function
  41. _start:
  42. /* At program start-up, gr16 contains a pointer to a memory
  43. map, that we use to relocate addresses. */
  44. call .Lcall
  45. .Lcall:
  46. movsg lr, gr4
  47. sethi.p #gprelhi(.Lcall), gr5
  48. setlo #gprello(.Lcall), gr5
  49. sub.p gr4, gr5, gr4
  50. /* gr4 now holds the _gp address. */
  51. mov gr16, gr8
  52. sethi.p #gprelhi(__ROFIXUP_LIST__), gr9
  53. sethi #gprelhi(__ROFIXUP_END__), gr10
  54. setlo.p #gprello(__ROFIXUP_LIST__), gr9
  55. setlo #gprello(__ROFIXUP_END__), gr10
  56. add.p gr9, gr4, gr9
  57. add gr10, gr4, gr10
  58. call __self_reloc
  59. mov.p gr8, gr17
  60. mov gr8, gr15
  61. /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_
  62. address, because the linker added its unrelocated address as
  63. the last entry in the ROFIXUP list, and __self_reloc returns
  64. the last entry, relocated. */
  65. /* Prepare arguments for uClibc main. */
  66. ld @(sp, gr0), gr8
  67. slli gr8, #2, gr10
  68. add sp, gr10, gr10
  69. addi.p sp, #4, gr9
  70. addi gr10, #8, gr10
  71. /* Set up an invalid (NULL return address, NULL frame pointer)
  72. callers stack frame so anybody unrolling the stack knows where
  73. to stop */
  74. mov gr0, fp
  75. movgs gr0, lr
  76. #if (defined L_crt1 || defined L_gcrt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
  77. /* Pass .init and .fini arguments to __uClibc_start_main(). */
  78. sethi.p #gotfuncdeschi(_init), gr11
  79. sethi #gotfuncdeschi(_fini), gr12
  80. setlo.p #gotfuncdesclo(_init), gr11
  81. setlo #gotfuncdesclo(_fini), gr12
  82. ld.p @(gr11, gr17), gr11
  83. mov gr17, gr15
  84. ld.p @(gr12, gr17), gr12
  85. call __uClibc_start_main
  86. #else
  87. mov.p gr17, gr15
  88. call __uClibc_main
  89. #endif
  90. /* Crash if somehow `exit' returns anyways. */
  91. jmpl @(gr0,gr0)
  92. .size _start,.-_start
  93. #if defined L_gcrt1 && defined __UCLIBC_PROFILING__
  94. # include "./gmon-start.S"
  95. #endif
  96. /* Define a symbol for the first piece of initialized data. */
  97. .data
  98. .globl __data_start
  99. __data_start:
  100. .long 0
  101. .weak data_start
  102. data_start = __data_start