Subject: Re: CVS commit: src/sys/arch/sgimips
To: None <port-mips@netbsd.org>
From: Toru Nishimura <locore32@gaea.ocn.ne.jp>
List: port-mips
Date: 10/09/2003 00:09:18
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.

Toru Nishimura/ALKYL Technology