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.
Do I place the items with the least significant bits in first due to Little Endianness? (for example the LimitLow occupies bits 0-15 so I put it first)
The GDT entries are just 32-bit (or 64-bit numbers). So the easy way to answer your question is just to look at memory and see what has been put there by your code.
Your structure will be endian-dependent the moment you use data types larger than uint8_t or you use bit fields. Note that the bit fields layout order is also endian-dependent, which may be tricky to get right if you don't understand endianness that well. Personally, I am not that happy with bit fields and just assemble the values with shifts and or, such as gdt->foo = bar << 4 | qux << 0.
sortie wrote:Your structure will be endian-dependent the moment you use data types larger than uint8_t or you use bit fields. Note that the bit fields layout order is also endian-dependent, which may be tricky to get right if you don't understand endianness that well. Personally, I am not that happy with bit fields and just assemble the values with shifts and or, such as gdt->foo = bar << 4 | qux << 0.
Say if I use 8 1-bit bitfields for a byte, I would just order them from MSB to LSB aye?
e.g. is this correct?
But that is wrong isn't it? Because it would be passing the value pointed to by ptr to LGDT (which would be the first 4 bytes of the gdti structure...)
If I change it so that I am passing the POINTER to gdti, OS all broken...
BMW wrote:
Say if I use 8 1-bit bitfields for a byte, I would just order them from MSB to LSB aye?
e.g. is this correct?
...
Don't assume. If you are doing an ELF-operating system, look up what your compiler generates in the System V ABI (i386 version). Don't pay attention to me. On SysV targets, the bit fields are placed according to the host endianness. That is, struct { unsigned int a1: 1; unsigned int a2: 1; ... unsigned int a32: 1; } will have the exactly opposite order when switching endian (such as going from big endian to little endian). I recommend that you write a test program using bit fields for your host operating system with gcc and use objdump -d to see what the program does.
BMW wrote:EDIT: Sorry if this is a RTFM question, but there is a serious lack of DECENT GCC inline assembly information.
There is such a lack and it's kinda a problem. The root cause is that it's not really a compiler problem, because it depends on the backend and the assembly itself depends on the assembler. If in doubt, write an assembler function in a file instead.