Page 1 of 1

System calls & task switching

Posted: Sat Jul 12, 2003 11:37 am
by Lantz
Hi there. I've got a few questions on stuff I've been wondering about.

What do you consider to be the best way to do multitasking? Should I use the TSS stuff or do it in software? And what's this stuff about ESP0 and SS0 and automatic stack switching when changing rings? How do I handle that?

And about system calls, should the system call disable interrupts while it executes? What happens if an app calls the system and the scheduler kicks in, isn't there a risk that apps stack get lost since when the scheduler kicks in the current stack could be the kernels, right?

Hmm I'm a bit confused on this stuff. Any clarification would be great.

Thanks in advance,
Lantz

Re:System calls & task switching

Posted: Sun Jul 13, 2003 1:59 am
by Pype.Clicker
the CPU automatically re-loads a new stack pointer from pre-defined stack pointers (ESPx SSx) when a call gate or an interrupt makes the priviledge level be risen.

The reason why this is needed is that the stack segment must have the same privileges as the code segment. Using the ESPx SSx, a privileged handler will receive a clean stack with a known size when it runs (handling an interrupt on the user stack may lead to lack space, or not writable, etc. which could lead the OS in DarkLandz of Tripple Faults.

This has a drawback, though, as it means that you will have to alter ESPx and SSx for the TSS that hosts your software (stack-switched) threads everytime you have a switch. ESPx and SSx are static registers of the TSS, so it's not enough to make change SS and ESP at DPL0 and then returning to DPL3 to have them altered.

Re:System calls & task switching

Posted: Sun Jul 13, 2003 4:59 am
by Lantz
Hmm ok. So what method of task switching would you recommend? TSS or stack based?

Re:System calls & task switching

Posted: Sun Jul 13, 2003 7:58 am
by Pype.Clicker
it depends on what kind of OS you plan to do. software task switching is better for heavily multi-threaded process that have roughly all the same I/O priviledges, while hardware task switching may handle I/O priviledges change more easily (allowing a specific process to access graphic card exclusively while another one access the networking card, etc.), thus it could be better suited to microkernels.