tsan_rtl_ppc64.S 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #include "tsan_ppc_regs.h"
  2. .section .text
  3. .hidden __tsan_setjmp
  4. .globl _setjmp
  5. .type _setjmp, @function
  6. .align 4
  7. #if _CALL_ELF == 2
  8. _setjmp:
  9. #else
  10. .section ".opd","aw"
  11. .align 3
  12. _setjmp:
  13. .quad .L._setjmp,.TOC.@tocbase,0
  14. .previous
  15. #endif
  16. .L._setjmp:
  17. mflr r0
  18. stdu r1,-48(r1)
  19. std r2,24(r1)
  20. std r3,32(r1)
  21. std r0,40(r1)
  22. // r3 is the original stack pointer.
  23. addi r3,r1,48
  24. // r4 is the mangled stack pointer (see glibc)
  25. ld r4,-28696(r13)
  26. xor r4,r3,r4
  27. // Materialize a TOC in case we were called from libc.
  28. // For big-endian, we load the TOC from the OPD. For little-
  29. // endian, we use the .TOC. symbol to find it.
  30. nop
  31. bcl 20,31,0f
  32. 0:
  33. mflr r2
  34. #if _CALL_ELF == 2
  35. addis r2,r2,.TOC.-0b@ha
  36. addi r2,r2,.TOC.-0b@l
  37. #else
  38. addis r2,r2,_setjmp-0b@ha
  39. addi r2,r2,_setjmp-0b@l
  40. ld r2,8(r2)
  41. #endif
  42. // Call the interceptor.
  43. bl __tsan_setjmp
  44. nop
  45. // Restore regs needed for setjmp.
  46. ld r3,32(r1)
  47. ld r0,40(r1)
  48. // Emulate the real setjmp function. We do this because we can't
  49. // perform a sibcall: The real setjmp function trashes the TOC
  50. // pointer, and with a sibcall we have no way to restore it.
  51. // This way we can make sure our caller's stack pointer and
  52. // link register are saved correctly in the jmpbuf.
  53. ld r6,-28696(r13)
  54. addi r5,r1,48 // original stack ptr of caller
  55. xor r5,r6,r5
  56. std r5,0(r3) // mangled stack ptr of caller
  57. ld r5,24(r1)
  58. std r5,8(r3) // caller's saved TOC pointer
  59. xor r0,r6,r0
  60. std r0,16(r3) // caller's mangled return address
  61. mfcr r0
  62. // Nonvolatiles.
  63. std r14,24(r3)
  64. stfd f14,176(r3)
  65. stw r0,172(r3) // CR
  66. std r15,32(r3)
  67. stfd f15,184(r3)
  68. std r16,40(r3)
  69. stfd f16,192(r3)
  70. std r17,48(r3)
  71. stfd f17,200(r3)
  72. std r18,56(r3)
  73. stfd f18,208(r3)
  74. std r19,64(r3)
  75. stfd f19,216(r3)
  76. std r20,72(r3)
  77. stfd f20,224(r3)
  78. std r21,80(r3)
  79. stfd f21,232(r3)
  80. std r22,88(r3)
  81. stfd f22,240(r3)
  82. std r23,96(r3)
  83. stfd f23,248(r3)
  84. std r24,104(r3)
  85. stfd f24,256(r3)
  86. std r25,112(r3)
  87. stfd f25,264(r3)
  88. std r26,120(r3)
  89. stfd f26,272(r3)
  90. std r27,128(r3)
  91. stfd f27,280(r3)
  92. std r28,136(r3)
  93. stfd f28,288(r3)
  94. std r29,144(r3)
  95. stfd f29,296(r3)
  96. std r30,152(r3)
  97. stfd f30,304(r3)
  98. std r31,160(r3)
  99. stfd f31,312(r3)
  100. addi r5,r3,320
  101. mfspr r0,256
  102. stw r0,168(r3) // VRSAVE
  103. addi r6,r5,16
  104. stvx v20,0,r5
  105. addi r5,r5,32
  106. stvx v21,0,r6
  107. addi r6,r6,32
  108. stvx v22,0,r5
  109. addi r5,r5,32
  110. stvx v23,0,r6
  111. addi r6,r6,32
  112. stvx v24,0,r5
  113. addi r5,r5,32
  114. stvx v25,0,r6
  115. addi r6,r6,32
  116. stvx v26,0,r5
  117. addi r5,r5,32
  118. stvx v27,0,r6
  119. addi r6,r6,32
  120. stvx v28,0,r5
  121. addi r5,r5,32
  122. stvx v29,0,r6
  123. addi r6,r6,32
  124. stvx v30,0,r5
  125. stvx v31,0,r6
  126. // Clear the "mask-saved" slot.
  127. li r4,0
  128. stw r4,512(r3)
  129. // Restore TOC, LR, and stack and return to caller.
  130. ld r2,24(r1)
  131. ld r0,40(r1)
  132. addi r1,r1,48
  133. li r3,0 // This is the setjmp return path
  134. mtlr r0
  135. blr
  136. .size _setjmp, .-.L._setjmp
  137. .globl setjmp
  138. .type setjmp, @function
  139. .align 4
  140. setjmp:
  141. b _setjmp
  142. .size setjmp, .-setjmp
  143. // sigsetjmp is like setjmp, except that the mask in r4 needs
  144. // to be saved at offset 512 of the jump buffer.
  145. .globl __sigsetjmp
  146. .type __sigsetjmp, @function
  147. .align 4
  148. #if _CALL_ELF == 2
  149. __sigsetjmp:
  150. #else
  151. .section ".opd","aw"
  152. .align 3
  153. __sigsetjmp:
  154. .quad .L.__sigsetjmp,.TOC.@tocbase,0
  155. .previous
  156. #endif
  157. .L.__sigsetjmp:
  158. mflr r0
  159. stdu r1,-64(r1)
  160. std r2,24(r1)
  161. std r3,32(r1)
  162. std r4,40(r1)
  163. std r0,48(r1)
  164. // r3 is the original stack pointer.
  165. addi r3,r1,64
  166. // r4 is the mangled stack pointer (see glibc)
  167. ld r4,-28696(r13)
  168. xor r4,r3,r4
  169. // Materialize a TOC in case we were called from libc.
  170. // For big-endian, we load the TOC from the OPD. For little-
  171. // endian, we use the .TOC. symbol to find it.
  172. nop
  173. bcl 20,31,1f
  174. 1:
  175. mflr r2
  176. #if _CALL_ELF == 2
  177. addis r2,r2,.TOC.-1b@ha
  178. addi r2,r2,.TOC.-1b@l
  179. #else
  180. addis r2,r2,_setjmp-1b@ha
  181. addi r2,r2,_setjmp-1b@l
  182. ld r2,8(r2)
  183. #endif
  184. // Call the interceptor.
  185. bl __tsan_setjmp
  186. nop
  187. // Restore regs needed for __sigsetjmp.
  188. ld r3,32(r1)
  189. ld r4,40(r1)
  190. ld r0,48(r1)
  191. // Emulate the real sigsetjmp function. We do this because we can't
  192. // perform a sibcall: The real sigsetjmp function trashes the TOC
  193. // pointer, and with a sibcall we have no way to restore it.
  194. // This way we can make sure our caller's stack pointer and
  195. // link register are saved correctly in the jmpbuf.
  196. ld r6,-28696(r13)
  197. addi r5,r1,64 // original stack ptr of caller
  198. xor r5,r6,r5
  199. std r5,0(r3) // mangled stack ptr of caller
  200. ld r5,24(r1)
  201. std r5,8(r3) // caller's saved TOC pointer
  202. xor r0,r6,r0
  203. std r0,16(r3) // caller's mangled return address
  204. mfcr r0
  205. // Nonvolatiles.
  206. std r14,24(r3)
  207. stfd f14,176(r3)
  208. stw r0,172(r3) // CR
  209. std r15,32(r3)
  210. stfd f15,184(r3)
  211. std r16,40(r3)
  212. stfd f16,192(r3)
  213. std r17,48(r3)
  214. stfd f17,200(r3)
  215. std r18,56(r3)
  216. stfd f18,208(r3)
  217. std r19,64(r3)
  218. stfd f19,216(r3)
  219. std r20,72(r3)
  220. stfd f20,224(r3)
  221. std r21,80(r3)
  222. stfd f21,232(r3)
  223. std r22,88(r3)
  224. stfd f22,240(r3)
  225. std r23,96(r3)
  226. stfd f23,248(r3)
  227. std r24,104(r3)
  228. stfd f24,256(r3)
  229. std r25,112(r3)
  230. stfd f25,264(r3)
  231. std r26,120(r3)
  232. stfd f26,272(r3)
  233. std r27,128(r3)
  234. stfd f27,280(r3)
  235. std r28,136(r3)
  236. stfd f28,288(r3)
  237. std r29,144(r3)
  238. stfd f29,296(r3)
  239. std r30,152(r3)
  240. stfd f30,304(r3)
  241. std r31,160(r3)
  242. stfd f31,312(r3)
  243. addi r5,r3,320
  244. mfspr r0,256
  245. stw r0,168(r3) // VRSAVE
  246. addi r6,r5,16
  247. stvx v20,0,r5
  248. addi r5,r5,32
  249. stvx v21,0,r6
  250. addi r6,r6,32
  251. stvx v22,0,r5
  252. addi r5,r5,32
  253. stvx v23,0,r6
  254. addi r6,r6,32
  255. stvx v24,0,r5
  256. addi r5,r5,32
  257. stvx v25,0,r6
  258. addi r6,r6,32
  259. stvx v26,0,r5
  260. addi r5,r5,32
  261. stvx v27,0,r6
  262. addi r6,r6,32
  263. stvx v28,0,r5
  264. addi r5,r5,32
  265. stvx v29,0,r6
  266. addi r6,r6,32
  267. stvx v30,0,r5
  268. stvx v31,0,r6
  269. // Save into the "mask-saved" slot.
  270. stw r4,512(r3)
  271. // Restore TOC, LR, and stack and return to caller.
  272. ld r2,24(r1)
  273. ld r0,48(r1)
  274. addi r1,r1,64
  275. li r3,0 // This is the sigsetjmp return path
  276. mtlr r0
  277. blr
  278. .size __sigsetjmp, .-.L.__sigsetjmp
  279. .globl sigsetjmp
  280. .type sigsetjmp, @function
  281. .align 4
  282. sigsetjmp:
  283. b __sigsetjmp
  284. .size sigsetjmp, .-sigsetjmp