crt1.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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; if not, write to the Free
  33. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  34. 02111-1307 USA. */
  35. /* Stick in a dummy reference to main(), so that if an application
  36. * is linking when the main() function is in a static library (.a)
  37. * we can be sure that main() actually gets linked in */
  38. .type main,%function
  39. /* This is the canonical entry point, usually the first thing in the text
  40. segment.
  41. sp The stack contains the arguments and environment:
  42. 0(sp) argc
  43. 4(sp) argv[0]
  44. ...
  45. (4*argc)(sp) NULL
  46. (4*(argc+1))(sp) envp[0]
  47. ...
  48. NULL
  49. */
  50. #include <features.h>
  51. .text
  52. .globl _start
  53. .type _start,%function
  54. .global _start
  55. _start:
  56. #ifdef __PIC__
  57. /* Obtain a pointer to .got in r16 */
  58. l.jal .LPC0
  59. #ifndef __OR1K_NODELAY__
  60. l.nop
  61. #endif
  62. .LPC0:
  63. l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))
  64. l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))
  65. l.add r16, r16, r9
  66. #endif
  67. /* Push stack limit onto the stack */
  68. /* Provides highest stack address to user code (as stack grows
  69. * downwards
  70. * This is the seventh argument to __uClibc_main and thus needs to
  71. * be passed on the stack
  72. */
  73. l.sw -4(r1),r1
  74. /* Take values for argc and argv off the stack.
  75. * These will be passed as arguments two and three to __uClibc_main
  76. * and thus go in registers r4 and r5, respectively
  77. */
  78. l.lwz r4,0(r1)
  79. l.addi r5,r1,4
  80. #ifdef __PIC__
  81. l.lwz r3,got(main)(r16)
  82. #else
  83. l.movhi r3,hi(main)
  84. l.ori r3,r3,lo(main)
  85. #endif
  86. /* Put the constructor and destructor initialization as args four and
  87. five into r6 and r7 */
  88. #ifdef __PIC__
  89. l.lwz r6, got(_init)(r16)
  90. l.lwz r7, got(_fini)(r16)
  91. #else
  92. l.movhi r6,hi(_init)
  93. l.ori r6,r6,lo(_init)
  94. l.movhi r7,hi(_fini)
  95. l.ori r7,r7,lo(_fini)
  96. #endif
  97. /* rtld_fini = NULL */
  98. l.movhi r8, 0
  99. /* Adjust stack to account for a total of 7 args (i.e. the last one is
  100. on the stack. */
  101. l.addi r1,r1,-4
  102. /* Clear the frame pointer and link register since this is the
  103. * outermost frame.
  104. */
  105. l.add r2,r0,r0
  106. l.add r9,r0,r0
  107. /* Let the libc call main and exit with its return code. */
  108. #ifdef __PIC__
  109. l.j plt(__uClibc_main)
  110. #else
  111. l.j __uClibc_main
  112. #endif
  113. l.nop
  114. /* Define a symbol for the first piece of initialized data. */
  115. .data
  116. .globl __data_start
  117. __data_start:
  118. .long 0
  119. .weak data_start
  120. data_start = __data_start