gcc.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #ifndef _TOOLCHAIN_GCC_H_
  2. #define _TOOLCHAIN_GCC_H_
  3. /*
  4. * Copyright (C) 2012 by egnite GmbH
  5. * Copyright (C) 2001-2005 by egnite Software GmbH
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. */
  37. #ifndef _TOOLCHAIN_H_
  38. #error "Do not include this file directly, include <toolchain.h> instead."
  39. #endif
  40. /*!
  41. * \name General Compiler Feature Macros
  42. */
  43. /*@{*/
  44. #ifndef NUT_INLINE_FUNC
  45. /*!
  46. * \brief Inline function macro.
  47. *
  48. * Although not specified in ANSI C89, the inline keyword is essential
  49. * in embedded programming and had been supported by many compilers long
  50. * before its standardization in C99.
  51. *
  52. * In order to support compilers, which do not follow ANSI C99, Nut/OS
  53. * code must use this macro instead of the inline keyword to declare
  54. * inline functions.
  55. *
  56. * Note, that functions may not be inlined if compiler optimizations
  57. * had been disabled.
  58. */
  59. #define NUT_INLINE_FUNC inline
  60. #endif
  61. #ifndef NUT_FORCE_INLINE
  62. /*!
  63. * \brief Forced inline function attribute.
  64. *
  65. * Always inlines a function, even if optimization has been disabled.
  66. */
  67. #define NUT_FORCE_INLINE __attribute__((__always_inline__))
  68. #endif
  69. #ifndef NUT_FORCE_NO_INLINE
  70. /*!
  71. * \brief Forced inline function attribute.
  72. *
  73. * Always inlines a function, even if optimization has been disabled.
  74. */
  75. #define NUT_PREVENT_INLINE __attribute__((__noinline__))
  76. #endif
  77. #if !defined(NUT_NAKED_FUNC)
  78. /*!
  79. * \brief Naked function attribute.
  80. *
  81. * The compiler will not generate prolog and epilog code for functions
  82. * with this attribute.
  83. */
  84. #define NUT_NAKED_FUNC __attribute__((__naked__))
  85. #endif
  86. #ifndef NUT_PURE_FUNC
  87. /*!
  88. * \brief Pure function attribute.
  89. *
  90. * The result returned by a pure function depends only on their
  91. * parameters and global variables. Thus, it may be called less often
  92. * because the compiler may re-use the result from a previous call.
  93. */
  94. #define NUT_PURE_FUNC __attribute__((__pure__))
  95. #endif
  96. #ifndef NUT_CONST_FUNC
  97. /*!
  98. * \brief Constant function attribute.
  99. *
  100. * A constant function returns a value, which depends only on their
  101. * parameters. Furthermore, it will not have any other effect.
  102. */
  103. #define NUT_CONST_FUNC __attribute__((__const__))
  104. #endif
  105. #ifndef NUT_NORETURN_FUNC
  106. #define NUT_NORETURN_FUNC __attribute__((__noreturn__))
  107. #endif
  108. #ifndef NUT_USED_FUNC
  109. /*!
  110. * \brief Used function attribute.
  111. *
  112. * When this attribute is attached to a function, then the compiler
  113. * generates the function code, even if it appears to be unreferenced.
  114. */
  115. #define NUT_USED_FUNC __attribute__((__used__))
  116. #endif
  117. #ifndef NUT_ALLOC_FUNC
  118. /*!
  119. * \brief Memory allocation function attribute.
  120. *
  121. * Used for functions returning a pointer, which doesn't alias anything.
  122. */
  123. #define NUT_ALLOC_FUNC __attribute__((__malloc__))
  124. #endif
  125. #ifndef NUT_IRQ_HANDLER
  126. #if defined(__arm__)
  127. #define NUT_IRQ_HANDLER __attribute__((__interrupt__("IRQ")))
  128. #endif
  129. #endif
  130. #ifndef NUT_FIQ_HANDLER
  131. #if defined(__arm__)
  132. #define NUT_FIQ_HANDLER __attribute__((__interrupt__("FIQ")))
  133. #endif
  134. #endif
  135. #ifndef NUT_SWI_HANDLER
  136. #if defined(__arm__)
  137. #define NUT_SWI_HANDLER __attribute__((__interrupt__("SWI")))
  138. #endif
  139. #endif
  140. #ifndef NUT_ABORT_HANDLER
  141. #if defined(__arm__)
  142. #define NUT_ABORT_HANDLER __attribute__((__interrupt__("ABORT")))
  143. #endif
  144. #endif
  145. #ifndef NUT_UNDEF_HANDLER
  146. #if defined(__arm__)
  147. #define NUT_UNDEF_HANDLER __attribute__((__interrupt__("UNDEF")))
  148. #endif
  149. #endif
  150. #ifndef RAMFUNC
  151. /*!
  152. * \brief Function running in RAM.
  153. *
  154. * This section will be copied to RAM during runtime initialization.
  155. */
  156. #define RAMFUNC __attribute__((__long_call__, __section__(".ramfunc")))
  157. #endif
  158. #ifndef NUT_PACKED_TYPE
  159. /*!
  160. * \brief Packed type attribute.
  161. *
  162. * Specifies, that the minimum required memory be used to represent the
  163. * type.
  164. */
  165. #define NUT_PACKED_TYPE __attribute__((__packed__))
  166. #endif
  167. #ifndef NUT_ALIGNED_TYPE
  168. /*!
  169. * \brief Aligned type attribute.
  170. *
  171. * Specifies a minimum alignment for variables in bytes.
  172. *
  173. * \note The actual alignment is not guaranteed, but limited by the
  174. * capabilities of the linker.
  175. */
  176. #define NUT_ALIGNED_TYPE(bytes) __attribute__((__aligned__(bytes)))
  177. #endif
  178. #ifndef NUT_LINKER_SECT
  179. /*!
  180. * \brief Linker section attribute.
  181. *
  182. * By default, the compiler will put code in the .text segment,
  183. */
  184. #define NUT_LINKER_SECT(name) __attribute__((__section__(name)))
  185. #endif
  186. #ifndef NUT_WEAK_SYMBOL
  187. /*!
  188. * \brief Weak symbol attribute.
  189. *
  190. * Weak functions or variables may be replaced by the linker with
  191. * non-weak functions or variables specified elsewhere, including
  192. * application code.
  193. */
  194. #define NUT_WEAK_SYMBOL __attribute__((__weak__))
  195. #endif
  196. #ifndef NUT_DEPRECATED
  197. /*!
  198. * \brief Deprecated attribute.
  199. */
  200. #define NUT_DEPRECATED __attribute__((__deprecated__))
  201. #endif
  202. #define COMPRESS_DISABLE
  203. #define COMPRESS_REENABLE
  204. /*@}*/
  205. /*!
  206. * \name General Compiler-Specific Workarounds
  207. */
  208. /*@{*/
  209. #ifndef CONST
  210. /*!
  211. * \brief Constant qualifier.
  212. *
  213. * Compilers interpret const variables in a different way. Most notably,
  214. * the ImageCraft compilers up to version 6 use it to specify data in
  215. * program space for Harvard architectures. Therefore, const was
  216. * replaced by this macro throughout the code.
  217. *
  218. * Since Nut/OS version 5 such abuse of the const qualifier is no longer
  219. * supported. In order not to break existing applications, we keep this
  220. * deprecated macro.
  221. */
  222. #define CONST const
  223. #endif
  224. /*@}*/
  225. /*!
  226. * \brief Compiler memory barrier.
  227. *
  228. * This function does not generate any code by itself, but forbids the
  229. * compiler to reorder read and write commands around it.
  230. */
  231. #define mem_barrier() __asm__ __volatile__("":::"memory")
  232. /*
  233. * Include the runtime library header here. It may override any of the
  234. * following definitions.
  235. */
  236. #if defined(__AVR__)
  237. /* Only avr-libc is currently supported for GCC. */
  238. #include <toolchain/avrlibc.h>
  239. #elif defined(__AVR32__)
  240. #include <arch/avr32.h>
  241. #include <toolchain/generic.h>
  242. #elif defined(__CORTEX__)
  243. #include <arch/cm3.h>
  244. #include <toolchain/generic.h>
  245. #elif defined(__arm__)
  246. /* Note, that newlib is the default. */
  247. #if defined(__CROSSWORKS_ARM)
  248. #include <toolchain/crossworks.h>
  249. #include <toolchain/newlib.h>
  250. #else
  251. #include <toolchain/newlib.h>
  252. #endif
  253. #elif defined(__m68k__)
  254. #include <arch/m68k.h>
  255. #include <toolchain/generic.h>
  256. #endif
  257. #ifndef PROGMEM
  258. #define PROGMEM
  259. #endif
  260. /*!
  261. * \brief NOP instruction.
  262. *
  263. * Several Nut/OS drivers use one or more single cycle operations
  264. * for very short delays. It's implementation depends on the inline
  265. * assembler and the target family.
  266. */
  267. #ifndef _NOP
  268. #if defined(__arm__)
  269. #define _NOP() __asm__ __volatile__("mov r0, r0 @ _NOP")
  270. #elif defined(__AVR__) || defined(__AVR32__)
  271. #define _NOP() __asm__ __volatile__("nop")
  272. #endif
  273. #endif
  274. #endif