Cogent 637 board

Jay Monkman jtm at
Thu Nov 10 16:08:32 UTC 2005

Jiri Gaisler wrote:
> This issue is also a problem for the SPARC port, which does
> not allow miss-aligned access. In my opinion, the network stack
> has a bug here as it uses a pointer to structure without checking
> the pointer alignment. The whole problem would be solved by
> splitting that access to the IP address in the IP header into
> two 16-bit reads, rather than a 32-bit read. It would require
> to modify the IP stack, but all these issues would be solved
> once and for all. Maybe the access could be done through a
> #define which would be empty on targets supporting unaligned
> access.
> An other solution (which is used in eCos) is to implement an
> unaligned access trap handler. The trap handler emulates the
> access using two 16-bit reads. The overhead should not be
> that large as it is only the IP addresses in the IP header
> which are miss-aligned.

This is also a problem on MIPS.

The network stack is from an older version of FreeBSD, from a time when it must
have only supported x86 and m68k, which can deal with misaligned data. The stack
actually goes out of its way to make the problem worse. In at least one place it
uses two 16 bit fields to store a 32 bit value, where the first 16 bit field is
not 4-byte aligned. Something like this:

	| Byte 0 | Byte 1 | Byte 2 | Byte 3 |
        |            long 1                 |
	|    ?   |   ?    |     short 1     |
	|     short 2     |    ?   |   ?    |

So, the 32 bit value is stored in short 1:short 2. So no matter what you do,
something is misaligned.

If you search the networking code for __arm__, you'll find the places we had to
change to fix the misaligned accesses for ARM.

I think the real solution would be to update the network stack to a recent
version of NetBSD. (FreeBSD would probably be fine, but I think NetBSD would be
safer since it runs on more platforms.) Unfortunately, it's hard to find time to
do it.

More information about the users mailing list