]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - include/mach-o/unwind.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / include / mach-o / unwind.h
CommitLineData
167e1c1f 1/* Mach-O compact unwind encoding.
a2c58332 2 Copyright (C) 2014-2022 Free Software Foundation, Inc.
167e1c1f
TG
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21#ifndef _MACH_O_UNWIND_H
22#define _MACH_O_UNWIND_H
23
24/* Encodings bits for all cpus. */
25#define MACH_O_UNWIND_IS_NOT_FUNCTION_START 0x80000000
26#define MACH_O_UNWIND_HAS_LSDA 0x40000000
27#define MACH_O_UNWIND_PERSONALITY_MASK 0x30000000
28#define MACH_O_UNWIND_PERSONALITY_SHIFT 28
29
30/* Encodings for x86-64. */
31
32/* Kind of encoding (4 bits). */
33#define MACH_O_UNWIND_X86_64_MODE_MASK 0x0f000000
34
35/* Frame is RBP based, using the standard sequence: push %rbp; mov %rsp, %rbp.
36 Non-volatile registers must be saved in the stack starting at %rbp-8 to
37 %rbp-2040 (offset is encoded in offset bits * 8). Registers saved are
38 encoded in registers bits, 3 bits per register. */
39#define MACH_O_UNWIND_X86_64_MODE_RBP_FRAME 0x01000000
84f9f8c3 40#define MACH_O_UNWIND_X86_64_RBP_FRAME_REGISTERS 0x00007FFF
167e1c1f
TG
41#define MACH_O_UNWIND_X86_64_RBP_FRAME_OFFSET 0x00FF0000
42
43/* Frameless function, with a small stack size. */
44#define MACH_O_UNWIND_X86_64_MODE_STACK_IMMD 0x02000000
45#define MACH_O_UNWIND_X86_64_FRAMELESS_STACK_SIZE 0x00FF0000
46#define MACH_O_UNWIND_X86_64_FRAMELESS_REG_COUNT 0x00001C00
47#define MACH_O_UNWIND_X86_64_FRAMELESS_REG_PERMUTATION 0x000003FF
48
49/* Frameless function, with a larger stack size. The stack size is the sum
50 of the X in subq $X,%rsp (address of X is at function + stack size bits)
51 and stack adjust. */
52#define MACH_O_UNWIND_X86_64_MODE_STACK_IND 0x03000000
53#define MACH_O_UNWIND_X86_64_FRAMELESS_STACK_ADJUST 0x0000E000
54
55/* Use dwarf. */
56#define MACH_O_UNWIND_X86_64_MODE_DWARF 0x04000000
57#define MACH_O_UNWIND_X86_64_DWARF_SECTION_OFFSET 0x00ffffff
58
59/* Registers. */
60#define MACH_O_UNWIND_X86_64_REG_NONE 0
61#define MACH_O_UNWIND_X86_64_REG_RBX 1
62#define MACH_O_UNWIND_X86_64_REG_R12 2
63#define MACH_O_UNWIND_X86_64_REG_R13 3
64#define MACH_O_UNWIND_X86_64_REG_R14 4
65#define MACH_O_UNWIND_X86_64_REG_R15 5
66#define MACH_O_UNWIND_X86_64_REG_RBP 6
67
68/* Encodings for x86 (almot the same as x86-64). */
69
70/* Kind of encoding (4 bits). */
71#define MACH_O_UNWIND_X86_MODE_MASK 0x0f000000
72
73/* Frame is EBP based, using the standard sequence: push %ebp; mov %esp, %ebp.
74 Non-volatile registers must be saved in the stack starting at %ebp-4 to
75 %ebp-240 (offset is encoded in offset bits * 4). Registers saved are
76 encoded in registers bits, 3 bits per register. */
77#define MACH_O_UNWIND_X86_MODE_EBP_FRAME 0x01000000
84f9f8c3 78#define MACH_O_UNWIND_X86_EBP_FRAME_REGISTERS 0x00007FFF
167e1c1f
TG
79#define MACH_O_UNWIND_X86_EBP_FRAME_OFFSET 0x00FF0000
80
81/* Frameless function, with a small stack size. */
82#define MACH_O_UNWIND_X86_MODE_STACK_IMMD 0x02000000
83#define MACH_O_UNWIND_X86_FRAMELESS_STACK_SIZE 0x00FF0000
84#define MACH_O_UNWIND_X86_FRAMELESS_REG_COUNT 0x00001C00
85#define MACH_O_UNWIND_X86_FRAMELESS_REG_PERMUTATION 0x000003FF
86
87/* Frameless function, with a larger stack size. The stack size is the sum
88 of the X in subq $X,%esp (address of X is at function + stack size bits)
89 and stack adjust. */
90#define MACH_O_UNWIND_X86_MODE_STACK_IND 0x03000000
91#define MACH_O_UNWIND_X86_FRAMELESS_STACK_ADJUST 0x0000E000
92
93/* Use dwarf. */
94#define MACH_O_UNWIND_X86_MODE_DWARF 0x04000000
95#define MACH_O_UNWIND_X86_DWARF_SECTION_OFFSET 0x00ffffff
96
97/* Registers. */
98#define MACH_O_UNWIND_X86_REG_NONE 0
99#define MACH_O_UNWIND_X86_REG_EBX 1
100#define MACH_O_UNWIND_X86_REG_ECX 2
101#define MACH_O_UNWIND_X86_REG_EDX 3
102#define MACH_O_UNWIND_X86_REG_EDI 4
103#define MACH_O_UNWIND_X86_REG_ESI 5
104#define MACH_O_UNWIND_X86_REG_EBP 6
105
c25b1ab6
TG
106/* Encodings for arm64. */
107
108#define MACH_O_UNWIND_ARM64_MODE_MASK 0x0f000000
109
110/* Leaf function: FP/LR are *not* saved, none or some non-volatile registers
111 are saved, stack is allocated. The size of the frame (register saved and
112 memory) is encoded in STACK_SIZE in 16 byte units. */
113#define MACH_O_UNWIND_ARM64_MODE_FRAMELESS 0x02000000
114
115#define MACH_O_UNWIND_ARM64_MODE_DWARF 0x03000000
116
117/* Standard frame: FP/LR are pushed, SP is copied to FP, then non-volatile
118 registers are saved. */
119#define MACH_O_UNWIND_ARM64_MODE_FRAME 0x04000000
120
121/* Registers (for FRAME). */
122#define MACH_O_UNWIND_ARM64_FRAME_X19_X20_PAIR 0x00000001
123#define MACH_O_UNWIND_ARM64_FRAME_X21_X22_PAIR 0x00000002
124#define MACH_O_UNWIND_ARM64_FRAME_X23_X24_PAIR 0x00000004
125#define MACH_O_UNWIND_ARM64_FRAME_X25_X26_PAIR 0x00000008
126#define MACH_O_UNWIND_ARM64_FRAME_X27_X28_PAIR 0x00000010
127#define MACH_O_UNWIND_ARM64_FRAME_D8_D9_PAIR 0x00000100
128#define MACH_O_UNWIND_ARM64_FRAME_D10_D11_PAIR 0x00000200
129#define MACH_O_UNWIND_ARM64_FRAME_D12_D13_PAIR 0x00000400
130#define MACH_O_UNWIND_ARM64_FRAME_D14_D15_PAIR 0x00000800
131
132#define MACH_O_UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK 0x00fff000
133#define MACH_O_UNWIND_ARM64_DWARF_SECTION_OFFSET 0x00ffffff
134
167e1c1f
TG
135/* Entry in object file (in __LD,__compact_unwind section). */
136
137struct mach_o_compact_unwind_32
138{
139 unsigned char start[4];
140 unsigned char length[4];
141 unsigned char encoding[4];
142 unsigned char personality[4];
143 unsigned char lsda[4];
144};
145
146struct mach_o_compact_unwind_64
147{
148 unsigned char start[8];
149 unsigned char length[4];
150 unsigned char encoding[4];
965b60c9 151 unsigned char personality[8];
167e1c1f
TG
152 unsigned char lsda[8];
153};
154
155/* Header in images (in __TEXT,__unwind_info). */
156
157#define MACH_O_UNWIND_SECTION_VERSION 1 /* Current verion in header. */
158struct mach_o_unwind_info_header
159{
160 unsigned char version[4]; /* Currently MACH_O_UNWIND_SECTION_VERSION. */
161 unsigned char encodings_array_offset[4];
162 unsigned char encodings_array_count[4];
163 unsigned char personality_array_offset[4];
164 unsigned char personality_array_count[4];
165 unsigned char index_offset[4];
166 unsigned char index_count[4];
167 /* Followed by:
168 - encodings array
169 These are the encodings shared, for index < encoding_array_count
170 - personality array
171 count given by personality_array_count
172 - index entries
173 count given by index_count
174 - lsda index entries
175 last offset given by lsda offset of last index_entry.
176 */
177};
178
179struct mach_o_unwind_index_entry
180{
181 unsigned char function_offset[4];
182 unsigned char second_level_offset[4];
183 unsigned char lsda_index_offset[4];
184};
185
186struct mach_o_unwind_lsda_index_entry
187{
188 unsigned char function_offset[4];
189 unsigned char lsda_offset[4];
190};
191
192/* Second level index pages. */
193
194#define MACH_O_UNWIND_SECOND_LEVEL_REGULAR 2
195struct mach_o_unwind_regular_second_level_page_header
196{
197 unsigned char kind[4];
198 unsigned char entry_page_offset[2];
199 unsigned char entry_count[2];
200 /* Array of entries. */
201};
202
203struct mach_o_unwind_regular_second_level_entry
204{
205 unsigned char function_offset[4];
206 unsigned char encoding[4];
207};
208
209#define MACH_O_UNWIND_SECOND_LEVEL_COMPRESSED 3
210struct mach_o_unwind_compressed_second_level_page_header
211{
212 unsigned char kind[4];
213 unsigned char entry_page_offset[2];
214 unsigned char entry_count[2];
215 unsigned char encodings_offset[2];
216 unsigned char encodings_count[2];
217 /* Followed by entries array (one word, see below). */
218 /* Followed by (non-common) encodings array. */
219};
220
221/* Compressed entries are one word, containing function offset and encoding
222 index. */
223#define MACH_O_UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(en) \
224 ((en) & 0x00FFFFFF)
225#define MACH_O_UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(en) \
226 (((en) >> 24) & 0xFF)
227
228#endif /* _MACH_O_UNWIND_H */