* gas/tc-avr.c: Add new devices
[deliverable/binutils-gdb.git] / gas / config / obj-coff-seh.h
1 /* seh pdata/xdata coff object file format
2 Copyright (C) 2009-2014 Free Software Foundation, Inc.
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
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
47 .seh_handler <handler>[,@unwind][,@except] (x64)
48 .seh_handler <handler>[,<handler_data>] (others)
49 .seh_handlerdata
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
57 .seh_savexmm
58 .seh_pushframe
59 */
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}, \
65 {"seh_pushreg", obj_coff_seh_pushreg, 0}, \
66 {"seh_savereg", obj_coff_seh_save, 1}, \
67 {"seh_savexmm", obj_coff_seh_save, 2}, \
68 {"seh_pushframe", obj_coff_seh_pushframe, 0}, \
69 {"seh_endprologue", obj_coff_seh_endprologue, 0}, \
70 {"seh_setframe", obj_coff_seh_setframe, 0}, \
71 {"seh_stackalloc", obj_coff_seh_stackalloc, 0}, \
72 {"seh_eh", obj_coff_seh_eh, 0}, \
73 {"seh_32", obj_coff_seh_32, 1}, \
74 {"seh_no32", obj_coff_seh_32, 0}, \
75 {"seh_handler", obj_coff_seh_handler, 0}, \
76 {"seh_handlerdata", obj_coff_seh_handlerdata, 0},
77
78 /* Type definitions. */
79
80 typedef struct seh_prologue_element
81 {
82 int code;
83 int info;
84 offsetT off;
85 symbolS *pc_addr;
86 } seh_prologue_element;
87
88 typedef struct seh_context
89 {
90 struct seh_context *next;
91
92 /* Initial code-segment. */
93 segT code_seg;
94 /* Function name. */
95 char *func_name;
96 /* BeginAddress. */
97 symbolS *start_addr;
98 /* EndAddress. */
99 symbolS *end_addr;
100 /* Unwind data. */
101 symbolS *xdata_addr;
102 /* PrologueEnd. */
103 symbolS *endprologue_addr;
104 /* ExceptionHandler. */
105 expressionS handler;
106 /* ExceptionHandlerData. (arm, mips) */
107 expressionS handler_data;
108
109 /* ARM .seh_eh directive seen. */
110 int handler_written;
111
112 /* WinCE specific data. */
113 int use_instruction_32;
114 /* Was record already processed. */
115 int done;
116
117 /* x64 flags for the xdata header. */
118 int handler_flags;
119 int subsection;
120
121 /* x64 framereg and frame offset information. */
122 int framereg;
123 int frameoff;
124
125 /* Information about x64 specific unwind data fields. */
126 int elems_count;
127 int elems_max;
128 seh_prologue_element *elems;
129 } seh_context;
130
131 typedef 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. */
139 static void obj_coff_seh_stackalloc (int);
140 static void obj_coff_seh_setframe (int);
141 static void obj_coff_seh_endprologue (int);
142 static void obj_coff_seh_save (int);
143 static void obj_coff_seh_pushreg (int);
144 static void obj_coff_seh_pushframe (int);
145 static void obj_coff_seh_endproc (int);
146 static void obj_coff_seh_eh (int);
147 static void obj_coff_seh_32 (int);
148 static void obj_coff_seh_proc (int);
149 static void obj_coff_seh_handler (int);
150 static void obj_coff_seh_handlerdata (int);
151
152 #define UNDSEC bfd_und_section_ptr
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.045581 seconds and 4 git commands to generate.