Task switching

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
MagicalTux
Posts: 22
Joined: Mon Dec 04, 2006 5:34 pm

Task switching

Post 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.
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post 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.
Post Reply