Hi,
Izzette wrote:
I don't understand how the IDT and the TSS fit together with system calls. The wiki suggests that a TSS is necessary for system calls and that the only values in the TSS I have to worry about are SS0, ESP0, and IOPB [1].
Usually when the CPU switches from a less privileged level (e.g. CPL=3) to a more privileged level (e.g. CPL=0) it changes stack, so that the more privileged code doesn't (temporarily) have to use the less privileged code's "untrusted" stack. The details for the new stack come from the TSS (e.g. the SS0 and ESP0 fields).
For hardware task switching (where you're switching from one task to a complete different task and not switching privilege levels within the same task) the SS0 and ESP0 fields aren't used. In this case everything gets loaded from the TSS's normal fields, including ESP being loaded from the "ESP" field (and not the "ESP0" field).
Izzette wrote:
Could someone kindly clear this up for me? How am I "supposed" to handle syscalls? What gate type do I use in my IDT? etc. Thanks in advance!
For syscalls, you probably don't want to do a software task switch or a hardware task switch (and only want to change privilege level), so you don't want a task gate. For software interrupts you'd want to use an interrupt gate or trap gate (depending on whether you want IRQs to be disabled by CPU before starting the syscall handling code).
Cheers,
Brendan