blob: a1d4695525da0db69e5f0d6e77c55034eef60509 [file] [log] [blame]
Raghu Gandham405b8022012-07-25 18:16:42 -07001/* $OpenBSD: setjmp.S,v 1.5 2005/08/07 16:40:15 espie Exp $ */
2
3/*
4 * Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com)
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Opsycon AB nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
Elliott Hughes851e68a2014-02-19 16:53:20 -080032#include <private/bionic_asm.h>
David 'Digit' Turnerc1b44ec2012-10-17 19:10:11 +020033#include <machine/signal.h>
Raghu Gandham405b8022012-07-25 18:16:42 -070034
35/*
Duane Sand3a478632014-11-25 17:33:10 -080036 * _setjmp, _longjmp (restoring signal state)
37 *
38 * GPOFF and FRAMESIZE must be the same for both _setjmp and _longjmp!
Raghu Gandham405b8022012-07-25 18:16:42 -070039 *
40 */
41
42FRAMESZ= MKFSIZ(2,6)
43A1OFF= FRAMESZ-4*REGSZ
44A0OFF= FRAMESZ-3*REGSZ
45GPOFF= FRAMESZ-2*REGSZ
46RAOFF= FRAMESZ-1*REGSZ
47
Raghu Gandham405b8022012-07-25 18:16:42 -070048NON_LEAF(setjmp, FRAMESZ, ra)
49 .mask 0x80000000, RAOFF
50 PTR_SUBU sp, FRAMESZ # allocate stack frame
51 SETUP_GP64(GPOFF, setjmp)
52 SAVE_GP(GPOFF)
53 .set reorder
Duane Sand3a478632014-11-25 17:33:10 -080054
55#ifndef __LP64__
56 addiu a0, 7 # roundup jmpbuf addr to 8-byte boundary
57 li t0, ~7
58 and a0, t0
59#endif
60
Raghu Gandham405b8022012-07-25 18:16:42 -070061 REG_S ra, RAOFF(sp) # save state
62 REG_S a0, A0OFF(sp)
Raghu Gandham405b8022012-07-25 18:16:42 -070063 move a0, zero # get current signal mask
64 jal sigblock
Duane Sand3a478632014-11-25 17:33:10 -080065 REG_L a0, A0OFF(sp)
Raghu Gandham405b8022012-07-25 18:16:42 -070066 REG_L ra, RAOFF(sp)
Raghu Gandham405b8022012-07-25 18:16:42 -070067
Duane Sand3a478632014-11-25 17:33:10 -080068 REG_S v0, SC_MASK(a0) # save sc_mask = sigblock(0)
69
70 li v0, 0xACEDBADE # sigcontext magic number
71 sw v0, SC_MAGIC(a0)
72 # callee-saved long-sized regs:
73 REG_S ra, SC_REGS+0*REGSZ(a0)
74 REG_S s0, SC_REGS+1*REGSZ(a0)
75 REG_S s1, SC_REGS+2*REGSZ(a0)
76 REG_S s2, SC_REGS+3*REGSZ(a0)
77 REG_S s3, SC_REGS+4*REGSZ(a0)
78 REG_S s4, SC_REGS+5*REGSZ(a0)
79 REG_S s5, SC_REGS+6*REGSZ(a0)
80 REG_S s6, SC_REGS+7*REGSZ(a0)
81 REG_S s7, SC_REGS+8*REGSZ(a0)
82 REG_S s8, SC_REGS+9*REGSZ(a0)
83 REG_L v0, GPOFF(sp)
84 REG_S v0, SC_REGS+10*REGSZ(a0)
85 PTR_ADDU v0, sp, FRAMESZ
86 REG_S v0, SC_REGS+11*REGSZ(a0)
87
Raghu Gandham405b8022012-07-25 18:16:42 -070088 cfc1 v0, $31
Duane Sand3a478632014-11-25 17:33:10 -080089
90#ifdef __LP64__
91 # callee-saved fp regs on mips n64 ABI are $f24..$f31
92 s.d $f24, SC_FPREGS+0*REGSZ_FP(a0)
93 s.d $f25, SC_FPREGS+1*REGSZ_FP(a0)
94 s.d $f26, SC_FPREGS+2*REGSZ_FP(a0)
95 s.d $f27, SC_FPREGS+3*REGSZ_FP(a0)
96 s.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
97 s.d $f29, SC_FPREGS+5*REGSZ_FP(a0)
98 s.d $f30, SC_FPREGS+6*REGSZ_FP(a0)
99 s.d $f31, SC_FPREGS+7*REGSZ_FP(a0)
100#else
101 # callee-saved fp regs on mips o32 ABI are
102 # the even-numbered fp regs $f20,$f22,...$f30
103 s.d $f20, SC_FPREGS+0*REGSZ_FP(a0)
104 s.d $f22, SC_FPREGS+1*REGSZ_FP(a0)
105 s.d $f24, SC_FPREGS+2*REGSZ_FP(a0)
106 s.d $f26, SC_FPREGS+3*REGSZ_FP(a0)
107 s.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
108 s.d $f30, SC_FPREGS+5*REGSZ_FP(a0)
Raghu Gandham405b8022012-07-25 18:16:42 -0700109#endif
Duane Sand3a478632014-11-25 17:33:10 -0800110 sw v0, SC_FPSR(a0)
Raghu Gandham405b8022012-07-25 18:16:42 -0700111 move v0, zero
112 RESTORE_GP64
113 PTR_ADDU sp, FRAMESZ
114 j ra
Duane Sand3a478632014-11-25 17:33:10 -0800115END(setjmp)
116
117
118NON_LEAF(longjmp, FRAMESZ, ra)
119 .mask 0x80000000, RAOFF
120 PTR_SUBU sp, FRAMESZ
121 SETUP_GP64(GPOFF, longjmp)
122 SAVE_GP(GPOFF)
123 .set reorder
124
125#ifndef __LP64__
126 addiu a0, 7 # roundup jmpbuf addr to 8-byte boundary
127 li t0, ~7
128 and a0, t0
129#endif
130
131 REG_S a1, A1OFF(sp)
132 REG_S a0, A0OFF(sp)
133 lw a0, SC_MASK(a0)
134 jal sigsetmask
135 REG_L a0, A0OFF(sp)
136 REG_L a1, A1OFF(sp)
137
138 lw v0, SC_MAGIC(a0)
139 li t0, 0xACEDBADE
140 bne v0, t0, botch # jump if error
141
142 # callee-saved long-sized regs:
143 REG_L ra, SC_REGS+0*REGSZ(a0)
144 REG_L s0, SC_REGS+1*REGSZ(a0)
145 REG_L s1, SC_REGS+2*REGSZ(a0)
146 REG_L s2, SC_REGS+3*REGSZ(a0)
147 REG_L s3, SC_REGS+4*REGSZ(a0)
148 REG_L s4, SC_REGS+5*REGSZ(a0)
149 REG_L s5, SC_REGS+6*REGSZ(a0)
150 REG_L s6, SC_REGS+7*REGSZ(a0)
151 REG_L s7, SC_REGS+8*REGSZ(a0)
152 REG_L s8, SC_REGS+9*REGSZ(a0)
153 REG_L gp, SC_REGS+10*REGSZ(a0)
154 REG_L sp, SC_REGS+11*REGSZ(a0)
155
156 lw v0, SC_FPSR(a0)
157 ctc1 v0, $31
158#ifdef __LP64__
159 # callee-saved fp regs on mips n64 ABI are $f24..$f31
160 l.d $f24, SC_FPREGS+0*REGSZ_FP(a0)
161 l.d $f25, SC_FPREGS+1*REGSZ_FP(a0)
162 l.d $f26, SC_FPREGS+2*REGSZ_FP(a0)
163 l.d $f27, SC_FPREGS+3*REGSZ_FP(a0)
164 l.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
165 l.d $f29, SC_FPREGS+5*REGSZ_FP(a0)
166 l.d $f30, SC_FPREGS+6*REGSZ_FP(a0)
167 l.d $f31, SC_FPREGS+7*REGSZ_FP(a0)
168#else
169 # callee-saved fp regs on mips o32 ABI are
170 # the even-numbered fp regs $f20,$f22,...$f30
171 l.d $f20, SC_FPREGS+0*REGSZ_FP(a0)
172 l.d $f22, SC_FPREGS+1*REGSZ_FP(a0)
173 l.d $f24, SC_FPREGS+2*REGSZ_FP(a0)
174 l.d $f26, SC_FPREGS+3*REGSZ_FP(a0)
175 l.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
176 l.d $f30, SC_FPREGS+5*REGSZ_FP(a0)
177#endif
178 bne a1, zero, 1f
179 li a1, 1 # never return 0!
1801:
181 move v0, a1
182 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -0700183
184botch:
185 jal longjmperror
186 jal abort
187 RESTORE_GP64
188 PTR_ADDU sp, FRAMESZ
Raghu Gandham405b8022012-07-25 18:16:42 -0700189END(longjmp)