2 Copyright (c) 2012, Broadcom Europe Ltd
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 /*=============================================================================
29 VideoCore OS Abstraction Layer - compiler-specific attributes
30 =============================================================================*/
36 * Type attribute indicating the enum should be stored in as few bytes as
37 * possible. MetaWare does this by default, so the attribute is useful when
38 * structs need to be portable to GCC too.
40 * MSVC doesn't support VCOS_ENUM_PACKED, so code that needs to be portable
41 * across all platforms but wants the type-safety and debug-info benefits
42 * of enum types when possible, should do:
44 * typedef enum VCOS_ENUM_PACKED { a = 0, b = 0xffff } EXAMPLE_T;
47 * #if VCOS_HAS_ENUM_PACKED
55 #if defined(__VECTORC__)
56 # define VCOS_ENUM_PACKED
57 # define VCOS_HAS_ENUM_PACKED 0
58 #elif defined(__GNUC__)
59 # define VCOS_ENUM_PACKED __attribute__ ((packed))
60 # define VCOS_HAS_ENUM_PACKED 1
61 #elif defined(__HIGHC__)
62 # define VCOS_ENUM_PACKED /* packed enums are default on Metaware */
63 # define VCOS_HAS_ENUM_PACKED 1
65 # define VCOS_ENUM_PACKED
66 # define VCOS_HAS_ENUM_PACKED 0
69 /** Variable attribute indicating the variable must be emitted even if it appears unused. */
70 #if defined(__GNUC__) || defined(__HIGHC__)
71 # define VCOS_ATTR_USED __attribute__ ((used))
73 # define VCOS_ATTR_USED
76 /** Variable attribute indicating the compiler should not warn if the variable is unused. */
77 #if defined(__GNUC__) || defined(__HIGHC__)
78 # define VCOS_ATTR_POSSIBLY_UNUSED __attribute__ ((unused))
80 # define VCOS_ATTR_POSSIBLY_UNUSED
83 /** Variable attribute requiring specific alignment.
86 * int VCOS_ATTR_ALIGNED(256) n;
88 * VCOS_ATTR_ALIGNED(256) int n;
89 * or if you don't want to support MSVC:
90 * int n VCOS_ATTR_ALIGNED(256);
92 #if defined(__GNUC__) || defined(__HIGHC__)
93 # define VCOS_ATTR_ALIGNED(n) __attribute__ ((aligned(n)))
94 #elif defined(_MSC_VER)
95 # define VCOS_ATTR_ALIGNED(n) __declspec(align(n))
97 /* Force a syntax error if this is used when the compiler doesn't support it,
98 * instead of silently misaligning */
99 # define VCOS_ATTR_ALIGNED(n) VCOS_ATTR_ALIGNED_NOT_SUPPORTED_ON_THIS_COMPILER
102 /** Variable attribute requiring specific ELF section.
105 * int n VCOS_ATTR_SECTION(".foo") = 1;
107 * A pointer like &n will have type "VCOS_ATTR_SECTION_QUALIFIER int *".
109 #if defined(__HIGHC__) || defined(__VECTORC__)
110 /* hcvc requires 'far' else it'll put small objects in .sdata/.rsdata/.sbss */
111 # define VCOS_ATTR_SECTION(s) __attribute__ ((far, section(s)))
112 # define VCOS_ATTR_SECTION_QUALIFIER _Far
113 #elif defined(__GNUC__)
114 # define VCOS_ATTR_SECTION(s) __attribute__ ((section(s)))
115 # define VCOS_ATTR_SECTION_QUALIFIER
117 /* Force a syntax error if this is used when the compiler doesn't support it */
118 # define VCOS_ATTR_SECTION(s) VCOS_ATTR_SECTION_NOT_SUPPORTED_ON_THIS_COMPILER
119 # define VCOS_ATTR_SECTION_QUALIFIER
122 /** Define a function as a weak alias to another function.
123 * @param ret_type Function return type.
124 * @param alias_name Name of the alias.
125 * @param param_list Function parameter list, including the parentheses.
126 * @param target_name Target function (bare function name, not a string).
128 #if defined(__GNUC__) || defined(__HIGHC__)
129 /* N.B. gcc allows __attribute__ after parameter list, but hcvc seems to silently ignore it. */
130 # define VCOS_WEAK_ALIAS(ret_type, alias_name, param_list, target_name) \
131 __attribute__ ((weak, alias(#target_name))) ret_type alias_name param_list
133 # define VCOS_WEAK_ALIAS(ret_type, alias, params, target) VCOS_CASSERT(0)
136 /** Define a function as a weak alias to another function, specified as a string.
137 * @param ret_type Function return type.
138 * @param alias_name Name of the alias.
139 * @param param_list Function parameter list, including the parentheses.
140 * @param target_name Target function name as a string.
141 * @note Prefer the use of VCOS_WEAK_ALIAS - it is likely to be more portable.
142 * Only use VCOS_WEAK_ALIAS_STR if you need to do pre-processor mangling of the target
145 #if defined(__GNUC__) || defined(__HIGHC__)
146 /* N.B. gcc allows __attribute__ after parameter list, but hcvc seems to silently ignore it. */
147 # define VCOS_WEAK_ALIAS_STR(ret_type, alias_name, param_list, target_name) \
148 __attribute__ ((weak, alias(target_name))) ret_type alias_name param_list
150 # define VCOS_WEAK_ALIAS_STR(ret_type, alias, params, target) VCOS_CASSERT(0)
153 #endif /* VCOS_ATTR_H */