1 /*
2                 C++ Library
3 
4         Copyright 1983-2009 Green Hills Software,Inc.
5 
6     This program is the property of Green Hills Software, Inc,
7     its contents are proprietary information and no part of it
8     is to be disclosed to anyone except employees of Green Hills
9     Software, Inc., or as agreed in writing signed by the President
10     of Green Hills Software, Inc.
11 */
12 
13 /*
14  * This file defines the _main function.  _main calls the constructor functions
15  * in the global _ctors table of function pointers.
16  *
17  * This file will not be linked into C++ shared objects or DLLs on Linux,
18  * Solaris, or Windows.  It's important that _main is not exported from a
19  * shared object on these targets.  The _ctors global array should also not be
20  * exported from a shared object.
21  */
22 
23 #include <stdlib.h>
24 
25 typedef void (*vfpt)();
26 extern vfpt _ctors[];
27 void __call_dtors(void);
28 
29 #if defined(GHS_TDEH)
30 // trg/ppc/default.gpj sets USE_TDEH which causes
31 // src/edg/lib_src/lib*edge.gpj and integrity_edg_objs.gpj to set -DGHS_TDEH.
32 // rtos/intlib/sharedcppobjects.c is duplicated from here.  The
33 // src/configuration/defaults/bld_rules/ppc.bod file has a GHS_SUPPORTS_TDEH
34 // which allows INTEGRITY to use #ifdef GHS_TDEH, but this usage is dead now.
35 #pragma weak __ghs_uw_reg_eh_table
36 #pragma weak __ghsbegin_ghs_tdeh_table
37 #pragma weak __ghsend_ghs_tdeh_table
38 extern void* __ghsbegin_ghs_tdeh_table;
39 extern void* __ghsend_ghs_tdeh_table;
40 extern "C" void __ghs_uw_reg_eh_table(void* begtable, void* endtable);
41 #endif
42 
43 /* Initialize the static constructors using the _ctors array.  Set up the call
44    to __call_dtors at the exit. */
_main(void)45 extern "C" void _main(void)
46 {
47     int i = 0;
48     static int been_here = 0;
49 
50     if (been_here)
51 	return;
52     been_here = 1;
53 
54 /*-----------------------------*/
55 /* initialize TDEH             */
56 /*-----------------------------*/
57 #if defined(GHS_TDEH)
58 #if defined(__ghs_pic)
59     static void (* tdeh_init_funcp)(void*, void*) = __ghs_uw_reg_eh_table;
60     if (tdeh_init_funcp)
61 #else  /* defined(__ghs_pic) */
62     if (__ghs_uw_reg_eh_table)
63 #endif /* defined(__ghs_pic) */
64 	__ghs_uw_reg_eh_table(&__ghsbegin_ghs_tdeh_table, &__ghsend_ghs_tdeh_table);
65 #endif
66 
67     atexit(__call_dtors);
68     while (_ctors[i])
69         (*_ctors[i++])();
70 }
71