blob: 5c956ff1a67f3c1418076173be911baff6fc9c01 [file] [log] [blame]
Serban Constantinescue2104882013-09-26 11:37:10 +01001/*
2 * Copyright (C) 2013 The Android Open Source Project
Elliott Hughes54a74942014-01-03 16:40:37 -08003 * All rights reserved.
Serban Constantinescue2104882013-09-26 11:37:10 +01004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Elliott Hughes851e68a2014-02-19 16:53:20 -080029#include <private/bionic_asm.h>
Serban Constantinescue2104882013-09-26 11:37:10 +010030
Elliott Hughes9fb536d2014-12-05 12:17:25 -080031// According to AARCH64 PCS document we need to save the following
32// registers:
33//
34// Core x19 - x30, sp (see section 5.1.1)
35// VFP d8 - d15 (see section 5.1.2)
36//
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080037// NOTE: All the registers saved here will have 64 bit vales.
Elliott Hughes9fb536d2014-12-05 12:17:25 -080038// AAPCS mandates that the higher part of q registers do not need to
39// be saved by the callee.
Elliott Hughes9fb536d2014-12-05 12:17:25 -080040
Elliott Hughes75096222014-12-08 16:01:20 -080041#define _JB_SIGFLAG 0
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080042#define _JB_SIGMASK (_JB_SIGFLAG + 1)
43#define _JB_X30_SP (_JB_SIGMASK + 1)
44#define _JB_X28_X29 (_JB_X30_SP + 2)
45#define _JB_X26_X27 (_JB_X28_X29 + 2)
46#define _JB_X24_X25 (_JB_X26_X27 + 2)
47#define _JB_X22_X23 (_JB_X24_X25 + 2)
48#define _JB_X20_X21 (_JB_X22_X23 + 2)
49#define _JB_X19 (_JB_X20_X21 + 2)
50#define _JB_D14_D15 (_JB_X19 + 1)
51#define _JB_D12_D13 (_JB_D14_D15 + 2)
52#define _JB_D10_D11 (_JB_D12_D13 + 1)
53#define _JB_D8_D9 (_JB_D10_D11 + 1)
Serban Constantinescue2104882013-09-26 11:37:10 +010054
55ENTRY(setjmp)
Elliott Hughes9fb536d2014-12-05 12:17:25 -080056 mov w1, #1
57 b sigsetjmp
Serban Constantinescue2104882013-09-26 11:37:10 +010058END(setjmp)
59
Elliott Hughes9fb536d2014-12-05 12:17:25 -080060ENTRY(_setjmp)
61 mov w1, #0
62 b sigsetjmp
63END(_setjmp)
Serban Constantinescue2104882013-09-26 11:37:10 +010064
Elliott Hughes9fb536d2014-12-05 12:17:25 -080065// int sigsetjmp(sigjmp_buf env, int save_signal_mask);
66ENTRY(sigsetjmp)
Elliott Hughes75096222014-12-08 16:01:20 -080067 // Record whether or not we're saving the signal mask.
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080068 str w1, [x0, #(_JB_SIGFLAG * 8)]
Elliott Hughes75096222014-12-08 16:01:20 -080069
Elliott Hughes9fb536d2014-12-05 12:17:25 -080070 // Do we need to save the signal mask?
Elliott Hughes9fb536d2014-12-05 12:17:25 -080071 cbz w1, 1f
Serban Constantinescue2104882013-09-26 11:37:10 +010072
Elliott Hughes7b78e812014-12-05 22:57:55 -080073 // Save current signal mask.
Elliott Hughes9fb536d2014-12-05 12:17:25 -080074 stp x0, x30, [sp, #-16]!
Elliott Hughes7b78e812014-12-05 22:57:55 -080075 // The 'how' argument is ignored if new_mask is NULL.
76 mov x1, #0 // NULL.
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080077 add x2, x0, #(_JB_SIGMASK * 8) // old_mask.
Elliott Hughes7b78e812014-12-05 22:57:55 -080078 bl sigprocmask
Elliott Hughes9fb536d2014-12-05 12:17:25 -080079 ldp x0, x30, [sp], #16
Serban Constantinescue2104882013-09-26 11:37:10 +010080
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800811:
Elliott Hughes9fb536d2014-12-05 12:17:25 -080082 // Save core registers.
83 mov x10, sp
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080084 stp x30, x10, [x0, #(_JB_X30_SP * 8)]
85 stp x28, x29, [x0, #(_JB_X28_X29 * 8)]
86 stp x26, x27, [x0, #(_JB_X26_X27 * 8)]
87 stp x24, x25, [x0, #(_JB_X24_X25 * 8)]
88 stp x22, x23, [x0, #(_JB_X22_X23 * 8)]
89 stp x20, x21, [x0, #(_JB_X20_X21 * 8)]
90 str x19, [x0, #(_JB_X19 * 8)]
Elliott Hughes9fb536d2014-12-05 12:17:25 -080091
92 // Save floating point registers.
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -080093 stp d14, d15, [x0, #(_JB_D14_D15 * 8)]
94 stp d12, d13, [x0, #(_JB_D12_D13 * 8)]
95 stp d10, d11, [x0, #(_JB_D10_D11 * 8)]
96 stp d8, d9, [x0, #(_JB_D8_D9 * 8)]
Elliott Hughes9fb536d2014-12-05 12:17:25 -080097
Elliott Hughes75096222014-12-08 16:01:20 -080098 mov w0, #0
Elliott Hughes9fb536d2014-12-05 12:17:25 -080099 ret
100END(sigsetjmp)
101
102// void siglongjmp(sigjmp_buf env, int value);
103ENTRY(siglongjmp)
Elliott Hughes75096222014-12-08 16:01:20 -0800104 // Do we need to restore the signal mask?
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -0800105 ldr w9, [x0, #(_JB_SIGFLAG * 8)]
Elliott Hughes75096222014-12-08 16:01:20 -0800106 cbz w9, 1f
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800107
108 // Restore signal mask.
109 stp x0, x30, [sp, #-16]!
Elliott Hughes7b78e812014-12-05 22:57:55 -0800110 mov x19, x1 // Save 'value'.
111 mov x2, x0
112 mov x0, #2 // SIG_SETMASK
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -0800113 add x1, x2, #(_JB_SIGMASK * 8) // new_mask.
Elliott Hughes7b78e812014-12-05 22:57:55 -0800114 mov x2, #0 // NULL.
115 bl sigprocmask
116 mov x1, x19 // Restore 'value'.
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800117 ldp x0, x30, [sp], #16
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800118
1191:
120 // Restore core registers.
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -0800121 ldp x30, x10, [x0, #(_JB_X30_SP * 8)]
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800122 mov sp, x10
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -0800123 ldp x28, x29, [x0, #(_JB_X28_X29 * 8)]
124 ldp x26, x27, [x0, #(_JB_X26_X27 * 8)]
125 ldp x24, x25, [x0, #(_JB_X24_X25 * 8)]
126 ldp x22, x23, [x0, #(_JB_X22_X23 * 8)]
127 ldp x20, x21, [x0, #(_JB_X20_X21 * 8)]
128 ldr x19, [x0, #(_JB_X19 * 8)]
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800129
130 // Restore floating point registers.
Elliott Hughes9fa2cfb2014-12-08 16:23:10 -0800131 ldp d14, d15, [x0, #(_JB_D14_D15 * 8)]
132 ldp d12, d13, [x0, #(_JB_D12_D13 * 8)]
133 ldp d10, d11, [x0, #(_JB_D10_D11 * 8)]
134 ldp d8, d9, [x0, #(_JB_D8_D9 * 8)]
Elliott Hughes9fb536d2014-12-05 12:17:25 -0800135
136 // Validate sp (sp mod 16 = 0) and lr (lr mod 4 = 0).
137 tst x30, #3
138 b.ne longjmperror
139 mov x10, sp
140 tst x10, #15
141 b.ne longjmperror
142
143 // Set return value.
144 cmp w1, wzr
145 csinc w0, w1, wzr, ne
146 ret
147END(siglongjmp)
148
149 .globl longjmp
150 .equ longjmp, siglongjmp
151 .globl _longjmp
152 .equ _longjmp, siglongjmp