blob: a8f614ffb27d095b78a6e7a97aeea35c8eaec968 [file] [log] [blame]
Elliott Hughes4906e562013-10-04 14:55:30 -07001/*
2 * Copyright (c) 2001 Wasabi Systems, Inc.
3 * All rights reserved.
4 *
5 * Written by Frank van der Linden for Wasabi Systems, Inc.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Wasabi Systems, Inc.
19 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
Elliott Hughes851e68a2014-02-19 16:53:20 -080036#include <private/bionic_asm.h>
Elliott Hughes4906e562013-10-04 14:55:30 -070037
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080038// These are only the callee-saved registers. Code calling setjmp
39// will expect the rest to be clobbered anyway.
40
41#define _JB_RBX 0
42#define _JB_RBP 1
43#define _JB_R12 2
44#define _JB_R13 3
45#define _JB_R14 4
46#define _JB_R15 5
47#define _JB_RSP 6
48#define _JB_PC 7
49#define _JB_SIGFLAG 8
50#define _JB_SIGMASK 9
Elliott Hughes4906e562013-10-04 14:55:30 -070051
52ENTRY(setjmp)
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080053 movl $1,%esi
54 jmp PIC_PLT(sigsetjmp)
Christopher Ferris507cfe22013-11-19 13:45:27 -080055END(setjmp)
Elliott Hughes4906e562013-10-04 14:55:30 -070056
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080057ENTRY(_setjmp)
58 movl $0,%esi
59 jmp PIC_PLT(sigsetjmp)
60END(_setjmp)
Elliott Hughes4906e562013-10-04 14:55:30 -070061
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080062// int sigsetjmp(sigjmp_buf env, int save_signal_mask);
63ENTRY(sigsetjmp)
64 // Record whether or not we're saving the signal mask.
65 movl %esi,(_JB_SIGFLAG * 8)(%rdi)
Elliott Hughes4906e562013-10-04 14:55:30 -070066
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080067 // Do we need to save the signal mask?
68 testl %esi,%esi
69 jz 2f
70
71 // Save the signal mask.
72 pushq %rdi
73 xorq %rdi,%rdi
74 call PIC_PLT(sigblock)
75 popq %rdi
76 movq %rax,(_JB_SIGMASK * 8)(%rdi)
77
782:
79 // Save the callee-save registers.
80 movq (%rsp),%r11
81 movq %rbx,(_JB_RBX * 8)(%rdi)
82 movq %rbp,(_JB_RBP * 8)(%rdi)
83 movq %r12,(_JB_R12 * 8)(%rdi)
84 movq %r13,(_JB_R13 * 8)(%rdi)
85 movq %r14,(_JB_R14 * 8)(%rdi)
86 movq %r15,(_JB_R15 * 8)(%rdi)
87 movq %rsp,(_JB_RSP * 8)(%rdi)
88 movq %r11,(_JB_PC * 8)(%rdi)
89
90 xorl %eax,%eax
91 ret
92END(sigsetjmp)
93
94// void siglongjmp(sigjmp_buf env, int value);
95ENTRY(siglongjmp)
96 movq %rdi,%r12
97 pushq %rsi // Push 'value'.
98
99 // Do we need to restore the signal mask?
100 cmpl $0, (_JB_SIGFLAG * 8)(%rdi)
101 jz 2f
102
103 // Restore the signal mask.
104 movq (_JB_SIGMASK * 8)(%rdi),%rdi
105 call PIC_PLT(sigsetmask)
106
1072:
108 popq %rax // Pop 'value'.
109
110 // Restore the callee-save registers.
111 movq (_JB_RBX * 8)(%r12),%rbx
112 movq (_JB_RBP * 8)(%r12),%rbp
113 movq (_JB_R13 * 8)(%r12),%r13
114 movq (_JB_R14 * 8)(%r12),%r14
115 movq (_JB_R15 * 8)(%r12),%r15
116 movq (_JB_RSP * 8)(%r12),%rsp
117 movq (_JB_PC * 8)(%r12),%r11
118 movq (_JB_R12 * 8)(%r12),%r12
119
120 testl %eax,%eax
121 jnz 1f
122 incl %eax
1231:
124 movq %r11,0(%rsp)
125 ret
126END(siglongjmp)
127
128 .globl longjmp
129 .equ longjmp, siglongjmp
130 .globl _longjmp
131 .equ _longjmp, siglongjmp