This is the mail archive of the mailing list for the eCos project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: network buffer alignment

On Fri, Sep 19, 2008 at 09:44:05AM +0200, Lars Poeschel wrote:
> Hello!
> I am writing an ethernet driver for coldfire architecture and I am using 
> redboot for simple ping tests.
> I had the problem of strange ethernet destination addresses on the wire 
> for outgoing packets. This was because the controller requires the 
> buffers for transmitting to be 4 byte aligned and the buffer in question 
> did not has this alignment. The buffer in question is in  
> redboot/current/src/net/enet.c in function __enet_send, the eth_hdr  
> stack variable. I now wonder if my ethernet controller is the only one  
> with this 4 byte aligning requirement or if other architectures had luck 
> in gcc aligning this buffer at a 4 byte boundary by random ?
> I could make it work by forcing gcc with __attribute__((aligned(4))) to 
> the right alignment. This would make a little change in the redboot  
> sources neccessary, but I am not sure if this applies for all the other 
> architectures out there. If this were not the case, my only other 
> solution is: In the driver right before sending the packet I would check 
> for the right buffer alignment and if it is not correct, I would have to 
> allocate memory with the alignment in place and copy the wrong buffer 
> there. This would be a really ugly solution.
> What are your opinions ?

This sounds like a toolchain issue. 

[Goes away and googles]

    Control whether GCC aligns int, long, long long, float, double,
    and long double variables on a 32-bit boundary (-malign-int) or a
    16-bit boundary (-mno-align-int). Aligning variables on 32-bit
    boundaries produces code that runs somewhat faster on processors
    with 32-bit busses at the expense of more memory.

    Warning: if you use the -malign-int switch, GCC will align
    structures containing the above types differently than most
    published application binary interface specifications for the

Does this help?


Before posting, please read the FAQ:
and search the list archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]