swapcontext.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Save current context and install the given one.
  2. Copyright (C) 2008-2016 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by David S. Miller <davem@davemloft.net>, 2008.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sysdep.h>
  17. #include "ucontext_i.h"
  18. #define ST_FLUSH_WINDOWS 3
  19. /* int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp);
  20. Saves the machine context in oucp such that when it is activated,
  21. it appears as if __swapcontext() returned again, restores the
  22. machine context in ucp and thereby resumes execution in that
  23. context.
  24. This implementation is intended to be used for *synchronous* context
  25. switches only. Therefore, it does not have to save anything
  26. other than the PRESERVED state. */
  27. ENTRY(__swapcontext)
  28. save %sp, -112, %sp
  29. ta ST_FLUSH_WINDOWS
  30. st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR]
  31. add %i7, 8, %o0
  32. st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC]
  33. add %o0, 4, %o0
  34. st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC]
  35. rd %y, %o1
  36. st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y]
  37. st %g1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G1]
  38. st %g2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2]
  39. st %g3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3]
  40. st %g4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4]
  41. st %g5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5]
  42. st %g6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6]
  43. st %g7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7]
  44. st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O0]
  45. st %i1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1]
  46. st %i2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2]
  47. st %i3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3]
  48. st %i4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4]
  49. st %i5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5]
  50. st %i6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6]
  51. st %i7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O7]
  52. st %g0, [%i0 + UC_MCONTEXT + MC_GWINS]
  53. stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN]
  54. st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID]
  55. st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR]
  56. mov SIG_SETMASK, %o0
  57. add %i1, UC_SIGMASK, %o1
  58. add %i0, UC_SIGMASK, %o2
  59. mov 8, %o3
  60. mov __NR_rt_sigprocmask, %g1
  61. ta 0x10
  62. mov %i1, %i0
  63. ldub [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN], %g1
  64. cmp %g1, 0
  65. be 1f
  66. nop
  67. ld [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_FSR], %fsr
  68. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D0], %f0
  69. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D2], %f2
  70. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D4], %f4
  71. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D6], %f6
  72. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D8], %f8
  73. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D10], %f10
  74. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D12], %f12
  75. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D14], %f14
  76. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D16], %f16
  77. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D18], %f18
  78. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D20], %f20
  79. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D22], %f22
  80. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D24], %f24
  81. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D26], %f26
  82. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D28], %f28
  83. ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D30], %f30
  84. 1:
  85. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y], %g1
  86. wr %g1, 0x0, %y
  87. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2], %g2
  88. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3], %g3
  89. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4], %g4
  90. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5], %g5
  91. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6], %g6
  92. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7], %g7
  93. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1], %i1
  94. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2], %i2
  95. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3], %i3
  96. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4], %i4
  97. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5], %i5
  98. ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6], %i6
  99. restore
  100. ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_O7], %o7
  101. ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_PC], %g1
  102. jmpl %g1, %g0
  103. ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_O0], %o0
  104. END(__swapcontext)
  105. weak_alias (__swapcontext, swapcontext)