rtel wrote on Wednesday, July 15, 2015:
The critical nesting method is the same between the ARM7 and Cortex-M,
but the context switching mechanism is completely different.
It is because the critical nesting count is just a variable that it has
to be saved and restored as part of the task context on the ARM7.
On the ARM7, when a task is switched out the variable is saved as part
of the task context, and when a task is switch in the critical nesting
count as that task expects to find it is restored again. This is just
like the registers on the CPU - which are also used by all tasks - and
so saved and restored as part of the task context. If an interrupt then
uses the critical nesting count, it is using the count of a specific
task - if the task context then gets saved before the interrupt exits
the critical section, then the wrong value for that task will be saved,
hence it is corrupt.
The way the Cortex-M is implemented, a context switch cannot happen
unless the critical nesting count is 0, so there is no need to save it
as part of the task’s context.