ssi_pal_compiler.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**************************************************************************************
  2. * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
  3. * *
  4. * This file and the related binary are licensed under the following license: *
  5. * *
  6. * ARM Object Code and Header Files License, v1.0 Redistribution. *
  7. * *
  8. * Redistribution and use of object code, header files, and documentation, without *
  9. * modification, are permitted provided that the following conditions are met: *
  10. * *
  11. * 1) Redistributions must reproduce the above copyright notice and the *
  12. * following disclaimer in the documentation and/or other materials *
  13. * provided with the distribution. *
  14. * *
  15. * 2) Unless to the extent explicitly permitted by law, no reverse *
  16. * engineering, decompilation, or disassembly of is permitted. *
  17. * *
  18. * 3) Redistribution and use is permitted solely for the purpose of *
  19. * developing or executing applications that are targeted for use *
  20. * on an ARM-based product. *
  21. * *
  22. * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  23. * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
  24. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
  25. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  33. **************************************************************************************/
  34. #ifndef __SSI_PAL_COMPILER_H__
  35. #define __SSI_PAL_COMPILER_H__
  36. /*!
  37. @file
  38. @brief This file contains compiler related definitions.
  39. @defgroup ssi_pal_compiler CryptoCell PAL platform dependant compiler specific definitions
  40. @{
  41. @ingroup ssi_pal
  42. */
  43. #ifdef __GNUC__
  44. /************************ Defines ******************************/
  45. /*! Associate a symbol with a link section. */
  46. #define SASI_PAL_COMPILER_SECTION(sectionName) __attribute__((section(sectionName)))
  47. /*! Mark symbol as used, i.e., prevent garbage collector from dropping it. */
  48. #define SASI_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
  49. /*! Make given data item aligned (alignment in bytes). */
  50. #define SASI_PAL_COMPILER_ALIGN(alignement) __attribute__((aligned(alignement)))
  51. /*! Mark function that never returns. */
  52. #define SASI_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
  53. /*! Prevent function from being inlined */
  54. #define SASI_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
  55. /*! Given data type may cast (alias) another data type pointer. */
  56. /* (this is used for "superclass" struct casting) */
  57. #define SASI_PAL_COMPILER_TYPE_MAY_ALIAS __attribute__((__may_alias__))
  58. /*! Get sizeof for a structure type member. */
  59. #define SASI_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
  60. sizeof(((type_name *)0)->member_name)
  61. /*! Assertion. */
  62. #define SASI_ASSERT_CONCAT_(a, b) a##b
  63. #define SASI_ASSERT_CONCAT(a, b) SASI_ASSERT_CONCAT_(a, b)
  64. #define SASI_PAL_COMPILER_ASSERT(cond, message) \
  65. enum { SASI_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
  66. #elif defined(__ARM_DSM__) || defined(__CC_ARM)
  67. #define inline
  68. /*! Associate a symbol with a link section. */
  69. #define SASI_PAL_COMPILER_SECTION(sectionName) __attribute__((section(sectionName)))
  70. /*! Mark symbol as used, i.e., prevent garbage collector from dropping it. */
  71. #define SASI_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
  72. /*! Make given data item aligned (alignment in bytes). */
  73. #define SASI_PAL_COMPILER_ALIGN(alignement) __attribute__((aligned(alignement)))
  74. /*! Mark function that never returns. */
  75. #define SASI_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
  76. /*! Prevent function from being inlined. */
  77. #define SASI_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
  78. /*! Given data type may cast (alias) another data type pointer. */
  79. /* (this is used for "superclass" struct casting) */
  80. #define SASI_PAL_COMPILER_TYPE_MAY_ALIAS __attribute__((__may_alias__))
  81. /*! Get sizeof for a structure type member. */
  82. #define SASI_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
  83. sizeof(((type_name *)0)->member_name)
  84. /*! Assertion. */
  85. #define SASI_ASSERT_CONCAT_(a, b) a##b
  86. #define SASI_ASSERT_CONCAT(a, b) SASI_ASSERT_CONCAT_(a, b)
  87. #define SASI_PAL_COMPILER_ASSERT(cond, message) \
  88. enum { SASI_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
  89. #elif defined(__ARM_DS__)
  90. #define inline
  91. /*! Associate a symbol with a link section. */
  92. #define SASI_PAL_COMPILER_SECTION(sectionName) __attribute__((section(sectionName)))
  93. /*! Mark symbol as used, i.e., prevent garbage collector from dropping it. */
  94. #define SASI_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
  95. /*! Make given data item aligned (alignment in bytes). */
  96. #define SASI_PAL_COMPILER_ALIGN(alignement) __attribute__((aligned(alignement)))
  97. /*! Mark function that never returns. */
  98. #define SASI_PAL_COMPILER_FUNC_NEVER_RETURNS __attribute__((noreturn))
  99. /*! Prevent function from being inlined. */
  100. #define SASI_PAL_COMPILER_FUNC_DONT_INLINE __attribute__((noinline))
  101. /*! Given data type may cast (alias) another data type pointer. */
  102. /* (this is used for "superclass" struct casting) */
  103. #define SASI_PAL_COMPILER_TYPE_MAY_ALIAS
  104. /*! Get sizeof for a structure type member. */
  105. #define SASI_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
  106. sizeof(((type_name *)0)->member_name)
  107. /*! Assertion. */
  108. #define SASI_ASSERT_CONCAT_(a, b) a##b
  109. #define SASI_ASSERT_CONCAT(a, b) SASI_ASSERT_CONCAT_(a, b)
  110. #define SASI_PAL_COMPILER_ASSERT(cond, message) \
  111. enum { SASI_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
  112. #elif defined(__ICCARM__)
  113. /************************ Defines ******************************/
  114. /*! Associate a symbol with a link section. */
  115. #define SASI_PAL_COMPILER_SECTION(sectionName) __attribute__((section(sectionName)))
  116. /*! Mark symbol as used, i.e., prevent garbage collector from dropping it. */
  117. #define SASI_PAL_COMPILER_KEEP_SYMBOL __attribute__((used))
  118. /*! Make given data item aligned (alignment in bytes). */
  119. #define STRING_PRAGMA(x) _Pragma(#x)
  120. //#define SASI_PAL_COMPILER_ALIGN(n) STRING_PRAGMA(data_alignment = n)
  121. #define SASI_PAL_COMPILER_ALIGN(n)
  122. /*! Mark function that never returns. Not implemented */
  123. #define SASI_PAL_COMPILER_FUNC_NEVER_RETURNS
  124. /* Prevent function from being inlined */
  125. #define SASI_PAL_COMPILER_FUNC_DONT_INLINE STRING_PRAGMA(optimize = no_inline)
  126. /*! Given data type may cast (alias) another data type pointer. */
  127. /* (this is used for "superclass" struct casting). Not implemented */
  128. #define SASI_PAL_COMPILER_TYPE_MAY_ALIAS
  129. /*! Get sizeof for a structure type member. */
  130. #define SASI_PAL_COMPILER_SIZEOF_STRUCT_MEMBER(type_name, member_name) \
  131. sizeof(((type_name *)0)->member_name)
  132. /*! Assertion. */
  133. #define SASI_ASSERT_CONCAT_(a, b) a##b
  134. #define SASI_ASSERT_CONCAT(a, b) SASI_ASSERT_CONCAT_(a, b)
  135. #define SASI_PAL_COMPILER_ASSERT(cond, message) \
  136. enum { SASI_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(cond)) }
  137. #else
  138. #error Unsupported compiler.
  139. #endif
  140. /**
  141. @}
  142. */
  143. #endif /*__SSI_PAL_COMPILER_H__*/