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

4.104.114.84.95
Last change on this file since 637df35 was 637df35, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 12, 1995 at 7:47:25 PM

Ada95, gnat, go32

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