1/* Save current context.
2 Copyright (C) 2008-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <sysdep.h>
20
21#include "ucontext_i.h"
22
23/* int __getcontext (ucontext_t *ucp)
24
25 Saves the machine context in UCP such that when it is activated,
26 it appears as if __getcontext() returned again.
27
28 This implementation is intended to be used for *synchronous* context
29 switches only. Therefore, it does not have to save anything
30 other than the PRESERVED state. */
31
32
33ENTRY(__getcontext)
34 save %sp, -112, %sp
35 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR]
36
37 /* In reality, we only use the GREG_PC value when setting
38 or swapping contexts. But we fill in NPC for completeness. */
39 add %i7, 8, %o0
40 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC]
41 add %o0, 4, %o0
42 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC]
43
44 rd %y, %o1
45 st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y]
46
47 st %g1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G1]
48 st %g2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2]
49 st %g3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3]
50 st %g4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4]
51 st %g5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5]
52 st %g6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6]
53 st %g7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7]
54
55 mov SIG_BLOCK, %o0
56 clr %o1
57 add %i0, UC_SIGMASK, %o2
58 mov 8, %o3
59 mov __NR_rt_sigprocmask, %g1
60 ta 0x10
61
62 /* Zero, success, return value. */
63 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O0]
64 st %i1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1]
65 st %i2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2]
66 st %i3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3]
67 st %i4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4]
68 st %i5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5]
69 st %i6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6]
70 st %i7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O7]
71
72 st %g0, [%i0 + UC_MCONTEXT + MC_GWINS]
73
74 /* Do not save FPU state, it is volatile across calls. */
75 stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN]
76
77 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID]
78 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR]
79 jmpl %i7 + 8, %g0
80 restore %g0, %g0, %o0
81END(__getcontext)
82
83weak_alias (__getcontext, getcontext)
84

source code of glibc/sysdeps/unix/sysv/linux/sparc/sparc32/getcontext.S