Bitfield for GDT structure?

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.
User avatar
CocaCola
Member
Member
Posts: 36
Joined: Fri Sep 07, 2012 9:11 am

Re: Bitfield for GDT structure?

Post by CocaCola »

I found these two:
http://stackoverflow.com/questions/6728 ... -bit-order
http://gcc.gnu.org/onlinedocs/gccint/St ... ayout.html

So according to this, everything should be fine if the machine is Little Endian?
GNU Online Docs wrote:— Macro: BITS_BIG_ENDIAN

Define this macro to have the value 1 if the most significant bit in a byte has the lowest number; otherwise define it to have the value zero. This means that bit-field instructions count from the most significant bit. If the machine has no bit-field instructions, then this must still be defined, but it doesn't matter which value it is defined to. This macro need not be a constant.

This macro does not affect the way structure fields are packed into bytes or words; that is controlled by BYTES_BIG_ENDIAN.

— Macro: BYTES_BIG_ENDIAN

Define this macro to have the value 1 if the most significant byte in a word has the lowest number. This macro need not be a constant.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Bitfield for GDT structure?

Post by bluemoon »

I would not recommend using compiler-specific MACRO to workaround issue arise from undefined behavior on the specification...
There is nothing wrong with method one (byte array), or file with serializer.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Bitfield for GDT structure?

Post by Owen »

You all seem to be ignoring that this is very defined behavior, just not by the C standard. As noted by the C standard, it is implementation defined; in particular, it is defined by whatever ABI your compiler follows:
i386 SystemV ABI
AMD64 SystemV ABI (read in conjunction with above)
ARM EABI AAPCS

When you pick an ABI for your OS (which is probably derived from one of the above), you decide what the bitfield packing is. For CPU structures, it is very much portable behavior; for device structs, somewhat less.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Bitfield for GDT structure?

Post by Love4Boobies »

We weren't ignoring it; implementation-defined means that the implementation must consistently do something and that something is specified by its ABI. I believe the point was to minimize ABI dependence.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply