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

4.104.114.84.95
Last change on this file since 4e58d80 was c1403ef1, checked in by Joel Sherrill <joel.sherrill@…>, on 08/11/95 at 14:30:27

Added flush of output on exit. On some UNIX's using the native library
resulted in no output when the output was redirected until this was done.
Redirection is important because runtest redirects test output.

Added support for numerous environment variables which make it easier
to run a multi-node system using a single executable and to tailor
the size of the workspace and heap.

  • Property mode set to 100644
File size: 2.5 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#include <stdio.h>
53#include <stdlib.h>
54
55/*
56 * RTEMS program name
57 * Probably not used by anyone, but it is nice to have it.
58 * Actually the UNIX version of CPU_INVOKE_DEBUGGER will probably
59 * need to use it
60 */
61
62char *rtems_progname;
63
64class RTEMS {
65    public:
66         RTEMS();
67        ~RTEMS();
68};
69
70RTEMS  rtems_constructor;
71
72RTEMS::RTEMS()
73{
74    bsp_start();
75}
76
77RTEMS::~RTEMS()
78{
79    bsp_cleanup();
80}
81
82extern "C" {
83    int
84    main(int argc,
85         char **argv,
86         char **environp)
87    {
88        rtems_argc = argc;
89        rtems_argv = argv;
90        rtems_envp = environp;
91
92        if ((argc > 0) && argv && argv[0])
93            rtems_progname = argv[0];
94        else
95            rtems_progname = "RTEMS";
96
97        /*
98         *  Start multitasking
99         */
100
101        rtems_initialize_executive_late( bsp_isr_level );
102
103        /*
104         * Returns when multitasking is stopped
105         * This allows our destructors to get run normally
106         */
107
108        fflush( stdout );
109        fflush( stderr );
110        return 0;
111    }
112}
Note: See TracBrowser for help on using the repository browser.