crt1.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002, 2005
  2. Free Software Foundation, Inc.
  3. Copyright (C) 2010 Embecosm Limited
  4. Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
  5. Contributor Joern Rennecke <joern.rennecke@embecosm.com>
  6. With other contributions from the OpenCores community.
  7. This file is part of the GNU C Library.
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. In addition to the permissions in the GNU Lesser General Public
  13. License, the Free Software Foundation gives you unlimited
  14. permission to link the compiled version of this file with other
  15. programs, and to distribute those programs without any restriction
  16. coming from the use of this file. (The GNU Lesser General Public
  17. License restrictions do apply in other respects; for example, they
  18. cover modification of the file, and distribution when not linked
  19. into another program.)
  20. Note that people who make modified versions of this file are not
  21. obligated to grant this special exception for their modified
  22. versions; it is their choice whether to do so. The GNU Lesser
  23. General Public License gives permission to release a modified
  24. version without this exception; this exception also makes it
  25. possible to release a modified version which carries forward this
  26. exception.
  27. The GNU C Library is distributed in the hope that it will be useful,
  28. but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. Lesser General Public License for more details.
  31. You should have received a copy of the GNU Lesser General Public
  32. License along with the GNU C Library; see the file COPYING.LIB. If
  33. not, see <http://www.gnu.org/licenses/>.  */
  34. /* Stick in a dummy reference to main(), so that if an application
  35. * is linking when the main() function is in a static library (.a)
  36. * we can be sure that main() actually gets linked in */
  37. .type main,%function
  38. /* This is the canonical entry point, usually the first thing in the text
  39. segment.
  40. sp The stack contains the arguments and environment:
  41. 0(sp) argc
  42. 4(sp) argv[0]
  43. ...
  44. (4*argc)(sp) NULL
  45. (4*(argc+1))(sp) envp[0]
  46. ...
  47. NULL
  48. */
  49. #include <features.h>
  50. .text
  51. .globl _start
  52. .type _start,%function
  53. .global _start
  54. _start:
  55. #ifdef __PIC__
  56. /* Obtain a pointer to .got in r16 */
  57. l.jal .LPC0
  58. #ifndef __OR1K_NODELAY__
  59. l.nop
  60. #endif
  61. .LPC0:
  62. l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))
  63. l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))
  64. l.add r16, r16, r9
  65. #endif
  66. /* Push stack limit onto the stack */
  67. /* Provides highest stack address to user code (as stack grows
  68. * downwards
  69. * This is the seventh argument to __uClibc_main and thus needs to
  70. * be passed on the stack
  71. */
  72. l.sw -4(r1),r1
  73. /* Take values for argc and argv off the stack.
  74. * These will be passed as arguments two and three to __uClibc_main
  75. * and thus go in registers r4 and r5, respectively
  76. */
  77. l.lwz r4,0(r1)
  78. l.addi r5,r1,4
  79. #ifdef __PIC__
  80. l.lwz r3,got(main)(r16)
  81. #else
  82. l.movhi r3,hi(main)
  83. l.ori r3,r3,lo(main)
  84. #endif
  85. /* Put the constructor and destructor initialization as args four and
  86. five into r6 and r7 */
  87. #ifdef __PIC__
  88. l.lwz r6, got(_init)(r16)
  89. l.lwz r7, got(_fini)(r16)
  90. #else
  91. l.movhi r6,hi(_init)
  92. l.ori r6,r6,lo(_init)
  93. l.movhi r7,hi(_fini)
  94. l.ori r7,r7,lo(_fini)
  95. #endif
  96. /* rtld_fini = NULL */
  97. l.movhi r8, 0
  98. /* Adjust stack to account for a total of 7 args (i.e. the last one is
  99. on the stack. */
  100. l.addi r1,r1,-4
  101. /* Clear the frame pointer and link register since this is the
  102. * outermost frame.
  103. */
  104. l.add r2,r0,r0
  105. l.add r9,r0,r0
  106. /* Let the libc call main and exit with its return code. */
  107. #ifdef __PIC__
  108. l.j plt(__uClibc_main)
  109. #else
  110. l.j __uClibc_main
  111. #endif
  112. l.nop
  113. /* Define a symbol for the first piece of initialized data. */
  114. .data
  115. .globl __data_start
  116. __data_start:
  117. .long 0
  118. .weak data_start
  119. data_start = __data_start