Global Descriptor Table Entry x86_64 32-bit format question

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tedavids
Posts: 11
Joined: Sun Apr 26, 2026 6:59 am

Global Descriptor Table Entry x86_64 32-bit format question

Post 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
Octocontrabass
Member
Member
Posts: 6275
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
tedavids
Posts: 11
Joined: Sun Apr 26, 2026 6:59 am

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

Post by tedavids »

Thank you!

I assumed I was doing something wrong.

Tom
tedavids
Posts: 11
Joined: Sun Apr 26, 2026 6:59 am

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

Post by tedavids »

Thank you!

I assumed I was doing something wrong.

Tom
Post Reply