eabi.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Special support for eabi and SVR4
  3. *
  4. * Copyright (C) 1995-2022 Free Software Foundation, Inc.
  5. * Written By Michael Meissner
  6. *
  7. * This file is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 3, or (at your option) any
  10. * later version.
  11. *
  12. * This file is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * Under Section 7 of GPL version 3, you are granted additional
  18. * permissions described in the GCC Runtime Library Exception, version
  19. * 3.1, as published by the Free Software Foundation.
  20. *
  21. * You should have received a copy of the GNU General Public License and
  22. * a copy of the GCC Runtime Library Exception along with this program;
  23. * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  24. * <http://www.gnu.org/licenses/>.
  25. */
  26. /* Do any initializations needed for the eabi environment */
  27. .section ".text"
  28. #include "ppc-asm.h"
  29. #ifndef __powerpc64__
  30. .section ".got2","aw"
  31. .align 2
  32. .LCTOC1 = . /* +32768 */
  33. /* Table of addresses */
  34. .Ltable = .-.LCTOC1
  35. .long .LCTOC1 /* address we are really at */
  36. .Lsda = .-.LCTOC1
  37. .long _SDA_BASE_ /* address of the first small data area */
  38. .Lsdas = .-.LCTOC1
  39. .long __SDATA_START__ /* start of .sdata/.sbss section */
  40. .Lsdae = .-.LCTOC1
  41. .long __SBSS_END__ /* end of .sdata/.sbss section */
  42. .Lsda2 = .-.LCTOC1
  43. .long _SDA2_BASE_ /* address of the second small data area */
  44. .Lsda2s = .-.LCTOC1
  45. .long __SDATA2_START__ /* start of .sdata2/.sbss2 section */
  46. .Lsda2e = .-.LCTOC1
  47. .long __SBSS2_END__ /* end of .sdata2/.sbss2 section */
  48. #ifdef _RELOCATABLE
  49. .Lgots = .-.LCTOC1
  50. .long __GOT_START__ /* Global offset table start */
  51. .Lgotm1 = .-.LCTOC1
  52. .long _GLOBAL_OFFSET_TABLE_-4 /* end of GOT ptrs before BLCL + 3 reserved words */
  53. .Lgotm2 = .-.LCTOC1
  54. .long _GLOBAL_OFFSET_TABLE_+12 /* start of GOT ptrs after BLCL + 3 reserved words */
  55. .Lgote = .-.LCTOC1
  56. .long __GOT_END__ /* Global offset table end */
  57. .Lgot2s = .-.LCTOC1
  58. .long __GOT2_START__ /* -mrelocatable GOT pointers start */
  59. .Lgot2e = .-.LCTOC1
  60. .long __GOT2_END__ /* -mrelocatable GOT pointers end */
  61. .Lfixups = .-.LCTOC1
  62. .long __FIXUP_START__ /* start of .fixup section */
  63. .Lfixupe = .-.LCTOC1
  64. .long __FIXUP_END__ /* end of .fixup section */
  65. .Lctors = .-.LCTOC1
  66. .long __CTOR_LIST__ /* start of .ctor section */
  67. .Lctore = .-.LCTOC1
  68. .long __CTOR_END__ /* end of .ctor section */
  69. .Ldtors = .-.LCTOC1
  70. .long __DTOR_LIST__ /* start of .dtor section */
  71. .Ldtore = .-.LCTOC1
  72. .long __DTOR_END__ /* end of .dtor section */
  73. .Lexcepts = .-.LCTOC1
  74. .long __EXCEPT_START__ /* start of .gcc_except_table section */
  75. .Lexcepte = .-.LCTOC1
  76. .long __EXCEPT_END__ /* end of .gcc_except_table section */
  77. .Linit = .-.LCTOC1
  78. .long .Linit_p /* address of variable to say we've been called */
  79. .text
  80. .align 2
  81. .Lptr:
  82. .long .LCTOC1-.Laddr /* PC relative pointer to .got2 */
  83. #endif
  84. .data
  85. .align 2
  86. .Linit_p:
  87. .long 0
  88. .text
  89. FUNC_START(__eabi)
  90. /* Eliminate -mrelocatable code if not -mrelocatable, so that this file can
  91. be assembled with other assemblers than GAS. */
  92. #ifndef _RELOCATABLE
  93. addis 10,0,.Linit_p@ha /* init flag */
  94. addis 11,0,.LCTOC1@ha /* load address of .LCTOC1 */
  95. lwz 9,.Linit_p@l(10) /* init flag */
  96. addi 11,11,.LCTOC1@l
  97. cmplwi 2,9,0 /* init flag != 0? */
  98. bnelr 2 /* return now, if we've been called already */
  99. stw 1,.Linit_p@l(10) /* store a nonzero value in the done flag */
  100. #else /* -mrelocatable */
  101. mflr 0
  102. bl .Laddr /* get current address */
  103. .Laddr:
  104. mflr 12 /* real address of .Laddr */
  105. lwz 11,(.Lptr-.Laddr)(12) /* linker generated address of .LCTOC1 */
  106. add 11,11,12 /* correct to real pointer */
  107. lwz 12,.Ltable(11) /* get linker's idea of where .Laddr is */
  108. lwz 10,.Linit(11) /* address of init flag */
  109. subf. 12,12,11 /* calculate difference */
  110. lwzx 9,10,12 /* done flag */
  111. cmplwi 2,9,0 /* init flag != 0? */
  112. mtlr 0 /* restore in case branch was taken */
  113. bnelr 2 /* return now, if we've been called already */
  114. stwx 1,10,12 /* store a nonzero value in the done flag */
  115. beq+ 0,.Lsdata /* skip if we don't need to relocate */
  116. /* We need to relocate the .got2 pointers. */
  117. lwz 3,.Lgot2s(11) /* GOT2 pointers start */
  118. lwz 4,.Lgot2e(11) /* GOT2 pointers end */
  119. add 3,12,3 /* adjust pointers */
  120. add 4,12,4
  121. bl FUNC_NAME(__eabi_convert) /* convert pointers in .got2 section */
  122. /* Fixup the .ctor section for static constructors */
  123. lwz 3,.Lctors(11) /* constructors pointers start */
  124. lwz 4,.Lctore(11) /* constructors pointers end */
  125. bl FUNC_NAME(__eabi_convert) /* convert constructors */
  126. /* Fixup the .dtor section for static destructors */
  127. lwz 3,.Ldtors(11) /* destructors pointers start */
  128. lwz 4,.Ldtore(11) /* destructors pointers end */
  129. bl FUNC_NAME(__eabi_convert) /* convert destructors */
  130. /* Fixup the .gcc_except_table section for G++ exceptions */
  131. lwz 3,.Lexcepts(11) /* exception table pointers start */
  132. lwz 4,.Lexcepte(11) /* exception table pointers end */
  133. bl FUNC_NAME(__eabi_convert) /* convert exceptions */
  134. /* Fixup the addresses in the GOT below _GLOBAL_OFFSET_TABLE_-4 */
  135. lwz 3,.Lgots(11) /* GOT table pointers start */
  136. lwz 4,.Lgotm1(11) /* GOT table pointers below _GLOBAL_OFFSET_TABLE-4 */
  137. bl FUNC_NAME(__eabi_convert) /* convert lower GOT */
  138. /* Fixup the addresses in the GOT above _GLOBAL_OFFSET_TABLE_+12 */
  139. lwz 3,.Lgotm2(11) /* GOT table pointers above _GLOBAL_OFFSET_TABLE+12 */
  140. lwz 4,.Lgote(11) /* GOT table pointers end */
  141. bl FUNC_NAME(__eabi_convert) /* convert lower GOT */
  142. /* Fixup any user initialized pointers now (the compiler drops pointers to */
  143. /* each of the relocs that it does in the .fixup section). */
  144. .Lfix:
  145. lwz 3,.Lfixups(11) /* fixup pointers start */
  146. lwz 4,.Lfixupe(11) /* fixup pointers end */
  147. bl FUNC_NAME(__eabi_uconvert) /* convert user initialized pointers */
  148. .Lsdata:
  149. mtlr 0 /* restore link register */
  150. #endif /* _RELOCATABLE */
  151. /* Only load up register 13 if there is a .sdata and/or .sbss section */
  152. lwz 3,.Lsdas(11) /* start of .sdata/.sbss section */
  153. lwz 4,.Lsdae(11) /* end of .sdata/.sbss section */
  154. cmpw 1,3,4 /* .sdata/.sbss section non-empty? */
  155. beq- 1,.Lsda2l /* skip loading r13 */
  156. lwz 13,.Lsda(11) /* load r13 with _SDA_BASE_ address */
  157. /* Only load up register 2 if there is a .sdata2 and/or .sbss2 section */
  158. .Lsda2l:
  159. lwz 3,.Lsda2s(11) /* start of .sdata/.sbss section */
  160. lwz 4,.Lsda2e(11) /* end of .sdata/.sbss section */
  161. cmpw 1,3,4 /* .sdata/.sbss section non-empty? */
  162. beq+ 1,.Ldone /* skip loading r2 */
  163. lwz 2,.Lsda2(11) /* load r2 with _SDA2_BASE_ address */
  164. /* Done adjusting pointers, return by way of doing the C++ global constructors. */
  165. .Ldone:
  166. b FUNC_NAME(__init) /* do any C++ global constructors (which returns to caller) */
  167. FUNC_END(__eabi)
  168. /* Special subroutine to convert a bunch of pointers directly.
  169. r0 has original link register
  170. r3 has low pointer to convert
  171. r4 has high pointer to convert
  172. r5 .. r10 are scratch registers
  173. r11 has the address of .LCTOC1 in it.
  174. r12 has the value to add to each pointer
  175. r13 .. r31 are unchanged */
  176. #ifdef _RELOCATABLE
  177. FUNC_START(__eabi_convert)
  178. cmplw 1,3,4 /* any pointers to convert? */
  179. subf 5,3,4 /* calculate number of words to convert */
  180. bclr 4,4 /* return if no pointers */
  181. srawi 5,5,2
  182. addi 3,3,-4 /* start-4 for use with lwzu */
  183. mtctr 5
  184. .Lcvt:
  185. lwzu 6,4(3) /* pointer to convert */
  186. cmpwi 0,6,0
  187. beq- .Lcvt2 /* if pointer is null, don't convert */
  188. add 6,6,12 /* convert pointer */
  189. stw 6,0(3)
  190. .Lcvt2:
  191. bdnz+ .Lcvt
  192. blr
  193. FUNC_END(__eabi_convert)
  194. /* Special subroutine to convert the pointers the user has initialized. The
  195. compiler has placed the address of the initialized pointer into the .fixup
  196. section.
  197. r0 has original link register
  198. r3 has low pointer to convert
  199. r4 has high pointer to convert
  200. r5 .. r10 are scratch registers
  201. r11 has the address of .LCTOC1 in it.
  202. r12 has the value to add to each pointer
  203. r13 .. r31 are unchanged */
  204. FUNC_START(__eabi_uconvert)
  205. cmplw 1,3,4 /* any pointers to convert? */
  206. subf 5,3,4 /* calculate number of words to convert */
  207. bclr 4,4 /* return if no pointers */
  208. srawi 5,5,2
  209. addi 3,3,-4 /* start-4 for use with lwzu */
  210. mtctr 5
  211. .Lucvt:
  212. lwzu 6,4(3) /* next pointer to pointer to convert */
  213. add 6,6,12 /* adjust pointer */
  214. lwz 7,0(6) /* get the pointer it points to */
  215. stw 6,0(3) /* store adjusted pointer */
  216. add 7,7,12 /* adjust */
  217. stw 7,0(6)
  218. bdnz+ .Lucvt
  219. blr
  220. FUNC_END(__eabi_uconvert)
  221. #endif
  222. #endif