In the midst of writing a task scheduler, I've decided that I would like to be able to create "kernel"-ring privileged threads, in addition to "normal" user-ring ones. I've already got all of the code for user-mode task-switching, and it is working perfectly (based off PIT interrupts). I can have multiple processes, they can make syscalls, tasks may enter a "sleep" state, and it's all really cool.
I encountered problems when I switched the descriptors for tasks I was making from user-PL to kernel-PL (CS and SS), expecting everything to run smoothly. As it turns out, when the CPU doesn't have to switch privilege levels after an interrupt, it doesn't push ESP or SS, nor will an IRET returning to the same PL pop them. This has several obvious problems, including the fact that interrupts will use the kernel-PL task's stack instead of the global kernel stack, etc.
I've had a good look at the manuals (as I hope you can tell) but I can't seem to find a feature of the x86 which could help me get around this problem.
Does anyone have any experience with doing this sort of thing already? Alternately, does anyone have any ideas?
Thanks in advance,
Keeley
P.S. As a side note, I'm quite aware that the Linux kernel does this already, but I haven't been able to identify how it's arch-dependant and independent code links together.


