blob: 7bf2aed0797b4dc74e233c99997187efe83e4b98 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $OpenBSD: setjmp.S,v 1.2 2004/02/01 05:40:52 drahn Exp $ */
2/* $NetBSD: setjmp.S,v 1.5 2003/04/05 23:08:51 bjh21 Exp $ */
3
4/*
5 * Copyright (c) 1997 Mark Brinicombe
David 'Digit' Turner68b5f552010-03-25 09:54:33 -07006 * Copyright (c) 2010 Android Open Source Project.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Mark Brinicombe
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
Elliott Hughes851e68a2014-02-19 16:53:20 -080037#include <private/bionic_asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038#include <machine/setjmp.h>
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070039#include <machine/cpu-features.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080040
41/*
42 * C library -- setjmp, longjmp
43 *
44 * longjmp(a,v)
45 * will generate a "return(v)" from the last call to
46 * setjmp(a)
47 * by restoring registers from the stack.
48 * The previous signal state is restored.
49 */
50
51ENTRY(setjmp)
52 /* Block all signals and retrieve the old signal mask */
53 stmfd sp!, {r0, r14}
Christopher Ferrised459702013-12-02 17:44:53 -080054 .cfi_def_cfa_offset 8
55 .cfi_rel_offset r0, 0
56 .cfi_rel_offset r14, 4
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057 mov r0, #0x00000000
58
Elliott Hughes651a0682014-08-07 11:52:38 -070059 bl sigblock
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080060 mov r1, r0
61
62 ldmfd sp!, {r0, r14}
Christopher Ferrised459702013-12-02 17:44:53 -080063 .cfi_def_cfa_offset 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080064
65 /* Store signal mask */
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070066 str r1, [r0, #(_JB_SIGMASK * 4)]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067
68 ldr r1, .Lsetjmp_magic
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070069 str r1, [r0, #(_JB_MAGIC * 4)]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080070
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070071 /* Store core registers */
72 add r1, r0, #(_JB_CORE_BASE * 4)
73 stmia r1, {r4-r14}
74
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070075 /* Store floating-point registers */
76 add r1, r0, #(_JB_FLOAT_BASE * 4)
77 vstmia r1, {d8-d15}
78 /* Store floating-point state */
79 fmrx r1, fpscr
80 str r1, [r0, #(_JB_FLOAT_STATE * 4)]
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070081
82 mov r0, #0x00000000
83 bx lr
Kenny Root420878c2011-02-16 11:55:58 -080084END(setjmp)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085
86.Lsetjmp_magic:
87 .word _JB_MAGIC_SETJMP
88
89
90ENTRY(longjmp)
91 ldr r2, .Lsetjmp_magic
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070092 ldr r3, [r0, #(_JB_MAGIC * 4)]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093 teq r2, r3
Elliott Hughes9fb536d2014-12-05 12:17:25 -080094 blne longjmperror
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080095
96 /* Fetch signal mask */
David 'Digit' Turner68b5f552010-03-25 09:54:33 -070097 ldr r2, [r0, #(_JB_SIGMASK * 4)]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080098
99 /* Set signal mask */
100 stmfd sp!, {r0, r1, r14}
Christopher Ferrised459702013-12-02 17:44:53 -0800101 .cfi_def_cfa_offset 12
102 .cfi_rel_offset r0, 0
103 .cfi_rel_offset r1, 4
104 .cfi_rel_offset r14, 8
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800105 sub sp, sp, #4 /* align the stack */
Christopher Ferrised459702013-12-02 17:44:53 -0800106 .cfi_adjust_cfa_offset 4
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800107
108 mov r0, r2
Elliott Hughes651a0682014-08-07 11:52:38 -0700109 bl sigsetmask
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800110
111 add sp, sp, #4 /* unalign the stack */
Christopher Ferrised459702013-12-02 17:44:53 -0800112 .cfi_adjust_cfa_offset -4
Elliott Hughes851e68a2014-02-19 16:53:20 -0800113 ldmfd sp!, {r0, r1, r14}
Christopher Ferrised459702013-12-02 17:44:53 -0800114 .cfi_def_cfa_offset 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800115
David 'Digit' Turner68b5f552010-03-25 09:54:33 -0700116 /* Restore floating-point registers */
117 add r2, r0, #(_JB_FLOAT_BASE * 4)
118 vldmia r2, {d8-d15}
119 /* Restore floating-point state */
120 ldr r2, [r0, #(_JB_FLOAT_STATE * 4)]
121 fmxr fpscr, r2
David 'Digit' Turner68b5f552010-03-25 09:54:33 -0700122
123 /* Restore core registers */
124 add r2, r0, #(_JB_CORE_BASE * 4)
125 ldmia r2, {r4-r14}
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800126
127 /* Validate sp and r14 */
128 teq sp, #0
129 teqne r14, #0
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800130 bleq longjmperror
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800131
132 /* Set return value */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800133 mov r0, r1
134 teq r0, #0x00000000
135 moveq r0, #0x00000001
136 bx lr
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800137 mov r15, r14
Kenny Root420878c2011-02-16 11:55:58 -0800138END(longjmp)