Forums

Endianess problem

Started by sid1977 October 8, 2007
Hi,

I am writing a driver for a ethernet controller. The controller is
connected to the io memory and expects data to be in the Little endian
format (will call it LE now and BE for big endian). The main cpu which
runs the driver code is a BE machine. During the startup I write the
descriptors into the  io memory in the LE format. In the send and receive
routine which is called by the IP stack I have pointers that access the
descriptors. The pointers are actually pointing to data which is in LE
format, so if I want to access a bit(a part of the desc bit field) like
ptr->own_bit it will refer to the wrong bit. How can I come over this
problem.

wr,
Sid



On Oct 8, 5:38 am, "sid1977" <sidbha...@yahoo.com> wrote:
> Hi, > > I am writing a driver for a ethernet controller. The controller is > connected to the io memory and expects data to be in the Little endian > format (will call it LE now and BE for big endian). The main cpu which > runs the driver code is a BE machine. During the startup I write the > descriptors into the io memory in the LE format. In the send and receive > routine which is called by the IP stack I have pointers that access the > descriptors. The pointers are actually pointing to data which is in LE > format, so if I want to access a bit(a part of the desc bit field) like > ptr->own_bit it will refer to the wrong bit. How can I come over this > problem. > > wr, > Sid
You have identified the problem. To overcome it, fix the code.
"sid1977" <sidbharij@yahoo.com> writes:
> > I am writing a driver for a ethernet controller. The controller is > connected to the io memory and expects data to be in the Little endian > format (will call it LE now and BE for big endian). The main cpu which > runs the driver code is a BE machine. During the startup I write the > descriptors into the io memory in the LE format. In the send and receive > routine which is called by the IP stack I have pointers that access the > descriptors. The pointers are actually pointing to data which is in LE > format, so if I want to access a bit(a part of the desc bit field) like > ptr->own_bit it will refer to the wrong bit. How can I come over this > problem.
I thought the comm data was in Big-Endian order. Are you talking about control and status registers' content? ----------------------------------------------------------------------- "Big-Endian byte order is known as 'normal', 'intuitive', or 'obvious'. Little-Endian is sometimes called 'perverse', 'annoying', 'dysfunctional', or 'stupid'. These designations do not, of course, imply any bias or preference." Christopher R. Hertel, "Implementing CIFS" 2004
"Everett M. Greene" <mojaveg@mojaveg.nodomain> wrote in message 
news:20071008.7A9FFF0.D043@mojaveg.lsan.mdsg-pacwest.com...
> "sid1977" <sidbharij@yahoo.com> writes: >> >> I am writing a driver for a ethernet controller. The controller is >> connected to the io memory and expects data to be in the Little endian >> format (will call it LE now and BE for big endian). The main cpu which >> runs the driver code is a BE machine. During the startup I write the >> descriptors into the io memory in the LE format. In the send and receive >> routine which is called by the IP stack I have pointers that access the >> descriptors. The pointers are actually pointing to data which is in LE >> format, so if I want to access a bit(a part of the desc bit field) like >> ptr->own_bit it will refer to the wrong bit. How can I come over this >> problem. > > I thought the comm data was in Big-Endian order. Are you talking > about control and status registers' content? > > ----------------------------------------------------------------------- > "Big-Endian byte order is known as 'normal', 'intuitive', or > 'obvious'. Little-Endian is sometimes called 'perverse', > 'annoying', 'dysfunctional', or 'stupid'. These designations > do not, of course, imply any bias or preference." > > Christopher R. Hertel, "Implementing CIFS" 2004
There is also the possibility that the two machines/compilers will allocate bit fields in a different order. Fortunately for me, the Keil 8051 and MSVC86 compilers both allocate bit fields from LS bit up. This only matters if you are hoping to share structure definitions between machines.
sid1977 wrote:

> I am writing a driver for a ethernet controller. The controller is > connected to the io memory and expects data to be in the Little endian > format (will call it LE now and BE for big endian). The main cpu which > runs the driver code is a BE machine. During the startup I write the > descriptors into the io memory in the LE format. In the send and receive > routine which is called by the IP stack I have pointers that access the > descriptors. The pointers are actually pointing to data which is in LE > format, so if I want to access a bit(a part of the desc bit field) like > ptr->own_bit it will refer to the wrong bit. How can I come over this > problem.
In the past I have written alternate forms of struct definitions, with the bitfields appropriately adjusted to align. One machine uses one definition and the other processor uses the other. An #ifdef selected the proper form based on the target. -- Thad