Task Switching issue

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
Crazed123

Task Switching issue

Post by Crazed123 »

I just realized when I went to fix up my task switching that it currently can only work with user->kernel transitions due to assuming the presence of useresp and ss fields in interrupt stack frames.

Given that at least one thread (kidle) WILL be running in kernel space, what can be done to make threads work when there may or may not be userland stack fields? My threads use data members to store the thread status.

Source code is at http://cvs.sourceforge.net/viewcvs.py/g ... 8&view=log
JAAman

Re:Task Switching issue

Post by JAAman »

why do you need to assume that the user ss:sep are on the stack? if your comming from user mode the CPU will save them, and restore them automatically, if not, then it wont save them or restore them automatically, but you shouldn't need to save them:
you should never need to save the user ss:esp (as long as your task-switch code is in ring0)

the only reason you should ever need to see the user ss:esp is if you are retreiveing parameters to syscalls from the stack, and in that case you can simply assume that the kernel will never call the syscall entry points (since it can directly call the proceedure it requires)
JoeKayzA

Re:Task Switching issue

Post by JoeKayzA »

You could examine the return cs which is pushed onto the stack when the CPU enters the interrupt. The cs should tell you in which ring the interrupt occured - when it is ring3, assume that user esp and ss are present.

cheers Joe
Post Reply