crti.S 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Special .init and .fini section support for Nios II.
  2. Copyright (C) 2012-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library. If not, see
  29. <http://www.gnu.org/licenses/>. */
  30. /* crti.S puts a function prologue at the beginning of the .init and
  31. .fini sections and defines global symbols for those addresses, so
  32. they can be called as functions. The symbols _init and _fini are
  33. magic and cause the linker to emit DT_INIT and DT_FINI. */
  34. #include <libc-symbols.h>
  35. #ifndef PREINIT_FUNCTION
  36. # define PREINIT_FUNCTION __gmon_start__
  37. #endif
  38. #ifndef PREINIT_FUNCTION_WEAK
  39. # define PREINIT_FUNCTION_WEAK 1
  40. #endif
  41. #if PREINIT_FUNCTION_WEAK
  42. weak_extern (PREINIT_FUNCTION)
  43. #else
  44. .hidden PREINIT_FUNCTION
  45. #endif
  46. .section .init,"ax",@progbits
  47. .align 2
  48. .global _init
  49. .hidden _init
  50. .type _init, @function
  51. _init:
  52. addi sp, sp, -8
  53. stw r22, 0(sp)
  54. nextpc r22
  55. 1:
  56. movhi r8, %hiadj(_gp_got - 1b)
  57. addi r8, r8, %lo(_gp_got - 1b)
  58. add r22, r22, r8
  59. stw ra, 4(sp)
  60. #if PREINIT_FUNCTION_WEAK
  61. movhi r2, %got_hiadj(PREINIT_FUNCTION)
  62. addi r2, r2, %got_lo(PREINIT_FUNCTION)
  63. add r2, r2, r22
  64. ldw r2, 0(r2)
  65. beq r2, zero, .L5
  66. #endif
  67. movhi r2, %call_hiadj(PREINIT_FUNCTION)
  68. addi r2, r2, %call_lo(PREINIT_FUNCTION)
  69. add r2, r2, r22
  70. ldw r2, 0(r2)
  71. callr r2
  72. .L5:
  73. .section .fini,"ax",@progbits
  74. .align 2
  75. .global _fini
  76. .hidden _fini
  77. .type _fini, @function
  78. _fini:
  79. addi sp, sp, -8
  80. stw r22, 0(sp)
  81. nextpc r22
  82. 1:
  83. movhi r8, %hiadj(_gp_got - 1b)
  84. addi r8, r8, %lo(_gp_got - 1b)
  85. stw ra, 4(sp)
  86. add r22, r22, r8