Task State Segment - Inner-level Stack Pointers

Inner-level Stack Pointers

The TSS contains 6 fields for specifying the new stack pointer when a privilege level change happens. The field SS0 contains the stack segment selector for CPL=0, and the field ESP0/RSP0 contains the new ESP/RSP value for CPL=0. When an interrupt happens in protected (32-bit) mode, the x86 CPU will look in the TSS for SS0 and ESP0 and load their values into SS and ESP respectively. This allows for the kernel to use a different stack than the user program, and also have this stack be unique for each user program.

A new feature introduced in the AMD64 extensions is called the Interrupt Stack Table (IST). This also resides in the TSS and contains logical (segment+offset) stack pointers. An interrupt descriptor table may specify an IST entry to use (there are 8). If that is the case, the processor will load the new stack from the IST instead. This allows known-good stacks to be used in case of serious errors (NMI or Double fault for example). Previously, to do this, the entry for the exception or interrupt in the IDT pointed to a task gate. This cause the processor to switch to the task that is pointed by the task gate. The original register values were saved in the TSS current at the time the interrupt or exception occurred, and the processor then set the registers, including SS:ESP, to a known value specified in the TSS and saved the selector to the previous TSS. The problem here is that hardware task switching is not supported on AMD64.

Read more about this topic:  Task State Segment

Famous quotes containing the word stack:

    What is a farm but a mute gospel? The chaff and the wheat, weeds and plants, blight, rain, insects, sun—it is a sacred emblem from the first furrow of spring to the last stack which the snow of winter overtakes in the fields.
    Ralph Waldo Emerson (1803–1882)