crt0.S 3.9 KB

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