source: trunk/libs/newlib/src/libgloss/bfin/include/builtins.h @ 679

Last change on this file since 679 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 8.2 KB
Line 
1/*
2 * The authors hereby grant permission to use, copy, modify, distribute,
3 * and license this software and its documentation for any purpose, provided
4 * that existing copyright notices are retained in all copies and that this
5 * notice is included verbatim in any distributions. No written agreement,
6 * license, or royalty fee is required for any of the authorized uses.
7 * Modifications to this software may be copyrighted by their authors
8 * and need not follow the licensing terms described here, provided that
9 * the new terms are clearly indicated on the first page of each file where
10 * they apply.
11 */
12
13#ifdef _MISRA_RULES
14#pragma diag(push)
15#pragma diag(suppress:misra_rule_2_4)
16#pragma diag(suppress:misra_rule_5_3)
17#pragma diag(suppress:misra_rule_6_3)
18#pragma diag(suppress:misra_rule_8_1)
19#pragma diag(suppress:misra_rule_8_8)
20#pragma diag(suppress:misra_rule_8_5)
21#pragma diag(suppress:misra_rule_19_7)
22#pragma diag(suppress:misra_rule_19_15)
23#pragma diag(suppress:misra_rule_20_2)
24#endif
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#if !defined(__NO_BUILTIN)
31
32/* VDSP -> GCC glue */
33#define __builtin_NOP()            __asm__ __volatile__ ("NOP;")
34#define __builtin_cli()            ({ unsigned int __rval; __asm__ __volatile__ ("cli %0;" : "=r"(__rval)); __rval; })
35#define __builtin_sti(x)           __asm__ __volatile__ ("sti %0;" : : "r"(x))
36#define __builtin_idle()           __asm__ __volatile__ ("IDLE;")
37#define __builtin_raise(x)         __asm__ __volatile__ ("raise %0;" : : "n"(x))
38#define __builtin_excpt(x)         __asm__ __volatile__ ("excpt %0;" : : "n"(x))
39#define __builtin_prefetch(x)      __asm__ __volatile__ ("PREFETCH[%0];" : : "p"(x))
40#define __builtin_prefetchmodup(x) ({ void *__p = &(x); __asm__ __volatile__ ("PREFETCH[%0++];" : "+p"(__p)); __p; })
41#define __builtin_flushinv(x)      __asm__ __volatile__ ("FLUSHINV[%0];" : : "p"(x))
42#define __builtin_flushinvmodup(x) ({ void *__p = &(x); __asm__ __volatile__ ("FLUSHINV[%0++];" : "+p"(__p)); __p; })
43#define __builtin_flush(x)         __asm__ __volatile__ ("FLUSH[%0];" : : "p"(x))
44#define __builtin_flushmodup(x)    ({ void *__p = &(x); __asm__ __volatile__ ("FLUSH[%0++];" : "+p"(__p)); __p; })
45#define __builtin_iflush(x)        __asm__ __volatile__ ("IFLUSH[%0];" : : "p"(x))
46#define __builtin_iflushmodup(x)   ({ void *__p = &(x); __asm__ __volatile__ ("IFLUSH[%0++];" : "+p"(__p)); __p; })
47#define __builtin_csync()          __builtin_bfin_csync()
48#define __builtin_ssync()          __builtin_bfin_ssync()
49
50#endif /* __NO_BUILTIN */
51
52
53#if !defined(__NO_BUILTIN) && !defined(__NO_SHORTNAMES)
54
55#if (!defined(__DEFINED_NOP) && \
56     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_NOP)) || \
57       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_NOP))))
58
59#define __DEFINED_NOP
60
61/* Insert a normal 16 bit NOP, which is treated as volatile.
62*/
63
64#pragma inline
65#pragma always_inline
66static void  NOP(void) {
67  __builtin_NOP();
68}
69
70#endif /* __DEFINED_NOP */
71
72#if (!defined(__DEFINED_CLI) && \
73     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_CLI)) || \
74       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_CLI))))
75
76#define __DEFINED_CLI
77
78#pragma inline
79#pragma always_inline
80static unsigned int  cli(void) {
81  unsigned int  __rval = __builtin_cli();
82  return __rval;
83}
84
85#endif /* __DEFINED_CLI */
86
87#if (!defined(__DEFINED_STI) && \
88     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_STI)) || \
89       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_STI))))
90
91#define __DEFINED_STI
92
93#pragma inline
94#pragma always_inline
95static void  sti(unsigned int  __a) {
96  __builtin_sti(__a);
97}
98
99#endif /* __DEFINED_STI */
100
101#if (!defined(__DEFINED_IDLE) && \
102     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_IDLE)) || \
103       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_IDLE))))
104
105#define __DEFINED_IDLE
106
107#pragma inline
108#pragma always_inline
109static void  idle(void) {
110  __builtin_idle();
111}
112
113#endif /* __DEFINED_IDLE */
114
115#if (!defined(__DEFINED_RAISE_INTR) && \
116     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_RAISE_INTR)) || \
117       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_RAISE_INTR))))
118
119#define __DEFINED_RAISE_INTR
120
121#define raise_intr(A) (__builtin_raise((A)))
122
123#endif /* __DEFINED_RAISE_INTR */
124
125#if (!defined(__DEFINED_EXCPT) && \
126     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_EXCPT)) || \
127       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_EXCPT))))
128
129#define __DEFINED_EXCPT
130
131#define excpt(A) (__builtin_excpt((A)))
132
133#endif /* __DEFINED_EXCPT */
134
135#if (!defined(__DEFINED_PREFETCH) && \
136     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_PREFETCH)) || \
137       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_PREFETCH))))
138
139#define __DEFINED_PREFETCH
140
141#pragma inline
142#pragma always_inline
143static void  prefetch(void * __a) {
144  __builtin_prefetch(__a);
145}
146
147#endif /* __DEFINED_PREFETCH */
148
149#if (!defined(__DEFINED_PREFETCHMODUP) && \
150     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_PREFETCHMODUP)) || \
151       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_PREFETCHMODUP))))
152
153#define __DEFINED_PREFETCHMODUP
154
155#pragma inline
156#pragma always_inline
157static void * prefetchmodup(void * __a) {
158  void * __rval = __builtin_prefetchmodup(__a);
159  return __rval;
160}
161
162#endif /* __DEFINED_PREFETCHMODUP */
163
164#if (!defined(__DEFINED_FLUSHINV) && \
165     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_FLUSHINV)) || \
166       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_FLUSHINV))))
167
168#define __DEFINED_FLUSHINV
169
170#pragma inline
171#pragma always_inline
172static void  flushinv(void * __a) {
173  __builtin_flushinv(__a);
174}
175
176#endif /* __DEFINED_FLUSHINV */
177
178#if (!defined(__DEFINED_FLUSHINVMODUP) && \
179     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_FLUSHINVMODUP)) || \
180       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_FLUSHINVMODUP))))
181
182#define __DEFINED_FLUSHINVMODUP
183
184#pragma inline
185#pragma always_inline
186static void * flushinvmodup(void * __a) {
187  void * __rval = __builtin_flushinvmodup(__a);
188  return __rval;
189}
190
191#endif /* __DEFINED_FLUSHINVMODUP */
192
193#if (!defined(__DEFINED_FLUSH) && \
194     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_FLUSH)) || \
195       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_FLUSH))))
196
197#define __DEFINED_FLUSH
198
199#pragma inline
200#pragma always_inline
201static void  flush(void * __a) {
202  __builtin_flush(__a);
203}
204
205#endif /* __DEFINED_FLUSH */
206
207#if (!defined(__DEFINED_FLUSHMODUP) && \
208     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_FLUSHMODUP)) || \
209       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_FLUSHMODUP))))
210
211#define __DEFINED_FLUSHMODUP
212
213#pragma inline
214#pragma always_inline
215static void * flushmodup(void * __a) {
216  void * __rval = __builtin_flushmodup(__a);
217  return __rval;
218}
219
220#endif /* __DEFINED_FLUSHMODUP */
221
222#if (!defined(__DEFINED_IFLUSH) && \
223     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_IFLUSH)) || \
224       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_IFLUSH))))
225
226#define __DEFINED_IFLUSH
227
228#pragma inline
229#pragma always_inline
230static void  iflush(void * __a) {
231  __builtin_iflush(__a);
232}
233
234#endif /* __DEFINED_IFLUSH */
235
236#if (!defined(__DEFINED_IFLUSHMODUP) && \
237     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_IFLUSHMODUP)) || \
238       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_IFLUSHMODUP))))
239
240#define __DEFINED_IFLUSHMODUP
241
242#pragma inline
243#pragma always_inline
244static void * iflushmodup(void * __a) {
245  void * __rval = __builtin_iflushmodup(__a);
246  return __rval;
247}
248
249#endif /* __DEFINED_IFLUSHMODUP */
250
251#if (!defined(__DEFINED_CSYNC) && \
252     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_CSYNC)) || \
253       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_CSYNC))))
254
255#define __DEFINED_CSYNC
256
257/* generate a csync instruction protected by CLI/STI for anomaly 05-00-0312;
258** you can generate an unprotected csync by using csync_int
259*/
260
261#pragma inline
262#pragma always_inline
263static void csync(void) {
264  __builtin_csync();
265}
266
267#endif /* __DEFINED_CSYNC */
268
269#if (!defined(__DEFINED_SSYNC) && \
270     ((defined(__SPECIFIC_NAMES) && defined(__ENABLE_SSYNC)) || \
271       (!defined(__SPECIFIC_NAMES) && !defined(__DISABLE_SSYNC))))
272
273#define __DEFINED_SSYNC
274
275/* generate a ssync instruction protected by CLI/STI for anomaly 05-00-0312;
276** you can generate an unprotected ssync by using ssync_int
277*/
278
279#pragma inline
280#pragma always_inline
281static void ssync(void) {
282  __builtin_ssync();
283}
284
285#endif /* __DEFINED_SSYNC */
286
287#endif /* __NO_BUILTIN */
288
289#ifdef _MISRA_RULES
290#pragma diag(pop)
291#endif
292
293#ifdef __cplusplus
294}
295#endif
Note: See TracBrowser for help on using the repository browser.