[En-Nut-Discussion] Not fixed!!!: Re: confirmed!!! Re: NutOS 4.4.0 on ARM7: possibly bug in NutEnterCritical / NutExitCritical
Ole Reinhardt
ole.reinhardt at embedded-it.de
Fri Feb 22 18:26:35 CET 2008
Hi,
I just tried to explain in private mail, but in short for everyone:
> Maybe my assumptions are wrong:
> - NutEnterCritical/NutExitCritical guard short sections of code which
> run with IRQs disabled
> - These are normally just a few lines to block IRQs minimally
> - They normally don't call other functions.
> - Even if they call other functions, those return and the ExitCritical
> is in the same context as the entry.
> - The stack pointer points to free space after the local (stack based)
> variables. You can push/pop stuff there
> as long as the pointer is correct before you exit.
> - If you call another function, the parameters are pushed on the
> stack, the call executed and the functions returns. an eventually
> stored ISR is still safe on the stack.
In general you are right, but there is one point you missed:
NutEnterCritical is a macro. It's just a short pice of assembler code
that leaves the stack modified. NutExitCritical is a macro too and
expects the stack in the same manner as NutEnterCritical leaved it.
The compiler does not know about modifiing the stack. The compiler may
use the stack for whatever. This also includes the possibility to
temporarily store some values on the stack if registers are needed for
any other purpose. You don't know if and when this option is used. If
this happens in a critical section, the stack is corrupted and returning
from the critical section destroys the stack.
This might be the reason why optimized code does not trigger this
problem that often as most values are held in registers and not on the
stack.
Bye,
Ole
--
_____________________________________________________________
| |
| Embedded-IT Hard- und Softwarelösungen |
| |
| Ole Reinhardt Tel. / Fax: +49 (0)271 7420433 |
| Luisenstraße 29 Mobil: +49 (0)177 7420433 |
| 57076 Siegen eMail: ole.reinhardt at embedded-it.de |
| Germany Web: http://www.embedded-it.de |
| UstID / VAT: DE198944716 |
|_____________________________________________________________|
More information about the En-Nut-Discussion
mailing list