NMSIS-Core  Version 1.2.0
NMSIS-Core support for Nuclei processor-based devices
nmsis_gcc.h
1 /*
2  * Copyright (c) 2019 Nuclei Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __NMSIS_GCC_H__
20 #define __NMSIS_GCC_H__
21 
25 #include <stdint.h>
26 
27 #ifdef __cplusplus
28  extern "C" {
29 #endif
30 
31 #include "riscv_encoding.h"
32 
33 /* ######################### Startup and Lowlevel Init ######################## */
47 /* Fallback for __has_builtin */
48 #ifndef __has_builtin
49  #define __has_builtin(x) (0)
50 #endif
51 
52 /* NMSIS compiler specific defines */
54 #ifndef __ASM
55  #define __ASM __asm
56 #endif
57 
59 #ifndef __INLINE
60  #define __INLINE inline
61 #endif
62 
64 #ifndef __STATIC_INLINE
65  #define __STATIC_INLINE static inline
66 #endif
67 
69 #ifndef __STATIC_FORCEINLINE
70  #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
71 #endif
72 
74 #ifndef __NO_RETURN
75  #define __NO_RETURN __attribute__((__noreturn__))
76 #endif
77 
79 #ifndef __USED
80  #define __USED __attribute__((used))
81 #endif
82 
84 #ifndef __WEAK
85  #define __WEAK __attribute__((weak))
86 #endif
87 
89 #ifndef __VECTOR_SIZE
90  #define __VECTOR_SIZE(x) __attribute__((vector_size(x)))
91 #endif
92 
94 #ifndef __PACKED
95  #define __PACKED __attribute__((packed, aligned(1)))
96 #endif
97 
99 #ifndef __PACKED_STRUCT
100  #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
101 #endif
102 
104 #ifndef __PACKED_UNION
105  #define __PACKED_UNION union __attribute__((packed, aligned(1)))
106 #endif
107 
108 #ifndef __UNALIGNED_UINT16_WRITE
109  #pragma GCC diagnostic push
110  #pragma GCC diagnostic ignored "-Wpacked"
111  #pragma GCC diagnostic ignored "-Wattributes"
112 
114  uint16_t v;
115  };
116  #pragma GCC diagnostic pop
117 
118  #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
119 #endif
120 
121 #ifndef __UNALIGNED_UINT16_READ
122  #pragma GCC diagnostic push
123  #pragma GCC diagnostic ignored "-Wpacked"
124  #pragma GCC diagnostic ignored "-Wattributes"
125 
127  uint16_t v;
128  };
129  #pragma GCC diagnostic pop
130 
131  #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
132 #endif
133 
134 #ifndef __UNALIGNED_UINT32_WRITE
135  #pragma GCC diagnostic push
136  #pragma GCC diagnostic ignored "-Wpacked"
137  #pragma GCC diagnostic ignored "-Wattributes"
138 
140  uint32_t v;
141  };
142  #pragma GCC diagnostic pop
143 
144  #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
145 #endif
146 
147 #ifndef __UNALIGNED_UINT32_READ
148  #pragma GCC diagnostic push
149  #pragma GCC diagnostic ignored "-Wpacked"
150  #pragma GCC diagnostic ignored "-Wattributes"
151 
153  uint32_t v;
154  };
155  #pragma GCC diagnostic pop
156 
157  #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
158 #endif
159 
161 #ifndef __ALIGNED
162  #define __ALIGNED(x) __attribute__((aligned(x)))
163 #endif
164 
166 #ifndef __RESTRICT
167  #define __RESTRICT __restrict
168 #endif
169 
171 #ifndef __COMPILER_BARRIER
172  #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
173 #endif
174 
176 #ifndef __USUALLY
177  #define __USUALLY(exp) __builtin_expect((exp), 1)
178 #endif
179 
181 #ifndef __RARELY
182  #define __RARELY(exp) __builtin_expect((exp), 0)
183 #endif
184 
186 #ifndef __INTERRUPT
187  #define __INTERRUPT __attribute__((interrupt))
188 #endif
189 
191 #ifndef __MACHINE_INTERRUPT
192  #define __MACHINE_INTERRUPT __attribute__ ((interrupt ("machine")))
193 #endif
194 
196 #ifndef __SUPERVISOR_INTERRUPT
197  #define __SUPERVISOR_INTERRUPT __attribute__ ((interrupt ("supervisor")))
198 #endif
199 
201 #ifndef __USER_INTERRUPT
202  #define __USER_INTERRUPT __attribute__ ((interrupt ("user")))
203 #endif
204  /* End of Doxygen Group NMSIS_Core_CompilerControl */
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 #endif /* __NMSIS_GCC_H__ */
__PACKED_STRUCT
#define __PACKED_STRUCT
Request smallest possible alignment for a structure.
Definition: nmsis_gcc.h:100
T_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE
Packed struct for unaligned uint32_t write access.
Definition: nmsis_gcc.h:139
T_UINT32_READ
__PACKED_STRUCT T_UINT32_READ
Packed struct for unaligned uint32_t read access.
Definition: nmsis_gcc.h:152
T_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE
Packed struct for unaligned uint16_t write access.
Definition: nmsis_gcc.h:113
T_UINT16_READ
__PACKED_STRUCT T_UINT16_READ
Packed struct for unaligned uint16_t read access.
Definition: nmsis_gcc.h:126