1 /* Save current context.
2 Copyright (C) 2008-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by David S. Miller <davem@davemloft.net>, 2008.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
22 #include "ucontext_i.h"
24 /* int __getcontext (ucontext_t *ucp)
26 Saves the machine context in UCP such that when it is activated,
27 it appears as if __getcontext() returned again.
29 This implementation is intended to be used for *synchronous* context
30 switches only. Therefore, it does not have to save anything
31 other than the PRESERVED state. */
36 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR]
38 /* In reality, we only use the GREG_PC value when setting
39 or swapping contexts. But we fill in NPC for completeness. */
41 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC]
43 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC]
46 st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y]
48 st %g1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G1]
49 st %g2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2]
50 st %g3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3]
51 st %g4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4]
52 st %g5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5]
53 st %g6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6]
54 st %g7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7]
58 add %i0, UC_SIGMASK, %o2
60 mov __NR_rt_sigprocmask, %g1
63 /* Zero, success, return value. */
64 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O0]
65 st %i1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1]
66 st %i2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2]
67 st %i3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3]
68 st %i4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4]
69 st %i5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5]
70 st %i6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6]
71 st %i7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O7]
73 st %g0, [%i0 + UC_MCONTEXT + MC_GWINS]
75 /* Do not save FPU state, it is volatile across calls. */
76 stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN]
78 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID]
79 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR]
84 weak_alias (__getcontext, getcontext)