getcontext.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Save current context.
  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. /* int __getcontext (ucontext_t *ucp)
  19. Saves the machine context in UCP such that when it is activated,
  20. it appears as if __getcontext() returned again.
  21. This implementation is intended to be used for *synchronous* context
  22. switches only. Therefore, it does not have to save anything
  23. other than the PRESERVED state. */
  24. ENTRY(__getcontext)
  25. save %sp, -112, %sp
  26. st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR]
  27. /* In reality, we only use the GREG_PC value when setting
  28. or swapping contexts. But we fill in NPC for completeness. */
  29. add %i7, 8, %o0
  30. st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC]
  31. add %o0, 4, %o0
  32. st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC]
  33. rd %y, %o1
  34. st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y]
  35. st %g1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G1]
  36. st %g2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2]
  37. st %g3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3]
  38. st %g4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4]
  39. st %g5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5]
  40. st %g6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6]
  41. st %g7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7]
  42. mov SIG_BLOCK, %o0
  43. clr %o1
  44. add %i0, UC_SIGMASK, %o2
  45. mov 8, %o3
  46. mov __NR_rt_sigprocmask, %g1
  47. ta 0x10
  48. /* Zero, success, return value. */
  49. st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O0]
  50. st %i1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1]
  51. st %i2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2]
  52. st %i3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3]
  53. st %i4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4]
  54. st %i5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5]
  55. st %i6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6]
  56. st %i7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O7]
  57. st %g0, [%i0 + UC_MCONTEXT + MC_GWINS]
  58. /* Do not save FPU state, it is volatile across calls. */
  59. stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN]
  60. st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID]
  61. st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR]
  62. jmpl %i7 + 8, %g0
  63. restore %g0, %g0, %o0
  64. END(__getcontext)
  65. weak_alias (__getcontext, getcontext)