Subject: dp8390.c question
To: None <tech-net@netbsd.org>
From: Frode Vatvedt Fjeld <frodef@acm.org>
List: tech-net
Date: 12/06/2001 02:37:28
Hi, I'm working on the bochs i386 PC emulator (bochs.sourceforge.net)
NE2000 NIC device emulation, and I'm using NetBSD as a guest OS for
testing and debugging purposes.

The NetBSD NE2000 driver in /sys/dev/ic/dp8390.c emits numerous
warnings that the NIC memory is corrupted. I do of course presume that
this means the bochs emulation is faulty. However, I am unable to
understand how the relevant NetBSD driver code is supposed to
work. This is the code:

            /*
             * Try do deal with old, buggy chips that sometimes duplicate
             * the low byte of the length into the high byte.  We do this
             * by simply ignoring the high byte of the length and always
             * recalculating it.
             *
             * NOTE: sc->next_packet is pointing at the current packet.
             */
            if (packet_hdr.next_packet >= sc->next_packet)
                    nlen = (packet_hdr.next_packet - sc->next_packet);
            else
                    nlen = ((packet_hdr.next_packet - sc->rec_page_start) +
                        (sc->rec_page_stop - sc->next_packet));
            --nlen;
     X      if ((len & ED_PAGE_MASK) + sizeof(packet_hdr) > ED_PAGE_SIZE)
     X              --nlen;
            len = (len & ED_PAGE_MASK) | (nlen << ED_PAGE_SHIFT);

The exact part I don't understand are the two lines marked with X. I
don't understand the purpose or the logic of it. What is causing me
trouble is that when the if test is true (for example when len is
0xfe) nlen will underflow and in consequence the final len value
computed is completely wrong.

Any enlightenment on this would be much appreciated.

I'm not subscribed to this mailing list.

Thank you,
-- 
Frode Vatvedt Fjeld