]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/mips/getcontext.S
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / getcontext.S
CommitLineData
ff347533 1/* Save current context.
04277e02 2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
ff347533
JM
3 This file is part of the GNU C Library.
4 Contributed by Maciej W. Rozycki <macro@codesourcery.com>.
5
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.
10
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.
15
16 You should have received a copy of the GNU Lesser General Public
ab84e3ff 17 License along with the GNU C Library. If not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
ff347533
JM
19
20#include <sysdep.h>
21#include <sys/asm.h>
22#include <sys/fpregdef.h>
23#include <sys/regdef.h>
24
25#include "ucontext_i.h"
26
27/* int getcontext (ucontext_t *ucp) */
28
29 .text
43301bd3 30 .set nomips16
ff347533
JM
31LOCALSZ = 0
32MASK = 0x00000000
33#ifdef __PIC__
34LOCALSZ = 1 /* save gp */
35# if _MIPS_SIM != _ABIO32
36MASK = 0x10000000
37# endif
38#endif
39FRAMESZ = ((LOCALSZ * SZREG) + ALSZ) & ALMASK
40GPOFF = FRAMESZ - (1 * SZREG)
b309f058
GC
41MCONTEXT_GREGSZ = 8
42#if _MIPS_SIM == _ABIO32 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
43MCONTEXT_GREGOFF = 4
44#else
45MCONTEXT_GREGOFF = 0
46#endif
ff347533
JM
47
48NESTED (__getcontext, FRAMESZ, ra)
49 .mask MASK, 0
50 .fmask 0x00000000, 0
51
52#ifdef __PIC__
53 SETUP_GP
54
55 move a2, sp
56# define _SP a2
57
58# if _MIPS_SIM != _ABIO32
59 move a3, gp
60# define _GP a3
61# endif
62
63 PTR_ADDIU sp, -FRAMESZ
aea7a9b9
JM
64 cfi_adjust_cfa_offset (FRAMESZ)
65 SETUP_GP64_STACK (GPOFF, __getcontext)
ff347533
JM
66 SAVE_GP (GPOFF)
67
68#else /* ! __PIC__ */
69# define _SP sp
70# define _GP gp
71
72#endif /* ! __PIC__ */
73
74#ifdef PROF
75 .set noat
76 move AT, ra
77 jal _mcount
78 .set at
79#endif
80
b309f058
GC
81 REG_S s0, (MCONTEXT_GREGOFF + 16 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
82 REG_S s1, (MCONTEXT_GREGOFF + 17 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
83 REG_S s2, (MCONTEXT_GREGOFF + 18 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
84 REG_S s3, (MCONTEXT_GREGOFF + 19 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
85 REG_S s4, (MCONTEXT_GREGOFF + 20 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
86 REG_S s5, (MCONTEXT_GREGOFF + 21 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
87 REG_S s6, (MCONTEXT_GREGOFF + 22 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
88 REG_S s7, (MCONTEXT_GREGOFF + 23 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
ff347533 89#if ! defined (__PIC__) || _MIPS_SIM != _ABIO32
b309f058 90 REG_S _GP, (MCONTEXT_GREGOFF + 28 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
ff347533 91#endif
b309f058
GC
92 REG_S _SP, (MCONTEXT_GREGOFF + 29 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
93 REG_S fp, (MCONTEXT_GREGOFF + 30 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
94 REG_S ra, (MCONTEXT_GREGOFF + 31 * MCONTEXT_GREGSZ + MCONTEXT_GREGS)(a0)
95 REG_S ra, (MCONTEXT_GREGOFF + MCONTEXT_PC)(a0)
ff347533
JM
96
97#ifdef __mips_hard_float
98# if _MIPS_SIM == _ABI64
99 s.d fs0, (24 * SZREG + MCONTEXT_FPREGS)(a0)
100 s.d fs1, (25 * SZREG + MCONTEXT_FPREGS)(a0)
101 s.d fs2, (26 * SZREG + MCONTEXT_FPREGS)(a0)
102 s.d fs3, (27 * SZREG + MCONTEXT_FPREGS)(a0)
103 s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
104 s.d fs5, (29 * SZREG + MCONTEXT_FPREGS)(a0)
105 s.d fs6, (30 * SZREG + MCONTEXT_FPREGS)(a0)
106 s.d fs7, (31 * SZREG + MCONTEXT_FPREGS)(a0)
107
108# else /* _MIPS_SIM != _ABI64 */
109 s.d fs0, (20 * SZREG + MCONTEXT_FPREGS)(a0)
110 s.d fs1, (22 * SZREG + MCONTEXT_FPREGS)(a0)
111 s.d fs2, (24 * SZREG + MCONTEXT_FPREGS)(a0)
112 s.d fs3, (26 * SZREG + MCONTEXT_FPREGS)(a0)
113 s.d fs4, (28 * SZREG + MCONTEXT_FPREGS)(a0)
114 s.d fs5, (30 * SZREG + MCONTEXT_FPREGS)(a0)
115
116# endif /* _MIPS_SIM != _ABI64 */
117
118 cfc1 v1, fcr31
119 sw v1, MCONTEXT_FPC_CSR(a0)
120#endif /* __mips_hard_float */
121
122/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
123 li a3, _NSIG8
124 PTR_ADDU a2, a0, UCONTEXT_SIGMASK
125 move a1, zero
126 li a0, SIG_BLOCK
127
128 li v0, SYS_ify (rt_sigprocmask)
129 syscall
130 bnez a3, 99f
aea7a9b9 131 cfi_remember_state
ff347533
JM
132
133#ifdef __PIC__
aea7a9b9 134 RESTORE_GP64_STACK
ff347533 135 PTR_ADDIU sp, FRAMESZ
aea7a9b9 136 cfi_adjust_cfa_offset (-FRAMESZ)
ff347533
JM
137#endif
138 move v0, zero
139 jr ra
140
14199:
aea7a9b9 142 cfi_restore_state
ff347533
JM
143#ifdef __PIC__
144 PTR_LA t9, JUMPTARGET (__syscall_error)
aea7a9b9 145 RESTORE_GP64_STACK
ff347533 146 PTR_ADDIU sp, FRAMESZ
aea7a9b9 147 cfi_adjust_cfa_offset (-FRAMESZ)
ff347533
JM
148 jr t9
149
150#else /* ! __PIC__ */
151
152 j JUMPTARGET (__syscall_error)
153#endif /* ! __PIC__ */
154PSEUDO_END (__getcontext)
155
156weak_alias (__getcontext, getcontext)