Update.
[glibc.git] / sysdeps / unix / sysv / linux / ia64 / getcontext.S
blobe396480a4039e343ee2a18488974f52dd55140c0
1 /* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
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.
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.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <features.h>
23 #include "ucontext_i.h"
25 /*  __getcontext (ucontext_t *ucp)
27   Saves the machine context in UCP such that when it is activated,
28   it appears as if __getcontext() returned again.  The only difference
29   is that on a first return, r9 contains 1 and on a subsequent
30   return, it contains 0.
32   This implementation in intended to be used for *synchronous* context
33   switches only.  Therefore, it does not have to save anything
34   other than the PRESERVED state.  */
36 ENTRY(__getcontext)
37         alloc r16 = ar.pfs, 1, 0, 3, 0
39         // sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask):
41         mov r2 = SC_MASK
42         mov r15 = __NR_rt_sigprocmask
43         ;;
44         mov out0 = SIG_BLOCK
45         mov out1 = 0
46         add out2 = r2, in0
48         break __BREAK_SYSCALL
49         flushrs                                 // save dirty partition on rbs
51         mov.m rFPSR = ar.fpsr
52         mov.m rRSC = ar.rsc
53         add r2 = SC_GR+1*8, r32
54         ;;
55         mov.m rBSP = ar.bsp
56         mov.m rUNAT = ar.unat
57         add r3 = SC_GR+4*8, r32
58         ;;
60 .mem.offset 0,0; st8.spill [r2] = r1, (5*8 - 1*8)
61 .mem.offset 8,0; st8.spill [r3] = r4, 16
62         mov.i rPFS = ar.pfs
63         ;;
64 .mem.offset 0,0; st8.spill [r2] = r5, 16
65 .mem.offset 8,0; st8.spill [r3] = r6, 48
66         and rTMP = ~0x3, rRSC
67         ;;
68         st8.spill [r2] = r7, (SC_FR+2*16-(SC_GR+7*8))
69         st8.spill [r3] = sp, (SC_FR+3*16-(SC_GR+12*8))
70         ;;
71         mov.m ar.rsc = rTMP             // put RSE into enforced lazy mode
72         mov.m rNAT = ar.unat
73         mov.i rLC = ar.lc
74         ;;
75         mov.m rRNAT = ar.rnat
76         mov.m ar.rsc = rRSC             // restore RSE mode
77         mov rPR = pr
79         /*
80          * Rotate NaT bits by rPOS positions to the right:
81          */
82         stf.spill [r2] = f2, 32
83         stf.spill [r3] = f3, 32
84         add rPOS = SC_GR, r32                   // rPOS <- &sc_gr[0]
85         ;;
86         stf.spill [r2] = f4, (16*16-4*16)
87         stf.spill [r3] = f5, (17*16-5*16)
88         extr.u rPOS = rPOS, 3, 6                // get NaT bit number for r0
89         ;;
90         stf.spill [r2] = f16, 32
91         stf.spill [r3] = f17, 32
92         sub rCPOS = 64, rPOS
93         ;;
94         stf.spill [r2] = f18, 32
95         stf.spill [r3] = f19, 32
96         shr.u rTMP = rNAT, rPOS
97         ;;
98         stf.spill [r2] = f20, 32
99         stf.spill [r3] = f21, 32
100         shl rNAT = rNAT, rCPOS
101         ;;
102         stf.spill [r2] = f22, 32
103         stf.spill [r3] = f23, 32
104         or rNAT = rNAT, rTMP
105         ;;
106         stf.spill [r2] = f24, 32
107         stf.spill [r3] = f25, 32
108         mov r8 = 0
109         ;;
110         stf.spill [r2] = f26, 32
111         stf.spill [r3] = f27, 32
112         mov r9 = 1
113         ;;
114         stf.spill [r2] = f28, 32
115         stf.spill [r3] = f29, 32
116         mov rB0 = b0
117         ;;
118         stf.spill [r2] = f30, 32
119         stf.spill [r3] = f31, 32
120         mov rB1 = b1
121         ;;
122         add r2 = SC_NAT, r32
123         nop 0
124         add r3 = SC_BSP, r32
125         ;;
126         st8 [r2] = rNAT, (SC_RNAT-SC_NAT)
127         st8 [r3] = rBSP, (SC_UNAT-SC_BSP)
128         mov rB2 = b2
129         ;;
130         st8 [r2] = rRNAT, (SC_FPSR-SC_RNAT)
131         st8 [r3] = rUNAT, (SC_PFS-SC_UNAT)
132         mov rB3 = b3
133         ;;
134         st8 [r2] = rFPSR, (SC_LC-SC_FPSR)
135         st8 [r3] = rPFS, (SC_PR-SC_PFS)
136         mov rB4 = b4
137         ;;
138         st8 [r2] = rLC, (SC_BR+0*8-SC_LC)
139         st8 [r3] = rPR, (SC_BR+1*8-SC_PR)
140         mov rB5 = b5
141         ;;
142         st8 [r2] = rB0, 16
143         st8 [r3] = rB1, 16
144         ;;
145         st8 [r2] = rB2, 16
146         st8 [r3] = rB3, 16
147         ;;
148         st8 [r2] = rB4
149         st8 [r3] = rB5
150         ret
151 END(__getcontext)
153 weak_alias(__getcontext, getcontext)