-
Notifications
You must be signed in to change notification settings - Fork 13
Context Switch
ScaraOS utilises hardware context switching. Each task has a task state segment embedded in to its task struct. Two TSS descriptors are defined and task switching is implemented by setting the currently available descriptors base and limit to the next task to be scheduled and then performing a jump to the new TSS selector.
The exec system call is handled with a rather cheeky hack. Then the current task (TR) register is loaded with the base and limit of a scratch TSS which is allocated as a global variable. This clears the BUSY flag in the tasks TSS descriptor which will come in handy later. The tasks TSS is fixed up, this entails setting the eip field to the address of the userspace entry point, esp is set to the address of the userspace stack and sp0 is set to the top of the kernel stack. Finally the jump to the TSS selector switches the task in to the appropriate userspace environment. If the scratch TSS hadn’t been setup then this would have generated a GPF for trying to jump to a busy task since x86 hardware tasks are not recursive. A global variable is a safe place for the scratch TSS because only one task switch operation can be in progress at any one time. ScaraOS does not support SMP yet.