source: rtems/c/src/lib/libbsp/unix/posix/startup/rtems-ctor.cc @ 550d13e

4.104.114.84.95
Last change on this file since 550d13e was 550d13e, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/06 at 22:23:46

2006-10-30 Joel Sherrill <joel@…>

  • startup/rtems-ctor.cc: Conditionally disable non-GCC code.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  rtems-ctor.cc
3 *
4 *  Description:
5 *  This file exists solely to (try to) ensure RTEMS is initialized
6 *      before any global constructors are run.
7 *
8 *  The problem:
9 *      Global constructors might reasonably expect that new() will
10 *      work, but since new() uses malloc() which uses RTEMS regions,
11 *      it can not be called until after initialize_executive().
12 *
13 *      Global constructors are called in GNU systems one of 2 ways:
14 *
15 *              an "invisible" call to __main() inserted by compiler
16 *              This __main() calls __do_global_ctors() which
17 *              walks thru the table and calls all global
18 *              constructors.
19 *
20 *       or -
21 *              A special section is put into the linked binary.  The
22 *              system startup code knows to run the constructors in
23 *              this special section before calling main().
24 *
25 *      By making RTEMS initialization a constructor, we avoid having
26 *      too much about all this.  All we have to guarantee is that
27 *      this constructor is the first one run.
28 *
29 *
30 *  So for the first case above, this is what happens
31 *
32 *    host crt0
33 *      main()
34 *          __main()
35 *              __do_global_ctors()
36 *                  bsp_start()
37 *                      init_executive_early()
38 *                  <<any other constructors>>
39 *
40 *          init_executive_late()
41 *          bsp_cleanup()
42 *
43 *  TODO:
44 *
45 *  $Id$
46 */
47
48#include <bsp.h>
49#include <stdio.h>
50#include <stdlib.h>
51
52/*
53 * RTEMS program name
54 * Probably not used by anyone, but it is nice to have it.
55 * Actually the UNIX version of CPU_INVOKE_DEBUGGER will probably
56 * need to use it
57 */
58
59char *rtems_progname;
60
61class RTEMS {
62    public:
63         RTEMS();
64        ~RTEMS();
65};
66
67RTEMS  rtems_constructor;
68
69RTEMS::RTEMS()
70{
71    bsp_start();
72}
73
74RTEMS::~RTEMS()
75{
76    bsp_cleanup();
77}
78
79extern "C" {
80    #ifndef __GNUC__
81      extern void invoke_non_gnu_constructors(void);
82    #endif
83
84    int
85    main(int argc,
86         char **argv,
87         char ** /* environp is unused */)
88    {
89        rtems_argc = argc;
90        rtems_argv = argv;
91
92        if ((argc > 0) && argv && argv[0])
93            rtems_progname = argv[0];
94        else
95            rtems_progname = "RTEMS";
96
97        /*
98         * run any non-gnu constructors we may need
99         */
100       
101        #ifndef __GNUC__
102          invoke_non_gnu_constructors();
103        #endif
104
105        /*
106         *  Start multitasking
107         */
108
109        rtems_initialize_executive_late( bsp_isr_level );
110
111        /*
112         * Returns when multitasking is stopped
113         * This allows our destructors to get run normally
114         */
115
116        fflush( stdout );
117        fflush( stderr );
118        return 0;
119    }
120}
Note: See TracBrowser for help on using the repository browser.