trouble with switching page directory

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
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

trouble with switching page directory

Post by yemista »

I was wondering how you deal with switching the page directory and having the stack changed. I noticed a nasty bug when trying to test multitasking. I call switch page directory before changing the register context to do a proc switch, but while calling switch page directory, the stack is changed so when it goes to return from switch page directory, it returns somwhere it shouldnt and eventually crashes.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: trouble with switching page directory

Post by davidv1992 »

There are two options basically, make sure that the stack you're using during switching is at the same location in both pagemaps. The other option is to simultaniously do a full stack switch and thus save/restore the stack and base pointers (x86) or whatever their equivalent might be on the architecture you're using.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: trouble with switching page directory

Post by Combuster »

I have a per-processor stack to use when changing address spaces and certain other system settings - you can store the state to the old stack, disable interrupts and switch to the "temporary" stack, change address space, switch to the right stack and enable interrupts, restore the other task's state, resume, profit
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply