Page 1 of 1

Task switching

Posted: Sun Feb 18, 2007 4:29 am
by MagicalTux
Ok, Well...

My current state : working kernel, software multitasking, paging, syscalls (via an int call), ...

Well it works quite well, however my problem today is how to handle kernel switching without using the guest process' stack ?

Basically when an interrupt happens (preempt current stack, syscall, process crash, ...) I push on the process' stack the registers.

This is bad, if, for example, the process generated a pagefault exception *because* the stack was full (in this case, I should dynamically allocate a new page to let the stack grow a bit more).

I tried on other oses (linux) and even if I mess up the stack (set esp to 0) the exceptions are still handled as expected.

I know that using hardware task switching allows to have the cpu switch directly to a new stack on entering the kernel, but it's also said to be slower and not used anymore in modern oses (as said here).

So, I was wondering which solution exists for that?

I could also decide to have a memory location containing the kernel stack but it doesn't sound like a good idea...

(I'm also trying to have the task run at ring3, after all it just calls a kernel interrupt (syscall), so it shouldn't be hard.

Any help on this matter is welcome.

Posted: Sun Feb 18, 2007 4:54 am
by Otter
I think even if you use software task switching, you still can use the hardware support for this. I mean you could load a simple tss (via ltr), which only contains a valid esp0-value. If you enter kernel space, the processor should change esp to the esp0-value of the current tss.