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.
struct gdt_entry{unsigned short limit_low;unsigned short base_low;unsigned char base_middle;unsigned char access;unsigned char granularity;unsigned char base_high;};
struct __attribute__ ((__packed__)) gdt_entry_nopad{unsigned short limit_low;unsigned short base_low;unsigned char base_middle;unsigned char access;unsigned char granularity;unsigned char base_high;};
struct gdt_ptr{unsigned short limit;unsigned int base;};
struct __attribute__ ((__packed__)) gdt_ptr_nopad{unsigned short limit;unsigned int base;};
printf("%u - %u\n", sizeof(struct gdt_entry), sizeof(struct gdt_entry_nopad));
printf("%u - %u\n", sizeof(struct gdt_ptr), sizeof(struct gdt_ptr_nopad));
If anyone declares and uses a Global Descriptor Pointer, then they need to make sure it is not padded by the compiler by using the compiler attribute for GCC, or MSVC (next line):
GCC:struct __attribute__ ((__packed__)) gdt_ptr;
MSVC:#pragma pack( push )
MSVC:#pragma pack( 1 )
MSVC:struct gdt_entry{ unsigned short limit; unsigned int base;};
MSVC:#pragma pack( pop )
It will work for both of them since the push saves the current padding specifier, then you actually set a new one, and finally pop the old padding specifier to return the default behavior.