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]

[Bug 1001275] Cortex-M (armV7) architecture endian instructions / Applied on lwIP

Please do not reply to this email. Use the web interface provided at:

--- Comment #2 from Sergei Gavrikov <> 2011-08-15 21:17:36 BST ---
Hi Ijlija,

Thank you for your attention to low-memory footprint eCos targets and your
ideas around, i.e. how to utilize every bit on such CPUs :-)

My $.02.

Instead hal_arch_instr.h I would create <arch>_regs.h header file to define
a few instructions in assembler.  In your case it is cortexm_regs.h.

NOTE: There are the precendents of such definitions in other architecture

I mean (snippets not tested!)

//==================================================== ...
//      cortexm_regs.h
//      Cortex-M CPU definitions
//      ...

#include <pkgconf/hal.h>

#include <cyg/hal/var_regs.h>

// Macro to embed rev instructions in C code
#define CYGARC_REV(_origin_, _swapped_)        \
    asm volatile( "rev %0, %1\n"        \
          : "=r" (_swapped_)         \
          : "r" (_origin_)        \

#define CYGARC_REV16(_origin_, _swapped_)    \
    asm volatile( "rev16 %0, %1\n"        \
          : "=r" (_swapped_)         \
          : "r" (_origin_)        \

// ---------------------------------------------------- ...
// End of cortexm_regs.h

And then I would add only needed inline functions and declarations in some
header file (again, not tested)

#include <cyg/hal/cortexm_regs.h>

#define LWIP_PLATFORM_HTONL( _hostlong_ )  hal_htol( _hostlong_ )
#define LWIP_PLATFORM_HTONS( _hostshort_ ) hal_htos( _hostshort_ )

static inline cyg_uint32 hal_htonl(cyg_uint32 hostslong)
    cyg_uint32      netlong;
    CYGARC_REV(hostlong, netlong);
    return netlong;

static inline cyg_uint16 hal_htons(cyg_uint16 hostshort)
    cyg_uint16      netshort;
    CYGARC_REV16(hostshort, netshort);
    return netshort;

But, I would resist to put them in hal_arch.h ...  And it is mine only. By
other hand lwipopts.h includes that header only. I thought it's pitty that we
have hal_io.h, but not hal_net.h. Thus, we need more expert views on code's


Configure bugmail:
------- You are receiving this mail because: -------
You are on the CC list for the bug.

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