crti.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Define _init and _fini entry points for C-SKY.
  2. # Copyright (C) 2018-2022 Free Software Foundation, Inc.
  3. # Contributed by C-SKY Microsystems and Mentor Graphics.
  4. #
  5. # This file is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation; either version 3, or (at your option) any
  8. # later version.
  9. #
  10. # This file is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # Under Section 7 of GPL version 3, you are granted additional
  16. # permissions described in the GCC Runtime Library Exception, version
  17. # 3.1, as published by the Free Software Foundation.
  18. #
  19. # You should have received a copy of the GNU General Public License and
  20. # a copy of the GCC Runtime Library Exception along with this program;
  21. # see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  22. # <http://www.gnu.org/licenses/>.
  23. # This file just makes a stack frame for the contents of the .fini and
  24. # .init sections. Users may put any desired instructions in those
  25. # sections.
  26. .file "crti.S"
  27. /* We use more complicated versions of this code with GLIBC. */
  28. #if defined(__gnu_linux__)
  29. #ifndef PREINIT_FUNCTION
  30. # define PREINIT_FUNCTION __gmon_start__
  31. #endif
  32. #ifndef PREINIT_FUNCTION_WEAK
  33. # define PREINIT_FUNCTION_WEAK 1
  34. #endif
  35. #if PREINIT_FUNCTION_WEAK
  36. .global PREINIT_FUNCTION
  37. .weak PREINIT_FUNCTION
  38. .align 4
  39. .type call_weak_fn, %function
  40. call_weak_fn:
  41. // push lr
  42. subi sp, 4
  43. stw lr, (sp)
  44. #ifdef __PIC__
  45. lrw a2, PREINIT_FUNCTION@GOT
  46. addu a2, gb
  47. ldw a2, (a2)
  48. #else
  49. lrw a2, PREINIT_FUNCTION
  50. #endif
  51. cmpnei a2, 0
  52. bf 1f
  53. jsr a2
  54. 1:
  55. // pop lr
  56. ldw lr, (sp)
  57. addi sp, 4
  58. rts
  59. .align 4
  60. #else
  61. .hidden PREINIT_FUNCTION
  62. #endif /* PREINIT_FUNCTION_WEAK */
  63. .section .init,"ax",@progbits
  64. .align 4
  65. .globl _init
  66. .type _init, @function
  67. _init:
  68. subi sp, 8
  69. stw lr, (sp, 0)
  70. #ifdef __PIC__
  71. // stw gb, (sp, 4)
  72. bsr .Lgetpc
  73. .Lgetpc:
  74. lrw gb, .Lgetpc@GOTPC
  75. add gb, lr
  76. #endif
  77. #if PREINIT_FUNCTION_WEAK
  78. #ifdef __PIC__
  79. lrw a2, call_weak_fn@GOTOFF
  80. add a2, gb
  81. jsr a2
  82. #else
  83. jsri call_weak_fn
  84. #endif
  85. #else /* !PREINIT_FUNCTION_WEAK */
  86. #ifdef __PIC__
  87. lrw a2, PREINIT_FUNCTION@PLT
  88. addu a2, gb
  89. ldw a2, (a2)
  90. jsr a2
  91. #else
  92. jsri PREINIT_FUNCTION
  93. #endif
  94. #endif /* PREINIT_FUNCTION_WEAK */
  95. br 2f
  96. .literals
  97. .align 4
  98. 2:
  99. .section .fini,"ax",@progbits
  100. .align 4
  101. .globl _fini
  102. .type _fini, @function
  103. _fini:
  104. subi sp,8
  105. stw lr, (sp, 0)
  106. br 2f
  107. .literals
  108. .align 4
  109. 2:
  110. /* These are the non-GLIBC versions. */
  111. #else /* !defined(__gnu_linux__) */
  112. .section ".init"
  113. .global _init
  114. .type _init,@function
  115. .align 2
  116. _init:
  117. subi sp, 16
  118. st.w lr, (sp, 12)
  119. mov r0, r0
  120. .section ".fini"
  121. .global _fini
  122. .type _fini,@function
  123. .align 2
  124. _fini:
  125. subi sp, 16
  126. st.w lr, (sp, 12)
  127. mov r0, r0
  128. #endif /* defined(__gnu_linux__) */