File in which the data structure for Global Descriptor and Local Descriptor table is defined?

A google search for the term "Linux Kernel file gdt" yields the exact results that you are looking for. This is the link to the search result of the book with the contents describing where the GDT and LDT are defined.

  • All GDTs are stored in the cpu_gdt_table array.

  • If you look in the source code index, you can see that these symbols are defined in the file arch/i386/kernel/head.S. However, I think the source code index can be viewed when you have a copy of the book. But nevertheless, the file where GDT is defined is given.

For the latest kernel, the GDT seems to be defined in at least 3 separate files.

  • arch/x86/include/asm/desc_defs.h
  • arch/x86/include/asm/desc.h
  • arch/x86/include/asm/segment.h

The layout of the main GDT seems to be defined in arch/x86/include/asm/segment.h around line 91. There are comments about the layout above this line.

The completed table is loaded in arch/x86/include/asm/desc.h with the function static inline void native_load_gdt(const struct desc_ptr *dtr) which just calls the assembly opcode lgdt. This is consistent with the way older kernels load the table into the processor. See line 303 here. However, I cannot find any calls to this function in the code base. Someone please help figure this out.

Also I cannot find the equivalent of defining the constants of the actual table as in line 479 in newer kernels.