[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A few BSPs have buggy ISR processing.



Sergei Organov wrote:
> 
> While looking at ISR processing code in different BSPs I've noticed that a few
> BSPs have bugs in the code. All the observations are made in the latest
> 20030128 snapshot. The BSPs affected are:
> 
> sh/sh7032
> sh/sh7045
> sh/sh7750
> c4x
> a29k

I think you are correct and am fixing the code to be even more
correct.  

> The first 4 have the same bug:
> 
> - if(( _Context_Switch_necessary) || (! _ISR_Signals_to_thread_executing))
> + if(( _Context_Switch_necessary) || (_ISR_Signals_to_thread_executing))

And this bug propagation is because the sh2, sh4, and c4x versions were
all based upon the original sh1 implementation.  The a29k is a special
case.

I have rewritten the logic to be as follows:

  /* nested interrupt */
  if ( _ISR_Nest_level )
    return;
 
  /* outermost ISR but inside RTEMS dispatching critical section */
  /* things will be evaluated at the end of the critical section */
  if ( _Thread_Dispatch_disable_level ) {
    _ISR_Signals_to_thread_executing = FALSE;
    return;
  }

  /* outermost interrupt and evaluation could be necessary */
  /* if either condition is true, clear the flag and dispatch */
  if ( _Context_Switch_necessary || _ISR_Signals_to_thread_executing ) {
    _ISR_Signals_to_thread_executing = FALSE;
    _Thread_Dispatch();
  }

I am nearly 100% certain that the above logic ensures that the 
outermost interrupt will always clear the
_ISR_Signals_to_thread_executing
boolean.  
 
> Here are the relevant lines:
> 
> rtems-ss-20030128/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c:305:      if(( _Context_Switch_necessary) || (! _ISR_Signals_to_thread_executing))
> rtems-ss-20030128/c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c:308:      if(( _Context_Switch_necessary) || (! _ISR_Signals_to_thread_executing))
> rtems-ss-20030128/c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c:305:      if(( _Context_Switch_necessary) || (! _ISR_Signals_to_thread_executing))
> rtems-ss-20030128/cpukit/score/cpu/c4x/irq.c:77:    if (_Context_Switch_necessary || !_ISR_Signals_to_thread_executing ) {
> 
> The a29k fails to reset _ISR_Signals_to_thread_executing to FALSE here:
> 
> rtems-ss-20030128/cpukit/score/cpu/a29k/cpu.c:274:    (_Context_Switch_necessary || _ISR_Signals_to_thread_executing ))
> 
> --
> Sergei.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985