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 /************************************************************************** 33 * FILE NAME 34 * 35 * rpmsg_compiler.h 36 * 37 * DESCRIPTION 38 * 39 * This file defines compiler-specific macros. 40 * 41 ***************************************************************************/ 42 #ifndef RPMSG_COMPILER_H_ 43 #define RPMSG_COMPILER_H_ 44 45 /* IAR ARM build tools */ 46 #if defined(__ICCARM__) 47 48 #include <intrinsics.h> 49 50 #define MEM_BARRIER() __DSB() 51 52 #ifndef RL_PACKED_BEGIN 53 #define RL_PACKED_BEGIN __packed 54 #endif 55 56 #ifndef RL_PACKED_END 57 #define RL_PACKED_END 58 #endif 59 60 /* ARM GCC */ 61 #elif defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 62 63 #if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 64 #include <arm_compat.h> 65 #endif 66 67 #define MEM_BARRIER() __schedule_barrier() 68 69 #ifndef RL_PACKED_BEGIN 70 #define RL_PACKED_BEGIN _Pragma("pack(1U)") 71 #endif 72 73 #ifndef RL_PACKED_END 74 #define RL_PACKED_END _Pragma("pack()") 75 #endif 76 77 /* XCC HiFi4 */ 78 #elif defined(__XCC__) 79 80 /* 81 * The XCC HiFi4 compiler is compatible with GNU compiler, with restrictions. 82 * For ARM __schedule_barrier, there's no identical intrinsic in HiFi4. 83 * A complete synchronization barrier would require initialize and wait ops. 84 * Here use NOP instead, similar to ARM __nop. 85 */ 86 #define MEM_BARRIER() __asm__ __volatile__("nop" : : : "memory") 87 88 #ifndef RL_PACKED_BEGIN 89 #define RL_PACKED_BEGIN 90 #endif 91 92 #ifndef RL_PACKED_END 93 #define RL_PACKED_END __attribute__((__packed__)) 94 #endif 95 96 /* GNUC */ 97 #elif defined(__GNUC__) 98 99 #if defined(__ARM_ARCH_8A) 100 #define MEM_BARRIER() __asm__ volatile("dsb sy" : : : "memory") 101 #else 102 #define MEM_BARRIER() __asm__ volatile("dsb" : : : "memory") 103 #endif 104 105 #ifndef RL_PACKED_BEGIN 106 #define RL_PACKED_BEGIN 107 #endif 108 109 #ifndef RL_PACKED_END 110 #define RL_PACKED_END __attribute__((__packed__)) 111 #endif 112 113 #else 114 /* There is no default definition here to avoid wrong structures packing in case of not supported compiler */ 115 #error Please implement the structure packing macros for your compiler here! 116 #endif 117 118 #endif /* RPMSG_COMPILER_H_ */ 119