XC2200 Derivatives
System Units (Vol. 1 of 2)
Interrupt and Trap Functions
User’s Manual
5-33
V2.1, 2008-08
ICU_X2K, V2.2
5.6
Context Switching and Saving Status
Before an interrupt request that has been arbitrated is actually serviced, the status of the
current task is automatically saved on the system stack. The CPU status (PSW) is saved
together with the location at which execution of the interrupted task is to be resumed after
returning from the service routine. This return location is specified through the Instruction
Pointer (IP) and, in the case of a segmented memory model, the Code Segment Pointer
(CSP). Bit SGTDIS in register CPUCON1 controls how the return location is stored.
The system stack receives the PSW first, followed by the IP (unsegmented), or followed
by CSP and then IP (segmented mode). This optimizes the usage of the system stack if
segmentation is disabled.
The CPU priority field (ILVL in PSW) is updated with the priority of the interrupt request
to be serviced, so the CPU now executes on the new level.
The register bank select field (BANK in PSW) is changed to select the register bank
associated with the interrupt request. The association between interrupt requests and
register banks are partly pre-defined and can partly be programmed.
The interrupt request flag of the source being serviced is cleared. IP and CSP are loaded
with the vector associated with the requesting source, and the first instruction of the
service routine is fetched from the vector location which is expected to branch to the
actual service routine (except when the interrupt jump table cache is used). All other
CPU resources, such as data page pointers and the context pointer, are not affected.
When the interrupt service routine is exited (RETI is executed), the status information is
popped from the system stack in the reverse order, taking into account the value of bit
SGTDIS.
Figure 5-5
Task Status Saved on the System Stack
(Unsegmented)
PSW
System Stack after
Interrupt Entry
Interrupt Entry
System Stack before
a)
b)
SP
High
Addresses
Low
Addresses
--
--
--
SP
IP
--
MCD02226
b)
Interrupt Entry
System Stack after
(Segmented)
Task
Interrupted
Status of
CSP
PSW
IP
SP