The GDT is a global description of the schedule, which primarily stores the operating system and the common descriptors for each task, such as common data and code snippet descriptors, TSS descriptors for each task, and the LDT descriptor. (TSS is a task status segment that holds individual task private run state information descriptors)
The LDT is a local descriptor, which mainly holds private descriptors for each task, such as the code snippet descriptor and data segment descriptor for this task.
The GDTR is a 48bit-length register that contains a 32-bit base address and a 16-bit segment limit. Where 32-bit base addresses refer to the GDT's address in memory.
LDTR is a local descriptor register consisting of a visible 16-bit register (segment selector) and an invisible descriptor register (the descriptor register is actually an invisible high-speed buffer area).
Here's what I understand: there should be a LDT descriptor in addition to the segment descriptor in the GDT, so when the microprocessor addresses the LDT in the GDT, it also needs to use the selector to maintain unity with the segment descriptor addressing.
There is also the concept of a segment selector to be introduced here. The segment selector is a register with a height of 13 bits indicating the index number of the descriptor in the descriptor table, the lower two bits representing the privilege level using the descriptor, and the other one (T1) is the semaphore of the GDT and the LDT, if t1=0, use GDTR if t1=1, then LDTR. The selection child will be loaded into the segment register. There are six segment registers in the system: CS, SS, DS, ES, FS, and GS. When a select child is loaded into a segment register, the microprocessor automatically loads its corresponding descriptor into the descriptor register.
When the system task is switched, the LDT switches, and the GDT does not switch (because there is only one GDT for the system), then the selector of the LDT descriptor for the new task is loaded into the LDTR.
Changes in the various related registers during the task switching process?
When the task is switched, if the use of the LDT, the first change is LDTR. The segment selector is loaded into the LDTR, and the LDT descriptor is automatically loaded into the descriptor register. The system uses segment selectors in LDTR to position the LDT descriptor in the GDT. What I don't understand here is what is the relationship between the LDT descriptor in LDTR and the descriptor in the GDT? Why did you do it? What exactly is the descriptor that is automatically loaded into LDTR? Where do you come from? Please expert guidance!
Why should there be a GDTR, and the structure of GDTR is not the same as LDTR?
This is mainly because the system has only one GDT, and the description of the GDT have cannot be stored in the GDT (the LDT descriptor is stored in the GDT), so a GDTR is required to indicate the location of the GDT in memory. Because GDTR directly indicates the memory address, LDTR mainly indicates the location and properties of the LDT descriptor in the GDT, so the structure of GDTR and LDTR is different.
Copyright notice: When reproduced, please indicate the original source and author information and this statement in the form of hyperlinks.
Http://xmurobin.blogbus.com/logs/11842842.html
-------------------------the following from elsewhere-----------------------------------------------------------------------
GDTR and LDTR How to convert a virtual address to a linear address
GDTR is a 48-bit register that points to the Global descriptor Table GDT, from 16 bits to 47 bits of the first 32 bits of the GDT in memory address, is a linear address, need to be converted to a physical address by the page table
LDTR is a 16-bit register, which is an index in the GDT, points to the local descriptor List LDT, each task has a LDT, and different Ldt occupies different memory segments, described by different system descriptors, which are placed in the GDT.
The index value is stored in the LDTR, pointing to the location of the LDT in the GDT
If you have a virtual address on hand xxxx:yyyyyyyy
First remove the GDT base BA from the GDTR to find the GDT
XXXX Total 16, according to the last third place is T1 bit judgment
If the first 13 bits of T1=0,XXXX represent the location index of the GDT, a descriptor is obtained based on the index
The descriptor contains the base address of the segment and various other information, and the beginning of the segment +yyyyyyyyy to get the thread address
If t1=1, then the location index of the LDT is obtained from LDTR, the LDT descriptor is found inside the GDT, and the LDT descriptor contains the linear address of the LDT.
Find the LDT, take out the first 13 of XXXX, find the segment descriptor in the LDT, the segment descriptor contains information such as the base address of the segment.
The base address of the latter segment plus yyyyyyyy to get the linear addresses
The understanding of GDT, GDTR, LDT, LDTR