sunnysideup wrote:
In your microkernel system, how do you do syscalls (traps - not necessarily the syscall instruction)? I'm not sure how it'd work on a microkernel, especially blocking syscalls.
My microkernel runs in long-mode, so what I say might not apply for real and protected mode:
In the TSS, you can select what stack to use for syscalls and interrupts (and you can even specify multiple stacks if you want to handle nested interrupts, such as catching if your interrupt handler code segfaults.)
For me, I have one kernel stack, which I share between syscalls and interrupts.
There is a bit in the
FLAGS register (bit 9) that tells the CPU if interrupts are enabled. When you use syscall/sysret, the kernel masks FLAGS with SFMASK. So if you set bit 9 in SFMASK, interrupts will be disabled upon entering a syscall, and re-enabled upon sysret.
Being a micro-kernel, my kernel is limited to scheduling, memory management, and messaging. I don't have any need for kernel threads, so the only way kernel code gets triggered is via an interrupt or syscall, and since interrupts won't trigger syscalls, and syscalls disable interrupts, kernel code won't interrupt kernel code and I only need one kernel stack.
When I implement multi-core support in the future, my plan is to have one TSS and kernel stack per processor, and use spin-locks around my data structures.