When I enable paging I would like that all tasks have their virtual space and thir PDEs and PTEs.
When an interrupt occurs while a user task is running I would like to call the interrupt handler managed by the kernel...
But the interrupt handler is located in the kernel space, thus when an interrupt occurs I should update the CR3 with the page directory base address of the kernel.
Well... if I define all my IDT entries with a TASK GATE, automatically a task switch occurs when an interrupt or exception is generated, so the CR3 is automatically updated... but AFAIK this takes a lot of time, because the context switches save a lot of data
Another way could be to map the kernel space in every task address space, so when an exception or an interrupt occurs the address in the IDT should be generated correctly without perform a task switch, but what about memory protection for the kernel space?!
What do you think?! Can you suggest me a better way?