Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / mips / swapcontext.S
blob2a799764110e03d004ec5e10fe0fb3c05db194e3
1 /* Save and set current context.
2    Copyright (C) 2009-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Maciej W. Rozycki <macro@codesourcery.com>.
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library.  If not, see
18    <http://www.gnu.org/licenses/>.  */
20 #include <sysdep.h>
21 #include <sys/asm.h>
22 #include <sys/fpregdef.h>
23 #include <sys/regdef.h>
25 #include "ucontext_i.h"
27 /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
29         .text
30         .set    nomips16
31 LOCALSZ = 0
32 ARGSZ = 0
33 MASK = 0x00000000
34 #ifdef __PIC__
35 LOCALSZ = 1                                             /* save gp */
36 #endif
37 #if _MIPS_SIM != _ABIO32
38 ARGSZ = 1                                               /* save a1 */
39 # ifdef __PIC__
40 MASK = 0x10000000
41 # endif
42 #endif
43 FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
44 GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
45 #if _MIPS_SIM != _ABIO32
46 A1OFF = FRAMESZ - (1 * SZREG)                           /* callee-allocated */
47 #else
48 A1OFF = FRAMESZ + (1 * SZREG)                           /* caller-allocated */
49 #endif
51 NESTED (__swapcontext, FRAMESZ, ra)
52         .mask   MASK, -(ARGSZ * SZREG)
53         .fmask  0x00000000, 0
55 #ifdef __PIC__
56         SETUP_GP
58         move    a2, sp
59 # define _SP a2
61 # if _MIPS_SIM != _ABIO32
62         move    a3, gp
63 #  define _GP a3
64 # endif
66         PTR_ADDIU sp, -FRAMESZ
67         cfi_adjust_cfa_offset (FRAMESZ)
68         SETUP_GP64_STACK (GPOFF, __swapcontext)
69         SAVE_GP (GPOFF)
71 #else  /* ! __PIC__ */
72 # define _SP sp
73 # define _GP gp
75 #endif /* ! __PIC__ */
77 #ifdef PROF
78         .set    noat
79         move    AT, ra
80         jal     _mcount
81         .set    at
82 #endif
84         /* Store a magic flag.  */
85         li      v1, 1
86         REG_S   v1, (0 * SZREG + MCONTEXT_GREGS)(a0)    /* zero */
88         REG_S   s0, (16 * SZREG + MCONTEXT_GREGS)(a0)
89         REG_S   s1, (17 * SZREG + MCONTEXT_GREGS)(a0)
90         REG_S   s2, (18 * SZREG + MCONTEXT_GREGS)(a0)
91         REG_S   s3, (19 * SZREG + MCONTEXT_GREGS)(a0)
92         REG_S   s4, (20 * SZREG + MCONTEXT_GREGS)(a0)
93         REG_S   s5, (21 * SZREG + MCONTEXT_GREGS)(a0)
94         REG_S   s6, (22 * SZREG + MCONTEXT_GREGS)(a0)
95         REG_S   s7, (23 * SZREG + MCONTEXT_GREGS)(a0)
96 #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
97         REG_S   _GP, (28 * SZREG + MCONTEXT_GREGS)(a0)
98 #endif
99         REG_S   _SP, (29 * SZREG + MCONTEXT_GREGS)(a0)
100         REG_S   fp, (30 * SZREG + MCONTEXT_GREGS)(a0)
101         REG_S   ra, (31 * SZREG + MCONTEXT_GREGS)(a0)
102         REG_S   ra, MCONTEXT_PC(a0)
104 #ifdef __mips_hard_float
105 # if _MIPS_SIM == _ABI64
106         s.d     fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
107         s.d     fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
108         s.d     fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
109         s.d     fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
110         s.d     fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
111         s.d     fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
112         s.d     fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
113         s.d     fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
115 # else  /* _MIPS_SIM != _ABI64 */
116         s.d     fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
117         s.d     fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
118         s.d     fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
119         s.d     fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
120         s.d     fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
121         s.d     fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
123 # endif /* _MIPS_SIM != _ABI64 */
125         cfc1    v1, fcr31
126         sw      v1, MCONTEXT_FPC_CSR(a0)
127 #endif /* __mips_hard_float */
129         REG_S   a1, A1OFF(sp)
131 /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
132         li      a3, _NSIG8
133         PTR_ADDU a2, a0, UCONTEXT_SIGMASK
134         PTR_ADDU a1, a1, UCONTEXT_SIGMASK
135         li      a0, SIG_SETMASK
137         li      v0, SYS_ify (rt_sigprocmask)
138         syscall
139         bnez    a3, 99f
141         REG_L   v0, A1OFF(sp)
143 #ifdef __mips_hard_float
144 # if _MIPS_SIM == _ABI64
145         l.d     fs0, (24 * SZREG + MCONTEXT_FPREGS)(v0)
146         l.d     fs1, (25 * SZREG + MCONTEXT_FPREGS)(v0)
147         l.d     fs2, (26 * SZREG + MCONTEXT_FPREGS)(v0)
148         l.d     fs3, (27 * SZREG + MCONTEXT_FPREGS)(v0)
149         l.d     fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
150         l.d     fs5, (29 * SZREG + MCONTEXT_FPREGS)(v0)
151         l.d     fs6, (30 * SZREG + MCONTEXT_FPREGS)(v0)
152         l.d     fs7, (31 * SZREG + MCONTEXT_FPREGS)(v0)
154 # else  /* _MIPS_SIM != _ABI64 */
155         l.d     fs0, (20 * SZREG + MCONTEXT_FPREGS)(v0)
156         l.d     fs1, (22 * SZREG + MCONTEXT_FPREGS)(v0)
157         l.d     fs2, (24 * SZREG + MCONTEXT_FPREGS)(v0)
158         l.d     fs3, (26 * SZREG + MCONTEXT_FPREGS)(v0)
159         l.d     fs4, (28 * SZREG + MCONTEXT_FPREGS)(v0)
160         l.d     fs5, (30 * SZREG + MCONTEXT_FPREGS)(v0)
162 # endif /* _MIPS_SIM != _ABI64 */
164         lw      v1, MCONTEXT_FPC_CSR(v0)
165         ctc1    v1, fcr31
166 #endif /* __mips_hard_float */
168         /* Note the contents of argument registers will be random
169            unless makecontext() has been called.  */
170         REG_L   a0, (4 * SZREG + MCONTEXT_GREGS)(v0)
171         REG_L   a1, (5 * SZREG + MCONTEXT_GREGS)(v0)
172         REG_L   a2, (6 * SZREG + MCONTEXT_GREGS)(v0)
173         REG_L   a3, (7 * SZREG + MCONTEXT_GREGS)(v0)
174 #if _MIPS_SIM != _ABIO32
175         REG_L   a4, (8 * SZREG + MCONTEXT_GREGS)(v0)
176         REG_L   a5, (9 * SZREG + MCONTEXT_GREGS)(v0)
177         REG_L   a6, (10 * SZREG + MCONTEXT_GREGS)(v0)
178         REG_L   a7, (11 * SZREG + MCONTEXT_GREGS)(v0)
179 #endif
181         REG_L   s0, (16 * SZREG + MCONTEXT_GREGS)(v0)
182         REG_L   s1, (17 * SZREG + MCONTEXT_GREGS)(v0)
183         REG_L   s2, (18 * SZREG + MCONTEXT_GREGS)(v0)
184         REG_L   s3, (19 * SZREG + MCONTEXT_GREGS)(v0)
185         REG_L   s4, (20 * SZREG + MCONTEXT_GREGS)(v0)
186         REG_L   s5, (21 * SZREG + MCONTEXT_GREGS)(v0)
187         REG_L   s6, (22 * SZREG + MCONTEXT_GREGS)(v0)
188         REG_L   s7, (23 * SZREG + MCONTEXT_GREGS)(v0)
189 #if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
190         REG_L   gp, (28 * SZREG + MCONTEXT_GREGS)(v0)
191 #endif
192         REG_L   sp, (29 * SZREG + MCONTEXT_GREGS)(v0)
193         REG_L   fp, (30 * SZREG + MCONTEXT_GREGS)(v0)
194         REG_L   ra, (31 * SZREG + MCONTEXT_GREGS)(v0)
195         REG_L   t9, MCONTEXT_PC(v0)
197         move    v0, zero
198         jr      t9
201 #ifdef __PIC__
202         PTR_LA  t9, JUMPTARGET (__syscall_error)
203         RESTORE_GP64_STACK
204         PTR_ADDIU sp, FRAMESZ
205         cfi_adjust_cfa_offset (-FRAMESZ)
206         jr      t9
208 #else  /* ! __PIC__ */
210         j       JUMPTARGET (__syscall_error)
211 #endif /* ! __PIC__ */
212 PSEUDO_END (__swapcontext)
214 weak_alias (__swapcontext, swapcontext)