[En-Nut-Discussion] Replacing compiler.h

Harald Kipp harald.kipp at egnite.de
Thu Oct 4 10:04:19 CEST 2012


Hi all,

I'm finally trying to unravel all those duplicate parts in compiler.h,
and those headers included by compiler.h, to make porting a bit easier
and more flexible.

We have two general dependencies, the toolchain and the runtime library.
Although we currently have both closely related today, other compilers
like Clang and other libraries like eglibc may become more interesting
in the future.

The plan is to replace compiler.h by toolchain.h containing

 #if defined(__GNUC__)
 #include <toolchain/gcc.h>
 #elif defined(__IMAGECRAFT__)
 #include <toolchain/icc.h>
 #else
 #include <toolchain/generic.h>
 #endif

plus a number of general macros like _BV().

In turn, toolchain/gcc.h will contain

 #if defined(__AVR__)
 /* Only avr-libc is currently supported for GCC. */
 #include <toolchain/avrlibc.h>
 #elif defined(__arm__)
 /* Only newlib is currently supported for GCC. */
 #include <toolchain/newlib.h>
 #endif

for all targets and runtime libraries that are supported by this
toolchain. Furthermore, this header will define all compiler related
macros like _NOP

 /*!
  * \brief NOP instruction.
  *
  * Several Nut/OS drivers use one or more single cycle operations are
  * for very short delays. It's implementation depends on the inline
  * assembler and the target family.
  */
 #ifndef _NOP
 #if defined(__arm__)
 #define _NOP() __asm__ __volatile__("mov r0, r0  @ _NOP")
 #elif defined(__AVR__) || defined(__AVR32__)
 #define _NOP() __asm__ __volatile__("nop")
 #endif
 #endif

IMHO, it's also a good idea to replace all those GCC attributes into
generally usable macros like

 #if !defined(NUT_NAKED_FUNC) && (defined(__AVR__) || defined(__arm__))
 /*!
  * \brief Naked function attribute.
  *
  * The compiler will not generate prolog and epilog code for functions
  * with this attribute.
  */
 #define NUT_NAKED_FUNC  __attribute__((naked))
 #endif


Finally, toolchain/avrlibc.h and toolchain/newlib.h will contain macros
related to the specific runtime library, like __SFR_OFFSET for AVR.
Furthermore they will include library specific header files like
avr/pgmspace.h.

For the time being we will keep compiler.h as

 #include <toolchain.h>

so existing applications need not to be changed. I already did that for
the 8-bit AVR with good results.

Any objections?

Regards,

Harald




More information about the En-Nut-Discussion mailing list