- Timestamp:
-
06/26/07 18:44:15 (17 years ago)
- Author:
-
Rsg
- Comment:
-
/* PowerPC Initialisation */
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v8
|
v9
|
|
56 | 56 | * However, there is a problem here, in that '''eabi()''' ends up calling '''init()''' (actually, '''__init()''', we renamed to fix the problem described here) when it is still too early to initialize the C++ environment. |
57 | 57 | |
58 | | '''Note''' both details are of the 'seems to work' type. You won't notice anything if you don't call '''eabi()''' until you try to use an essential SYSV/EABI feature. Likewise, calling '''init()''' too early might not cause problems in many cases until one of your constructors uses an yet unavailable feature provided by RTEMS such as '''malloc()'''. |
| 58 | '''Note''' both details are of the 'seems to work' type. You won't notice anything if you don't call '''eabi()''' until you try to use an essential SYSV/EABI feature. Likewise, calling '''init()''' too early might not cause problems in many cases until one of your constructors uses an yet unavailable feature provided by RTEMS such as '''malloc()'''. |
59 | 59 | |
60 | 60 | For the PowerPC a typical chicken and egg problem exists - |
61 | 61 | |
62 | | ##we want to call '''_eabi()''' early (libbsp/powerpc/shared/start/start.S) |
63 | | ##we want to prevent '''_init()''' from being called too early (by '''eabi()''') |
64 | | ##we want to call '''__init()''' at the apropriate time. |
65 | | ##we dont want to hack gcc. |
| 62 | #we want to call '''_eabi()''' early (libbsp/powerpc/shared/start/start.S) |
| 63 | #we want to prevent '''_init()''' from being called too early (by '''eabi()''') |
| 64 | #we want to call '''__init()''' at the apropriate time. |
| 65 | #we dont want to hack gcc. |
66 | 66 | |
67 | 67 | Here's the solution using the '''.init''' magic as described in the appendix - |
68 | | * an additional startup file '''rtems_crti.S''' terminates '''_init()''' |
69 | | * so it becomes a no-op and introduces a new '''_init()''' entry point |
70 | | * to be used by RTEMS ([wiki:ThreadHandler ThreadHandler]). |
| 68 | * an additional startup file '''rtems_crti.S''' terminates '''_init()''' |
| 69 | * so it becomes a no-op and introduces a new '''_init()''' entry point |
| 70 | * to be used by RTEMS ([wiki:ThreadHandler ThreadHandler]). |
71 | 71 | |
72 | 72 | Hence here's what you need : |
73 | | * BSP's 'start.S' file must call '_eabi()' |
74 | | * BSP's bsp_specs : |
| 73 | * BSP's 'start.S' file must call '_eabi()' |
| 74 | * BSP's bsp_specs : |
75 | 75 | |
76 | 76 | ''startfile'': must contain (order is crucial) : |
… |
… |
|
94 | 94 | Here's what happens (properly linked executable) : |
95 | 95 | |
96 | | ##BSP '''start.s''' calls '''_eabi()'''; SYSVI/EABI environment setup |
97 | | ##'''eabi()''' calls '''_init()''' |
98 | | ##'''__init()''' returns immediately |
99 | | ##BSP initializes |
100 | | ##RTEMS starts up; initializes newlibc |
101 | | ##[wiki:ThreadHandler ThreadHandler] calls '''''init()''' (points to what ''_init() was intended to do) |
102 | | ##'''_init()''' walks through code snippets provided by various '''.init''' sections |
103 | | ##'''''init()''' encounters '''''do''global''ctors_aux()''' (provided by '''crtend.o''') |
104 | | ##'''''do''global''ctors''aux()''' initializes C++ environment (exceptions, ctors) |
105 | | ##... |
| 96 | #BSP '''start.s''' calls '''_eabi()'''; SYSVI/EABI environment setup |
| 97 | #'''eabi()''' calls '''_init()''' |
| 98 | #'''__init()''' returns immediately |
| 99 | #BSP initializes |
| 100 | #RTEMS starts up; initializes newlibc |
| 101 | #[wiki:ThreadHandler ThreadHandler] calls '''''init()''' (points to what ''_init() was intended to do) |
| 102 | #'''_init()''' walks through code snippets provided by various '''.init''' sections |
| 103 | #'''''init()''' encounters '''''do''global''ctors_aux()''' (provided by '''crtend.o''') |
| 104 | #'''''do''global''ctors''aux()''' initializes C++ environment (exceptions, ctors) |
| 105 | #... |
106 | 106 | = C++ .init Linker Magic = |
107 | 107 | |