Hi,
This is in regards to switching from ring3 to ring0 (and back). I've been poring over some tutorials and this forum, and Intel docs, but I can't seem to wrap my head around something.
When an interrupt triggers a task switch from ring 3 to 0, the stack is switched to the kernel's stack and and all of the suspended process' registers are saved there. Ok, that's fine...
Does that mean one would then need to copy them off the stack somewhere else, then copy them back when the scheduler is about to restore the ring 3 process? I find it hard to swallow that all suspended processes' states are simply stored in one kernel stack and then left there until needed... the stack would be blown in no time.
This is the only thing I'm having trouble figuring out.
I have enabled threading support in my kernel (works a treat) but, the threads are all ring 0, so when you save their states, the values are going into their own stacks and are popped off later... but what do you do when a ring 3 process' state is saved into [one of] the kernel's ring 0 stack(s)?
My mind is boggling.......
Thanks for any help / suggestions!
P.S. I'm not looking for code, I can figure that out on my own once I understand what I'm implementing.
Yet another task switching question (Ring changes)
One way to deal with it is to give each task its own kernel stack that it stores its registers to when an interrupt is triggered. Then, just put the virtual address of the top of the stack into esp0 in your task structure. If you're using software task switching you can avoid having to update esp0 for each task by just mapping the kernel stack to the same place in each address space.
Regards,
John.
Regards,
John.
I'd actually considered doing it that way, but for some reason I dismissed it as being too much of a bother... but now that I think about it, it would work quite well as iret will pop the 'correct' stack pointer when the process / thread is resumed anyway.
I'm just over-thinking things I guess
Thanks John!
I'm just over-thinking things I guess
Thanks John!