In Linux, there are many similar concepts. This article briefly talks about the IDT (Interrupt Descriptor Table), GDT (Global Descriptor Table), LDT (Local Descriptor Table) and TSS(Task State Segment).
The whole system has only one IDT. In protected mode, IDT stores the address of all the ISR (Interrupt Service Routine). When interrupt happens, the system will directly find the corresponding ISR, with the help of IDT. It has similar function compared to the IVT (Interrupt Vector Table) in real mode. Their differences are that IVT has a fixed address but IDT’s address is stored in IDTR (Interrupt Descriptor Table Register) and it can be changed. Using the command,
we can write the address of IDT into IDTR. In IDT, there are many Interrupt Gate, each Interrupt Gate corresponds to a ISR. The structure of Interrupt Gate is shown below.
In the system, there is only one GDT. GDT stores the LDT and TSS of all the processes. We can treat it as a directory of processes. Like IDT, GDT can also be placed in any place of the memory and its address is stored in GDTR (Global Descriptor Table Register). Using the command,
we can write the address of GDT into GDTR. The structure of GDT is shown below.
In fact, LDT is a segment descriptor and it is used to locate the segment of corresponding process. Every process has a LDT and all the LDTs are stroed in GDT. Because there are many LDTs in the system, we need a selector to choose the current LDT. This selector is LDTR (Local Descriptor Table Register).
While the system is running, all the processes will alternate use the CPU. So the value in LDTR will keep changing all the time. While process switching, we use the “lldt” command to load a new segment. Some other commands can also modify the value in LDTR, for example, “jmpi”.(When Linux 0.11 entering the protected mode, the first used command is “jmpi”)
Each process has its own TSS, its address is stored in a segment descriptor next to LDT in GDT. TSS contains many register informations about current process and it is used to save and recover the context information.
In Linux 0.11, a “ljmp” command to switch the context information (this command has done many other works). “ljmp” command will put all the registers’ information into the TSS of current process, then load the register information in TSS of nest process to all the registers. At the same time, this command will change the value in LDTR, to make it point to the new sgement.
The structure of TSS is hown below.