Updated to fedora-glibc-20051020T0651
[glibc.git] / sysdeps / unix / sysv / linux / sh / sh3 / swapcontext.S
blobaa0129e9ac49a5bb54e78ba3e249373223a955df
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     r5, r8
67         /* sigprocmask (SIG_SETMASK, &uc->uc_sigmask, &ouc->uc_sigmask).  */
68         add     #oSIGMASK, r5
69         mov     r4, r6
70         add     #oSIGMASK, r6
71         mov     #SIG_SETMASK, r4
72         mov     #+SYS_ify(sigprocmask), r3
73         trapa   #0x13
74         mov     r0, r1
75         mov     #-12, r2
76         shad    r2, r1
77         not     r1, r1                  // r1=0 means r0 = -1 to -4095
78         tst     r1, r1                  // i.e. error in linux
79         bf      .Lswapcontext_restore
80 .Lsyscall_error:        
81         SYSCALL_ERROR_HANDLER
82 .Lpseudo_end:
83         rts
84          nop
85 .Lswapcontext_restore:  
86         mov     r8, r0
87         add     #(oPC), r0
88         mov.l   @r0+, r2
89         lds.l   @r0+, pr
91         /* Restore T frag.  */
92         mov.l   @r0+, r1
93         shlr    r1
94         /* Skip GBR which is used for thread pointer.  */
95         add     #4, r0
97         lds.l   @r0+, mach
98         lds.l   @r0+, macl
100         mov     r8, r0
101         add     #(oR9), r0
102         mov.l   @r0+, r9
103         mov.l   @r0+, r10
104         mov.l   @r0+, r11
105         mov.l   @r0+, r12
106         mov.l   @r0+, r13
107         mov.l   @r0+, r14
108         mov.l   @r0+, r15
110         mov     r8, r0
111         mov.l   @(oR0,r0), r1
112         mov.l   r1, @-r15
113         cfi_adjust_cfa_offset(4)
114         cfi_rel_offset (r1, 0)
115         mov.l   r2, @-r15
116         cfi_adjust_cfa_offset(4)
117         cfi_rel_offset (r2, 0)
119         mov.l   @(oR1,r0), r1
120         mov.l   @(oR2,r0), r2
121         mov.l   @(oR3,r0), r3
122         mov.l   @(oR4,r0), r4
123         mov.l   @(oR5,r0), r5
124         mov.l   @(oR6,r0), r6
125         mov.l   @(oR7,r0), r7
126         mov.l   @(oR8,r0), r8
127         mov.l   @r15+, r0
128         jmp     @r0
129          mov.l  @r15+, r0
130         
131         cfi_endproc
132 PSEUDO_END(__swapcontext)
134 weak_alias (__swapcontext, swapcontext)