Open In App

What is Global Descriptor Table

Global Descriptor Table :

Structure :
Exactly in protected mode, in the Intel Architecture, essentially the Interrupt Service Routines and the memory management are managed by tables of descriptors. Each descriptor keeps the information about a single object, For example; a task, a service routine, a portion of data or code, etc, which the CPU may need at some time. If someone tries to fill a new value into a segment register then the CPU requires carrying out safety and access control checks to see either you are literally allowed to access that specified memory area or not. If these checks are performed successfully then useful values are cached in invisible registers of the CPU. Intel represents 3 types of tables as follows.



  1. The Interrupt Descriptor Table (which replaces the IVT)
  2. The Global Descriptor Table (GDT)
  3. The Local Descriptor Table (LDT)

Note –
All the above tables are represented as a linear address, size to the CPU by the LIDT, LGDT, LLDT instructions sequentially. In most cases, the OS directly informs where those tables are at boot time and then clearly, the OS goes writing or reading the tables by a pointer.

GDT overview :
The Global Descriptor Table carries entries that tell the CPU about the memory segment. It is peculiar to the IA32 architecture.



Composition :
Here, we will understand GDT composition step by step as follows.
Step-1 :
By using the LGDT assembly instruction, the GDT is loaded. It looks for the location of a structure of GDT description. :

GDTR

Step-2 :
Here, the Offset is the linear address of the descriptor table, the meaning of which is that paging applies and the Size here is the size of the descriptor table which is subtracted by 1. The size of the descriptor table is subtracted by 1 because 65535 is the maximum value for size but the GDT can only be up to 65536 bytes (which means that the entries can be maximum of 8192). Also, no GDT can carry a size of 0.

Step-3 :
The GDT contains 8-byte entries, each having a complex structure as follows.

GDT Entry

Step-4 :
Here, Limit 0:15 means that the field carries 0-15 bits of the limit value. The base has 32 bits value which contains the linear address from where the segment starts and a 20-bit value here indicates the maximum addressable unit (which is either in 1 byte of units or in pages). Therefore, if someone selects the page granularity such as 4 KiB and then sets the limit value to 0 × FFFFF, the segment here will length 4 GiB address space. Following is the composition of flags and access byte shown as follows.

GDT Bits

Step-5 : 
Symbol description –

Step-6 :           
Conforming Bit for code selectors –
If 1 code in the given segment is carried out from an equal or lower privilege level. For example, code in ring 3 far-jump to conforming code in ring 2 segments. The privl bits show the highest privilege level which is allowed to execute the segment. For example, code in ring 0 cannot far jump to a conforming code segment with privl == 0 × 2, but code in ring 2 and 3 can do this. Therefore, the privilege level remains the same, i.e, a far-jump form ring 3 to a privl == 2 — segment remains in ring 3 after the jump. If 0, then the code in this segment can only be executed from the ring set in privl.

Step-7 : 
Symbol description –

  1.  Readable bit for code selectors : 
    In-case read access for this segment is allowed. Write access is never allowed for code segments.
  2.  Writable bit for data selectors : 
    In case write access for this segment is allowed. Read access is always allowed for data segments.

What is kept in GDT :
For the purpose of keeping balance, one should always store the following items in the GDT as follows.

Article Tags :