When a guest OS wishes to context switch between two processes,
it can use the page table and segmentation hypercalls described
above to perform the the bulk of the privileged work. In addition,
however, it will need to invoke Xen to switch the kernel (ring 1)
stack pointer:
stack_switch(unsigned long ss, unsigned long esp)
Request kernel stack switch from hypervisor; ss is the new
stack segment, which esp is the new stack pointer.
A useful hypercall for context switching allows ``lazy'' save and
restore of floating point state:
fpu_taskswitch(int set)
This call instructs Xen to set the TS bit in the cr0
control register; this means that the next attempt to use floating
point will cause a trap which the guest OS can trap. Typically it will
then save/restore the FP state, and clear the TS bit, using the
same call.
This is provided as an optimization only; guest OSes can also choose
to save and restore FP state on all context switches for simplicity.
Finally, a hypercall is provided for entering vm86 mode:
switch_vm86
This allows the guest to run code in vm86 mode, which is needed for
some legacy software.