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

4.104.114.95
Last change on this file since 200748bf was 200748bf, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:46:10

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • clock/clock.c, include/bsp.h, startup/bspstart.c, startup/rtems-ctor.cc: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • 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
52class RTEMS {
53    public:
54         RTEMS();
55        ~RTEMS();
56};
57
58RTEMS  rtems_constructor;
59
60RTEMS::RTEMS()
61{
62    bsp_start();
63}
64
65RTEMS::~RTEMS()
66{
67    bsp_cleanup();
68}
69
70extern "C" {
71    #ifndef __GNUC__
72      extern void invoke_non_gnu_constructors(void);
73    #endif
74
75    int
76    main(int argc,
77         char **argv,
78         char ** /* environp is unused */)
79    {
80        rtems_argc = argc;
81        rtems_argv = argv;
82
83        rtems_interrupt_level bsp_isr_level;
84
85        /*
86         *  Make sure interrupts are disabled.
87         */
88
89        rtems_interrupt_disable( bsp_isr_level );
90
91        if ((argc > 0) && argv && argv[0])
92            rtems_progname = argv[0];
93        else
94            rtems_progname = "RTEMS";
95
96        /*
97         * run any non-gnu constructors we may need
98         */
99       
100        #ifndef __GNUC__
101          invoke_non_gnu_constructors();
102        #endif
103
104        rtems_initialize_executive_early( &Configuration );
105
106        /*
107         *  Start multitasking
108         */
109
110        rtems_initialize_executive_late( bsp_isr_level );
111
112        /*
113         * Returns when multitasking is stopped
114         * This allows our destructors to get run normally
115         */
116
117        fflush( stdout );
118        fflush( stderr );
119        return 0;
120    }
121}
Note: See TracBrowser for help on using the repository browser.