blob: 5977eab41006e4bb53e8a2c728a51533032a9dd6 [file] [log] [blame]
Serban Constantinescue2104882013-09-26 11:37:10 +01001/*
Elliott Hughes7dc2b7b2014-09-10 15:20:40 -07002 * Copyright (C) 2014 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>
Ryan Prichardfd8d6872020-04-17 19:46:51 -070030#include <private/bionic_asm_dwarf_exprs.h>
Pavel Chupin8eb8c392014-09-26 16:02:09 +040031
32// Offsets into struct sigcontext.
33#define OFFSET_EDI 16
34#define OFFSET_ESI 20
35#define OFFSET_EBP 24
36#define OFFSET_ESP 28
37#define OFFSET_EBX 32
38#define OFFSET_EDX 36
39#define OFFSET_ECX 40
40#define OFFSET_EAX 44
41#define OFFSET_EIP 56
42
43// Non-standard DWARF constants for the x86 registers.
44#define DW_x86_REG_EAX 0
45#define DW_x86_REG_ECX 1
46#define DW_x86_REG_EDX 2
47#define DW_x86_REG_EBX 3
Ryan Prichardfd8d6872020-04-17 19:46:51 -070048#define DW_x86_REG_ESP 4
Pavel Chupin8eb8c392014-09-26 16:02:09 +040049#define DW_x86_REG_EBP 5
50#define DW_x86_REG_ESI 6
51#define DW_x86_REG_EDI 7
52#define DW_x86_REG_EIP 8
53
Ryan Prichardfd8d6872020-04-17 19:46:51 -070054#define RESTORE_GPR(reg, extra_offset) \
55 m_cfi_breg_offset DW_x86_REG_ ## reg, \
56 DW_x86_REG_ESP, \
57 (OFFSET_ ## reg + (extra_offset));
Pavel Chupin8eb8c392014-09-26 16:02:09 +040058
Ryan Prichardfd8d6872020-04-17 19:46:51 -070059// Restoring ESP is unnecessary as the unwinder simply uses the CFA value.
60#define RESTORE_GPRS(extra_offset) \
61 m_cfi_def_cfa_deref DW_x86_REG_ESP, (OFFSET_ESP + (extra_offset)); \
62 RESTORE_GPR(EDI, extra_offset) \
63 RESTORE_GPR(ESI, extra_offset) \
64 RESTORE_GPR(EBP, extra_offset) \
65 RESTORE_GPR(EBX, extra_offset) \
66 RESTORE_GPR(EDX, extra_offset) \
67 RESTORE_GPR(ECX, extra_offset) \
68 RESTORE_GPR(EAX, extra_offset) \
69 RESTORE_GPR(EIP, extra_offset) \
Pavel Chupin8eb8c392014-09-26 16:02:09 +040070
Ryan Prichardfd8d6872020-04-17 19:46:51 -070071 .text
Pavel Chupin8eb8c392014-09-26 16:02:09 +040072
Ryan Prichardfd8d6872020-04-17 19:46:51 -070073 .cfi_startproc
74 .cfi_signal_frame
75 RESTORE_GPRS(4)
76 nop // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop.
77ENTRY_PRIVATE_NO_DWARF(__restore)
Elliott Hughes7dc2b7b2014-09-10 15:20:40 -070078 popl %eax
Ryan Prichardfd8d6872020-04-17 19:46:51 -070079 RESTORE_GPRS(0)
Elliott Hughes7dc2b7b2014-09-10 15:20:40 -070080 movl $__NR_sigreturn, %eax
81 int $0x80
82END(__restore)
Pavel Chupin8eb8c392014-09-26 16:02:09 +040083
Ryan Prichardfd8d6872020-04-17 19:46:51 -070084 .cfi_startproc
85 .cfi_signal_frame
86 RESTORE_GPRS(160)
87 nop // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop.
88ENTRY_PRIVATE_NO_DWARF(__restore_rt)
Pavel Chupin8eb8c392014-09-26 16:02:09 +040089 movl $__NR_rt_sigreturn, %eax
90 int $0x80
Pavel Chupin8eb8c392014-09-26 16:02:09 +040091END(__restore_rt)