When I want to switch between two processes, I have to save registers for the old process and restore registers values for the new one.
There's no problem with this : I get it work with several processes.
I'm using the quiet simple technique below:
Code: Select all
; push all registers, including cr3
; call C function to save the values on the stack and put the new values in this stack
; pop all registers back, to make the system believe the new process is the one that was interrupted
But when I want different paging structures, I have to pop cr3 back (well through a general register at all, but this doesn't matter here).
When I set the new cr3 values, each address after this is interpreted using the new paging structures, including EIP, so the end of my code (which pops back the rest of the registers) is not executed.
Worse : the processor "jumps" to an address that has nothing to deal with code and crashes my kernel.
How can I reload cr3 and continue executing the end of my asm routine ?