
Application Note
Exception Context Switch
AN1281
MOTOROLA
7
Exception Context Switch
After an interrupt or any other exception is recognized, the hardware
automatically performs a context switch, which includes the following:
1.
Saves the current state of the machine:
a.
The address of the next instruction is saved in register SRR0
b.
The MSR value is saved in register SRR1
2.
Changes the MSR:
a.
Disables further interrupts by clearing the EE bit
b.
Sets the privilege level to supervisor but clears the PR bit
c.
Clears the RI bit to indicate that the interrupt may not be able
to recover if another exception immediately follows.
3.
Branches to the interrupt exception vector
Key Handler Issues
Where to Store
Local Data
for Handler
Interrupt handlers require at least enough data storage to preserve the
previous state of the machine. Typically storage is allocated on the
stack. Special purpose registers SPRG0:3 can also be used for storage,
but the registers provide only four words of storage, and using them
prevents nesting of exceptions. Since this method makes the interrupt
handler non-reentrant, it can only be used for the highest priority
interrupt.
Assuming the stack is used for storage, care must be taken to ensure
there is enough room on the stack for a worst case of nested exceptions.
All stack manipulation code must also be carefully designed to ensure
that an interrupt during a stack operation does not cause problems.
Some programs use separate stacks for interrupt and non-interrupt
code.