A task stack and a context pointer in a task control block (TCB) are
implemented to provide more efficient context switching. Additionally,
multiple routines each of which saves or restores a certain combination
of volatile registers is implemented. A task can store in its task
control block a routine identifier to select from the multiple routines a
set of routines for saving and restoring volatile registers during
context switching. On the occurrence of an event that may lead to a
context switch a scheduler selects based on the routine identifier a
routine that only saves registers used by the task, thereby, reducing
execution overhead. The registers are saved on the task stack and a
context pointer to the registers is saved in the TCB. In the event a
context switch is necessary, it is not necessary to copy the registers to
the TCB because the context pointer is in the TCB. A non-volatile
register indicator that indicates whether non-volatile registers are used
is stored in the task control block. The non-volatile registers are only
saved if used, also reducing execution overhead. Furthermore, a storage
area is implemented for saving task context for the task when it is
interrupted during context switch in. Upon the occurrence of an interrupt
the task context is saved in the storage area. If the interrupt leads to
a second task which has a higher priority being made ready, the second
task is switched in without first returning to switch-in the task.