]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_clang.h
Core(M): Add support for LLVM/Clang
[cmsis] / CMSIS / Core / Include / cmsis_clang.h
1 /**************************************************************************//**
2  * @file     cmsis_clang.h
3  * @brief    CMSIS compiler LLVM/Clang header file
4  * @version  V1.0.0
5  * @date     28. June 2023
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * 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, WITHOUT
20  * 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 #ifndef __CMSIS_CLANG_H
26 #define __CMSIS_CLANG_H
27
28 #pragma clang system_header
29
30 #include <arm_acle.h>
31
32 /* Fallback for __has_builtin */
33 #ifndef __has_builtin
34   #define __has_builtin(x) (0)
35 #endif
36
37 /* CMSIS compiler specific defines */
38 #ifndef   __ASM
39   #define __ASM                                  __asm
40 #endif
41 #ifndef   __INLINE
42   #define __INLINE                               inline
43 #endif
44 #ifndef   __STATIC_INLINE
45   #define __STATIC_INLINE                        static inline
46 #endif
47 #ifndef   __STATIC_FORCEINLINE
48   #define __STATIC_FORCEINLINE                   __attribute__((always_inline)) static inline
49 #endif
50 #ifndef   __NO_RETURN
51   #define __NO_RETURN                            __attribute__((__noreturn__))
52 #endif
53 #ifndef   __USED
54   #define __USED                                 __attribute__((used))
55 #endif
56 #ifndef   __WEAK
57   #define __WEAK                                 __attribute__((weak))
58 #endif
59 #ifndef   __PACKED
60   #define __PACKED                               __attribute__((packed, aligned(1)))
61 #endif
62 #ifndef   __PACKED_STRUCT
63   #define __PACKED_STRUCT                        struct __attribute__((packed, aligned(1)))
64 #endif
65 #ifndef   __PACKED_UNION
66   #define __PACKED_UNION                         union __attribute__((packed, aligned(1)))
67 #endif
68 #ifndef   __UNALIGNED_UINT16_WRITE
69   #pragma clang diagnostic push
70   #pragma clang diagnostic ignored "-Wpacked"
71   __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
72   #pragma clang diagnostic pop
73   #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
74 #endif
75 #ifndef   __UNALIGNED_UINT16_READ
76   #pragma clang diagnostic push
77   #pragma clang diagnostic ignored "-Wpacked"
78   __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
79   #pragma clang diagnostic pop
80   #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
81 #endif
82 #ifndef   __UNALIGNED_UINT32_WRITE
83   #pragma clang diagnostic push
84   #pragma clang diagnostic ignored "-Wpacked"
85   __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
86   #pragma clang diagnostic pop
87   #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
88 #endif
89 #ifndef   __UNALIGNED_UINT32_READ
90   #pragma clang diagnostic push
91   #pragma clang diagnostic ignored "-Wpacked"
92   __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
93   #pragma clang diagnostic pop
94   #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
95 #endif
96 #ifndef   __ALIGNED
97   #define __ALIGNED(x)                           __attribute__((aligned(x)))
98 #endif
99 #ifndef   __RESTRICT
100   #define __RESTRICT                             __restrict
101 #endif
102 #ifndef   __COMPILER_BARRIER
103   #define __COMPILER_BARRIER()                   __ASM volatile("":::"memory")
104 #endif
105 #ifndef __NO_INIT
106   #define __NO_INIT                              __attribute__ ((section (".bss.noinit")))
107 #endif
108 #ifndef __ALIAS
109   #define __ALIAS(x)                             __attribute__ ((alias(x)))
110 #endif
111
112 /* #########################  Startup and Lowlevel Init  ######################## */
113
114 #ifndef __PROGRAM_START
115 #define __PROGRAM_START           _start
116 #endif
117
118 #ifndef __INITIAL_SP
119 #define __INITIAL_SP              __stack
120 #endif
121
122 #ifndef __STACK_LIMIT
123 #define __STACK_LIMIT             __stack_limit
124 #endif
125
126 #ifndef __VECTOR_TABLE
127 #define __VECTOR_TABLE            __Vectors
128 #endif
129
130 #ifndef __VECTOR_TABLE_ATTRIBUTE
131 #define __VECTOR_TABLE_ATTRIBUTE  __attribute__((used, section(".vectors")))
132 #endif
133
134 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
135 #ifndef __STACK_SEAL
136 #define __STACK_SEAL              __stack_seal
137 #endif
138
139 #ifndef __TZ_STACK_SEAL_SIZE
140 #define __TZ_STACK_SEAL_SIZE      8U
141 #endif
142
143 #ifndef __TZ_STACK_SEAL_VALUE
144 #define __TZ_STACK_SEAL_VALUE     0xFEF5EDA5FEF5EDA5ULL
145 #endif
146
147
148 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
149   *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
150 }
151 #endif
152
153
154 /* ##########################  Core Instruction Access  ######################### */
155 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
156   Access to dedicated instructions
157   @{
158 */
159
160 /* Define macros for porting to both thumb1 and thumb2.
161  * For thumb1, use low register (r0-r7), specified by constraint "l"
162  * Otherwise, use general registers, specified by constraint "r" */
163 #if defined (__thumb__) && !defined (__thumb2__)
164 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
165 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
166 #define __CMSIS_GCC_USE_REG(r) "l" (r)
167 #else
168 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
169 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
170 #define __CMSIS_GCC_USE_REG(r) "r" (r)
171 #endif
172
173 /**
174   \brief   No Operation
175   \details No Operation does nothing. This instruction can be used for code alignment purposes.
176  */
177 #define __NOP() __nop()
178
179 /**
180   \brief   Wait For Interrupt
181   \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
182  */
183 #define __WFI() __wfi()
184
185
186 /**
187   \brief   Wait For Event
188   \details Wait For Event is a hint instruction that permits the processor to enter
189            a low-power state until one of a number of events occurs.
190  */
191 #define __WFE() __wfe()
192
193
194 /**
195   \brief   Send Event
196   \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
197  */
198 #define __SEV() __sev()
199
200
201 /**
202   \brief   Instruction Synchronization Barrier
203   \details Instruction Synchronization Barrier flushes the pipeline in the processor,
204            so that all instructions following the ISB are fetched from cache or memory,
205            after the instruction has been completed.
206  */
207 #define __ISB() __isb(0xF)
208
209 /**
210   \brief   Data Synchronization Barrier
211   \details Acts as a special kind of Data Memory Barrier.
212            It completes when all explicit memory accesses before this instruction complete.
213  */
214 #define __DSB() __dsb(0xF)
215
216 /**
217   \brief   Data Memory Barrier
218   \details Ensures the apparent order of the explicit memory operations before
219            and after the instruction, without ensuring their completion.
220  */
221 #define __DMB() __dmb(0xF)
222
223 /**
224   \brief   Reverse byte order (32 bit)
225   \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
226   \param [in]    value  Value to reverse
227   \return               Reversed value
228  */
229 #define __REV(value) __rev(value)
230
231 /**
232   \brief   Reverse byte order (16 bit)
233   \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
234   \param [in]    value  Value to reverse
235   \return               Reversed value
236  */
237 #define __REV16(value) __rev16(value)
238
239 /**
240   \brief   Reverse byte order (16 bit)
241   \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
242   \param [in]    value  Value to reverse
243   \return               Reversed value
244  */
245 #define __REVSH(value) __revsh(value)
246
247 /**
248   \brief   Rotate Right in unsigned value (32 bit)
249   \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
250   \param [in]    op1  Value to rotate
251   \param [in]    op2  Number of Bits to rotate
252   \return               Rotated value
253  */
254 #define __ROR(op1, op2) __ror(op1, op2)
255
256 /**
257   \brief   Breakpoint
258   \details Causes the processor to enter Debug state.
259            Debug tools can use this to investigate system state when the instruction at a particular address is reached.
260   \param [in]    value  is ignored by the processor.
261                  If required, a debugger can use it to store additional information about the breakpoint.
262  */
263 #define __BKPT(value) __ASM volatile ("bkpt "#value)
264
265 /**
266   \brief   Reverse bit order of value
267   \details Reverses the bit order of the given value.
268   \param [in]    value  Value to reverse
269   \return               Reversed value
270  */
271 #define __RBIT(value) __rbit(value)
272
273 /**
274   \brief   Count leading zeros
275   \details Counts the number of leading zeros of a data value.
276   \param [in]  value  Value to count the leading zeros
277   \return             number of leading zeros in value
278  */
279 #define __CLZ(value) __clz(value)
280
281 // Workaround for wrong features set by Clang for Armv8-M Baseline devices
282 #if defined(__ARM_FEATURE_SAT) && (__ARM_ARCH_ISA_THUMB >= 2)
283 /**
284   \brief   Signed Saturate
285   \details Saturates a signed value.
286   \param [in]  value  Value to be saturated
287   \param [in]    sat  Bit position to saturate to (1..32)
288   \return             Saturated value
289  */
290 #define __SSAT(value, sat) __ssat(value, sat)
291
292 /**
293   \brief   Unsigned Saturate
294   \details Saturates an unsigned value.
295   \param [in]  value  Value to be saturated
296   \param [in]    sat  Bit position to saturate to (0..31)
297   \return             Saturated value
298  */
299 #define __USAT(value, sat) __usat(value, sat)
300
301 #else /* __ARM_FEATURE_SAT */
302
303 /**
304   \brief   Signed Saturate
305   \details Saturates a signed value.
306   \param [in]  value  Value to be saturated
307   \param [in]    sat  Bit position to saturate to (1..32)
308   \return             Saturated value
309  */
310 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
311 {
312   if ((sat >= 1U) && (sat <= 32U))
313   {
314     const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
315     const int32_t min = -1 - max ;
316     if (val > max)
317     {
318       return max;
319     }
320     else if (val < min)
321     {
322       return min;
323     }
324   }
325   return val;
326 }
327
328 /**
329   \brief   Unsigned Saturate
330   \details Saturates an unsigned value.
331   \param [in]  value  Value to be saturated
332   \param [in]    sat  Bit position to saturate to (0..31)
333   \return             Saturated value
334  */
335 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
336 {
337   if (sat <= 31U)
338   {
339     const uint32_t max = ((1U << sat) - 1U);
340     if (val > (int32_t)max)
341     {
342       return max;
343     }
344     else if (val < 0)
345     {
346       return 0U;
347     }
348   }
349   return (uint32_t)val;
350 }
351
352 #endif /* __ARM_FEATURE_SAT */
353
354 #if __ARM_ARCH_ISA_THUMB >= 2
355 /**
356   \brief   Rotate Right with Extend (32 bit)
357   \details Moves each bit of a bitstring right by one bit.
358            The carry input is shifted in at the left end of the bitstring.
359   \param [in]    value  Value to rotate
360   \return               Rotated value
361  */
362 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
363 {
364   uint32_t result;
365
366   __ASM volatile ("rrx %0, %1" : "=r" (result) : "r" (value));
367   return result;
368 }
369 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
370
371 #if __ARM_FEATURE_LDREX >= 4
372 /**
373   \brief   LDR Exclusive (32 bit)
374   \details Executes a exclusive LDR instruction for 32 bit values.
375   \param [in]    ptr  Pointer to data
376   \return        value of type uint32_t at (*ptr)
377  */
378 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
379 {
380     uint32_t result;
381
382    __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
383    return result;
384 }
385
386 /**
387   \brief   STR Exclusive (32 bit)
388   \details Executes a exclusive STR instruction for 32 bit values.
389   \param [in]  value  Value to store
390   \param [in]    ptr  Pointer to location
391   \return          0  Function succeeded
392   \return          1  Function failed
393  */
394 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
395 {
396    uint32_t result;
397
398    __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
399    return result;
400 }
401
402 #endif /* __ARM_FEATURE_LDREX => 4 */
403
404 #if __ARM_FEATURE_LDREX >= 7
405 /**
406   \brief   LDR Exclusive (16 bit)
407   \details Executes a exclusive LDR instruction for 16 bit values.
408   \param [in]    ptr  Pointer to data
409   \return        value of type uint16_t at (*ptr)
410  */
411 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
412 {
413     uint32_t result;
414
415    __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
416    return ((uint16_t) result);    /* Add explicit type cast here */
417 }
418
419 /**
420   \brief   STR Exclusive (16 bit)
421   \details Executes a exclusive STR instruction for 16 bit values.
422   \param [in]  value  Value to store
423   \param [in]    ptr  Pointer to location
424   \return          0  Function succeeded
425   \return          1  Function failed
426  */
427 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
428 {
429    uint32_t result;
430
431    __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
432    return result;
433 }
434
435 /**
436   \brief   LDR Exclusive (8 bit)
437   \details Executes a exclusive LDR instruction for 8 bit value.
438   \param [in]    ptr  Pointer to data
439   \return             value of type uint8_t at (*ptr)
440  */
441 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
442 {
443     uint32_t result;
444
445    __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
446    return ((uint8_t) result);    /* Add explicit type cast here */
447 }
448
449 /**
450   \brief   STR Exclusive (8 bit)
451   \details Executes a exclusive STR instruction for 8 bit values.
452   \param [in]  value  Value to store
453   \param [in]    ptr  Pointer to location
454   \return          0  Function succeeded
455   \return          1  Function failed
456  */
457 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
458 {
459    uint32_t result;
460
461    __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
462    return result;
463 }
464
465 /**
466   \brief   Remove the exclusive lock
467   \details Removes the exclusive lock which is created by LDREX.
468  */
469 __STATIC_FORCEINLINE void __CLREX(void)
470 {
471   __ASM volatile ("clrex" ::: "memory");
472 }
473 #endif /* __ARM_FEATURE_LDREX */
474
475 #if __ARM_ARCH_ISA_THUMB >= 2
476
477 /**
478   \brief   LDRT Unprivileged (8 bit)
479   \details Executes a Unprivileged LDRT instruction for 8 bit value.
480   \param [in]    ptr  Pointer to data
481   \return             value of type uint8_t at (*ptr)
482  */
483 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
484 {
485     uint32_t result;
486
487    __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
488    return ((uint8_t) result);    /* Add explicit type cast here */
489 }
490
491
492 /**
493   \brief   LDRT Unprivileged (16 bit)
494   \details Executes a Unprivileged LDRT instruction for 16 bit values.
495   \param [in]    ptr  Pointer to data
496   \return        value of type uint16_t at (*ptr)
497  */
498 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
499 {
500     uint32_t result;
501
502    __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
503    return ((uint16_t) result);    /* Add explicit type cast here */
504 }
505
506
507 /**
508   \brief   LDRT Unprivileged (32 bit)
509   \details Executes a Unprivileged LDRT instruction for 32 bit values.
510   \param [in]    ptr  Pointer to data
511   \return        value of type uint32_t at (*ptr)
512  */
513 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
514 {
515     uint32_t result;
516
517    __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
518    return result;
519 }
520
521
522 /**
523   \brief   STRT Unprivileged (8 bit)
524   \details Executes a Unprivileged STRT instruction for 8 bit values.
525   \param [in]  value  Value to store
526   \param [in]    ptr  Pointer to location
527  */
528 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
529 {
530    __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
531 }
532
533
534 /**
535   \brief   STRT Unprivileged (16 bit)
536   \details Executes a Unprivileged STRT instruction for 16 bit values.
537   \param [in]  value  Value to store
538   \param [in]    ptr  Pointer to location
539  */
540 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
541 {
542    __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
543 }
544
545
546 /**
547   \brief   STRT Unprivileged (32 bit)
548   \details Executes a Unprivileged STRT instruction for 32 bit values.
549   \param [in]  value  Value to store
550   \param [in]    ptr  Pointer to location
551  */
552 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
553 {
554    __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
555 }
556 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
557
558 #if __ARM_ARCH >= 8
559 /**
560   \brief   Load-Acquire (8 bit)
561   \details Executes a LDAB instruction for 8 bit value.
562   \param [in]    ptr  Pointer to data
563   \return             value of type uint8_t at (*ptr)
564  */
565 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
566 {
567     uint32_t result;
568
569    __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
570    return ((uint8_t) result);
571 }
572
573
574 /**
575   \brief   Load-Acquire (16 bit)
576   \details Executes a LDAH instruction for 16 bit values.
577   \param [in]    ptr  Pointer to data
578   \return        value of type uint16_t at (*ptr)
579  */
580 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
581 {
582     uint32_t result;
583
584    __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
585    return ((uint16_t) result);
586 }
587
588
589 /**
590   \brief   Load-Acquire (32 bit)
591   \details Executes a LDA instruction for 32 bit values.
592   \param [in]    ptr  Pointer to data
593   \return        value of type uint32_t at (*ptr)
594  */
595 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
596 {
597     uint32_t result;
598
599    __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
600    return result;
601 }
602
603
604 /**
605   \brief   Store-Release (8 bit)
606   \details Executes a STLB instruction for 8 bit values.
607   \param [in]  value  Value to store
608   \param [in]    ptr  Pointer to location
609  */
610 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
611 {
612    __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
613 }
614
615
616 /**
617   \brief   Store-Release (16 bit)
618   \details Executes a STLH instruction for 16 bit values.
619   \param [in]  value  Value to store
620   \param [in]    ptr  Pointer to location
621  */
622 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
623 {
624    __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
625 }
626
627
628 /**
629   \brief   Store-Release (32 bit)
630   \details Executes a STL instruction for 32 bit values.
631   \param [in]  value  Value to store
632   \param [in]    ptr  Pointer to location
633  */
634 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
635 {
636    __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
637 }
638
639
640 /**
641   \brief   Load-Acquire Exclusive (8 bit)
642   \details Executes a LDAB exclusive instruction for 8 bit value.
643   \param [in]    ptr  Pointer to data
644   \return             value of type uint8_t at (*ptr)
645  */
646 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
647 {
648     uint32_t result;
649
650    __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
651    return ((uint8_t) result);
652 }
653
654
655 /**
656   \brief   Load-Acquire Exclusive (16 bit)
657   \details Executes a LDAH exclusive instruction for 16 bit values.
658   \param [in]    ptr  Pointer to data
659   \return        value of type uint16_t at (*ptr)
660  */
661 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
662 {
663     uint32_t result;
664
665    __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
666    return ((uint16_t) result);
667 }
668
669
670 /**
671   \brief   Load-Acquire Exclusive (32 bit)
672   \details Executes a LDA exclusive instruction for 32 bit values.
673   \param [in]    ptr  Pointer to data
674   \return        value of type uint32_t at (*ptr)
675  */
676 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
677 {
678     uint32_t result;
679
680    __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
681    return result;
682 }
683
684
685 /**
686   \brief   Store-Release Exclusive (8 bit)
687   \details Executes a STLB exclusive instruction for 8 bit values.
688   \param [in]  value  Value to store
689   \param [in]    ptr  Pointer to location
690   \return          0  Function succeeded
691   \return          1  Function failed
692  */
693 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
694 {
695    uint32_t result;
696
697    __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
698    return result;
699 }
700
701
702 /**
703   \brief   Store-Release Exclusive (16 bit)
704   \details Executes a STLH exclusive instruction for 16 bit values.
705   \param [in]  value  Value to store
706   \param [in]    ptr  Pointer to location
707   \return          0  Function succeeded
708   \return          1  Function failed
709  */
710 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
711 {
712    uint32_t result;
713
714    __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
715    return result;
716 }
717
718
719 /**
720   \brief   Store-Release Exclusive (32 bit)
721   \details Executes a STL exclusive instruction for 32 bit values.
722   \param [in]  value  Value to store
723   \param [in]    ptr  Pointer to location
724   \return          0  Function succeeded
725   \return          1  Function failed
726  */
727 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
728 {
729    uint32_t result;
730
731    __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
732    return result;
733 }
734
735 #endif /* __ARM_ARCH >= 8 */
736
737 /** @}*/ /* end of group CMSIS_Core_InstructionInterface */
738
739
740 /* ###########################  Core Function Access  ########################### */
741 /** \ingroup  CMSIS_Core_FunctionInterface
742     \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
743   @{
744  */
745
746 /**
747   \brief   Enable IRQ Interrupts
748   \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
749            Can only be executed in Privileged modes.
750  */
751 __STATIC_FORCEINLINE void __enable_irq(void)
752 {
753   __ASM volatile ("cpsie i" : : : "memory");
754 }
755
756
757 /**
758   \brief   Disable IRQ Interrupts
759   \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
760            Can only be executed in Privileged modes.
761  */
762 __STATIC_FORCEINLINE void __disable_irq(void)
763 {
764   __ASM volatile ("cpsid i" : : : "memory");
765 }
766
767
768 /**
769   \brief   Get Control Register
770   \details Returns the content of the Control Register.
771   \return               Control Register value
772  */
773 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
774 {
775   uint32_t result;
776
777   __ASM volatile ("MRS %0, control" : "=r" (result) );
778   return result;
779 }
780
781
782 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
783 /**
784   \brief   Get Control Register (non-secure)
785   \details Returns the content of the non-secure Control Register when in secure mode.
786   \return               non-secure Control Register value
787  */
788 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
789 {
790   uint32_t result;
791
792   __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
793   return result;
794 }
795 #endif
796
797
798 /**
799   \brief   Set Control Register
800   \details Writes the given value to the Control Register.
801   \param [in]    control  Control Register value to set
802  */
803 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
804 {
805   __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
806   __ISB();
807 }
808
809
810 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
811 /**
812   \brief   Set Control Register (non-secure)
813   \details Writes the given value to the non-secure Control Register when in secure state.
814   \param [in]    control  Control Register value to set
815  */
816 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
817 {
818   __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
819   __ISB();
820 }
821 #endif
822
823
824 /**
825   \brief   Get IPSR Register
826   \details Returns the content of the IPSR Register.
827   \return               IPSR Register value
828  */
829 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
830 {
831   uint32_t result;
832
833   __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
834   return result;
835 }
836
837
838 /**
839   \brief   Get APSR Register
840   \details Returns the content of the APSR Register.
841   \return               APSR Register value
842  */
843 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
844 {
845   uint32_t result;
846
847   __ASM volatile ("MRS %0, apsr" : "=r" (result) );
848   return result;
849 }
850
851
852 /**
853   \brief   Get xPSR Register
854   \details Returns the content of the xPSR Register.
855   \return               xPSR Register value
856  */
857 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
858 {
859   uint32_t result;
860
861   __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
862   return result;
863 }
864
865
866 /**
867   \brief   Get Process Stack Pointer
868   \details Returns the current value of the Process Stack Pointer (PSP).
869   \return               PSP Register value
870  */
871 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
872 {
873   uint32_t result;
874
875   __ASM volatile ("MRS %0, psp"  : "=r" (result) );
876   return result;
877 }
878
879
880 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
881 /**
882   \brief   Get Process Stack Pointer (non-secure)
883   \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
884   \return               PSP Register value
885  */
886 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
887 {
888   uint32_t result;
889
890   __ASM volatile ("MRS %0, psp_ns"  : "=r" (result) );
891   return result;
892 }
893 #endif
894
895
896 /**
897   \brief   Set Process Stack Pointer
898   \details Assigns the given value to the Process Stack Pointer (PSP).
899   \param [in]    topOfProcStack  Process Stack Pointer value to set
900  */
901 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
902 {
903   __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
904 }
905
906
907 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
908 /**
909   \brief   Set Process Stack Pointer (non-secure)
910   \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
911   \param [in]    topOfProcStack  Process Stack Pointer value to set
912  */
913 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
914 {
915   __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
916 }
917 #endif
918
919
920 /**
921   \brief   Get Main Stack Pointer
922   \details Returns the current value of the Main Stack Pointer (MSP).
923   \return               MSP Register value
924  */
925 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
926 {
927   uint32_t result;
928
929   __ASM volatile ("MRS %0, msp" : "=r" (result) );
930   return result;
931 }
932
933
934 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
935 /**
936   \brief   Get Main Stack Pointer (non-secure)
937   \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
938   \return               MSP Register value
939  */
940 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
941 {
942   uint32_t result;
943
944   __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
945   return result;
946 }
947 #endif
948
949
950 /**
951   \brief   Set Main Stack Pointer
952   \details Assigns the given value to the Main Stack Pointer (MSP).
953   \param [in]    topOfMainStack  Main Stack Pointer value to set
954  */
955 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
956 {
957   __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
958 }
959
960
961 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
962 /**
963   \brief   Set Main Stack Pointer (non-secure)
964   \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
965   \param [in]    topOfMainStack  Main Stack Pointer value to set
966  */
967 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
968 {
969   __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
970 }
971 #endif
972
973
974 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
975 /**
976   \brief   Get Stack Pointer (non-secure)
977   \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
978   \return               SP Register value
979  */
980 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
981 {
982   uint32_t result;
983
984   __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
985   return result;
986 }
987
988
989 /**
990   \brief   Set Stack Pointer (non-secure)
991   \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
992   \param [in]    topOfStack  Stack Pointer value to set
993  */
994 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
995 {
996   __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
997 }
998 #endif
999
1000
1001 /**
1002   \brief   Get Priority Mask
1003   \details Returns the current state of the priority mask bit from the Priority Mask Register.
1004   \return               Priority Mask value
1005  */
1006 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
1007 {
1008   uint32_t result;
1009
1010   __ASM volatile ("MRS %0, primask" : "=r" (result) );
1011   return result;
1012 }
1013
1014
1015 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1016 /**
1017   \brief   Get Priority Mask (non-secure)
1018   \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
1019   \return               Priority Mask value
1020  */
1021 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
1022 {
1023   uint32_t result;
1024
1025   __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
1026   return result;
1027 }
1028 #endif
1029
1030
1031 /**
1032   \brief   Set Priority Mask
1033   \details Assigns the given value to the Priority Mask Register.
1034   \param [in]    priMask  Priority Mask
1035  */
1036 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
1037 {
1038   __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
1039 }
1040
1041
1042 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1043 /**
1044   \brief   Set Priority Mask (non-secure)
1045   \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
1046   \param [in]    priMask  Priority Mask
1047  */
1048 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
1049 {
1050   __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
1051 }
1052 #endif
1053
1054
1055 #if __ARM_ARCH_ISA_THUMB >= 2
1056 /**
1057   \brief   Enable FIQ
1058   \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
1059            Can only be executed in Privileged modes.
1060  */
1061 __STATIC_FORCEINLINE void __enable_fault_irq(void)
1062 {
1063   __ASM volatile ("cpsie f" : : : "memory");
1064 }
1065
1066
1067 /**
1068   \brief   Disable FIQ
1069   \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
1070            Can only be executed in Privileged modes.
1071  */
1072 __STATIC_FORCEINLINE void __disable_fault_irq(void)
1073 {
1074   __ASM volatile ("cpsid f" : : : "memory");
1075 }
1076
1077
1078 /**
1079   \brief   Get Base Priority
1080   \details Returns the current value of the Base Priority register.
1081   \return               Base Priority register value
1082  */
1083 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
1084 {
1085   uint32_t result;
1086
1087   __ASM volatile ("MRS %0, basepri" : "=r" (result) );
1088   return result;
1089 }
1090
1091
1092 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1093 /**
1094   \brief   Get Base Priority (non-secure)
1095   \details Returns the current value of the non-secure Base Priority register when in secure state.
1096   \return               Base Priority register value
1097  */
1098 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
1099 {
1100   uint32_t result;
1101
1102   __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
1103   return result;
1104 }
1105 #endif
1106
1107
1108 /**
1109   \brief   Set Base Priority
1110   \details Assigns the given value to the Base Priority register.
1111   \param [in]    basePri  Base Priority value to set
1112  */
1113 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
1114 {
1115   __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
1116 }
1117
1118
1119 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1120 /**
1121   \brief   Set Base Priority (non-secure)
1122   \details Assigns the given value to the non-secure Base Priority register when in secure state.
1123   \param [in]    basePri  Base Priority value to set
1124  */
1125 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
1126 {
1127   __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
1128 }
1129 #endif
1130
1131
1132 /**
1133   \brief   Set Base Priority with condition
1134   \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
1135            or the new value increases the BASEPRI priority level.
1136   \param [in]    basePri  Base Priority value to set
1137  */
1138 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
1139 {
1140   __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
1141 }
1142
1143
1144 /**
1145   \brief   Get Fault Mask
1146   \details Returns the current value of the Fault Mask register.
1147   \return               Fault Mask register value
1148  */
1149 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
1150 {
1151   uint32_t result;
1152
1153   __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
1154   return result;
1155 }
1156
1157
1158 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1159 /**
1160   \brief   Get Fault Mask (non-secure)
1161   \details Returns the current value of the non-secure Fault Mask register when in secure state.
1162   \return               Fault Mask register value
1163  */
1164 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
1165 {
1166   uint32_t result;
1167
1168   __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
1169   return result;
1170 }
1171 #endif
1172
1173
1174 /**
1175   \brief   Set Fault Mask
1176   \details Assigns the given value to the Fault Mask register.
1177   \param [in]    faultMask  Fault Mask value to set
1178  */
1179 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
1180 {
1181   __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
1182 }
1183
1184
1185 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1186 /**
1187   \brief   Set Fault Mask (non-secure)
1188   \details Assigns the given value to the non-secure Fault Mask register when in secure state.
1189   \param [in]    faultMask  Fault Mask value to set
1190  */
1191 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
1192 {
1193   __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
1194 }
1195 #endif
1196
1197 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
1198
1199
1200 #if __ARM_ARCH >= 8
1201
1202 /**
1203   \brief   Get Process Stack Pointer Limit
1204   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1205   Stack Pointer Limit register hence zero is returned always in non-secure
1206   mode.
1207
1208   \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
1209   \return               PSPLIM Register value
1210  */
1211 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
1212 {
1213 #if (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1214     // without main extensions, the non-secure PSPLIM is RAZ/WI
1215   return 0U;
1216 #else
1217   uint32_t result;
1218   __ASM volatile ("MRS %0, psplim"  : "=r" (result) );
1219   return result;
1220 #endif
1221 }
1222
1223 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
1224 /**
1225   \brief   Get Process Stack Pointer Limit (non-secure)
1226   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1227   Stack Pointer Limit register hence zero is returned always.
1228
1229   \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1230   \return               PSPLIM Register value
1231  */
1232 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
1233 {
1234 #if __ARM_ARCH_ISA_THUMB < 2
1235   // without main extensions, the non-secure PSPLIM is RAZ/WI
1236   return 0U;
1237 #else
1238   uint32_t result;
1239   __ASM volatile ("MRS %0, psplim_ns"  : "=r" (result) );
1240   return result;
1241 #endif
1242 }
1243 #endif
1244
1245
1246 /**
1247   \brief   Set Process Stack Pointer Limit
1248   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1249   Stack Pointer Limit register hence the write is silently ignored in non-secure
1250   mode.
1251
1252   \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
1253   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
1254  */
1255 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
1256 {
1257 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1258   // without main extensions, the non-secure PSPLIM is RAZ/WI
1259   (void)ProcStackPtrLimit;
1260 #else
1261   __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
1262 #endif
1263 }
1264
1265
1266 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
1267 /**
1268   \brief   Set Process Stack Pointer (non-secure)
1269   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1270   Stack Pointer Limit register hence the write is silently ignored.
1271
1272   \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1273   \param [in]    ProcStackPtrLimit  Process Stack Pointer Limit value to set
1274  */
1275 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
1276 {
1277 #if __ARM_ARCH_ISA_THUMB < 2
1278   // without main extensions, the non-secure PSPLIM is RAZ/WI
1279   (void)ProcStackPtrLimit;
1280 #else
1281   __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
1282 #endif
1283 }
1284 #endif
1285
1286
1287 /**
1288   \brief   Get Main Stack Pointer Limit
1289   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1290   Stack Pointer Limit register hence zero is returned always in non-secure
1291   mode.
1292
1293   \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
1294   \return               MSPLIM Register value
1295  */
1296 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
1297 {
1298 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1299   // without main extensions, the non-secure MSPLIM is RAZ/WI
1300   return 0U;
1301 #else
1302   uint32_t result;
1303   __ASM volatile ("MRS %0, msplim" : "=r" (result) );
1304   return result;
1305 #endif
1306 }
1307
1308
1309 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
1310 /**
1311   \brief   Get Main Stack Pointer Limit (non-secure)
1312   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1313   Stack Pointer Limit register hence zero is returned always.
1314
1315   \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
1316   \return               MSPLIM Register value
1317  */
1318 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
1319 {
1320 #if __ARM_ARCH_ISA_THUMB < 2
1321   // without main extensions, the non-secure MSPLIM is RAZ/WI
1322   return 0U;
1323 #else
1324   uint32_t result;
1325   __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
1326   return result;
1327 #endif
1328 }
1329 #endif
1330
1331
1332 /**
1333   \brief   Set Main Stack Pointer Limit
1334   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1335   Stack Pointer Limit register hence the write is silently ignored in non-secure
1336   mode.
1337
1338   \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
1339   \param [in]    MainStackPtrLimit  Main Stack Pointer Limit value to set
1340  */
1341 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
1342 {
1343 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1344   // without main extensions, the non-secure MSPLIM is RAZ/WI
1345   (void)MainStackPtrLimit;
1346 #else
1347   __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
1348 #endif
1349 }
1350
1351
1352 #if (defined (__ARM_FEATURE_CMSE  ) && (__ARM_FEATURE_CMSE   == 3))
1353 /**
1354   \brief   Set Main Stack Pointer Limit (non-secure)
1355   Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1356   Stack Pointer Limit register hence the write is silently ignored.
1357
1358   \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
1359   \param [in]    MainStackPtrLimit  Main Stack Pointer value to set
1360  */
1361 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
1362 {
1363 #if __ARM_ARCH_ISA_THUMB < 2
1364   // without main extensions, the non-secure MSPLIM is RAZ/WI
1365   (void)MainStackPtrLimit;
1366 #else
1367   __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
1368 #endif
1369 }
1370 #endif
1371
1372 #endif /* __ARM_ARCH >= 8 */
1373
1374
1375 /**
1376   \brief   Get FPSCR
1377   \details Returns the current value of the Floating Point Status/Control register.
1378   \return               Floating Point Status/Control register value
1379  */
1380 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
1381 {
1382 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1383      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
1384   return __builtin_arm_get_fpscr();
1385 #else
1386   return 0U;
1387 #endif
1388 }
1389
1390
1391 /**
1392   \brief   Set FPSCR
1393   \details Assigns the given value to the Floating Point Status/Control register.
1394   \param [in]    fpscr  Floating Point Status/Control value to set
1395  */
1396 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
1397 {
1398 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1399      (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
1400   __builtin_arm_set_fpscr(fpscr);
1401 #else
1402   (void)fpscr;
1403 #endif
1404 }
1405
1406
1407 /** @} end of CMSIS_Core_RegAccFunctions */
1408
1409
1410 /* ###################  Compiler specific Intrinsics  ########################### */
1411 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1412   Access to dedicated SIMD instructions
1413   @{
1414 */
1415
1416 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1417
1418 #define     __SADD8                 __sadd8
1419 #define     __QADD8                 __qadd8
1420 #define     __SHADD8                __shadd8
1421 #define     __UADD8                 __uadd8
1422 #define     __UQADD8                __uqadd8
1423 #define     __UHADD8                __uhadd8
1424 #define     __SSUB8                 __ssub8
1425 #define     __QSUB8                 __qsub8
1426 #define     __SHSUB8                __shsub8
1427 #define     __USUB8                 __usub8
1428 #define     __UQSUB8                __uqsub8
1429 #define     __UHSUB8                __uhsub8
1430 #define     __SADD16                __sadd16
1431 #define     __QADD16                __qadd16
1432 #define     __SHADD16               __shadd16
1433 #define     __UADD16                __uadd16
1434 #define     __UQADD16               __uqadd16
1435 #define     __UHADD16               __uhadd16
1436 #define     __SSUB16                __ssub16
1437 #define     __QSUB16                __qsub16
1438 #define     __SHSUB16               __shsub16
1439 #define     __USUB16                __usub16
1440 #define     __UQSUB16               __uqsub16
1441 #define     __UHSUB16               __uhsub16
1442 #define     __SASX                  __sasx
1443 #define     __QASX                  __qasx
1444 #define     __SHASX                 __shasx
1445 #define     __UASX                  __uasx
1446 #define     __UQASX                 __uqasx
1447 #define     __UHASX                 __uhasx
1448 #define     __SSAX                  __ssax
1449 #define     __QSAX                  __qsax
1450 #define     __SHSAX                 __shsax
1451 #define     __USAX                  __usax
1452 #define     __UQSAX                 __uqsax
1453 #define     __UHSAX                 __uhsax
1454 #define     __USAD8                 __usad8
1455 #define     __USADA8                __usada8
1456 #define     __SSAT16                __ssat16
1457 #define     __USAT16                __usat16
1458 #define     __UXTB16                __uxtb16
1459 #define     __UXTAB16               __uxtab16
1460 #define     __SXTB16                __sxtb16
1461 #define     __SXTAB16               __sxtab16
1462 #define     __SMUAD                 __smuad
1463 #define     __SMUADX                __smuadx
1464 #define     __SMLAD                 __smlad
1465 #define     __SMLADX                __smladx
1466 #define     __SMLALD                __smlald
1467 #define     __SMLALDX               __smlaldx
1468 #define     __SMUSD                 __smusd
1469 #define     __SMUSDX                __smusdx
1470 #define     __SMLSD                 __smlsd
1471 #define     __SMLSDX                __smlsdx
1472 #define     __SMLSLD                __smlsld
1473 #define     __SMLSLDX               __smlsldx
1474 #define     __SEL                   __sel
1475 #define     __QADD                  __qadd
1476 #define     __QSUB                  __qsub
1477
1478 #define __PKHBT(ARG1,ARG2,ARG3) \
1479 __extension__ \
1480 ({                          \
1481   uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1482   __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2), "I" (ARG3)  ); \
1483   __RES; \
1484  })
1485
1486 #define __PKHTB(ARG1,ARG2,ARG3) \
1487 __extension__ \
1488 ({                          \
1489   uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1490   if (ARG3 == 0) \
1491     __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2)  ); \
1492   else \
1493     __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) :  "r" (__ARG1), "r" (__ARG2), "I" (ARG3)  ); \
1494   __RES; \
1495  })
1496
1497 #define __SXTB16_RORn(ARG1, ARG2)        __SXTB16(__ROR(ARG1, ARG2))
1498
1499 #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
1500
1501 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1502 {
1503  int32_t result;
1504
1505  __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r"  (op1), "r" (op2), "r" (op3) );
1506  return result;
1507 }
1508
1509 #endif /* (__ARM_FEATURE_DSP == 1) */
1510 /** @} end of group CMSIS_SIMD_intrinsics */
1511
1512 #endif /* __CMSIS_CLANG_H */