2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / alpha / getcontext.S
blobf010f337e6f05e61f6f1500a7f9f2d0f5eac97a8
1 /* Save current context.
2    Copyright (C) 2004, 2006 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
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 <ucontext-offsets.h>
23 /* ??? Should be a better place for this that's asm friendly.  */
24 #define SIG_BLOCK     1
27 ENTRY (__getcontext)
28 #ifdef PROF
29         ldgp    gp, 0(pv)
30         .set noat
31         lda     AT, _mcount
32         jsr     AT, (AT), _mcount
33         .set at
34         .prologue 1
35 #else
36         .prologue 0
37 #endif
39         bsr     $0, __getcontext_x
40         mov     $31, $0
41         ret
43 END(__getcontext)
44 weak_alias (__getcontext, getcontext)
47 /* An internal routine used by getcontext and setcontext.
48    The incomming return address register is $0.  */
50         .align  4
51         .globl  __getcontext_x
52         .hidden __getcontext_x
53         .usepv  __getcontext_x, no
55         cfi_startproc
56         cfi_return_column (64)
57 __getcontext_x:
58         cfi_register (64, 0)
60         .set noat
62         /* Return value of getcontext.  $0 is the only register
63            whose value is not preserved. */
64         stq     $31, UC_SIGCTX+SC_REGS($16)
66         /* Store all registers into the context.  */
67         stq     $1, UC_SIGCTX+SC_REGS+1*8($16)
68         stq     $2, UC_SIGCTX+SC_REGS+2*8($16)
69         stq     $3, UC_SIGCTX+SC_REGS+3*8($16)
70         stq     $4, UC_SIGCTX+SC_REGS+4*8($16)
71         stq     $5, UC_SIGCTX+SC_REGS+5*8($16)
72         stq     $6, UC_SIGCTX+SC_REGS+6*8($16)
73         stq     $7, UC_SIGCTX+SC_REGS+7*8($16)
74         stq     $8, UC_SIGCTX+SC_REGS+8*8($16)
75         stq     $9, UC_SIGCTX+SC_REGS+9*8($16)
76         stq     $10, UC_SIGCTX+SC_REGS+10*8($16)
77         stq     $11, UC_SIGCTX+SC_REGS+11*8($16)
78         stq     $12, UC_SIGCTX+SC_REGS+12*8($16)
79         stq     $13, UC_SIGCTX+SC_REGS+13*8($16)
80         stq     $14, UC_SIGCTX+SC_REGS+14*8($16)
81         stq     $15, UC_SIGCTX+SC_REGS+15*8($16)
82         stq     $16, UC_SIGCTX+SC_REGS+16*8($16)
83         stq     $17, UC_SIGCTX+SC_REGS+17*8($16)
84         stq     $18, UC_SIGCTX+SC_REGS+18*8($16)
85         stq     $19, UC_SIGCTX+SC_REGS+19*8($16)
86         stq     $20, UC_SIGCTX+SC_REGS+20*8($16)
87         stq     $21, UC_SIGCTX+SC_REGS+21*8($16)
88         stq     $22, UC_SIGCTX+SC_REGS+22*8($16)
89         stq     $23, UC_SIGCTX+SC_REGS+23*8($16)
90         stq     $24, UC_SIGCTX+SC_REGS+24*8($16)
91         stq     $25, UC_SIGCTX+SC_REGS+25*8($16)
92         stq     $26, UC_SIGCTX+SC_REGS+26*8($16)
93         stq     $27, UC_SIGCTX+SC_REGS+27*8($16)
94         stq     $28, UC_SIGCTX+SC_REGS+28*8($16)
95         stq     $29, UC_SIGCTX+SC_REGS+29*8($16)
96         stq     $30, UC_SIGCTX+SC_REGS+30*8($16)
97         stq     $31, UC_SIGCTX+SC_REGS+31*8($16)
99         stt     $f0, UC_SIGCTX+SC_FPREGS+0*8($16)
100         stt     $f1, UC_SIGCTX+SC_FPREGS+1*8($16)
101         stt     $f2, UC_SIGCTX+SC_FPREGS+2*8($16)
102         stt     $f3, UC_SIGCTX+SC_FPREGS+3*8($16)
103         stt     $f4, UC_SIGCTX+SC_FPREGS+4*8($16)
104         stt     $f5, UC_SIGCTX+SC_FPREGS+5*8($16)
105         stt     $f6, UC_SIGCTX+SC_FPREGS+6*8($16)
106         stt     $f7, UC_SIGCTX+SC_FPREGS+7*8($16)
107         stt     $f8, UC_SIGCTX+SC_FPREGS+8*8($16)
108         stt     $f9, UC_SIGCTX+SC_FPREGS+9*8($16)
109         stt     $f10, UC_SIGCTX+SC_FPREGS+10*8($16)
110         stt     $f11, UC_SIGCTX+SC_FPREGS+11*8($16)
111         stt     $f12, UC_SIGCTX+SC_FPREGS+12*8($16)
112         stt     $f13, UC_SIGCTX+SC_FPREGS+13*8($16)
113         stt     $f14, UC_SIGCTX+SC_FPREGS+14*8($16)
114         stt     $f15, UC_SIGCTX+SC_FPREGS+15*8($16)
115         stt     $f16, UC_SIGCTX+SC_FPREGS+16*8($16)
116         stt     $f17, UC_SIGCTX+SC_FPREGS+17*8($16)
117         stt     $f18, UC_SIGCTX+SC_FPREGS+18*8($16)
118         stt     $f19, UC_SIGCTX+SC_FPREGS+19*8($16)
119         stt     $f20, UC_SIGCTX+SC_FPREGS+20*8($16)
120         stt     $f21, UC_SIGCTX+SC_FPREGS+21*8($16)
121         stt     $f22, UC_SIGCTX+SC_FPREGS+22*8($16)
122         stt     $f23, UC_SIGCTX+SC_FPREGS+23*8($16)
123         stt     $f24, UC_SIGCTX+SC_FPREGS+24*8($16)
124         stt     $f25, UC_SIGCTX+SC_FPREGS+25*8($16)
125         stt     $f26, UC_SIGCTX+SC_FPREGS+26*8($16)
126         stt     $f27, UC_SIGCTX+SC_FPREGS+27*8($16)
127         stt     $f28, UC_SIGCTX+SC_FPREGS+28*8($16)
128         stt     $f29, UC_SIGCTX+SC_FPREGS+29*8($16)
129         stt     $f30, UC_SIGCTX+SC_FPREGS+30*8($16)
130         stt     $f31, UC_SIGCTX+SC_FPREGS+31*8($16)
132         mf_fpcr $f0
133         lda     $1, 8
134         stt     $f0, UC_SIGCTX+SC_FPCR($16)
136         /* The return address of getcontext is the restart pc.  */
137         stq     $26, UC_SIGCTX+SC_PC($16)
139         /* Userlevel always has a processor status word of 8.  */
140         stq     $1, UC_SIGCTX+SC_PS($16)
142         /* Save registers around the syscall.  We preserve $17
143            for the benefit of swapcontext.  */
144         subq    $30, 4*8, $30
145         cfi_adjust_cfa_offset(4*8)
146         stq     $0, 0($30)
147         cfi_rel_offset(64, 0)
148         stq     $16, 8($30)
149         stq     $17, 16($30)
151         /* Save the current signal mask.  Whee, there are three
152            copies of this in the alpha ucontext_t.  */
153         lda     $16, SIG_BLOCK
154         lda     $17, 0
155         lda     $0, __NR_osf_sigprocmask
156         callsys
158         ldq     $16, 8($30)
159         ldq     $17, 16($30)
161         stq     $0, UC_OSF_SIGMASK($16)
162         stq     $0, UC_SIGCTX+SC_MASK($16)
163         stq     $0, UC_SIGMASK($16)
164         stq     $31, UC_SIGMASK + 1*8($16)
165         stq     $31, UC_SIGMASK + 2*8($16)
166         stq     $31, UC_SIGMASK + 3*8($16)
167         stq     $31, UC_SIGMASK + 4*8($16)
168         stq     $31, UC_SIGMASK + 5*8($16)
169         stq     $31, UC_SIGMASK + 6*8($16)
170         stq     $31, UC_SIGMASK + 7*8($16)
171         stq     $31, UC_SIGMASK + 8*8($16)
172         stq     $31, UC_SIGMASK + 9*8($16)
173         stq     $31, UC_SIGMASK +10*8($16)
174         stq     $31, UC_SIGMASK +11*8($16)
175         stq     $31, UC_SIGMASK +12*8($16)
176         stq     $31, UC_SIGMASK +13*8($16)
177         stq     $31, UC_SIGMASK +14*8($16)
178         stq     $31, UC_SIGMASK +15*8($16)
180         ldq     $0, 0($30)
181         addq    $30, 4*8, $30
182         cfi_register (64, 0)
183         cfi_adjust_cfa_offset(-4*8)
184         ret     $31, ($0), 1
186         cfi_endproc
187         .size   __getcontext_x, .-__getcontext_x
188         .type   __getcontext_x, @function