]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sparc/sparc32/swapcontext.S
d5f2bba1c5b5969c234aac1d9694a09cc3ef4747
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc32 / swapcontext.S
1 /* Save current context and install the given one.
2 Copyright (C) 2008-2020 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 <https://www.gnu.org/licenses/>. */
19
20 #include <sysdep.h>
21 #include <sys/trap.h>
22
23 #include "ucontext_i.h"
24
25
26 /* int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp);
27
28 Saves the machine context in oucp such that when it is activated,
29 it appears as if __swapcontext() returned again, restores the
30 machine context in ucp and thereby resumes execution in that
31 context.
32
33 This implementation is intended to be used for *synchronous* context
34 switches only. Therefore, it does not have to save anything
35 other than the PRESERVED state. */
36
37 ENTRY(__swapcontext)
38 save %sp, -112, %sp
39 ta ST_FLUSH_WINDOWS
40 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PSR]
41 add %i7, 8, %o0
42 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_PC]
43 add %o0, 4, %o0
44 st %o0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_NPC]
45 rd %y, %o1
46 st %o1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y]
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 st %g0, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O0]
55 st %i1, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1]
56 st %i2, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2]
57 st %i3, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3]
58 st %i4, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4]
59 st %i5, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5]
60 st %i6, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6]
61 st %i7, [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O7]
62 st %g0, [%i0 + UC_MCONTEXT + MC_GWINS]
63 stb %g0, [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN]
64 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_ID]
65 st %g0, [%i0 + UC_MCONTEXT + MC_XRS + XRS_PTR]
66
67 mov SIG_SETMASK, %o0
68 add %i1, UC_SIGMASK, %o1
69 add %i0, UC_SIGMASK, %o2
70 mov 8, %o3
71 mov __NR_rt_sigprocmask, %g1
72 ta 0x10
73
74 mov %i1, %i0
75 ldub [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_EN], %g1
76 cmp %g1, 0
77 be 1f
78 nop
79 ld [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_FSR], %fsr
80 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D0], %f0
81 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D2], %f2
82 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D4], %f4
83 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D6], %f6
84 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D8], %f8
85 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D10], %f10
86 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D12], %f12
87 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D14], %f14
88 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D16], %f16
89 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D18], %f18
90 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D20], %f20
91 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D22], %f22
92 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D24], %f24
93 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D26], %f26
94 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D28], %f28
95 ldd [%i0 + UC_MCONTEXT + MC_FPREGS + FPU_D30], %f30
96 1:
97 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_Y], %g1
98 wr %g1, 0x0, %y
99 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G2], %g2
100 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G3], %g3
101 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G4], %g4
102 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G5], %g5
103 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G6], %g6
104 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_G7], %g7
105 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O1], %i1
106 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O2], %i2
107 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O3], %i3
108 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O4], %i4
109 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O5], %i5
110 ld [%i0 + UC_MCONTEXT + MC_GREGS + GREG_O6], %i6
111 restore
112 ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_O7], %o7
113 ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_PC], %g1
114 jmpl %g1, %g0
115 ld [%o0 + UC_MCONTEXT + MC_GREGS + GREG_O0], %o0
116 END(__swapcontext)
117
118 weak_alias (__swapcontext, swapcontext)