Home > Bachelor Thesis, Linux Kernel > GDT – Global Descriptor Table

GDT – Global Descriptor Table

The GDT is type of data structure used by Intel x86 family processors, in order to define the characteristics of the various memory used during program execution. It defines base access privileges for certain parts of memory. We can use an entry in the GDT to generate segment violation exceptions and kernel is thus given an opportunity to end a process that it shouldn’t be doing. Most modern operating systems use the concept of ‘Paging’ to do this. It is alot more versatile and flexible.
The GDT is a list of 64 bit long entries. These entries defines where exactly in memory that the allowed region will start, the limit of this region and the access privileges associated with the entry. Each entry also defines whether or not the current segment that the processor is running in is for system use (ring 0) or for application use (ring 3). Major OS today only use ring 0 and ring 3. Any application causes an exception if it tries to access system or ring 0 data. This is mainly to prevent an application causing the kernel to crash. As far as GDT is concerned, the ring levels tell the processor if it is allowed to execute special privileged instructions or not. Certain instructions are privileged, meaning that they can only be run in higher ring levels. eg: ‘cli’ – to enable interrupts and ‘sti’ – to disable the interrupts. If an application is allowed to use these instructions then it could effectively stop the kernel from running.
While creating a GDT, mainly 3 entries are important :
One, dummy descriptor in the beginning to act as the NULL segment for the processor’s memory protection features. Entry 0 is known as the NULL descriptor and no segment register should be set to 0 as otherwise this will cause a General Protection fault, and is a protection feature of the processor.
Second, entry for the code segment. The Code Segment (CS) tells the processor which offset into the GDT that it will find the access privilege in which to execute the current code.
Third, entry for the data segment registers. The Data Segment (DS) defines the access privileges for the current data. ES, FS and GS are simply alternate DS registers and are not important as such.

Reference : Bran’s Kernel Development Tutorial

  1. March 11, 2011 at 2:38 am | #1

    It’s interesting to see this point of view. I can’t say fore sure if I agree or not, but it is something I will think about now.

  1. March 8, 2011 at 1:56 am | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.