Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am reading Understanding Linux Kernel, and in it I read about the Global Descriptor table and the Local Descriptor Table.

In which source file(s)(of linux kernel) the data structure for GDT and LDT are defined?

like image 234
user3686233 Avatar asked Sep 09 '14 19:09

user3686233


2 Answers

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.

like image 171
Ramesh Avatar answered Oct 19 '22 01:10

Ramesh


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.

like image 44
Daniel Avatar answered Oct 19 '22 03:10

Daniel