OSDN Git Service

Make -fdata-sections work for AVR port.
[pf3gnuchains/gcc-fork.git] / gcc / unwind.h
1 /* Exception handling and frame unwind runtime interface routines.
2    Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
6    GCC is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GCC is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GCC; see the file COPYING.  If not, write to the Free
18    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19    02111-1307, USA.  */
20
21 /* As a special exception, if you include this header file into source
22    files compiled by GCC, this header file does not by itself cause
23    the resulting executable to be covered by the GNU General Public
24    License.  This exception does not however invalidate any other
25    reasons why the executable file might be covered by the GNU General
26    Public License.  */
27
28 /* This is derived from the C++ ABI for IA-64.  Where we diverge
29    for cross-architecture compatibility are noted with "@@@".  */
30
31 #ifndef _UNWIND_H
32 #define _UNWIND_H
33
34 #pragma GCC visibility push(default)
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* Level 1: Base ABI  */
41
42 /* @@@ The IA-64 ABI uses uint64 throughout.  Most places this is
43    inefficient for 32-bit and smaller machines.  */
44 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
45 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
46 #if defined(__ia64__) && defined(__hpux__)
47 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
48 #else
49 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
50 #endif
51 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
52
53 /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
54    consumer of an exception.  We'll go along with this for now even on
55    32-bit machines.  We'll need to provide some other option for
56    16-bit machines and for machines with > 8 bits per byte.  */
57 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
58
59 /* The unwind interface uses reason codes in several contexts to
60    identify the reasons for failures or other actions.  */
61 typedef enum
62 {
63   _URC_NO_REASON = 0,
64   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
65   _URC_FATAL_PHASE2_ERROR = 2,
66   _URC_FATAL_PHASE1_ERROR = 3,
67   _URC_NORMAL_STOP = 4,
68   _URC_END_OF_STACK = 5,
69   _URC_HANDLER_FOUND = 6,
70   _URC_INSTALL_CONTEXT = 7,
71   _URC_CONTINUE_UNWIND = 8
72 } _Unwind_Reason_Code;
73
74
75 /* The unwind interface uses a pointer to an exception header object
76    as its representation of an exception being thrown. In general, the
77    full representation of an exception object is language- and
78    implementation-specific, but it will be prefixed by a header
79    understood by the unwind interface.  */
80
81 struct _Unwind_Exception;
82
83 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
84                                               struct _Unwind_Exception *);
85
86 struct _Unwind_Exception
87 {
88   _Unwind_Exception_Class exception_class;
89   _Unwind_Exception_Cleanup_Fn exception_cleanup;
90   _Unwind_Word private_1;
91   _Unwind_Word private_2;
92
93   /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
94      Taking that literally does not make much sense generically.  Instead we
95      provide the maximum alignment required by any type for the machine.  */
96 } __attribute__((__aligned__));
97
98
99 /* The ACTIONS argument to the personality routine is a bitwise OR of one
100    or more of the following constants.  */
101 typedef int _Unwind_Action;
102
103 #define _UA_SEARCH_PHASE        1
104 #define _UA_CLEANUP_PHASE       2
105 #define _UA_HANDLER_FRAME       4
106 #define _UA_FORCE_UNWIND        8
107 #define _UA_END_OF_STACK        16
108
109 /* This is an opaque type used to refer to a system-specific data
110    structure used by the system unwinder. This context is created and
111    destroyed by the system, and passed to the personality routine
112    during unwinding.  */
113 struct _Unwind_Context;
114
115 /* Raise an exception, passing along the given exception object.  */
116 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
117
118 /* Raise an exception for forced unwinding.  */
119
120 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
121      (int, _Unwind_Action, _Unwind_Exception_Class,
122       struct _Unwind_Exception *, struct _Unwind_Context *, void *);
123
124 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
125                                                  _Unwind_Stop_Fn,
126                                                  void *);
127
128 /* Helper to invoke the exception_cleanup routine.  */
129 extern void _Unwind_DeleteException (struct _Unwind_Exception *);
130
131 /* Resume propagation of an existing exception.  This is used after
132    e.g. executing cleanup code, and not to implement rethrowing.  */
133 extern void _Unwind_Resume (struct _Unwind_Exception *);
134
135 /* @@@ Resume propagation of an FORCE_UNWIND exception, or to rethrow
136    a normal exception that was handled.  */
137 extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
138
139 /* @@@ Use unwind data to perform a stack backtrace.  The trace callback
140    is called for every stack frame in the call chain, but no cleanup
141    actions are performed.  */
142 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
143      (struct _Unwind_Context *, void *);
144
145 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
146
147 /* These functions are used for communicating information about the unwind
148    context (i.e. the unwind descriptors and the user register state) between
149    the unwind library and the personality routine and landing pad.  Only
150    selected registers maybe manipulated.  */
151
152 extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
153 extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
154
155 extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
156 extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
157
158 /* @@@ Retrieve the CFA of the given context.  */
159 extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
160
161 extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
162
163 extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
164
165
166 /* The personality routine is the function in the C++ (or other language)
167    runtime library which serves as an interface between the system unwind
168    library and language-specific exception handling semantics.  It is
169    specific to the code fragment described by an unwind info block, and
170    it is always referenced via the pointer in the unwind info block, and
171    hence it has no ABI-specified name.
172
173    Note that this implies that two different C++ implementations can
174    use different names, and have different contents in the language
175    specific data area.  Moreover, that the language specific data
176    area contains no version info because name of the function invoked
177    provides more effective versioning by detecting at link time the
178    lack of code to handle the different data format.  */
179
180 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
181      (int, _Unwind_Action, _Unwind_Exception_Class,
182       struct _Unwind_Exception *, struct _Unwind_Context *);
183
184 /* @@@ The following alternate entry points are for setjmp/longjmp
185    based unwinding.  */
186
187 struct SjLj_Function_Context;
188 extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
189 extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
190
191 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
192      (struct _Unwind_Exception *);
193 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
194      (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
195 extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
196 extern _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *);
197
198 /* @@@ The following provide access to the base addresses for text
199    and data-relative addressing in the LDSA.  In order to stay link
200    compatible with the standard ABI for IA-64, we inline these.  */
201
202 #ifdef __ia64__
203 #include <stdlib.h>
204
205 static inline _Unwind_Ptr
206 _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
207 {
208   /* The GP is stored in R1.  */
209   return _Unwind_GetGR (_C, 1);
210 }
211
212 static inline _Unwind_Ptr
213 _Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__)))
214 {
215   abort ();
216   return 0;
217 }
218
219 /* @@@ Retrieve the Backing Store Pointer of the given context.  */
220 extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
221 #else
222 extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
223 extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
224 #endif
225
226 /* @@@ Given an address, return the entry point of the function that
227    contains it.  */
228 extern void * _Unwind_FindEnclosingFunction (void *pc);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #pragma GCC visibility pop
235
236 #endif /* unwind.h */