Re: Bit field ordering on Big-Endian (SPARC) processor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 11 of December 2012 18:31:06 Dipanjan Das wrote:
> Consider the code below:
> 
> #define FORCE_CAST(var, type) *(type*)&var

^^^^^^^^^^^^^^^^ don't forget to use -fno-strict-aliasing with such ugly tricks.

> struct processor_status_register
> {
> unsigned int cwp:5;
> unsigned int et:1;
> unsigned int ps:1;
> unsigned int s:1;
> unsigned int pil:4;
> unsigned int ef:1;
> unsigned int ec:1;
> unsigned int reserved:6;
> 
> unsigned int c:1;
> unsigned int v:1;
> unsigned int z:1;
> unsigned int n:1;
> 
> unsigned int ver:4;
> unsigned int impl:4;
> }__attribute__ ((__packed__));

iirc, the C language gives no guarantee of the ordering of fields within machine words,
so if you use them for the h/w register modeling, you program will not only be nonportable,
it will be compiler-dependent too. you should really read suitable byte/word/doubleword
from mapped h/w memory, convert it with le/be_to_cpu() method and shift/mask to access bits.

BR,
Paweł.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux