Ticket #182: exit_during_start.diff

File exit_during_start.diff, 6.1 KB (added by Joel Sherrill, on 12/11/06 at 14:29:38)

!st attempt

  • c/src/lib/libbsp/shared/bootcard.c

    RCS file: /usr1/CVS/rtems/c/src/lib/libbsp/shared/bootcard.c,v
    retrieving revision 1.15
    diff -u -r1.15 bootcard.c
     
    3131 *  $Id: bootcard.c,v 1.15 2006/11/15 15:20:05 joel Exp $
    3232 */
    3333
     34#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
    3435#include <bsp.h>
    3536
    3637#if defined(__USE_INIT_FINI__)
     
    6566
    6667int boot_card(int argc, char **argv, char **envp)
    6768{
    68   int    status;
     69  int    status = 0;
    6970  static char  *argv_pointer = NULL;
    7071  static char  *envp_pointer = NULL;
    7172  char **argv_p = &argv_pointer;
     
    115116#endif
    116117
    117118  /*
    118    * XXX
     119   * Invoke the BSP specific pre-device driver initialization code.
    119120   */
    120121
    121122  bsp_start();
     
    127128  bsp_isr_level =
    128129    rtems_initialize_executive_early( &BSP_Configuration, &Cpu_table );
    129130
    130   /*
    131    *  The atexit hook will be before the static destructor list's entry
    132    *  point.
    133    */
    134 
    135 #if defined(__USE_INIT_FINI__)
    136    atexit( _fini );
    137 #endif
    138 
    139   /*
    140    *  Call c_rtems_main() and eventually let the first task or the real
    141    *  main() invoke the global constructors if there are any.
    142    */
    143 
    144   if ((argc > 0) && argv && argv[0])
    145     rtems_progname = argv[0];
    146   else
    147     rtems_progname = "RTEMS";
    148 
    149   rtems_initialize_executive_late( bsp_isr_level );
    150 
    151   /*
    152    *  Perform any BSP specific shutdown actions.
    153    */
    154 
    155   bsp_cleanup();
     131  if ( _System_state_Get() == SYSTEM_STATE_BETWEEN_EARLY_AND_LATE ) {
     132    /*
     133     *  The atexit hook will be before the static destructor list's entry
     134     *  point.
     135     */
     136    #if defined(__USE_INIT_FINI__)
     137      atexit( _fini );
     138    #endif
     139
     140    /*
     141     *  Provide enough information to pass arguments.
     142     */
     143    if ((argc > 0) && argv && argv[0])
     144      rtems_progname = argv[0];
     145    else
     146      rtems_progname = "RTEMS";
     147
     148    rtems_initialize_executive_late( bsp_isr_level );
     149
     150    /*
     151     *  Perform any BSP specific shutdown actions.
     152     */
     153    bsp_cleanup();
     154  }
    156155
    157156  /*
    158157   *  Now return to the start code.
    159158   */
    160 
    161159  return status;
    162160}
  • cpukit/libcsupport/src/newlibc.c

    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/newlibc.c,v
    retrieving revision 1.52
    diff -u -r1.52 newlibc.c
     
    368368   *  associated with this task.
    369369   */
    370370
    371   libc_wrapup();
     371  if (_System_state_Is_up(_System_state_Get()))
     372    libc_wrapup();
    372373  rtems_shutdown_executive(status);
    373374  for (;;) ; /* to avoid warnings */
    374375}
     
    377378
    378379void exit(int status)
    379380{
    380   libc_wrapup();
     381  if (_System_state_Is_up(_System_state_Get()))
     382    libc_wrapup();
    381383  rtems_shutdown_executive(status);
    382384  for (;;) ; /* to avoid warnings */
    383385}
  • cpukit/sapi/src/exinit.c

    RCS file: /usr1/CVS/rtems/cpukit/sapi/src/exinit.c,v
    retrieving revision 1.34
    diff -u -r1.34 exinit.c
     
    125125
    126126  _CPU_Initialize( cpu_table, _Thread_Dispatch );
    127127
     128
     129  /*
     130   * At this point, we should be able to context switch to ourselves
     131   * so we can shutdown back to here.
     132   */
     133  _Context_Switch( &_Thread_BSP_context, &_Thread_BSP_context );
     134  if ( _System_state_Get () != SYSTEM_STATE_BEFORE_INITIALIZATION ) {
     135    _System_state_Set( SYSTEM_STATE_SHUTDOWN );
     136    return bsp_level;
     137  }
     138
     139  _System_state_Set( SYSTEM_STATE_BEFORE_SCORE_INITIALIZATION );
     140
    128141  /*
    129142   *  Do this as early as possible to insure no debugging output
    130143   *  is even attempted to be printed.
     
    257270  if ( _CPU_Table.postdriver_hook )
    258271    (*_CPU_Table.postdriver_hook)();
    259272
     273  _System_state_Set( SYSTEM_STATE_BETWEEN_EARLY_AND_LATE );
    260274  return bsp_level;
    261275}
    262276
     
    296310   uint32_t   result
    297311)
    298312{
    299   if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) {
    300     _System_state_Set( SYSTEM_STATE_SHUTDOWN );
    301     _Thread_Stop_multitasking();
     313  switch ( _System_state_Get() ) {
     314    case SYSTEM_STATE_BEFORE_INITIALIZATION:
     315    case SYSTEM_STATE_BEFORE_SCORE_INITIALIZATION:
     316    case SYSTEM_STATE_BEFORE_MULTITASKING:
     317    case SYSTEM_STATE_BEGIN_MULTITASKING:
     318    case SYSTEM_STATE_BETWEEN_EARLY_AND_LATE:
     319    {
     320      Context_Control junk;
     321      _System_state_Set( SYSTEM_STATE_FAILED );
     322      _Context_Switch( &junk, &_Thread_BSP_context );
     323      break;
     324    }
     325    case SYSTEM_STATE_UP:
     326      _System_state_Set( SYSTEM_STATE_SHUTDOWN );
     327      _Thread_Stop_multitasking();
     328      break;
     329    case SYSTEM_STATE_SHUTDOWN:
     330    case SYSTEM_STATE_FAILED:
     331      break;
    302332  }
    303333}
  • cpukit/score/include/rtems/score/sysstate.h

    RCS file: /usr1/CVS/rtems/cpukit/score/include/rtems/score/sysstate.h,v
    retrieving revision 1.21
    diff -u -r1.21 sysstate.h
     
    4646  /** This indicates that the system state is between end of the first
    4747   *  phase of initializatin but before  multitasking is started.
    4848   */
     49  SYSTEM_STATE_BEFORE_SCORE_INITIALIZATION,
     50  /** This indicates that the system state is between end of SuperCore
     51   *  initialization but before  multitasking is started.
     52   */
    4953  SYSTEM_STATE_BEFORE_MULTITASKING,
    5054  /** This indicates that the system state is attempting to initiate
    5155   *  multitasking.
    5256   */
    5357  SYSTEM_STATE_BEGIN_MULTITASKING,
     58  /** This indicates that the system is normal and between
     59   *  rtems_initialize_executive_early and rtems_initialize_executive_late.
     60   */
     61  SYSTEM_STATE_BETWEEN_EARLY_AND_LATE,
    5462  /** This indicates that the system is up and operating normally. */
    5563  SYSTEM_STATE_UP,
    5664  /** This indicates that the system is in the midst of a shutdown. */