getcontext.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #include "ucontext_i.h"
  22. #define GR(n) (SC_GR + (n)*8)
  23. #define BR(n) (SC_BR + (n)*8)
  24. #define FR(n) (SC_FR + (n)*16)
  25. /* This should be compatible to the libc's getcontext(), except that
  26. the sc->sc_mask field is always cleared and that the name is
  27. prefixed with _Uia64_ so we don't step on the application's
  28. name-space. */
  29. .align 32
  30. .protected _Uia64_getcontext
  31. .global _Uia64_getcontext
  32. .proc _Uia64_getcontext
  33. _Uia64_getcontext:
  34. .prologue
  35. alloc rPFS = ar.pfs, 1, 0, 0, 0 // M2
  36. mov rPR = pr // I0, 2 cycles
  37. add r2 = GR(1), in0 // I1
  38. ;;
  39. .save ar.unat, rUNAT
  40. mov.m rUNAT = ar.unat // M2, 5 cycles
  41. .body
  42. st8.spill [r2] = r1, (SC_FLAGS - GR(1)) // M3
  43. dep.z rFLAGS = -1, IA64_SC_FLAG_SYNCHRONOUS_BIT, 1 // I0, 1 cycle
  44. ;;
  45. mov.m rRSC = ar.rsc // M2, 12 cyc.
  46. st8 [r2] = rFLAGS, (SC_PR - SC_FLAGS) // M3
  47. add r3 = FR(2), in0
  48. ;;
  49. mov.m rBSP = ar.bsp // M2, 12 cyc.
  50. st8 [r2] = rPR, (GR(12) - SC_PR) // M3
  51. add r8 = FR(16), in0
  52. ;;
  53. mov.m rFPSR = ar.fpsr // M2, 12 cyc.
  54. st8.spill [r2] = r12, (GR(4) - GR(12)) // M3
  55. add r9 = FR(24), in0
  56. ;;
  57. stf.spill [r3] = f2 // M2
  58. stf.spill [r8] = f16 // M3
  59. add r3 = GR(7), in0
  60. ;;
  61. flushrs // M0
  62. stf.spill [r9] = f24, (FR(31) - FR(24)) // M2
  63. mov rB0 = b0 // I0, 2 cycles
  64. ;;
  65. stf.spill [r9] = f31 // M2
  66. st8.spill [r2] = r4, (GR(5) - GR(4)) // M3, bank 1
  67. mov rB1 = b1 // I0, 2 cycles
  68. ;;
  69. .mem.offset 0,0; st8.spill [r2] = r5, (GR(6) - GR(5)) // M4, bank 0
  70. .mem.offset 8,0; st8.spill [r3] = r7, (BR(0) - GR(7)) // M3, bank 0
  71. mov rB2 = b2 // I0, 2 cycles
  72. ;;
  73. st8.spill [r2] = r6, (BR(1) - GR(6)) // M2, bank 1
  74. st8 [r3] = rB0, (BR(4) - BR(0)) // M3, bank 1
  75. mov rB4 = b4 // I0, 2 cycles
  76. ;;
  77. mov.m rNAT = ar.unat // M2, 5 cycles
  78. st8 [r2] = rB1, (BR(2) - BR(1)) // M3, bank 0
  79. mov rB3 = b3
  80. ;;
  81. st8 [r2] = rB2, (BR(3) - BR(2)) // M2, bank 1
  82. st8 [r3] = rB4, (SC_LC - BR(4)) // M3, bank 1
  83. mov rB5 = b5 // I0, 2 cycles
  84. ;;
  85. and rTMP = ~0x3, rRSC // M0
  86. add rPOS = GR(0), in0 // rPOS <- &sc_gr[0] // M1
  87. mov.i rLC = ar.lc // I0, 2 cycles
  88. ;;
  89. mov.m ar.rsc = rTMP // put RSE into lazy mode // M2, ? cycles
  90. st8 [r2] = rB3, (BR(5) - BR(3)) // M3, bank 0
  91. extr.u rPOS = rPOS, 3, 6 // get NaT bitnr for r0 // I0
  92. ;;
  93. mov.m rRNAT = ar.rnat // M2, 5 cycles
  94. st8 [r2] = rB5, (SC_PFS - BR(5)) // M3, bank 0
  95. sub rCPOS = 64, rPOS // I0
  96. ;;
  97. st8 [r2] = rPFS, (SC_UNAT - SC_PFS) // M2
  98. st8 [r3] = rLC, (SC_BSP - SC_LC) // M3
  99. shr.u rTMP = rNAT, rPOS // I0, 3 cycles
  100. ;;
  101. st8 [r2] = rUNAT, (SC_FPSR - SC_UNAT) // M2
  102. st8 [r3] = rBSP // M3
  103. add r8 = FR(3), in0
  104. ;;
  105. st8 [r2] = rFPSR, (SC_RNAT - SC_FPSR) // M2
  106. stf.spill [r8] = f3, (FR(4) - FR(3)) // M3
  107. add r9 = FR(5), in0
  108. ;;
  109. stf.spill [r8] = f4, (FR(17) - FR(4)) // M2
  110. stf.spill [r9] = f5, (FR(19) - FR(5)) // M3
  111. shl rNAT = rNAT, rCPOS // I0, 3 cycles
  112. ;;
  113. st8 [r2] = rRNAT, (SC_NAT - SC_RNAT) // M2
  114. stf.spill [r8] = f17, (FR(18) - FR(17)) // M3
  115. nop.i 0
  116. ;;
  117. stf.spill [r8] = f18, (FR(20) - FR(18)) // M2
  118. stf.spill [r9] = f19, (FR(21) - FR(19)) // M3
  119. nop.i 0
  120. ;;
  121. stf.spill [r8] = f20, (FR(22) - FR(20)) // M2
  122. stf.spill [r9] = f21, (FR(23) - FR(21)) // M3
  123. or rNAT = rNAT, rTMP // I0
  124. ;;
  125. st8 [r2] = rNAT // M2
  126. stf.spill [r8] = f22, (FR(25) - FR(22)) // M3
  127. ;;
  128. stf.spill [r9] = f23, (FR(26) - FR(23)) // M2
  129. stf.spill [r8] = f25, (FR(27) - FR(25)) // M3
  130. ;;
  131. stf.spill [r9] = f26, (FR(28) - FR(26)) // M2
  132. stf.spill [r8] = f27, (FR(29) - FR(27)) // M3
  133. ;;
  134. mov.m ar.rsc = rRSC // restore RSE mode // M2
  135. stf.spill [r9] = f28, (FR(30) - FR(28)) // M3
  136. ;;
  137. mov.m ar.unat = rUNAT // restore caller's UNaT // M2
  138. stf.spill [r8] = f29 // M3
  139. ;;
  140. stf.spill [r9] = f30 // M2
  141. mov r8 = 0
  142. br.ret.sptk.many rp
  143. .endp _Uia64_getcontext
  144. #ifdef __linux__
  145. /* We do not need executable stack. */
  146. .section .note.GNU-stack,"",@progbits
  147. #endif