rpmsg_compiler.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2014, Mentor Graphics Corporation
  3. * Copyright (c) 2016 Freescale Semiconductor, Inc.
  4. * Copyright 2016,2022 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /**************************************************************************
  32. * FILE NAME
  33. *
  34. * rpmsg_compiler.h
  35. *
  36. * DESCRIPTION
  37. *
  38. * This file defines compiler-specific macros.
  39. *
  40. ***************************************************************************/
  41. #ifndef RPMSG_COMPILER_H_
  42. #define RPMSG_COMPILER_H_
  43. /* IAR ARM build tools */
  44. #if defined(__ICCARM__)
  45. #include <intrinsics.h>
  46. #define MEM_BARRIER() __DSB()
  47. #ifndef RL_PACKED_BEGIN
  48. #define RL_PACKED_BEGIN __packed
  49. #endif
  50. #ifndef RL_PACKED_END
  51. #define RL_PACKED_END
  52. #endif
  53. /* ARM GCC */
  54. #elif defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
  55. #if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
  56. #include <arm_compat.h>
  57. #endif
  58. #define MEM_BARRIER() __schedule_barrier()
  59. #ifndef RL_PACKED_BEGIN
  60. #define RL_PACKED_BEGIN _Pragma("pack(1U)")
  61. #endif
  62. #ifndef RL_PACKED_END
  63. #define RL_PACKED_END _Pragma("pack()")
  64. #endif
  65. /* XCC HiFi4 */
  66. #elif defined(__XCC__)
  67. /*
  68. * The XCC HiFi4 compiler is compatible with GNU compiler, with restrictions.
  69. * For ARM __schedule_barrier, there's no identical intrinsic in HiFi4.
  70. * A complete synchronization barrier would require initialize and wait ops.
  71. * Here use NOP instead, similar to ARM __nop.
  72. */
  73. #define MEM_BARRIER() __asm__ __volatile__("nop" : : : "memory")
  74. #ifndef RL_PACKED_BEGIN
  75. #define RL_PACKED_BEGIN
  76. #endif
  77. #ifndef RL_PACKED_END
  78. #define RL_PACKED_END __attribute__((__packed__))
  79. #endif
  80. /* GNUC */
  81. #elif defined(__GNUC__)
  82. #if defined(__ARM_ARCH_8A)
  83. #define MEM_BARRIER() __asm__ volatile("dsb sy" : : : "memory")
  84. #elif defined(__riscv)
  85. #define MEM_BARRIER() __asm__ volatile("fence")
  86. #else
  87. #define MEM_BARRIER() __asm__ volatile("dsb" : : : "memory")
  88. #endif
  89. #ifndef RL_PACKED_BEGIN
  90. #define RL_PACKED_BEGIN
  91. #endif
  92. #ifndef RL_PACKED_END
  93. #define RL_PACKED_END __attribute__((__packed__))
  94. #endif
  95. #else
  96. /* There is no default definition here to avoid wrong structures packing in case of not supported compiler */
  97. #error Please implement the structure packing macros for your compiler here!
  98. #endif
  99. #endif /* RPMSG_COMPILER_H_ */