]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/makecontext.S
4a578ee92ee6ca693e52344250fd3ee237292332
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / makecontext.S
1 /* Modify saved context.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
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
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
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 makecontext (ucontext_t *ucp, (void *func) (), int argc, ...) */
28
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 = 5 /* save a3-a7 */
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 A3OFF = FRAMESZ - (5 * SZREG) /* callee-allocated */
47 A4OFF = FRAMESZ - (4 * SZREG)
48 A5OFF = FRAMESZ - (3 * SZREG)
49 A6OFF = FRAMESZ - (2 * SZREG)
50 A7OFF = FRAMESZ - (1 * SZREG)
51 NARGREGS = 8
52 #else
53 A3OFF = FRAMESZ + (3 * SZREG) /* caller-allocated */
54 NARGREGS = 4
55 #endif
56
57 NESTED (__makecontext, FRAMESZ, ra)
58 .mask MASK, -(ARGSZ * SZREG)
59 .fmask 0x00000000, 0
60
61 98:
62 #ifdef __PIC__
63 SETUP_GP
64 #endif
65
66 PTR_ADDIU sp, -FRAMESZ
67 cfi_adjust_cfa_offset (FRAMESZ)
68
69 #ifdef __PIC__
70 SETUP_GP64_STACK (GPOFF, __makecontext)
71 SAVE_GP (GPOFF)
72 #endif
73
74 #ifdef PROF
75 .set noat
76 move AT, ra
77 jal _mcount
78 .set at
79 #endif
80
81 /* Store args to be passed. */
82 REG_S a3, A3OFF(sp)
83 #if _MIPS_SIM != _ABIO32
84 REG_S a4, A4OFF(sp)
85 REG_S a5, A5OFF(sp)
86 REG_S a6, A6OFF(sp)
87 REG_S a7, A7OFF(sp)
88 #endif
89
90 /* Store a magic flag. */
91 li v1, 1
92 REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
93
94 /* Set up the stack. */
95 PTR_L t0, STACK_SP(a0)
96 PTR_L t2, STACK_SIZE(a0)
97 PTR_ADDIU t1, sp, A3OFF
98 PTR_ADDU t0, t2
99 and t0, ALMASK
100 blez a2, 2f /* no arguments */
101
102 /* Store register arguments. */
103 PTR_ADDIU t2, a0, MCONTEXT_GREGS + 4 * SZREG
104 move t3, zero
105 0:
106 addiu t3, 1
107 REG_L v1, (t1)
108 PTR_ADDIU t1, SZREG
109 REG_S v1, (t2)
110 PTR_ADDIU t2, SZREG
111 bgeu t3, a2, 2f /* all done */
112 bltu t3, NARGREGS, 0b /* next */
113
114 /* Make room for stack arguments. */
115 PTR_SUBU t2, a2, t3
116 PTR_SLL t2, 3
117 PTR_SUBU t0, t2
118 and t0, ALMASK
119
120 /* Store stack arguments. */
121 move t2, t0
122 1:
123 addiu t3, 1
124 REG_L v1, (t1)
125 PTR_ADDIU t1, SZREG
126 REG_S v1, (t2)
127 PTR_ADDIU t2, SZREG
128 bltu t3, a2, 1b /* next */
129
130 2:
131 #if _MIPS_SIM == _ABIO32
132 /* Make room for a0-a3 storage. */
133 PTR_ADDIU t0, -(NARGSAVE * SZREG)
134 #endif
135 PTR_L v1, UCONTEXT_LINK(a0)
136 #ifdef __PIC__
137 PTR_ADDIU t9, 99f - 98b
138 #else
139 PTR_LA t9, 99f
140 #endif
141 REG_S t0, (29 * SZREG + MCONTEXT_GREGS)(a0) /* sp */
142 REG_S v1, (16 * SZREG + MCONTEXT_GREGS)(a0) /* s0 */
143 #ifdef __PIC__
144 REG_S gp, (17 * SZREG + MCONTEXT_GREGS)(a0) /* s1 */
145 #endif
146 REG_S t9, (31 * SZREG + MCONTEXT_GREGS)(a0) /* ra */
147 REG_S a1, MCONTEXT_PC(a0)
148
149 #ifdef __PIC__
150 RESTORE_GP64_STACK
151 PTR_ADDIU sp, FRAMESZ
152 cfi_adjust_cfa_offset (-FRAMESZ)
153 #endif
154 jr ra
155
156 99:
157 #ifdef __PIC__
158 move gp, s1
159 #endif
160 move a0, zero
161 beqz s0, 0f
162
163 /* setcontext (ucp) */
164 move a0, s0
165 #ifdef __PIC__
166 PTR_LA t9, JUMPTARGET (__setcontext)
167 jalr t9
168 # if _MIPS_SIM == _ABIO32
169 move gp, s1
170 # endif
171 #else
172 jal JUMPTARGET (__setcontext)
173 #endif
174 move a0, v0
175
176 0:
177 /* exit (a0) */
178 #ifdef __PIC__
179 PTR_LA t9, HIDDEN_JUMPTARGET (exit)
180 jalr t9
181 #else
182 jal HIDDEN_JUMPTARGET (exit)
183 #endif
184
185 /* You don't exist, you won't feel anything. */
186 1:
187 lb zero, (zero)
188 b 1b
189 PSEUDO_END (__makecontext)
190
191 weak_alias (__makecontext, makecontext)