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