assemblyx86osdevgdtmultiboot

Which segment descriptor does Intel assembly command "sgdt" returns


I want to implement 32-bit 4Gb Flat Memory mapping for an application, for this purpose I have to get and update Data Segment Descriptor and Code Segment Descriptors. By using assembly command "sgdt" i can get Global Descriptor Table but I am not sure if its CS or DS or any other descriptor. It would be really appreciated if some one can help me deal with this confusion.

I am relying on GRUB to set GDT that's why i don't know the exact location where it put all the segment descriptors. By viewing the GDT table entries I can see 5 same Code Segment Entries and 6 Same Data Segment entries, with base address of each entry set to '0' and limit of each set to '0xfffff'. Can you please tell me reason for these duplicate entries? And from these viewing, can you kindly confirm that Flat Memory mode is already being set by GRUB?


Solution

  • Answering my own question after getting great response in comments section. GDT Table contains the entries for Segment descriptors in protected mode, The Code Segment and Data Segment are identified by reading value of Code Segment Register / Data Segment Register where it contains the index for particular segment (also called Segment Selector) in GDT table.