make_ppc64_sysv_elf_gas.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*******************************************************
  8. * *
  9. * ------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * ------------------------------------------------- *
  12. * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
  13. * ------------------------------------------------- *
  14. * | TOC | R14 | R15 | R16 | *
  15. * ------------------------------------------------- *
  16. * ------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ------------------------------------------------- *
  19. * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
  20. * ------------------------------------------------- *
  21. * | R17 | R18 | R19 | R20 | *
  22. * ------------------------------------------------- *
  23. * ------------------------------------------------- *
  24. * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
  25. * ------------------------------------------------- *
  26. * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
  27. * ------------------------------------------------- *
  28. * | R21 | R22 | R23 | R24 | *
  29. * ------------------------------------------------- *
  30. * ------------------------------------------------- *
  31. * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
  32. * ------------------------------------------------- *
  33. * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
  34. * ------------------------------------------------- *
  35. * | R25 | R26 | R27 | R28 | *
  36. * ------------------------------------------------- *
  37. * ------------------------------------------------- *
  38. * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
  39. * ------------------------------------------------- *
  40. * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
  41. * ------------------------------------------------- *
  42. * | R29 | R30 | R31 | hidden | *
  43. * ------------------------------------------------- *
  44. * ------------------------------------------------- *
  45. * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
  46. * ------------------------------------------------- *
  47. * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
  48. * ------------------------------------------------- *
  49. * | CR | LR | PC | back-chain| *
  50. * ------------------------------------------------- *
  51. * ------------------------------------------------- *
  52. * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
  53. * ------------------------------------------------- *
  54. * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
  55. * ------------------------------------------------- *
  56. * | cr saved | lr saved | compiler | linker | *
  57. * ------------------------------------------------- *
  58. * ------------------------------------------------- *
  59. * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
  60. * ------------------------------------------------- *
  61. * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
  62. * ------------------------------------------------- *
  63. * | TOC saved | FCTX | DATA | | *
  64. * ------------------------------------------------- *
  65. * *
  66. *******************************************************/
  67. .globl make_fcontext
  68. #if _CALL_ELF == 2
  69. .text
  70. .align 2
  71. make_fcontext:
  72. addis %r2, %r12, .TOC.-make_fcontext@ha
  73. addi %r2, %r2, .TOC.-make_fcontext@l
  74. .localentry make_fcontext, . - make_fcontext
  75. #else
  76. .section ".opd","aw"
  77. .align 3
  78. make_fcontext:
  79. # ifdef _CALL_LINUX
  80. .quad .L.make_fcontext,.TOC.@tocbase,0
  81. .type make_fcontext,@function
  82. .text
  83. .align 2
  84. .L.make_fcontext:
  85. # else
  86. .hidden .make_fcontext
  87. .globl .make_fcontext
  88. .quad .make_fcontext,.TOC.@tocbase,0
  89. .size make_fcontext,24
  90. .type .make_fcontext,@function
  91. .text
  92. .align 2
  93. .make_fcontext:
  94. # endif
  95. #endif
  96. # save return address into R6
  97. mflr %r6
  98. # first arg of make_fcontext() == top address of context-stack
  99. # shift address in R3 to lower 16 byte boundary
  100. clrrdi %r3, %r3, 4
  101. # reserve space for context-data on context-stack
  102. # including 64 byte of linkage + parameter area (R1 % 16 == 0)
  103. subi %r3, %r3, 248
  104. # third arg of make_fcontext() == address of context-function
  105. # entry point (ELFv2) or descriptor (ELFv1)
  106. #if _CALL_ELF == 2
  107. # save address of context-function entry point
  108. std %r5, 176(%r3)
  109. #else
  110. # save address of context-function entry point
  111. ld %r4, 0(%r5)
  112. std %r4, 176(%r3)
  113. # save TOC of context-function
  114. ld %r4, 8(%r5)
  115. std %r4, 0(%r3)
  116. #endif
  117. # set back-chain to zero
  118. li %r0, 0
  119. std %r0, 184(%r3)
  120. #if _CALL_ELF != 2
  121. # zero in r3 indicates first jump to context-function
  122. std %r0, 152(%r3)
  123. #endif
  124. # load LR
  125. mflr %r0
  126. # jump to label 1
  127. bl 1f
  128. 1:
  129. # load LR into R4
  130. mflr %r4
  131. # compute abs address of label finish
  132. addi %r4, %r4, finish - 1b
  133. # restore LR
  134. mtlr %r0
  135. # save address of finish as return-address for context-function
  136. # will be entered after context-function returns
  137. std %r4, 168(%r3)
  138. # restore return address from R6
  139. mtlr %r6
  140. blr # return pointer to context-data
  141. finish:
  142. # save return address into R0
  143. mflr %r0
  144. # save return address on stack, set up stack frame
  145. std %r0, 8(%r1)
  146. # allocate stack space, R1 % 16 == 0
  147. stdu %r1, -32(%r1)
  148. # exit code is zero
  149. li %r3, 0
  150. # exit application
  151. bl _exit
  152. nop
  153. #if _CALL_ELF == 2
  154. .size make_fcontext, .-make_fcontext
  155. #else
  156. # ifdef _CALL_LINUX
  157. .size .make_fcontext, .-.L.make_fcontext
  158. # else
  159. .size .make_fcontext, .-.make_fcontext
  160. # endif
  161. #endif
  162. /* Mark that we don't need executable stack. */
  163. .section .note.GNU-stack,"",%progbits