[En-Nut-Discussion] Replacing compiler.h
harald.kipp at egnite.de
Thu Oct 4 10:04:19 CEST 2012
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
plus a number of general macros like _BV().
In turn, toolchain/gcc.h will contain
/* Only avr-libc is currently supported for GCC. */
/* Only newlib is currently supported for GCC. */
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.
#define _NOP() __asm__ __volatile__("mov r0, r0 @ _NOP")
#elif defined(__AVR__) || defined(__AVR32__)
#define _NOP() __asm__ __volatile__("nop")
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))
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
For the time being we will keep compiler.h as
so existing applications need not to be changed. I already did that for
the 8-bit AVR with good results.
More information about the En-Nut-Discussion