Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Changes between Version 8 and Version 9 of TBR/UserManual/Using_C_Plus_Plus


Ignore:
Timestamp:
06/26/07 18:44:15 (17 years ago)
Author:
Rsg
Comment:

/* PowerPC Initialisation */

Legend:

Unmodified
Added
Removed
Modified
  • TBR/UserManual/Using_C_Plus_Plus

    v8 v9  
    5656 * 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.
    5757
    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()'''.
    5959
    6060For the PowerPC a typical chicken and egg problem exists -
    6161
    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.
    6666
    6767Here'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]).
    7171
    7272Hence 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 :
    7575
    7676    ''startfile'': must contain (order is crucial) :
     
    9494Here's what happens (properly linked executable) :
    9595
    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#...
    106106= C++ .init Linker Magic =
    107107