]> begriffs open source - cmsis/blob - CMSIS/Core_A/Include/cmsis_iccarm.h
CMSIS-Zone limited to Cortex-M as Cache support for complex Cortex-A/R systems is...
[cmsis] / CMSIS / Core_A / Include / cmsis_iccarm.h
1 /**************************************************************************//**
2  * @file     cmsis_iccarm.h
3  * @brief    CMSIS compiler ICCARM (IAR Compiler for Arm) header file
4  * @version  V5.0.7
5  * @date     15. May 2019
6  ******************************************************************************/
7
8 //------------------------------------------------------------------------------
9 //
10 // Copyright (c) 2017-2018 IAR Systems
11 // Copyright (c) 2018-2019 Arm Limited 
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License")
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
23 //
24 //------------------------------------------------------------------------------
25
26
27 #ifndef __CMSIS_ICCARM_H__
28 #define __CMSIS_ICCARM_H__
29
30 #ifndef __ICCARM__
31   #error This file should only be compiled by ICCARM
32 #endif
33
34 #pragma system_include
35
36 #define __IAR_FT _Pragma("inline=forced") __intrinsic
37
38 #if (__VER__ >= 8000000)
39   #define __ICCARM_V8 1
40 #else
41   #define __ICCARM_V8 0
42 #endif
43
44 #pragma language=extended
45
46 #ifndef __ALIGNED
47   #if __ICCARM_V8
48     #define __ALIGNED(x) __attribute__((aligned(x)))
49   #elif (__VER__ >= 7080000)
50     /* Needs IAR language extensions */
51     #define __ALIGNED(x) __attribute__((aligned(x)))
52   #else
53     #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
54     #define __ALIGNED(x)
55   #endif
56 #endif
57
58
59 /* Define compiler macros for CPU architecture, used in CMSIS 5.
60  */
61 #if __ARM_ARCH_7A__
62 /* Macro already defined */
63 #else
64   #if defined(__ARM7A__)
65     #define __ARM_ARCH_7A__ 1
66   #endif
67 #endif
68
69 #ifndef __ASM
70   #define __ASM __asm
71 #endif
72
73 #ifndef   __COMPILER_BARRIER
74   #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
75 #endif
76
77 #ifndef __INLINE
78   #define __INLINE inline
79 #endif
80
81 #ifndef   __NO_RETURN
82   #if __ICCARM_V8
83     #define __NO_RETURN __attribute__((__noreturn__))
84   #else
85     #define __NO_RETURN _Pragma("object_attribute=__noreturn")
86   #endif
87 #endif
88
89 #ifndef   __PACKED
90   /* Needs IAR language extensions */
91   #if __ICCARM_V8
92     #define __PACKED __attribute__((packed, aligned(1)))
93   #else
94     #define __PACKED __packed
95   #endif
96 #endif
97
98 #ifndef   __PACKED_STRUCT
99   /* Needs IAR language extensions */
100   #if __ICCARM_V8
101     #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
102   #else
103     #define __PACKED_STRUCT __packed struct
104   #endif
105 #endif
106
107 #ifndef   __PACKED_UNION
108   /* Needs IAR language extensions */
109   #if __ICCARM_V8
110     #define __PACKED_UNION union __attribute__((packed, aligned(1)))
111   #else
112     #define __PACKED_UNION __packed union
113   #endif
114 #endif
115
116 #ifndef   __RESTRICT
117   #if __ICCARM_V8
118     #define __RESTRICT            __restrict
119   #else
120     /* Needs IAR language extensions */
121     #define __RESTRICT            restrict
122   #endif
123 #endif
124
125 #ifndef   __STATIC_INLINE
126   #define __STATIC_INLINE       static inline
127 #endif
128
129 #ifndef   __FORCEINLINE
130   #define __FORCEINLINE         _Pragma("inline=forced")
131 #endif
132
133 #ifndef   __STATIC_FORCEINLINE
134   #define __STATIC_FORCEINLINE  __FORCEINLINE __STATIC_INLINE
135 #endif
136
137 #ifndef   CMSIS_DEPRECATED
138   #define CMSIS_DEPRECATED      __attribute__((deprecated))
139 #endif
140
141 #ifndef __UNALIGNED_UINT16_READ
142   #pragma language=save
143   #pragma language=extended
144   __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
145   {
146     return *(__packed uint16_t*)(ptr);
147   }
148   #pragma language=restore
149   #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
150 #endif
151
152
153 #ifndef __UNALIGNED_UINT16_WRITE
154   #pragma language=save
155   #pragma language=extended
156   __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
157   {
158     *(__packed uint16_t*)(ptr) = val;;
159   }
160   #pragma language=restore
161   #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
162 #endif
163
164 #ifndef __UNALIGNED_UINT32_READ
165   #pragma language=save
166   #pragma language=extended
167   __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
168   {
169     return *(__packed uint32_t*)(ptr);
170   }
171   #pragma language=restore
172   #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
173 #endif
174
175 #ifndef __UNALIGNED_UINT32_WRITE
176   #pragma language=save
177   #pragma language=extended
178   __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
179   {
180     *(__packed uint32_t*)(ptr) = val;;
181   }
182   #pragma language=restore
183   #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
184 #endif
185
186 #if 0
187 #ifndef __UNALIGNED_UINT32   /* deprecated */
188   #pragma language=save
189   #pragma language=extended
190   __packed struct  __iar_u32 { uint32_t v; };
191   #pragma language=restore
192   #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
193 #endif
194 #endif
195
196 #ifndef   __USED
197   #if __ICCARM_V8
198     #define __USED __attribute__((used))
199   #else
200     #define __USED _Pragma("__root")
201   #endif
202 #endif
203
204 #ifndef   __WEAK
205   #if __ICCARM_V8
206     #define __WEAK __attribute__((weak))
207   #else
208     #define __WEAK _Pragma("__weak")
209   #endif
210 #endif
211
212
213 #ifndef __ICCARM_INTRINSICS_VERSION__
214   #define __ICCARM_INTRINSICS_VERSION__  0
215 #endif
216
217 #if __ICCARM_INTRINSICS_VERSION__ == 2
218
219   #if defined(__CLZ)
220     #undef __CLZ
221   #endif
222   #if defined(__REVSH)
223     #undef __REVSH
224   #endif
225   #if defined(__RBIT)
226     #undef __RBIT
227   #endif
228   #if defined(__SSAT)
229     #undef __SSAT
230   #endif
231   #if defined(__USAT)
232     #undef __USAT
233   #endif
234
235   #include "iccarm_builtin.h"
236
237   #define __enable_irq        __iar_builtin_enable_interrupt
238   #define __disable_irq       __iar_builtin_disable_interrupt
239   #define __enable_fault_irq    __iar_builtin_enable_fiq
240   #define __disable_fault_irq   __iar_builtin_disable_fiq
241   #define __arm_rsr           __iar_builtin_rsr
242   #define __arm_wsr           __iar_builtin_wsr
243
244   #if __FPU_PRESENT
245     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
246   #else
247     #define __get_FPSCR()             ( 0 )
248   #endif
249
250   #define __set_FPSCR(VALUE)          (__arm_wsr("FPSCR", VALUE))
251
252   #define __get_CPSR()                (__arm_rsr("CPSR"))
253   #define __get_mode()                (__get_CPSR() & 0x1FU)
254
255   #define __set_CPSR(VALUE)           (__arm_wsr("CPSR", (VALUE)))
256   #define __set_mode(VALUE)           (__arm_wsr("CPSR_c", (VALUE)))
257
258
259   #define __get_FPEXC()       (__arm_rsr("FPEXC"))
260   #define __set_FPEXC(VALUE)    (__arm_wsr("FPEXC", VALUE))
261
262   #define __get_CP(cp, op1, RT, CRn, CRm, op2) \
263     ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2))
264
265   #define __set_CP(cp, op1, RT, CRn, CRm, op2) \
266     (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT)))
267
268   #define __get_CP64(cp, op1, Rt, CRm) \
269     __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : "=r" (Rt) : : "memory" )
270
271   #define __set_CP64(cp, op1, Rt, CRm) \
272     __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : : "r" (Rt) : "memory" )
273
274   #include "cmsis_cp15.h"
275
276   #define __NOP     __iar_builtin_no_operation
277
278   #define __CLZ     __iar_builtin_CLZ
279   #define __CLREX   __iar_builtin_CLREX
280
281   #define __DMB     __iar_builtin_DMB
282   #define __DSB     __iar_builtin_DSB
283   #define __ISB     __iar_builtin_ISB
284
285   #define __LDREXB  __iar_builtin_LDREXB
286   #define __LDREXH  __iar_builtin_LDREXH
287   #define __LDREXW  __iar_builtin_LDREX
288
289   #define __RBIT    __iar_builtin_RBIT
290   #define __REV     __iar_builtin_REV
291   #define __REV16   __iar_builtin_REV16
292
293   __IAR_FT int16_t __REVSH(int16_t val)
294   {
295     return (int16_t) __iar_builtin_REVSH(val);
296   }
297
298   #define __ROR     __iar_builtin_ROR
299   #define __RRX     __iar_builtin_RRX
300
301   #define __SEV     __iar_builtin_SEV
302
303   #define __SSAT    __iar_builtin_SSAT
304
305   #define __STREXB  __iar_builtin_STREXB
306   #define __STREXH  __iar_builtin_STREXH
307   #define __STREXW  __iar_builtin_STREX
308
309   #define __USAT    __iar_builtin_USAT
310
311   #define __WFE     __iar_builtin_WFE
312   #define __WFI     __iar_builtin_WFI
313
314   #define __SADD8   __iar_builtin_SADD8
315   #define __QADD8   __iar_builtin_QADD8
316   #define __SHADD8  __iar_builtin_SHADD8
317   #define __UADD8   __iar_builtin_UADD8
318   #define __UQADD8  __iar_builtin_UQADD8
319   #define __UHADD8  __iar_builtin_UHADD8
320   #define __SSUB8   __iar_builtin_SSUB8
321   #define __QSUB8   __iar_builtin_QSUB8
322   #define __SHSUB8  __iar_builtin_SHSUB8
323   #define __USUB8   __iar_builtin_USUB8
324   #define __UQSUB8  __iar_builtin_UQSUB8
325   #define __UHSUB8  __iar_builtin_UHSUB8
326   #define __SADD16  __iar_builtin_SADD16
327   #define __QADD16  __iar_builtin_QADD16
328   #define __SHADD16 __iar_builtin_SHADD16
329   #define __UADD16  __iar_builtin_UADD16
330   #define __UQADD16 __iar_builtin_UQADD16
331   #define __UHADD16 __iar_builtin_UHADD16
332   #define __SSUB16  __iar_builtin_SSUB16
333   #define __QSUB16  __iar_builtin_QSUB16
334   #define __SHSUB16 __iar_builtin_SHSUB16
335   #define __USUB16  __iar_builtin_USUB16
336   #define __UQSUB16 __iar_builtin_UQSUB16
337   #define __UHSUB16 __iar_builtin_UHSUB16
338   #define __SASX    __iar_builtin_SASX
339   #define __QASX    __iar_builtin_QASX
340   #define __SHASX   __iar_builtin_SHASX
341   #define __UASX    __iar_builtin_UASX
342   #define __UQASX   __iar_builtin_UQASX
343   #define __UHASX   __iar_builtin_UHASX
344   #define __SSAX    __iar_builtin_SSAX
345   #define __QSAX    __iar_builtin_QSAX
346   #define __SHSAX   __iar_builtin_SHSAX
347   #define __USAX    __iar_builtin_USAX
348   #define __UQSAX   __iar_builtin_UQSAX
349   #define __UHSAX   __iar_builtin_UHSAX
350   #define __USAD8   __iar_builtin_USAD8
351   #define __USADA8  __iar_builtin_USADA8
352   #define __SSAT16  __iar_builtin_SSAT16
353   #define __USAT16  __iar_builtin_USAT16
354   #define __UXTB16  __iar_builtin_UXTB16
355   #define __UXTAB16 __iar_builtin_UXTAB16
356   #define __SXTB16  __iar_builtin_SXTB16
357   #define __SXTAB16 __iar_builtin_SXTAB16
358   #define __SMUAD   __iar_builtin_SMUAD
359   #define __SMUADX  __iar_builtin_SMUADX
360   #define __SMMLA   __iar_builtin_SMMLA
361   #define __SMLAD   __iar_builtin_SMLAD
362   #define __SMLADX  __iar_builtin_SMLADX
363   #define __SMLALD  __iar_builtin_SMLALD
364   #define __SMLALDX __iar_builtin_SMLALDX
365   #define __SMUSD   __iar_builtin_SMUSD
366   #define __SMUSDX  __iar_builtin_SMUSDX
367   #define __SMLSD   __iar_builtin_SMLSD
368   #define __SMLSDX  __iar_builtin_SMLSDX
369   #define __SMLSLD  __iar_builtin_SMLSLD
370   #define __SMLSLDX __iar_builtin_SMLSLDX
371   #define __SEL     __iar_builtin_SEL
372   #define __QADD    __iar_builtin_QADD
373   #define __QSUB    __iar_builtin_QSUB
374   #define __PKHBT   __iar_builtin_PKHBT
375   #define __PKHTB   __iar_builtin_PKHTB
376
377 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
378
379   #if !__FPU_PRESENT
380   #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
381   #endif
382
383   #ifdef __INTRINSICS_INCLUDED
384   #error intrinsics.h is already included previously!
385   #endif
386
387   #include <intrinsics.h>
388
389   #if !__FPU_PRESENT
390   #define __get_FPSCR() (0)
391   #endif
392
393   #pragma diag_suppress=Pe940
394   #pragma diag_suppress=Pe177
395
396   #define __enable_irq        __enable_interrupt
397   #define __disable_irq       __disable_interrupt
398   #define __enable_fault_irq    __enable_fiq
399   #define __disable_fault_irq   __disable_fiq
400   #define __NOP               __no_operation
401
402   #define __get_xPSR          __get_PSR
403
404   __IAR_FT void __set_mode(uint32_t mode)
405   {
406     __ASM volatile("MSR  cpsr_c, %0" : : "r" (mode) : "memory");
407   }
408
409   __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
410   {
411     return __LDREX((unsigned long *)ptr);
412   }
413
414   __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
415   {
416     return __STREX(value, (unsigned long *)ptr);
417   }
418
419
420   __IAR_FT uint32_t __RRX(uint32_t value)
421   {
422     uint32_t result;
423     __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
424     return(result);
425   }
426
427
428   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
429   {
430     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
431   }
432
433   __IAR_FT uint32_t __get_FPEXC(void)
434   {
435   #if (__FPU_PRESENT == 1)
436     uint32_t result;
437     __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
438     return(result);
439   #else
440     return(0);
441   #endif
442   }
443
444   __IAR_FT void __set_FPEXC(uint32_t fpexc)
445   {
446   #if (__FPU_PRESENT == 1)
447     __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
448   #endif
449   }
450
451
452   #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \
453     __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
454   #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \
455     __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
456   #define __get_CP64(cp, op1, Rt, CRm) \
457     __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : "=r" (Rt) : : "memory" )
458   #define __set_CP64(cp, op1, Rt, CRm) \
459     __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm  : : "r" (Rt) : "memory" )
460
461   #include "cmsis_cp15.h"
462
463 #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
464
465 #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
466
467
468 __IAR_FT uint32_t __get_SP_usr(void)
469 {
470   uint32_t cpsr;
471   uint32_t result;
472   __ASM volatile(
473     "MRS     %0, cpsr   \n"
474     "CPS     #0x1F      \n" // no effect in USR mode
475     "MOV     %1, sp     \n"
476     "MSR     cpsr_c, %2 \n" // no effect in USR mode
477     "ISB" :  "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory"
478    );
479   return result;
480 }
481
482 __IAR_FT void __set_SP_usr(uint32_t topOfProcStack)
483 {
484   uint32_t cpsr;
485   __ASM volatile(
486     "MRS     %0, cpsr   \n"
487     "CPS     #0x1F      \n" // no effect in USR mode
488     "MOV     sp, %1     \n"
489     "MSR     cpsr_c, %2 \n" // no effect in USR mode
490     "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory"
491    );
492 }
493
494 #define __get_mode()                (__get_CPSR() & 0x1FU)
495
496 __STATIC_INLINE
497 void __FPU_Enable(void)
498 {
499   __ASM volatile(
500     //Permit access to VFP/NEON, registers by modifying CPACR
501     "        MRC     p15,0,R1,c1,c0,2  \n"
502     "        ORR     R1,R1,#0x00F00000 \n"
503     "        MCR     p15,0,R1,c1,c0,2  \n"
504
505     //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
506     "        ISB                       \n"
507
508     //Enable VFP/NEON
509     "        VMRS    R1,FPEXC          \n"
510     "        ORR     R1,R1,#0x40000000 \n"
511     "        VMSR    FPEXC,R1          \n"
512
513     //Initialise VFP/NEON registers to 0
514     "        MOV     R2,#0             \n"
515
516     //Initialise D16 registers to 0
517     "        VMOV    D0, R2,R2         \n"
518     "        VMOV    D1, R2,R2         \n"
519     "        VMOV    D2, R2,R2         \n"
520     "        VMOV    D3, R2,R2         \n"
521     "        VMOV    D4, R2,R2         \n"
522     "        VMOV    D5, R2,R2         \n"
523     "        VMOV    D6, R2,R2         \n"
524     "        VMOV    D7, R2,R2         \n"
525     "        VMOV    D8, R2,R2         \n"
526     "        VMOV    D9, R2,R2         \n"
527     "        VMOV    D10,R2,R2         \n"
528     "        VMOV    D11,R2,R2         \n"
529     "        VMOV    D12,R2,R2         \n"
530     "        VMOV    D13,R2,R2         \n"
531     "        VMOV    D14,R2,R2         \n"
532     "        VMOV    D15,R2,R2         \n"
533
534 #ifdef __ARM_ADVANCED_SIMD__
535     //Initialise D32 registers to 0
536     "        VMOV    D16,R2,R2         \n"
537     "        VMOV    D17,R2,R2         \n"
538     "        VMOV    D18,R2,R2         \n"
539     "        VMOV    D19,R2,R2         \n"
540     "        VMOV    D20,R2,R2         \n"
541     "        VMOV    D21,R2,R2         \n"
542     "        VMOV    D22,R2,R2         \n"
543     "        VMOV    D23,R2,R2         \n"
544     "        VMOV    D24,R2,R2         \n"
545     "        VMOV    D25,R2,R2         \n"
546     "        VMOV    D26,R2,R2         \n"
547     "        VMOV    D27,R2,R2         \n"
548     "        VMOV    D28,R2,R2         \n"
549     "        VMOV    D29,R2,R2         \n"
550     "        VMOV    D30,R2,R2         \n"
551     "        VMOV    D31,R2,R2         \n"
552 #endif
553
554     //Initialise FPSCR to a known state
555     "        VMRS    R1,FPSCR          \n"
556     "        MOV32   R2,#0x00086060    \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
557     "        AND     R1,R1,R2          \n"
558     "        VMSR    FPSCR,R1          \n"
559     : : : "cc", "r1", "r2"
560   );
561 }
562
563
564
565 #undef __IAR_FT
566 #undef __ICCARM_V8
567
568 #pragma diag_default=Pe940
569 #pragma diag_default=Pe177
570
571 #endif /* __CMSIS_ICCARM_H__ */