Changeset d196e48 in rtems for c/src/exec/score/cpu


Ignore:
Timestamp:
05/23/96 15:34:54 (27 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
859f17ce
Parents:
2328475
Message:

updates from Tony Bennett.

Broke the setjmp/longjmp pair in the context switch into a separate routine
so no code depended on local variables surviving the jump.

Location:
c/src/exec/score/cpu/unix
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/cpu/unix/cpu.c

    r2328475 rd196e48  
    5656typedef struct {
    5757  jmp_buf   regs;
    58   sigset_t  isr_level;
     58  unsigned32  isr_level;
    5959} Context_Control_overlay;
    6060
     
    6363void  _CPU_ISR_Handler(int);
    6464
    65 sigset_t         _CPU_Signal_mask;
    66 Context_Control  _CPU_Context_Default_with_ISRs_enabled;
    67 Context_Control  _CPU_Context_Default_with_ISRs_disabled;
     65static sigset_t         _CPU_Signal_mask;
     66static Context_Control_overlay  _CPU_Context_Default_with_ISRs_enabled;
     67static Context_Control_overlay  _CPU_Context_Default_with_ISRs_disabled;
    6868
    6969/*
     
    9393  /*
    9494   * Block all the signals except SIGTRAP for the debugger
    95    * and SIGABRT for fatal errors.
     95   * and fatal error signals.
    9696   */
    9797
     
    101101  (void) sigdelset(&_CPU_Signal_mask, SIGIOT);
    102102  (void) sigdelset(&_CPU_Signal_mask, SIGCONT);
     103  (void) sigdelset(&_CPU_Signal_mask, SIGSEGV);
     104  (void) sigdelset(&_CPU_Signal_mask, SIGBUS);
     105  (void) sigdelset(&_CPU_Signal_mask, SIGFPE);
    103106
    104107  _CPU_ISR_Enable(1);
     
    121124  struct sigaction  act;
    122125  sigset_t          mask;
    123 
     126 
    124127  /* mark them all active except for TraceTrap  and Abort */
    125 
    126   sigfillset(&mask);
    127   sigdelset(&mask, SIGTRAP);
    128   sigdelset(&mask, SIGABRT);
    129   sigdelset(&mask, SIGIOT);
    130   sigdelset(&mask, SIGCONT);
     128 
     129  mask = _CPU_Signal_mask;
    131130  sigprocmask(SIG_UNBLOCK, &mask, 0);
    132 
     131 
    133132  act.sa_handler = _CPU_ISR_Handler;
    134133  act.sa_mask = mask;
    135134  act.sa_flags = SA_RESTART;
    136 
     135 
    137136  sigaction(SIGHUP, &act, 0);
    138137  sigaction(SIGINT, &act, 0);
     
    168167    sigaction(SIGLOST, &act, 0);
    169168#endif
    170 
    171169}
    172170
     
    210208  _CPU_ISR_Set_level( 0 );
    211209  _CPU_Context_switch(
    212     &_CPU_Context_Default_with_ISRs_enabled,
    213     &_CPU_Context_Default_with_ISRs_enabled
     210    (Context_Control *) &_CPU_Context_Default_with_ISRs_enabled,
     211    (Context_Control *) &_CPU_Context_Default_with_ISRs_enabled
    214212  );
    215 
     213 
    216214  _CPU_ISR_Set_level( 1 );
    217215  _CPU_Context_switch(
    218     &_CPU_Context_Default_with_ISRs_disabled,
    219     &_CPU_Context_Default_with_ISRs_disabled
     216    (Context_Control *) &_CPU_Context_Default_with_ISRs_disabled,
     217    (Context_Control *) &_CPU_Context_Default_with_ISRs_disabled
    220218  );
    221219}
     
    226224 */
    227225
    228 sigset_t GET_old_mask;
    229 
    230226unsigned32 _CPU_ISR_Get_level( void )
    231227{
    232 /*  sigset_t  old_mask; */
    233    unsigned32 old_level;
    234  
    235   sigprocmask(0, 0, &GET_old_mask);
    236  
    237   if (memcmp((void *)&posix_empty_mask, (void *)&GET_old_mask, sizeof(sigset_t)))
    238     old_level = 1;
    239   else
    240     old_level = 0;
    241 
    242   return old_level;
     228  sigset_t old_mask;
     229 
     230  sigprocmask(SIG_BLOCK, 0, &old_mask);
     231 
     232  if (memcmp((void *)&posix_empty_mask, (void *)&old_mask, sizeof(sigset_t)))
     233      return 1;
     234 
     235  return 0;
    243236}
    244237
     
    362355void _CPU_Thread_Idle_body( void )
    363356{
    364   while (1)
     357  while (1) {
     358#ifdef RTEMS_DEBUG
     359    /* interrupts had better be enabled at this point! */
     360    if (_CPU_ISR_Get_level() != 0)
     361       abort();
     362#endif
    365363    pause();
     364  }
     365
    366366}
    367367
     
    380380)
    381381{
    382   void        *source;
    383382  unsigned32  *addr;
    384383  unsigned32   jmp_addr;
     
    411410
    412411  if ( _new_level == 0 )
    413     source = &_CPU_Context_Default_with_ISRs_enabled;
     412      *_the_context = *(Context_Control *)
     413                         &_CPU_Context_Default_with_ISRs_enabled;
    414414  else
    415     source = &_CPU_Context_Default_with_ISRs_disabled;
     415      *_the_context = *(Context_Control *)
     416                         &_CPU_Context_Default_with_ISRs_disabled;
    416417     
    417   memcpy(
    418     _the_context,
    419     source,
    420     sizeof(Context_Control)                /* sizeof(jmp_buf)); */
    421   );
    422 
    423418  addr = (unsigned32 *)_the_context;
    424419
     
    493488  Context_Control_overlay *nextp = (Context_Control_overlay *)next;
    494489
    495   sigprocmask( SIG_SETMASK, &nextp->isr_level, 0 );
     490  _CPU_ISR_Enable(nextp->isr_level);
    496491  longjmp( nextp->regs, 0 );
    497492}
     
    501496 *  _CPU_Context_switch
    502497 */
     498
     499static void do_jump(
     500  Context_Control_overlay *currentp,
     501  Context_Control_overlay *nextp
     502);
    503503
    504504void _CPU_Context_switch(
     
    509509  Context_Control_overlay *currentp = (Context_Control_overlay *)current;
    510510  Context_Control_overlay *nextp = (Context_Control_overlay *)next;
    511 
     511#if 0
    512512  int status;
    513 
    514   /*
    515    *  Switch levels in one operation
    516    */
    517 
    518   status = sigprocmask( SIG_SETMASK, &nextp->isr_level, &currentp->isr_level );
    519   if ( status )
    520     _Internal_error_Occurred(
    521       INTERNAL_ERROR_CORE,
    522       TRUE,
    523       status
    524     );
    525 
    526   if (setjmp(currentp->regs) == 0) {    /* Save the current context */
    527      longjmp(nextp->regs, 0);           /* Switch to the new context */
    528      if ( status )
    529        _Internal_error_Occurred(
     513#endif
     514 
     515  currentp->isr_level = _CPU_ISR_Disable_support();
     516 
     517  do_jump( currentp, nextp );
     518
     519#if 0
     520  if (sigsetjmp(currentp->regs, 1) == 0) {    /* Save the current context */
     521     siglongjmp(nextp->regs, 0);           /* Switch to the new context */
     522     _Internal_error_Occurred(
    530523         INTERNAL_ERROR_CORE,
    531524         TRUE,
     
    533526       );
    534527  }
    535 
    536 }
    537  
     528#endif
     529 
     530#ifdef RTEMS_DEBUG
     531    if (_CPU_ISR_Get_level() == 0)
     532       abort();
     533#endif
     534 
     535  _CPU_ISR_Enable(currentp->isr_level);
     536}
     537 
     538static void do_jump(
     539  Context_Control_overlay *currentp,
     540  Context_Control_overlay *nextp
     541)
     542{
     543  int status;
     544
     545  if (setjmp(currentp->regs) == 0) {    /* Save the current context */
     546     longjmp(nextp->regs, 0);           /* Switch to the new context */
     547     _Internal_error_Occurred(
     548         INTERNAL_ERROR_CORE,
     549         TRUE,
     550         status
     551       );
     552  }
     553}
     554
    538555/*PAGE
    539556 *
     
    715732      case SIGSEGV:
    716733      case SIGTERM:
     734      case SIGIOT:
    717735        _CPU_Fatal_error(0x100 + sig_num);
    718736  }
  • c/src/exec/score/cpu/unix/cpu.h

    r2328475 rd196e48  
    437437 *  This is really just the area for the following fields.
    438438 *
    439  *    jmp_buf   regs;
    440  *    sigset_t isr_level;
     439 *    jmp_buf    regs;
     440 *    unsigned32 isr_level;
    441441 *
    442442 *  Doing it this way avoids conflicts between the native stuff and the
Note: See TracChangeset for help on using the changeset viewer.