Linux Kernel series-4. LDT and linuxldt for Operating System Development
For a long time, we have put all the segment descriptors in GDT, no matter whether it is a kernel or a user program, in order to effectively implement isolation between tasks, the processor recommends that each task have its own Descriptor Table, called the Local Descriptor Table LDT, and put the segments dedicated to itself in the LDT.
Like GDT, LDT is used to store descriptors. The difference is that LDT only belongs to a specific task. In other words, each task has its own LDT, and each task's private segment should be described in LDT. In addition, the LDT's 1st descriptors, that is, the 0 slot, are also valid and usable.
LABEL_DESC_LDT: Descriptor 0, LDTLen-1, DA_LDT; LDTSelectorLDTequLABEL_DESC_LDT-LABEL_GDT [SECTION. s16]; initialize the LDT descriptor xoreax, eaxmovax, dsshleax, 4 addeax, LABEL_LDTmovword [forward + 2], axshreax, 16 movbyte [LABEL_DESC_LDT + 4] In GDT. almovbyte [forward + 7], ah; initialize the descriptors xoreax, eaxmovax, dsshleax, 4 addeax, LABEL_CODE_Amovword [forward + 2], axshreax, 16 movbyte [forward + 4], almovbyte [LABEL_LDT_DESC_CODEA + 7], ah
The LDTR register is only used to point to the LDT of the current task. When a task is switched, the content of LDTR is updated to point to the LDT of the new task. If the selected sub-TI is set to 1, the system will find the corresponding descriptor from the current LDT. When SelectorLDTCodeA is used, the system will find the LABEL_LDT_DESC_CODEA descriptor from the LDT and jump to the corresponding segment. Before using LDT, use the lldt command to load ldtr. The lldt operand is the LDT descriptor used to describe LDT in GDT.
; LDT [SECTION. ldt] ALIGN32LABEL_LDT:; Segment Base Address segment boundary attributes: Descriptor 0, CodeALen-1, DA_C + DA_32; Code, 32-bit LDTLenequ $-LABEL_LDT; LDT select sub, SA_TIL set the TI position of the selected sub-item to 1. selectorLDTCodeAequLABEL_LDT_DESC_CODEA-LABEL_LDT + SA_TIL; END of [SECTION. ldt]
The running result is as follows:
【Source code and floppy disk image]