OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [ppcn_60x/] [startup/] [rtems-ctor.cc] - Blame information for rev 846

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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
 *
46
 *  COPYRIGHT (c) 1989-1997.
47
 *  On-Line Applications Research Corporation (OAR).
48
 *  Copyright assigned to U.S. Government, 1994.
49
 *
50
 *  The license and distribution terms for this file may in
51
 *  the file LICENSE in this distribution or at
52
 *  http://www.OARcorp.com/rtems/license.html.
53
 *
54
 *  $Id:
55
 */
56
 
57
#include <bsp.h>
58
 
59
/*
60
 * RTEMS program name
61
 * Probably not used by anyone, but it is nice to have it.
62
 * Actually the UNIX version of CPU_INVOKE_DEBUGGER will probably
63
 * need to use it
64
 */
65
 
66
char *rtems_progname;
67
char **rtems_environp;
68
 
69
#ifdef USE_CONSTRUCTORS_FOR_INIT_EXEC
70
 
71
class RTEMS {
72
    public:
73
        RTEMS();
74
        ~RTEMS();
75
};
76
 
77
RTEMS  rtems_constructor;
78
 
79
RTEMS::RTEMS()
80
{
81
    bsp_start();
82
}
83
 
84
RTEMS::~RTEMS()
85
{
86
    bsp_cleanup();
87
}
88
#endif
89
 
90
extern "C" {
91
    int
92
    main(int argc,
93
         char **argv,
94
         char **environp)
95
    {
96
 
97
#ifndef USE_CONSTRUCTORS_FOR_INIT_EXEC
98
        bsp_start();
99
#endif
100
 
101
        if ((argc > 0) && argv && argv[0])
102
            rtems_progname = argv[0];
103
        else
104
            rtems_progname = "RTEMS";
105
 
106
        rtems_environp = environp;
107
 
108
        /*
109
         *  Start multitasking
110
         */
111
        rtems_initialize_executive_late( bsp_isr_level );
112
 
113
#ifndef USE_CONSTRUCTORS_FOR_INIT_EXEC
114
        bsp_cleanup();
115
#endif
116
 
117
        /*
118
         * Returns when multitasking is stopped
119
         * This allows our destructors to get run normally
120
         */
121
 
122
        return 0;
123
    }
124
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.