/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
57 by edam
added ulibc
1
/*	Copyright (C) 2004 Garrett A. Kajmowicz
2
3
	This file is part of the uClibc++ Library.
4
5
	This library is free software; you can redistribute it and/or
6
	modify it under the terms of the GNU Lesser General Public
7
	License as published by the Free Software Foundation; either
8
	version 2.1 of the License, or (at your option) any later version.
9
10
	This library is distributed in the hope that it will be useful,
11
	but WITHOUT ANY WARRANTY; without even the implied warranty of
12
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
	Lesser General Public License for more details.
14
15
	You should have received a copy of the GNU Lesser General Public
16
	License along with this library; if not, write to the Free Software
17
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
19
20
#include <exception>
21
#include <cstdlib>
22
#include <typeinfo>
23
24
#ifndef HEADER_ULC_SUPPORT
25
#define HEADER_ULC_SUPPORT 1
26
27
using namespace std;
28
29
//From C++ ABI spec
30
typedef enum {
31
	_URC_NO_REASON = 0,
32
	_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
33
	_URC_FATAL_PHASE2_ERROR = 2,
34
	_URC_FATAL_PHASE1_ERROR = 3,
35
	_URC_NORMAL_STOP = 4,
36
	_URC_END_OF_STACK = 5,
37
	_URC_HANDLER_FOUND = 6,
38
	_URC_INSTALL_CONTEXT = 7,
39
	_URC_CONTINUE_UNWIND = 8
40
} _Unwind_Reason_Code;
41
42
43
typedef void (*_Unwind_Exception_Cleanup_Fn)
44
	(_Unwind_Reason_Code reason, struct _Unwind_Exception *exc);
45
46
//The following definitions were grabbed from the gcc implementation
47
typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
48
typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
49
typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
50
typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
51
typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, struct _Unwind_Exception *);
52
53
typedef int _Unwind_Action;
54
static const _Unwind_Action _UA_SEARCH_PHASE = 1;
55
static const _Unwind_Action _UA_CLEANUP_PHASE = 2;
56
static const _Unwind_Action _UA_HANDLER_FRAME = 4;
57
static const _Unwind_Action _UA_FORCE_UNWIND = 8;
58
59
const _Unwind_Exception_Class __uclibcxx_exception_class = ((((((((
60
	_Unwind_Exception_Class) 'u' << 8 | (_Unwind_Exception_Class) 'l') << 8 
61
	| (_Unwind_Exception_Class) 'i') << 8 | (_Unwind_Exception_Class) 'b') << 8
62
	| (_Unwind_Exception_Class) 'C')<< 8 | (_Unwind_Exception_Class) '+') << 8 
63
	| (_Unwind_Exception_Class) '+') << 8 | (_Unwind_Exception_Class) '\0');
64
65
66
#define _UA_SEARCH_PHASE        1
67
#define _UA_CLEANUP_PHASE       2
68
#define _UA_HANDLER_FRAME       4
69
#define _UA_FORCE_UNWIND        8
70
#define _UA_END_OF_STACK        16
71
72
struct _Unwind_Exception{
73
        _Unwind_Exception_Class exception_class;		//Type of exception, eg ulibC++\0
74
        _Unwind_Exception_Cleanup_Fn exception_cleanup;		//Destructor if from diff runtime
75
        _Unwind_Word private_1;					//Don't touch at all!
76
        _Unwind_Word private_2;					//Don't touch at all!
77
} __attribute__((__aligned__));
78
79
80
//The following structure is system-dependent and defined by the compiler
81
//Thus it's definition was copied from the gcc 3.4.0 header files
82
struct _Unwind_Context;
83
//{
84
//	void *reg[DWARF_FRAME_REGISTERS+1];
85
//	void *cfa;
86
//	void *ra;
87
//	void *lsda;
88
//	struct dwarf_eh_bases bases;
89
//	_Unwind_Word args_size;
90
//};
91
92
93
94
_Unwind_Reason_Code _Unwind_RaiseException ( struct _Unwind_Exception *exception_object );
95
96
//_Unwind_ForcedUnwind 
97
98
typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
99
	(int version, _Unwind_Action actions,  _Unwind_Exception_Class exceptionClass,
100
	struct _Unwind_Exception *exceptionObject, 
101
	struct _Unwind_Context *context, void *stop_parameter );
102
103
_Unwind_Reason_Code _Unwind_ForcedUnwind ( 
104
	struct _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop,
105
	void *stop_parameter );
106
107
void _Unwind_Resume (struct _Unwind_Exception *exception_object);
108
void _Unwind_DeleteException (struct _Unwind_Exception *exception_object);
109
110
_Unwind_Word _Unwind_GetGR (struct _Unwind_Context *context, int index);
111
void _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word);
112
113
_Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *context);
114
void _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr new_value);
115
116
_Unwind_Ptr _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context);
117
_Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *context);
118
119
_Unwind_Reason_Code (*__personality_routine)
120
	(int version,					//Should be 1
121
	_Unwind_Action actions,				//Actions the routine will perform (bitmask)
122
	_Unwind_Exception_Class exceptionClass,		//Type of exception - vendor is high 4 bytes
123
	struct _Unwind_Exception *exceptionObject,	//Points to exception header
124
	struct _Unwind_Context *context);		//Unwinder state information
125
126
127
/*The following part is the Level II ABI which is required for compatability*/
128
//This might be the only stuff that *I* need to implement
129
130
struct __cxa_exception { 
131
	std::type_info *exceptionType;		//Type of thrown exception
132
	void (*exceptionDestructor) (void *); 	//Pointer to the destructor
133
	unexpected_handler unexpectedHandler;	//Unexpected handler to use
134
	terminate_handler terminateHandler;	//Terminate handle to use
135
	__cxa_exception *nextException;		//per thread linked list
136
137
	int handlerCount;			//How many handlers have caught this
138
	int handlerSwitchValue;			
139
	const char *actionRecord;
140
	const char *languageSpecificData;
141
	void *catchTemp;
142
	void *adjustedPtr;
143
144
	_Unwind_Exception unwindHeader;
145
};
146
147
struct __cxa_eh_globals {
148
	__cxa_exception *caughtExceptions;
149
	unsigned int uncaughtExceptions;
150
};
151
152
extern "C" __cxa_eh_globals *__cxa_get_globals(void);	//Return ptr to the eh_globals object for current thread
153
extern "C" __cxa_eh_globals *__cxa_get_globals_fast(void);	//Same as above, assumes that above called at least once
154
155
extern "C" void *__cxa_allocate_exception(size_t thrown_size);	//Allocate space for exception plus header
156
extern "C" void __cxa_free_exception(void *thrown_exception);	//Free space allocated from the above
157
158
extern "C" void __cxa_throw (void *thrown_exception, 	//This is the actual throw call
159
//	std::type_info *tinfo, 			//Type of object
160
	void * tinfo, 			//Type of object
161
	void (*dest) (void *) );		//Pointer to destructor destroy object
162
163
164
#endif
165
166
167