Task switching (ring0<->ring3)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
nicesj
Member
Member
Posts: 27
Joined: Fri May 06, 2005 11:00 pm
Location: South Korea
Contact:

Task switching (ring0<->ring3)

Post 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?
Aali
Member
Member
Posts: 58
Joined: Sat Apr 14, 2007 12:13 pm

Post 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
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post 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..
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
Post Reply