00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "defaults.h"
00033 #include <stddef.h>
00034 #include "unwind-dw2-fde.h"
00035 #include "gbl-ctors.h"
00036
00037
00038 #define STATIC static
00039
00040 #ifdef __FRV_UNDERSCORE__
00041 #define UNDERSCORE "_"
00042 #else
00043 #define UNDERSCORE ""
00044 #endif
00045
00046 #define INIT_SECTION_NEG_ONE(SECTION, FLAGS, NAME) \
00047 __asm__ (".section " SECTION "," FLAGS "\n\t" \
00048 ".globl " UNDERSCORE NAME "\n\t" \
00049 ".type " UNDERSCORE NAME ",@object\n\t" \
00050 ".p2align 2\n" \
00051 UNDERSCORE NAME ":\n\t" \
00052 ".word -1\n\t" \
00053 ".previous")
00054
00055 #define INIT_SECTION(SECTION, FLAGS, NAME) \
00056 __asm__ (".section " SECTION "," FLAGS "\n\t" \
00057 ".globl " UNDERSCORE NAME "\n\t" \
00058 ".type " UNDERSCORE NAME ",@object\n\t" \
00059 ".p2align 2\n" \
00060 UNDERSCORE NAME ":\n\t" \
00061 ".previous")
00062
00063
00064
00065
00066 INIT_SECTION_NEG_ONE (".ctors", "\"aw\"", "__CTOR_LIST__");
00067 INIT_SECTION_NEG_ONE (".dtors", "\"aw\"", "__DTOR_LIST__");
00068
00069
00070
00071
00072 INIT_SECTION (".eh_frame", "\"aw\"", "__EH_FRAME_BEGIN__");
00073
00074 #if ! __FRV_FDPIC__
00075
00076
00077
00078
00079 INIT_SECTION (".rofixup", "\"a\"", "__ROFIXUP_LIST__");
00080 #endif
00081
00082 extern void __frv_register_eh(void) __attribute__((__constructor__));
00083 extern void __frv_deregister_eh(void) __attribute__((__destructor__));
00084
00085 extern func_ptr __EH_FRAME_BEGIN__[];
00086
00087
00088 void
00089 __frv_register_eh (void)
00090 {
00091 static struct object object;
00092 if (__register_frame_info)
00093 __register_frame_info (__EH_FRAME_BEGIN__, &object);
00094 }
00095
00096
00097
00098
00099
00100 void
00101 __frv_deregister_eh (void)
00102 {
00103 static int completed = 0;
00104
00105 if (completed)
00106 return;
00107
00108 if (__deregister_frame_info)
00109 __deregister_frame_info (__EH_FRAME_BEGIN__);
00110
00111 completed = 1;
00112 }
00113
00114
00115 void
00116 __do_global_dtors (void)
00117 {
00118 static func_ptr *p = __DTOR_LIST__ + 1;
00119 while (*p)
00120 {
00121 p++;
00122 (*(p-1)) ();
00123 }
00124 }
00125
00126
00127 void
00128 __do_global_ctors (void)
00129 {
00130 unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
00131 unsigned i;
00132
00133 if (nptrs == (unsigned long)-1)
00134 for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
00135
00136 for (i = nptrs; i >= 1; i--)
00137 __CTOR_LIST__[i] ();
00138
00139 atexit (__do_global_dtors);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 void
00151 __main (void)
00152 {
00153
00154 static int initialized;
00155 if (! initialized)
00156 {
00157 initialized = 1;
00158 __do_global_ctors ();
00159 }
00160 }