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.
This ring-3 call wrapper took quite a bit of clever coding and debugging to achieve. However, when I attempt to return from the event handler, in reverse order, back to the position at which the IRQ1 handler interrupted at, I simply seem to jump back to the line after the ring-3 call wrapper returns.
Gigasoft wrote:I don't see tss_rsp0 being updated anywhere, so you are overwriting the interrupt handler's stack.
tss_rsp0 is updated in setup_syscalls:user/syscalls.asm.
Besides, I don't ever use the stack before I switch back to the same stack that was being used before the ring-3 switch. [source: ring0_return:drivers/evsys/callring3.asm]
Let me just check if I'm understanding this correctly.
You set RSP0 in the TSS when you initialize your kernel.
Then you get an IRQ in ring 3, which pushes its return address onto the RSP0 stack.
Then you call your user mode function and use INT 0x80 to return, which pushes its return address onto the same RSP0 stack, overwriting the IRQ handler's return address.
Octocontrabass wrote:Let me just check if I'm understanding this correctly.
You set RSP0 in the TSS when you initialize your kernel.
Then you get an IRQ in ring 3, which pushes its return address onto the RSP0 stack.
Then you call your user mode function and use INT 0x80 to return, which pushes its return address onto the same RSP0 stack, overwriting the IRQ handler's return address.
Is that right?
1) Yes. I do set RSP0 in the TSS.
2) I do get an IRQ in ring 3, but it pushes its return address onto the IST1 stack.
3) INT 0x80 uses the IST2 stack, not the IST1 stack.
But if you don't allow IRQs, the ring 3 call could deadlock the kernel.
Other OSes don't directly call ring 3 code. Instead, they have threads that sleep until a specific event occurs, and one possible event is an IRQ. Since they're ordinary threads, they can be interrupted like normal.