darwin-tramp.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Special support for trampolines
  2. *
  3. * Copyright (C) 1996-2022 Free Software Foundation, Inc.
  4. * Written By Michael Meissner
  5. *
  6. * This file is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 3, or (at your option) any
  9. * later version.
  10. *
  11. * This file is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * Under Section 7 of GPL version 3, you are granted additional
  17. * permissions described in the GCC Runtime Library Exception, version
  18. * 3.1, as published by the Free Software Foundation.
  19. *
  20. * You should have received a copy of the GNU General Public License and
  21. * a copy of the GCC Runtime Library Exception along with this program;
  22. * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  23. * <http://www.gnu.org/licenses/>.
  24. */
  25. #include "darwin-asm.h"
  26. /* Set up trampolines. */
  27. .text
  28. .align LOG2_GPR_BYTES
  29. Ltrampoline_initial:
  30. mflr r0
  31. bl 1f
  32. Lfunc = .-Ltrampoline_initial
  33. .g_long 0 /* will be replaced with function address */
  34. Lchain = .-Ltrampoline_initial
  35. .g_long 0 /* will be replaced with static chain */
  36. 1: mflr r11
  37. lg r12,0(r11) /* function address */
  38. mtlr r0
  39. mtctr r12
  40. lg r11,GPR_BYTES(r11) /* static chain */
  41. bctr
  42. trampoline_size = .-Ltrampoline_initial
  43. /* R3 = stack address to store trampoline */
  44. /* R4 = length of trampoline area */
  45. /* R5 = function address */
  46. /* R6 = static chain */
  47. .globl ___trampoline_setup
  48. ___trampoline_setup:
  49. mflr r0 /* save return address */
  50. bcl 20,31,LCF0 /* load up __trampoline_initial into r7 */
  51. LCF0:
  52. mflr r11
  53. addis r7,r11,ha16(LTRAMP-LCF0)
  54. lg r7,lo16(LTRAMP-LCF0)(r7)
  55. subi r7,r7,4
  56. li r8,trampoline_size /* verify trampoline big enough */
  57. cmpg cr1,r8,r4
  58. srwi r4,r4,2 /* # words to move (insns always 4-byte) */
  59. addi r9,r3,-4 /* adjust pointer for lgu */
  60. mtctr r4
  61. blt cr1,Labort
  62. mtlr r0
  63. /* Copy the instructions to the stack */
  64. Lmove:
  65. lwzu r10,4(r7)
  66. stwu r10,4(r9)
  67. bdnz Lmove
  68. /* Store correct function and static chain */
  69. stg r5,Lfunc(r3)
  70. stg r6,Lchain(r3)
  71. /* Now flush both caches */
  72. mtctr r4
  73. Lcache:
  74. icbi 0,r3
  75. dcbf 0,r3
  76. addi r3,r3,4
  77. bdnz Lcache
  78. /* Ensure cache-flushing has finished. */
  79. sync
  80. isync
  81. /* Make stack writeable. */
  82. b ___enable_execute_stack
  83. Labort:
  84. #ifdef __DYNAMIC__
  85. bl L_abort$stub
  86. .data
  87. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  88. .align 2
  89. L_abort$stub:
  90. .indirect_symbol _abort
  91. mflr r0
  92. bcl 20,31,L0$_abort
  93. L0$_abort:
  94. mflr r11
  95. addis r11,r11,ha16(L_abort$lazy_ptr-L0$_abort)
  96. mtlr r0
  97. lgu r12,lo16(L_abort$lazy_ptr-L0$_abort)(r11)
  98. mtctr r12
  99. bctr
  100. .data
  101. .lazy_symbol_pointer
  102. L_abort$lazy_ptr:
  103. .indirect_symbol _abort
  104. .g_long dyld_stub_binding_helper
  105. #else
  106. bl _abort
  107. #endif
  108. .data
  109. .align LOG2_GPR_BYTES
  110. LTRAMP:
  111. .g_long Ltrampoline_initial