Page 1 of 1

Task Switching issue

Posted: Tue Nov 15, 2005 9:59 pm
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

Re:Task Switching issue

Posted: Thu Nov 17, 2005 3:17 pm
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)

Re:Task Switching issue

Posted: Thu Nov 17, 2005 3:22 pm
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