blob: 052dacb4db222729ba553c5747e2ddc0a7df113a [file] [log] [blame]
Raghu Gandham405b8022012-07-25 18:16:42 -07001/* $OpenBSD: _setjmp.S,v 1.4 2005/08/07 16:40:15 espie Exp $ */
2
3/*
4 * Copyright (c) 2002 Opsycon AB (www.opsycon.se / www.opsycon.com)
Elliott Hughes851e68a2014-02-19 16:53:20 -08005 *
Raghu Gandham405b8022012-07-25 18:16:42 -07006 * 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/*
36 * _setjmp, _longjmp (not restoring signal state)
37 *
Raghu Gandham405b8022012-07-25 18:16:42 -070038 * GPOFF and FRAMESIZE must be the same for both _setjmp and _longjmp!
39 *
40 */
41
42FRAMESZ= MKFSIZ(0,4)
43GPOFF= FRAMESZ-2*REGSZ
44
Raghu Gandham405b8022012-07-25 18:16:42 -070045LEAF(_setjmp, FRAMESZ)
46 PTR_SUBU sp, FRAMESZ
47 SETUP_GP64(GPOFF, _setjmp)
48 SAVE_GP(GPOFF)
Duane Sand3a478632014-11-25 17:33:10 -080049 .set reorder
Raghu Gandham405b8022012-07-25 18:16:42 -070050
Duane Sand3a478632014-11-25 17:33:10 -080051#ifndef __LP64__
52 addiu a0, 7 # roundup jmpbuf addr to 8-byte boundary
53 li t0, ~7
54 and a0, t0
Raghu Gandham405b8022012-07-25 18:16:42 -070055#endif
Duane Sand3a478632014-11-25 17:33:10 -080056
57 # SC_MASK is unused here
58
59 li v0, 0xACEDBADE # sigcontext magic number
60 sw v0, SC_MAGIC(a0)
61 # callee-saved long-sized regs:
62 REG_S ra, SC_REGS+0*REGSZ(a0)
63 REG_S s0, SC_REGS+1*REGSZ(a0)
64 REG_S s1, SC_REGS+2*REGSZ(a0)
65 REG_S s2, SC_REGS+3*REGSZ(a0)
66 REG_S s3, SC_REGS+4*REGSZ(a0)
67 REG_S s4, SC_REGS+5*REGSZ(a0)
68 REG_S s5, SC_REGS+6*REGSZ(a0)
69 REG_S s6, SC_REGS+7*REGSZ(a0)
70 REG_S s7, SC_REGS+8*REGSZ(a0)
71 REG_S s8, SC_REGS+9*REGSZ(a0)
72 REG_L v0, GPOFF(sp)
73 REG_S v0, SC_REGS+10*REGSZ(a0)
74 PTR_ADDU v0, sp, FRAMESZ
75 REG_S v0, SC_REGS+11*REGSZ(a0)
76
77 cfc1 v0, $31
78
79#ifdef __LP64__
80 # callee-saved fp regs on mips n64 ABI are $f24..$f31
81 s.d $f24, SC_FPREGS+0*REGSZ_FP(a0)
82 s.d $f25, SC_FPREGS+1*REGSZ_FP(a0)
83 s.d $f26, SC_FPREGS+2*REGSZ_FP(a0)
84 s.d $f27, SC_FPREGS+3*REGSZ_FP(a0)
85 s.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
86 s.d $f29, SC_FPREGS+5*REGSZ_FP(a0)
87 s.d $f30, SC_FPREGS+6*REGSZ_FP(a0)
88 s.d $f31, SC_FPREGS+7*REGSZ_FP(a0)
89#else
90 # callee-saved fp regs on mips o32 ABI are
91 # the even-numbered fp regs $f20,$f22,...$f30
92 s.d $f20, SC_FPREGS+0*REGSZ_FP(a0)
93 s.d $f22, SC_FPREGS+1*REGSZ_FP(a0)
94 s.d $f24, SC_FPREGS+2*REGSZ_FP(a0)
95 s.d $f26, SC_FPREGS+3*REGSZ_FP(a0)
96 s.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
97 s.d $f30, SC_FPREGS+5*REGSZ_FP(a0)
98#endif
99 sw v0, SC_FPSR(a0)
100 move v0, zero
Raghu Gandham405b8022012-07-25 18:16:42 -0700101 RESTORE_GP64
102 PTR_ADDU sp, FRAMESZ
103 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -0700104END(_setjmp)
105
Duane Sand3a478632014-11-25 17:33:10 -0800106
Raghu Gandham405b8022012-07-25 18:16:42 -0700107LEAF(_longjmp, FRAMESZ)
108 PTR_SUBU sp, FRAMESZ
109 SETUP_GP64(GPOFF, _longjmp)
110 SAVE_GP(GPOFF)
Duane Sand3a478632014-11-25 17:33:10 -0800111 .set reorder
112
113#ifndef __LP64__
114 addiu a0, 7 # roundup jmpbuf addr to 8-byte boundary
115 li t0, ~7
116 and a0, t0
Raghu Gandham405b8022012-07-25 18:16:42 -0700117#endif
Duane Sand3a478632014-11-25 17:33:10 -0800118
119 # SC_MASK is unused here
120
121 lw v0, SC_MAGIC(a0)
122 li t0, 0xACEDBADE
123 bne v0, t0, botch # jump if error
124
125 # callee-saved long-sized regs:
126 REG_L ra, SC_REGS+0*REGSZ(a0)
127 REG_L s0, SC_REGS+1*REGSZ(a0)
128 REG_L s1, SC_REGS+2*REGSZ(a0)
129 REG_L s2, SC_REGS+3*REGSZ(a0)
130 REG_L s3, SC_REGS+4*REGSZ(a0)
131 REG_L s4, SC_REGS+5*REGSZ(a0)
132 REG_L s5, SC_REGS+6*REGSZ(a0)
133 REG_L s6, SC_REGS+7*REGSZ(a0)
134 REG_L s7, SC_REGS+8*REGSZ(a0)
135 REG_L s8, SC_REGS+9*REGSZ(a0)
136 REG_L gp, SC_REGS+10*REGSZ(a0)
137 REG_L sp, SC_REGS+11*REGSZ(a0)
138
139 lw v0, SC_FPSR(a0)
140 ctc1 v0, $31
141#ifdef __LP64__
142 # callee-saved fp regs on mips n64 ABI are $f24..$f31
143 l.d $f24, SC_FPREGS+0*REGSZ_FP(a0)
144 l.d $f25, SC_FPREGS+1*REGSZ_FP(a0)
145 l.d $f26, SC_FPREGS+2*REGSZ_FP(a0)
146 l.d $f27, SC_FPREGS+3*REGSZ_FP(a0)
147 l.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
148 l.d $f29, SC_FPREGS+5*REGSZ_FP(a0)
149 l.d $f30, SC_FPREGS+6*REGSZ_FP(a0)
150 l.d $f31, SC_FPREGS+7*REGSZ_FP(a0)
151#else
152 # callee-saved fp regs on mips o32 ABI are
153 # the even-numbered fp regs $f20,$f22,...$f30
154 l.d $f20, SC_FPREGS+0*REGSZ_FP(a0)
155 l.d $f22, SC_FPREGS+1*REGSZ_FP(a0)
156 l.d $f24, SC_FPREGS+2*REGSZ_FP(a0)
157 l.d $f26, SC_FPREGS+3*REGSZ_FP(a0)
158 l.d $f28, SC_FPREGS+4*REGSZ_FP(a0)
159 l.d $f30, SC_FPREGS+5*REGSZ_FP(a0)
160#endif
Raghu Gandham405b8022012-07-25 18:16:42 -0700161 bne a1, zero, 1f
Raghu Gandham405b8022012-07-25 18:16:42 -0700162 li a1, 1 # never return 0!
1631:
Duane Sand3a478632014-11-25 17:33:10 -0800164 move v0, a1
Raghu Gandham405b8022012-07-25 18:16:42 -0700165 j ra
Raghu Gandham405b8022012-07-25 18:16:42 -0700166
167botch:
168 jal longjmperror
Raghu Gandham405b8022012-07-25 18:16:42 -0700169 jal abort
Raghu Gandham405b8022012-07-25 18:16:42 -0700170 RESTORE_GP64
171 PTR_ADDU sp, FRAMESZ
172END(_longjmp)