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 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. 10 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. 15 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/>. */ 19 20#include <sysdep.h> 21 22#include "ucontext_i.h" 23 24/* int __getcontext (ucontext_t *ucp) 25 26 Saves the machine context in UCP such that when it is activated, 27 it appears as if __getcontext() returned again. 28 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. */ 32 33 34ENTRY(__getcontext) 35 save %sp, -112, %sp 36 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR] 37 38 /* In reality, we only use the GREG_PC value when setting 39 or swapping contexts. But we fill in NPC for completeness. */ 40 add %i7, 8, %o0 41 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC] 42 add %o0, 4, %o0 43 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC] 44 45 rd %y, %o1 46 st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y] 47 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] 55 56 mov SIG_BLOCK, %o0 57 clr %o1 58 add %i0, UC_SIGMASK, %o2 59 mov 8, %o3 60 mov __NR_rt_sigprocmask, %g1 61 ta 0x10 62 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] 72 73 st %g0, [%i0 + UC_MCONTEXT + MC_GWINS] 74 75 /* Do not save FPU state, it is volatile across calls. */ 76 stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN] 77 78 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID] 79 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR] 80 jmpl %i7 + 8, %g0 81 restore %g0, %g0, %o0 82END(__getcontext) 83 84weak_alias (__getcontext, getcontext) 85