On 08.06.2018 22:05, Laurent Vivier wrote: > This is needed by Quadra 800, this card can run on little-endian > or big-endian bus. > > Signed-off-by: Laurent Vivier <laur...@vivier.eu> > --- > hw/net/dp8393x.c | 101 > ++++++++++++++++++++++++++++++++++++++----------------- > 1 file changed, 70 insertions(+), 31 deletions(-) > > diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c > index ef5f1eb94f..5061474e6b 100644 > --- a/hw/net/dp8393x.c > +++ b/hw/net/dp8393x.c > @@ -150,6 +150,7 @@ typedef struct dp8393xState { > > /* Hardware */ > uint8_t it_shift; > + bool big_endian; > qemu_irq irq; > #ifdef DEBUG_SONIC > int irq_level; > @@ -174,6 +175,12 @@ typedef struct dp8393xState { > AddressSpace as; > } dp8393xState; > > +#ifdef HOST_WORDS_BIGENDIAN > +static const bool host_big_endian = true; > +#else > +static const bool host_big_endian = false; > +#endif > + > /* Accessor functions for values which are formed by > * concatenating two 16 bit device registers. By putting these > * in their own functions with a uint32_t return type we avoid the > @@ -220,6 +227,36 @@ static uint32_t dp8393x_wt(dp8393xState *s) > return s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0]; > } > > +static uint16_t dp8393x_get(dp8393xState *s, int width, uint16_t *base, > + int offset) > +{ > + uint16_t val; > + > + if (s->big_endian) { > + val = base[offset * width + width - 1]; > + } else { > + val = base[offset * width]; > + } > + if (s->big_endian != host_big_endian) { > + val = bswap16(val); > + } > + return val; > +}
Could you maybe write that like this instead: { uint16_t val; if (s->big_endian) { val = base[offset * width + width - 1]; val = be16_to_cpu(val); } else { val = base[offset * width]; val = le16_to_cpu(val); } return val; } ? ... then you don't need that ugly host_big_endian variable anymore. Thomas