ontop_ppc64_sysv_elf_gas.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 ontop_fcontext
  68. #if _CALL_ELF == 2
  69. .text
  70. .align 2
  71. ontop_fcontext:
  72. addis %r2, %r12, .TOC.-ontop_fcontext@ha
  73. addi %r2, %r2, .TOC.-ontop_fcontext@l
  74. .localentry ontop_fcontext, . - ontop_fcontext
  75. #else
  76. .section ".opd","aw"
  77. .align 3
  78. ontop_fcontext:
  79. # ifdef _CALL_LINUX
  80. .quad .L.ontop_fcontext,.TOC.@tocbase,0
  81. .type ontop_fcontext,@function
  82. .text
  83. .align 2
  84. .L.ontop_fcontext:
  85. # else
  86. .hidden .ontop_fcontext
  87. .globl .ontop_fcontext
  88. .quad .ontop_fcontext,.TOC.@tocbase,0
  89. .size ontop_fcontext,24
  90. .type .ontop_fcontext,@function
  91. .text
  92. .align 2
  93. .ontop_fcontext:
  94. # endif
  95. #endif
  96. # reserve space on stack
  97. subi %r1, %r1, 184
  98. #if _CALL_ELF != 2
  99. std %r2, 0(%r1) # save TOC
  100. #endif
  101. std %r14, 8(%r1) # save R14
  102. std %r15, 16(%r1) # save R15
  103. std %r16, 24(%r1) # save R16
  104. std %r17, 32(%r1) # save R17
  105. std %r18, 40(%r1) # save R18
  106. std %r19, 48(%r1) # save R19
  107. std %r20, 56(%r1) # save R20
  108. std %r21, 64(%r1) # save R21
  109. std %r22, 72(%r1) # save R22
  110. std %r23, 80(%r1) # save R23
  111. std %r24, 88(%r1) # save R24
  112. std %r25, 96(%r1) # save R25
  113. std %r26, 104(%r1) # save R26
  114. std %r27, 112(%r1) # save R27
  115. std %r28, 120(%r1) # save R28
  116. std %r29, 128(%r1) # save R29
  117. std %r30, 136(%r1) # save R30
  118. std %r31, 144(%r1) # save R31
  119. #if _CALL_ELF != 2
  120. std %r3, 152(%r1) # save hidden
  121. #endif
  122. # save CR
  123. mfcr %r0
  124. std %r0, 160(%r1)
  125. # save LR
  126. mflr %r0
  127. std %r0, 168(%r1)
  128. # save LR as PC
  129. std %r0, 176(%r1)
  130. # store RSP (pointing to context-data) in R7
  131. mr %r7, %r1
  132. #if _CALL_ELF == 2
  133. # restore RSP (pointing to context-data) from R3
  134. mr %r1, %r3
  135. #else
  136. # restore RSP (pointing to context-data) from R4
  137. mr %r1, %r4
  138. #endif
  139. ld %r14, 8(%r1) # restore R14
  140. ld %r15, 16(%r1) # restore R15
  141. ld %r16, 24(%r1) # restore R16
  142. ld %r17, 32(%r1) # restore R17
  143. ld %r18, 40(%r1) # restore R18
  144. ld %r19, 48(%r1) # restore R19
  145. ld %r20, 56(%r1) # restore R20
  146. ld %r21, 64(%r1) # restore R21
  147. ld %r22, 72(%r1) # restore R22
  148. ld %r23, 80(%r1) # restore R23
  149. ld %r24, 88(%r1) # restore R24
  150. ld %r25, 96(%r1) # restore R25
  151. ld %r26, 104(%r1) # restore R26
  152. ld %r27, 112(%r1) # restore R27
  153. ld %r28, 120(%r1) # restore R28
  154. ld %r29, 128(%r1) # restore R29
  155. ld %r30, 136(%r1) # restore R30
  156. ld %r31, 144(%r1) # restore R31
  157. #if _CALL_ELF != 2
  158. ld %r3, 152(%r1) # restore hidden
  159. #endif
  160. # restore CR
  161. ld %r0, 160(%r1)
  162. mtcr %r0
  163. #if _CALL_ELF == 2
  164. # restore CTR
  165. mtctr %r5
  166. # copy transfer_t into ontop_fn arg registers
  167. mr %r3, %r7
  168. # arg pointer already in %r4
  169. #else
  170. # copy transfer_t into ontop_fn arg registers
  171. mr %r4, %r7
  172. # arg pointer already in %r5
  173. # hidden arg already in %r3
  174. # restore CTR
  175. ld %r7, 0(%r6)
  176. mtctr %r7
  177. # restore TOC
  178. ld %r2, 8(%r6)
  179. # zero in r3 indicates first jump to context-function
  180. cmpdi %r3, 0
  181. beq use_entry_arg
  182. #endif
  183. return_to_ctx:
  184. # restore LR
  185. ld %r0, 168(%r1)
  186. mtlr %r0
  187. # adjust stack
  188. addi %r1, %r1, 184
  189. # jump to context
  190. bctr
  191. #if _CALL_ELF == 2
  192. .size ontop_fcontext, .-ontop_fcontext
  193. #else
  194. use_entry_arg:
  195. # compute return-value struct address
  196. # (passed has hidden arg to ontop_fn)
  197. addi %r3, %r1, 8
  198. # jump to context and update LR
  199. bctrl
  200. # restore CTR
  201. ld %r7, 176(%r1)
  202. mtctr %r7
  203. #if _CALL_ELF != 2
  204. # restore TOC
  205. ld %r2, 0(%r1)
  206. #endif
  207. # copy returned transfer_t into entry_fn arg registers
  208. ld %r3, 8(%r1)
  209. ld %r4, 16(%r1)
  210. b return_to_ctx
  211. # ifdef _CALL_LINUX
  212. .size .ontop_fcontext, .-.L.ontop_fcontext
  213. # else
  214. .size .ontop_fcontext, .-.ontop_fcontext
  215. # endif
  216. #endif
  217. /* Mark that we don't need executable stack. */
  218. .section .note.GNU-stack,"",%progbits