Page 1 of 1

Global Descriptor Table Entry x86_64 32-bit format question

Posted: Sun Apr 26, 2026 7:30 am
by tedavids
My question has to do with the format of the GDT entry. I am using this article: https://wiki.osdev.org/Global_Descriptor_Table

The article shows the GDT segment descriptor. (Please see article)

My interpretation of this is:

Code: Select all

struct __attribute__((packed)) gdt_entry {
    uint8_t     membasehigh;    // byte 0
    uint8_t     flagslimit;     // byte 1
    uint8_t     access;         // byte 2
    uint8_t     membasemiddle;  // byte 3
    uint16_t    membaselow;     // bytes 4-5
    uint16_t    limit;          // bytes 6-7
};
Yet what I find on the internet shows the uint16_t entries (membaselow, limit) as being first in the structure.

I find it hard to believe that being a newbie at this, my interpretation is the correct one. I think it is more likely that I am missing something basic.

Could someone please tell me if I am correct, or explain what I'm missing?

Tom

Re: Global Descriptor Table Entry x86_64 32-bit format question

Posted: Sun Apr 26, 2026 1:50 pm
by Octocontrabass
The wiki diagrams are following the conventions of the Intel SDM, which shows data structures with the most-significant bit first. Since x86 is little-endian, that also means the byte at the highest address is first. In C, structs are laid out in the opposite direction, with the byte at the lowest address first.

Re: Global Descriptor Table Entry x86_64 32-bit format question

Posted: Sun Apr 26, 2026 2:10 pm
by tedavids
Thank you!

I assumed I was doing something wrong.

Tom

Re: Global Descriptor Table Entry x86_64 32-bit format question

Posted: Sun Apr 26, 2026 2:15 pm
by tedavids
Thank you!

I assumed I was doing something wrong.

Tom