Support gdb.asm/asm-source.exp on powerpc64le
[deliverable/binutils-gdb.git] / gas / config / obj-coff-seh.h
CommitLineData
284e0531 1/* seh pdata/xdata coff object file format
4b95cf5c 2 Copyright (C) 2009-2014 Free Software Foundation, Inc.
284e0531
KT
3
4 This file is part of GAS.
5
6 GAS 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, or (at your option)
9 any later version.
10
11 GAS 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 GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
987499b2
KT
21/* Short overview:
22 There are at the moment three different function entry formats preset.
23 The first is the MIPS one. The second version
24 is for ARM, PPC, SH3, and SH4 mainly for Windows CE.
25 The third is the IA64 and x64 version. Note, the IA64 isn't implemented yet,
26 but to find information about it, please see specification about IA64 on
27 http://download.intel.com/design/Itanium/Downloads/245358.pdf file.
28
29 The first version has just entries in the pdata section: BeginAddress,
30 EndAddress, ExceptionHandler, HandlerData, and PrologueEndAddress. Each
31 value is a pointer to the corresponding data and has size of 4 bytes.
32
33 The second variant has the following entries in the pdata section.
34 BeginAddress, PrologueLength (8 bits), EndAddress (22 bits),
35 Use-32-bit-instruction (1 bit), and Exception-Handler-Exists (1 bit).
36 If the FunctionLength is zero, or the Exception-Handler-Exists bit
37 is true, a PDATA_EH block is placed directly before function entry.
38
39 The third version has a function entry block of BeginAddress (RVA),
40 EndAddress (RVA), and UnwindData (RVA). The description of the
41 prologue, excepetion-handler, and additional SEH data is stored
42 within the UNWIND_DATA field in the xdata section.
43
44 The pseudos:
45 .seh_proc <fct_name>
46 .seh_endprologue
681418c2
RH
47 .seh_handler <handler>[,@unwind][,@except] (x64)
48 .seh_handler <handler>[,<handler_data>] (others)
49 .seh_handlerdata
987499b2
KT
50 .seh_eh
51 .seh_32/.seh_no32
52 .seh_endproc
53 .seh_setframe <reg>,<offset>
54 .seh_stackalloc
55 .seh_pushreg
56 .seh_savereg
987499b2
KT
57 .seh_savexmm
58 .seh_pushframe
681418c2 59*/
987499b2
KT
60
61/* architecture specific pdata/xdata handling. */
62#define SEH_CMDS \
63 {"seh_proc", obj_coff_seh_proc, 0}, \
64 {"seh_endproc", obj_coff_seh_endproc, 0}, \
681418c2
RH
65 {"seh_pushreg", obj_coff_seh_pushreg, 0}, \
66 {"seh_savereg", obj_coff_seh_save, 1}, \
987499b2 67 {"seh_savexmm", obj_coff_seh_save, 2}, \
681418c2 68 {"seh_pushframe", obj_coff_seh_pushframe, 0}, \
987499b2
KT
69 {"seh_endprologue", obj_coff_seh_endprologue, 0}, \
70 {"seh_setframe", obj_coff_seh_setframe, 0}, \
681418c2 71 {"seh_stackalloc", obj_coff_seh_stackalloc, 0}, \
987499b2
KT
72 {"seh_eh", obj_coff_seh_eh, 0}, \
73 {"seh_32", obj_coff_seh_32, 1}, \
74 {"seh_no32", obj_coff_seh_32, 0}, \
681418c2
RH
75 {"seh_handler", obj_coff_seh_handler, 0}, \
76 {"seh_handlerdata", obj_coff_seh_handlerdata, 0},
987499b2
KT
77
78/* Type definitions. */
79
80typedef struct seh_prologue_element
81{
681418c2
RH
82 int code;
83 int info;
84 offsetT off;
987499b2 85 symbolS *pc_addr;
987499b2
KT
86} seh_prologue_element;
87
987499b2
KT
88typedef struct seh_context
89{
90 struct seh_context *next;
681418c2 91
2d7f4929
KT
92 /* Initial code-segment. */
93 segT code_seg;
987499b2
KT
94 /* Function name. */
95 char *func_name;
96 /* BeginAddress. */
987499b2 97 symbolS *start_addr;
987499b2 98 /* EndAddress. */
987499b2 99 symbolS *end_addr;
681418c2
RH
100 /* Unwind data. */
101 symbolS *xdata_addr;
987499b2 102 /* PrologueEnd. */
987499b2 103 symbolS *endprologue_addr;
987499b2 104 /* ExceptionHandler. */
681418c2
RH
105 expressionS handler;
106 /* ExceptionHandlerData. (arm, mips) */
107 expressionS handler_data;
108
109 /* ARM .seh_eh directive seen. */
987499b2 110 int handler_written;
681418c2 111
987499b2
KT
112 /* WinCE specific data. */
113 int use_instruction_32;
681418c2
RH
114 /* Was record already processed. */
115 int done;
116
117 /* x64 flags for the xdata header. */
118 int handler_flags;
119 int subsection;
987499b2 120
987499b2
KT
121 /* x64 framereg and frame offset information. */
122 int framereg;
681418c2
RH
123 int frameoff;
124
987499b2 125 /* Information about x64 specific unwind data fields. */
681418c2
RH
126 int elems_count;
127 int elems_max;
987499b2 128 seh_prologue_element *elems;
987499b2
KT
129} seh_context;
130
131typedef enum seh_kind {
132 seh_kind_unknown = 0,
133 seh_kind_mips = 1, /* Used for MIPS and x86 pdata generation. */
134 seh_kind_arm = 2, /* Used for ARM, PPC, SH3, and SH4 pdata (PDATA_EH) generation. */
135 seh_kind_x64 = 3 /* Used for IA64 and x64 pdata/xdata generation. */
136} seh_kind;
137
138/* Forward declarations. */
681418c2 139static void obj_coff_seh_stackalloc (int);
987499b2
KT
140static void obj_coff_seh_setframe (int);
141static void obj_coff_seh_endprologue (int);
681418c2
RH
142static void obj_coff_seh_save (int);
143static void obj_coff_seh_pushreg (int);
144static void obj_coff_seh_pushframe (int);
987499b2
KT
145static void obj_coff_seh_endproc (int);
146static void obj_coff_seh_eh (int);
147static void obj_coff_seh_32 (int);
148static void obj_coff_seh_proc (int);
149static void obj_coff_seh_handler (int);
681418c2 150static void obj_coff_seh_handlerdata (int);
987499b2 151
45dfa85a 152#define UNDSEC bfd_und_section_ptr
284e0531
KT
153
154/* Check if x64 UNW_... macros are already defined. */
155#ifndef PEX64_FLAG_NHANDLER
156/* We can't include here coff/pe.h header. So we have to copy macros
157 from coff/pe.h here. */
158#define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
159#define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
160
161/* The unwind info. */
162#define UNW_FLAG_NHANDLER 0
163#define UNW_FLAG_EHANDLER 1
164#define UNW_FLAG_UHANDLER 2
165#define UNW_FLAG_FHANDLER 3
166#define UNW_FLAG_CHAININFO 4
167
168#define UNW_FLAG_MASK 0x1f
169
170/* The unwind codes. */
171#define UWOP_PUSH_NONVOL 0
172#define UWOP_ALLOC_LARGE 1
173#define UWOP_ALLOC_SMALL 2
174#define UWOP_SET_FPREG 3
175#define UWOP_SAVE_NONVOL 4
176#define UWOP_SAVE_NONVOL_FAR 5
177#define UWOP_SAVE_XMM 6
178#define UWOP_SAVE_XMM_FAR 7
179#define UWOP_SAVE_XMM128 8
180#define UWOP_SAVE_XMM128_FAR 9
181#define UWOP_PUSH_MACHFRAME 10
182
183#define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
184#define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
185#define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
186#define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
187#define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
188 ((((VAL) + 1) & ~1) * 2)
189
190#define PEX64_OFFSET_TO_UNWIND_CODE 0x4
191
192#define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
193 (PEX64_OFFSET_TO_UNWIND_CODE + \
194 PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
195
196#define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
197 (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
198
199#define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
200 (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
201 PEX64_SCOPE_ENTRY_SIZE * (IDX))
202
203#endif
204
This page took 0.214679 seconds and 4 git commands to generate.