Page 1 of 1

Task switching (ring0<->ring3)

Posted: Fri Apr 20, 2007 12:48 am
by nicesj
I heard about TSS to switch between processes.
(whatever sw or hw task switching)

then I think, I should to make the default TSS data.
and I have to fill the value of ESP0 and SS0 in the TSS.

in this case, When task switching occurs, CPU will load ESP0 and SS0 in a default initialized TSS. but current stack is used by another process. and it indicates same area. it means, next process will overwrite current process's first area of stack.

isn't it make any problem?

Posted: Fri Apr 20, 2007 1:14 am
by Aali
with hardware switching you have separate TSS structures for every process

with software switching you could either have one kernel thread (never change ss0/esp0) or real multithreading where you load the kernel stack for each thread into the TSS before you switch to ring3

Posted: Fri Apr 20, 2007 4:08 pm
by mystran
Having done software task-switching both with a single kernel stack (single threaded kernel) and multiple kernel stacks/threads (threads are scheduled by stack-switching in kernel, some of them return to userspace, some of them don't) I personally find the latter approach somewhat easier to work with (it's more or less like writing a multi-threaded server).

There are some advantages to a single kernel stack, but a lot more explicit book-keeping is required, so YMMV..