source: rtems/c/src/lib/libbsp/powerpc/dmv177/startup/rtems-ctor.cc @ c932d85

4.104.114.84.95
Last change on this file since c932d85 was c932d85, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 10:09:14

New files -- from rtems-LM-980406 which was based on an RTEMS from 12/97.
This was called the dmv170 BSP in that source tree but since the DMV171
is now obsolete, we have transitioned to the DMV177 and have no intention
of checking compatibility with any other models.

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[c932d85]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 *          rtems_init_executive_late()
41 *          bsp_cleanup()
42 *
43 *  TODO:
44 *
45 *  COPYRIGHT (c) 1989-1998.
46 *  On-Line Applications Research Corporation (OAR).
47 *  Copyright assigned to U.S. Government, 1994.
48 *
49 *  The license and distribution terms for this file may in
50 *  the file LICENSE in this distribution or at
51 *  http://www.OARcorp.com/rtems/license.html.
52 *
53 *  $Id$
54 */
55
56#include <bsp.h>
57
58/*
59 * RTEMS program name
60 * Probably not used by anyone, but it is nice to have it.
61 * Actually the UNIX version of CPU_INVOKE_DEBUGGER will probably
62 * need to use it
63 */
64
65char *rtems_progname;
66char **rtems_environp;
67
68#ifdef USE_CONSTRUCTORS_FOR_INIT_EXEC
69
70class RTEMS {
71    public:
72        RTEMS();
73        ~RTEMS();
74};
75
76RTEMS  rtems_constructor;
77
78
79/*  PAGE
80 *
81 *  RTEMS::RTEMS
82 *
83 *  RTEMS constructor routine
84 *
85 *  Input parameters:  NONE
86 *
87 *  Output parameters:  NONE
88 *
89 *  Return values:  NONE
90 */
91
92RTEMS::RTEMS()
93{
94    bsp_start();
95}
96
97/*  PAGE
98 *
99 *  RTEMS::~RTEMS
100 *
101 *  RTEMS distructor routine
102 *
103 *  Input parameters:  NONE
104 *
105 *  Output parameters:  NONE
106 *
107 *  Return values:  NONE
108 */
109
110RTEMS::~RTEMS()
111{
112    bsp_cleanup();
113}
114#endif
115
116extern "C" {
117    int
118    main(int argc,
119         char **argv,
120         char **environp)
121    {
122
123#ifndef USE_CONSTRUCTORS_FOR_INIT_EXEC
124        bsp_start();
125#endif
126
127        if ((argc > 0) && argv && argv[0])
128            rtems_progname = argv[0];
129        else
130            rtems_progname = "RTEMS";
131
132        rtems_environp = environp;
133
134        /*
135         *  Start multitasking
136         */
137
138        rtems_initialize_executive_late( bsp_isr_level );
139
140#ifndef USE_CONSTRUCTORS_FOR_INIT_EXEC
141        bsp_cleanup();
142#endif
143
144        /*
145         * Returns when multitasking is stopped
146         * This allows our destructors to get run normally
147         */
148
149        return 0;
150    }
151}
Note: See TracBrowser for help on using the repository browser.