Updated to fedora-glibc-20051020T0651
[glibc.git] / sysdeps / unix / sysv / linux / sh / sh4 / swapcontext.S
blob1d58a40e7023608058445fa20c6fdf9ce9c4b80b
1 /* Save current context and install the given one.
2    Copyright (C) 2005 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>
22 #include "ucontext_i.h"
24 /*  int __swapcontext (ucontext_t *ouc, const ucontext_t *uc);  */
26         .text
27         .align  5
28         cfi_startproc
29 ENTRY(__swapcontext)
31         /* Return value of getcontext.  R0 is the only register whose
32            value is not preserved.  */
33         mov     #0, r0
34         mov.l   r0, @(oR0,r4)
35         mov.l   r1, @(oR1,r4)
36         mov.l   r2, @(oR2,r4)
37         mov.l   r3, @(oR3,r4)
38         mov.l   r4, @(oR4,r4)
39         mov.l   r5, @(oR5,r4)
40         mov.l   r6, @(oR6,r4)
41         mov.l   r7, @(oR7,r4)
42         mov     r4, r0
43         add     #(oMACL+4), r0
44         sts.l   macl, @-r0
45         sts.l   mach, @-r0
46         stc.l   gbr, @-r0
48         /* Save T flag to SR.  */
49         movt    r1
50         mov.l   r1, @-r0
51         sts.l   pr, @-r0
53         /* The return address of getcontext is the restart pc.  */
54         sts.l   pr, @-r0
56         mov.l   r15, @-r0
57         mov.l   r14, @-r0
58         mov.l   r13, @-r0
59         mov.l   r12, @-r0
60         mov.l   r11, @-r0
61         mov.l   r10, @-r0
62         mov.l   r9, @-r0
63         mov.l   r8, @-r0
65         mov     r4, r0
66         /* We need 2 add instruction because oFPUL+4 >= 127.  */
67         add     #124,r0
68         add     #(oFPUL+4-124),r0
69         sts.l   fpul, @-r0
70         sts.l   fpscr, @-r0
71         frchg
72         fmov.s  fr15, @-r0
73         fmov.s  fr14, @-r0
74         fmov.s  fr13, @-r0
75         fmov.s  fr12, @-r0
76         fmov.s  fr11, @-r0
77         fmov.s  fr10, @-r0
78         fmov.s  fr9, @-r0
79         fmov.s  fr8, @-r0
80         fmov.s  fr7, @-r0
81         fmov.s  fr6, @-r0
82         fmov.s  fr5, @-r0
83         fmov.s  fr4, @-r0
84         fmov.s  fr3, @-r0
85         fmov.s  fr2, @-r0
86         fmov.s  fr1, @-r0
87         fmov.s  fr0, @-r0
88         frchg
89         fmov.s  fr15, @-r0
90         fmov.s  fr14, @-r0
91         fmov.s  fr13, @-r0
92         fmov.s  fr12, @-r0
93         fmov.s  fr11, @-r0
94         fmov.s  fr10, @-r0
95         fmov.s  fr9, @-r0
96         fmov.s  fr8, @-r0
97         fmov.s  fr7, @-r0
98         fmov.s  fr6, @-r0
99         fmov.s  fr5, @-r0
100         fmov.s  fr4, @-r0
101         fmov.s  fr3, @-r0
102         fmov.s  fr2, @-r0
103         fmov.s  fr1, @-r0
104         fmov.s  fr0, @-r0
106         mov     r5, r8
108         /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, &ouc->uc_sigmask).  */
109         mov     #oSIGMASK, r1
110         extu.b  r1, r1
111         add     r1, r5
112         mov     r4, r6
113         add     r1, r6
114         mov     #SIG_SETMASK, r4
115         mov     #+SYS_ify(sigprocmask), r3
116         trapa   #0x13
117         mov     r0, r1
118         mov     #-12, r2
119         shad    r2, r1
120         not     r1, r1                  // r1=0 means r0 = -1 to -4095
121         tst     r1, r1                  // i.e. error in linux
122         bf      .Lswapcontext_restore
123 .Lsyscall_error:        
124         SYSCALL_ERROR_HANDLER
125 .Lpseudo_end:
126         rts
127          nop
128 .Lswapcontext_restore:  
129         mov     r8, r0
130         add     #(oFR0),r0
131         fmov.s  @r0+, fr0
132         fmov.s  @r0+, fr1
133         fmov.s  @r0+, fr2
134         fmov.s  @r0+, fr3
135         fmov.s  @r0+, fr4
136         fmov.s  @r0+, fr5
137         fmov.s  @r0+, fr6
138         fmov.s  @r0+, fr7
139         fmov.s  @r0+, fr8
140         fmov.s  @r0+, fr9
141         fmov.s  @r0+, fr10
142         fmov.s  @r0+, fr11
143         fmov.s  @r0+, fr12
144         fmov.s  @r0+, fr13
145         fmov.s  @r0+, fr14
146         fmov.s  @r0+, fr15
147         frchg
148         fmov.s  @r0+, fr0
149         fmov.s  @r0+, fr1
150         fmov.s  @r0+, fr2
151         fmov.s  @r0+, fr3
152         fmov.s  @r0+, fr4
153         fmov.s  @r0+, fr5
154         fmov.s  @r0+, fr6
155         fmov.s  @r0+, fr7
156         fmov.s  @r0+, fr8
157         fmov.s  @r0+, fr9
158         fmov.s  @r0+, fr10
159         fmov.s  @r0+, fr11
160         fmov.s  @r0+, fr12
161         fmov.s  @r0+, fr13
162         fmov.s  @r0+, fr14
163         fmov.s  @r0+, fr15
164         frchg
165         lds.l   @r0+, fpscr
166         lds.l   @r0+, fpul
168         mov     r8, r0
169         add     #(oPC), r0
170         mov.l   @r0+, r2
171         lds.l   @r0+, pr
173         /* Restore T frag.  */
174         mov.l   @r0+, r1
175         shlr    r1
176         /* Skip GBR which is used for thread pointer.  */
177         add     #4, r0
179         lds.l   @r0+, mach
180         lds.l   @r0+, macl
182         mov     r8, r0
183         add     #(oR9), r0
184         mov.l   @r0+, r9
185         mov.l   @r0+, r10
186         mov.l   @r0+, r11
187         mov.l   @r0+, r12
188         mov.l   @r0+, r13
189         mov.l   @r0+, r14
190         mov.l   @r0+, r15
192         mov     r8, r0
193         mov.l   @(oR0,r0), r1
194         mov.l   r1, @-r15
195         cfi_adjust_cfa_offset(4)
196         cfi_rel_offset (r1, 0)
197         mov.l   r2, @-r15
198         cfi_adjust_cfa_offset(4)
199         cfi_rel_offset (r2, 0)
201         mov.l   @(oR1,r0), r1
202         mov.l   @(oR2,r0), r2
203         mov.l   @(oR3,r0), r3
204         mov.l   @(oR4,r0), r4
205         mov.l   @(oR5,r0), r5
206         mov.l   @(oR6,r0), r6
207         mov.l   @(oR7,r0), r7
208         mov.l   @(oR8,r0), r8
209         mov.l   @r15+, r0
210         jmp     @r0
211          mov.l  @r15+, r0
212         
213         cfi_endproc
214 PSEUDO_END(__swapcontext)
216 weak_alias (__swapcontext, swapcontext)