Subject: Re: CVS commit: src/sys/arch/sgimips
To: Toru Nishimura <locore32@gaea.ocn.ne.jp>
From: Andrey Petrov <petrov@netbsd.org>
List: port-mips
Date: 10/08/2003 10:47:12
On Thu, Oct 09, 2003 at 12:09:18AM +0900, Toru Nishimura wrote:
> Izumi Tsutsui asked about fixing endian issue in if_wmreg.h
>
> > With a quick glance, structure of wm(4) actually smells Intel-ism ;-p
> > uint8_t/uint16_t values in 32 bit DMA descriptors always cause
> > endian issue (and might cause race conditions on RISC CPUs.)
> >
> > How about the attached patch?
> >
> > typedef struct wiseman_rxdesc {
> > ...
> > +#if BYTE_ORDER == LITTLE_ENDIGN
> > uint16_t wrx_len; /* buffer length */
> > uint16_t wrx_cksum; /* checksum (starting at PCSS) */
> > +#else
> > + uint16_t wrx_cksum; /* checksum (starting at PCSS) */
> > + uint16_t wrx_len; /* buffer length */
> > +#endif
>
> It can be written in endian-neutral way by declaring a 32bit quantity of
> unsigned long and do explicit bitmasking and shifting. The solution
> is cheap and elegant, removing endian puzzles forever.
>
Generated code will be less efficient thou.
Andrey