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