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

4.104.114.84.95
Last change on this file since eb5a7e07 was eb5a7e07, checked in by Joel Sherrill <joel.sherrill@…>, on 10/06/95 at 20:48:38

fixed missing CVS IDs

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