Changes between Version 2 and Version 3 of TBR/UserManual/Using_C_Plus_Plus


Ignore:
Timestamp:
Oct 21, 2005, 7:40:54 PM (14 years ago)
Author:
JoelSherrill
Comment:

/* PowerPC Initialisation */ more format corrections

Legend:

Unmodified
Added
Removed
Modified
  • TBR/UserManual/Using_C_Plus_Plus

    v2 v3  
    3737BSP should call (gcc provided) '''_eabi()''' very early to set up a SYSV/EABI compliant environment (load r2/r13, stack align etc.). If you don't do this, e.g., SYSV/EABI short data areas won't work (see gcc -msdata -meabi options).
    3838
    39 RTEMS calls '''''init()''' which among other things works through the C++ static constructor list -- provided that your linker stript and '''bsp''specs''' files are correct. See [wiki:#InitMagic C++ .init Linker Magic] on how it works.
     39RTEMS calls '''init()''' which among other things works through the C++ static constructor list -- provided that your linker stript and '''bsp_specs''' files are correct. See [wiki:#InitMagic C++ .init Linker Magic] on how it works.
    4040
    41  * 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.
     41 * 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.
    4242
    43   '''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()'''.
     43  '''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()'''.
    4444
    4545For the PowerPC a typical chicken + egg. problem exists -
    4646
    4747##we want to call '''_eabi()''' early (libbsp/powerpc/shared/start/start.S)
    48 ##we want to prevent '''_''init()''' from being called too early (by '''''eabi()''')
     48##we want to prevent '''_init()''' from being called too early (by '''eabi()''')
    4949##we want to call '''__init()''' at the apropriate time.
    5050##we dont want to hack gcc.
    5151
    5252Here's the solution using the '''.init''' magic as described in the appendix -
    53   * an additional startup file '''rtems''crti.S''' ''terminates'' '''''_init()'''
     53  * an additional startup file '''rtems_crti.S''' terminates '''_init()'''
    5454  * so it becomes a no-op and introduces a new '''_init()''' entry point
    5555  * to be used by RTEMS ([wiki:ThreadHandler ThreadHandler]).
     
    7979Here's what happens (properly linked executable) :
    8080
    81    <verbatim></verbatim>
    82 
    8381##BSP '''start.s''' calls '''_eabi()'''; SYSVI/EABI environment setup
    84 ##'''''eabi()''' calls '''''_init()'''
     82##'''eabi()''' calls '''_init()'''
    8583##'''__init()''' returns immediately
    8684##BSP initializes