cmsis_armclang.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**************************************************************************//**
  2. * @file cmsis_armclang.h
  3. * @brief CMSIS compiler armclang (Arm Compiler 6) header file
  4. * @version V1.2.2
  5. * @date 13. November 2022
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2021 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. #ifndef __CMSIS_ARMCLANG_H
  25. #define __CMSIS_ARMCLANG_H
  26. #pragma clang system_header /* treat file as system include file */
  27. /* CMSIS compiler specific defines */
  28. #ifndef __ASM
  29. #define __ASM __asm
  30. #endif
  31. #ifndef __INLINE
  32. #define __INLINE __inline
  33. #endif
  34. #ifndef __FORCEINLINE
  35. #define __FORCEINLINE __attribute__((always_inline))
  36. #endif
  37. #ifndef __STATIC_INLINE
  38. #define __STATIC_INLINE static __inline
  39. #endif
  40. #ifndef __STATIC_FORCEINLINE
  41. #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
  42. #endif
  43. #ifndef __NO_RETURN
  44. #define __NO_RETURN __attribute__((__noreturn__))
  45. #endif
  46. #ifndef CMSIS_DEPRECATED
  47. #define CMSIS_DEPRECATED __attribute__((deprecated))
  48. #endif
  49. #ifndef __USED
  50. #define __USED __attribute__((used))
  51. #endif
  52. #ifndef __WEAK
  53. #define __WEAK __attribute__((weak))
  54. #endif
  55. #ifndef __PACKED
  56. #define __PACKED __attribute__((packed, aligned(1)))
  57. #endif
  58. #ifndef __PACKED_STRUCT
  59. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  60. #endif
  61. #ifndef __UNALIGNED_UINT16_WRITE
  62. #pragma clang diagnostic push
  63. #pragma clang diagnostic ignored "-Wpacked"
  64. /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
  65. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  66. #pragma clang diagnostic pop
  67. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  68. #endif
  69. #ifndef __UNALIGNED_UINT16_READ
  70. #pragma clang diagnostic push
  71. #pragma clang diagnostic ignored "-Wpacked"
  72. /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
  73. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  74. #pragma clang diagnostic pop
  75. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  76. #endif
  77. #ifndef __UNALIGNED_UINT32_WRITE
  78. #pragma clang diagnostic push
  79. #pragma clang diagnostic ignored "-Wpacked"
  80. /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
  81. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  82. #pragma clang diagnostic pop
  83. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  84. #endif
  85. #ifndef __UNALIGNED_UINT32_READ
  86. #pragma clang diagnostic push
  87. #pragma clang diagnostic ignored "-Wpacked"
  88. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  89. #pragma clang diagnostic pop
  90. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  91. #endif
  92. #ifndef __ALIGNED
  93. #define __ALIGNED(x) __attribute__((aligned(x)))
  94. #endif
  95. #ifndef __PACKED
  96. #define __PACKED __attribute__((packed))
  97. #endif
  98. #ifndef __COMPILER_BARRIER
  99. #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
  100. #endif
  101. /* ########################## Core Instruction Access ######################### */
  102. /**
  103. \brief No Operation
  104. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  105. */
  106. #define __NOP __builtin_arm_nop
  107. /**
  108. \brief Wait For Interrupt
  109. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  110. */
  111. #define __WFI __builtin_arm_wfi
  112. /**
  113. \brief Wait For Event
  114. \details Wait For Event is a hint instruction that permits the processor to enter
  115. a low-power state until one of a number of events occurs.
  116. */
  117. #define __WFE __builtin_arm_wfe
  118. /**
  119. \brief Send Event
  120. \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  121. */
  122. #define __SEV __builtin_arm_sev
  123. /**
  124. \brief Instruction Synchronization Barrier
  125. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  126. so that all instructions following the ISB are fetched from cache or memory,
  127. after the instruction has been completed.
  128. */
  129. #define __ISB() __builtin_arm_isb(0xF)
  130. /**
  131. \brief Data Synchronization Barrier
  132. \details Acts as a special kind of Data Memory Barrier.
  133. It completes when all explicit memory accesses before this instruction complete.
  134. */
  135. #define __DSB() __builtin_arm_dsb(0xF)
  136. /**
  137. \brief Data Memory Barrier
  138. \details Ensures the apparent order of the explicit memory operations before
  139. and after the instruction, without ensuring their completion.
  140. */
  141. #define __DMB() __builtin_arm_dmb(0xF)
  142. /**
  143. \brief Reverse byte order (32 bit)
  144. \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
  145. \param [in] value Value to reverse
  146. \return Reversed value
  147. */
  148. #define __REV(value) __builtin_bswap32(value)
  149. /**
  150. \brief Reverse byte order (16 bit)
  151. \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
  152. \param [in] value Value to reverse
  153. \return Reversed value
  154. */
  155. #define __REV16(value) __ROR(__REV(value), 16)
  156. /**
  157. \brief Reverse byte order (16 bit)
  158. \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
  159. \param [in] value Value to reverse
  160. \return Reversed value
  161. */
  162. #define __REVSH(value) (int16_t)__builtin_bswap16(value)
  163. /**
  164. \brief Rotate Right in unsigned value (32 bit)
  165. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  166. \param [in] op1 Value to rotate
  167. \param [in] op2 Number of Bits to rotate
  168. \return Rotated value
  169. */
  170. __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  171. {
  172. op2 %= 32U;
  173. if (op2 == 0U)
  174. {
  175. return op1;
  176. }
  177. return (op1 >> op2) | (op1 << (32U - op2));
  178. }
  179. /**
  180. \brief Breakpoint
  181. \details Causes the processor to enter Debug state.
  182. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  183. \param [in] value is ignored by the processor.
  184. If required, a debugger can use it to store additional information about the breakpoint.
  185. */
  186. #define __BKPT(value) __ASM volatile ("bkpt "#value)
  187. /**
  188. \brief Reverse bit order of value
  189. \details Reverses the bit order of the given value.
  190. \param [in] value Value to reverse
  191. \return Reversed value
  192. */
  193. #define __RBIT __builtin_arm_rbit
  194. /**
  195. \brief Count leading zeros
  196. \details Counts the number of leading zeros of a data value.
  197. \param [in] value Value to count the leading zeros
  198. \return number of leading zeros in value
  199. */
  200. __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
  201. {
  202. /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
  203. __builtin_clz(0) is undefined behaviour, so handle this case specially.
  204. This guarantees ARM-compatible results if happening to compile on a non-ARM
  205. target, and ensures the compiler doesn't decide to activate any
  206. optimisations using the logic "value was passed to __builtin_clz, so it
  207. is non-zero".
  208. ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
  209. single CLZ instruction.
  210. */
  211. if (value == 0U)
  212. {
  213. return 32U;
  214. }
  215. return __builtin_clz(value);
  216. }
  217. /**
  218. \brief LDR Exclusive (8 bit)
  219. \details Executes a exclusive LDR instruction for 8 bit value.
  220. \param [in] ptr Pointer to data
  221. \return value of type uint8_t at (*ptr)
  222. */
  223. #define __LDREXB (uint8_t)__builtin_arm_ldrex
  224. /**
  225. \brief LDR Exclusive (16 bit)
  226. \details Executes a exclusive LDR instruction for 16 bit values.
  227. \param [in] ptr Pointer to data
  228. \return value of type uint16_t at (*ptr)
  229. */
  230. #define __LDREXH (uint16_t)__builtin_arm_ldrex
  231. /**
  232. \brief LDR Exclusive (32 bit)
  233. \details Executes a exclusive LDR instruction for 32 bit values.
  234. \param [in] ptr Pointer to data
  235. \return value of type uint32_t at (*ptr)
  236. */
  237. #define __LDREXW (uint32_t)__builtin_arm_ldrex
  238. /**
  239. \brief STR Exclusive (8 bit)
  240. \details Executes a exclusive STR instruction for 8 bit values.
  241. \param [in] value Value to store
  242. \param [in] ptr Pointer to location
  243. \return 0 Function succeeded
  244. \return 1 Function failed
  245. */
  246. #define __STREXB (uint32_t)__builtin_arm_strex
  247. /**
  248. \brief STR Exclusive (16 bit)
  249. \details Executes a exclusive STR instruction for 16 bit values.
  250. \param [in] value Value to store
  251. \param [in] ptr Pointer to location
  252. \return 0 Function succeeded
  253. \return 1 Function failed
  254. */
  255. #define __STREXH (uint32_t)__builtin_arm_strex
  256. /**
  257. \brief STR Exclusive (32 bit)
  258. \details Executes a exclusive STR instruction for 32 bit values.
  259. \param [in] value Value to store
  260. \param [in] ptr Pointer to location
  261. \return 0 Function succeeded
  262. \return 1 Function failed
  263. */
  264. #define __STREXW (uint32_t)__builtin_arm_strex
  265. /**
  266. \brief Remove the exclusive lock
  267. \details Removes the exclusive lock which is created by LDREX.
  268. */
  269. #define __CLREX __builtin_arm_clrex
  270. /**
  271. \brief Signed Saturate
  272. \details Saturates a signed value.
  273. \param [in] value Value to be saturated
  274. \param [in] sat Bit position to saturate to (1..32)
  275. \return Saturated value
  276. */
  277. #define __SSAT __builtin_arm_ssat
  278. /**
  279. \brief Unsigned Saturate
  280. \details Saturates an unsigned value.
  281. \param [in] value Value to be saturated
  282. \param [in] sat Bit position to saturate to (0..31)
  283. \return Saturated value
  284. */
  285. #define __USAT __builtin_arm_usat
  286. /* ################### Compiler specific Intrinsics ########################### */
  287. /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
  288. Access to dedicated SIMD instructions
  289. @{
  290. */
  291. #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
  292. #define __SADD8 __builtin_arm_sadd8
  293. #define __SADD16 __builtin_arm_sadd16
  294. #define __QADD8 __builtin_arm_qadd8
  295. #define __QSUB8 __builtin_arm_qsub8
  296. #define __QADD16 __builtin_arm_qadd16
  297. #define __SHADD16 __builtin_arm_shadd16
  298. #define __QSUB16 __builtin_arm_qsub16
  299. #define __SHSUB16 __builtin_arm_shsub16
  300. #define __QASX __builtin_arm_qasx
  301. #define __SHASX __builtin_arm_shasx
  302. #define __QSAX __builtin_arm_qsax
  303. #define __SHSAX __builtin_arm_shsax
  304. #define __SXTB16 __builtin_arm_sxtb16
  305. #define __SMUAD __builtin_arm_smuad
  306. #define __SMUADX __builtin_arm_smuadx
  307. #define __SMLAD __builtin_arm_smlad
  308. #define __SMLADX __builtin_arm_smladx
  309. #define __SMLALD __builtin_arm_smlald
  310. #define __SMLALDX __builtin_arm_smlaldx
  311. #define __SMUSD __builtin_arm_smusd
  312. #define __SMUSDX __builtin_arm_smusdx
  313. #define __SMLSDX __builtin_arm_smlsdx
  314. #define __USAT16 __builtin_arm_usat16
  315. #define __SSUB8 __builtin_arm_ssub8
  316. #define __SXTB16 __builtin_arm_sxtb16
  317. #define __SXTAB16 __builtin_arm_sxtab16
  318. __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
  319. {
  320. int32_t result;
  321. __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  322. return(result);
  323. }
  324. __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
  325. {
  326. int32_t result;
  327. __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  328. return(result);
  329. }
  330. #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
  331. ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
  332. #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
  333. ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
  334. __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
  335. {
  336. int32_t result;
  337. __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
  338. return(result);
  339. }
  340. #endif /* (__ARM_FEATURE_DSP == 1) */
  341. /* ########################### Core Function Access ########################### */
  342. /**
  343. \brief Enable IRQ Interrupts
  344. \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
  345. Can only be executed in Privileged modes.
  346. */
  347. __STATIC_FORCEINLINE void __enable_irq(void)
  348. {
  349. __ASM volatile ("cpsie i" : : : "memory");
  350. }
  351. /**
  352. \brief Disable IRQ Interrupts
  353. \details Disables IRQ interrupts by setting the I-bit in the CPSR.
  354. Can only be executed in Privileged modes.
  355. */
  356. __STATIC_FORCEINLINE void __disable_irq(void)
  357. {
  358. __ASM volatile ("cpsid i" : : : "memory");
  359. }
  360. /**
  361. \brief Enable FIQ
  362. \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
  363. Can only be executed in Privileged modes.
  364. */
  365. __STATIC_FORCEINLINE void __enable_fault_irq(void)
  366. {
  367. __ASM volatile ("cpsie f" : : : "memory");
  368. }
  369. /**
  370. \brief Disable FIQ
  371. \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
  372. Can only be executed in Privileged modes.
  373. */
  374. __STATIC_FORCEINLINE void __disable_fault_irq(void)
  375. {
  376. __ASM volatile ("cpsid f" : : : "memory");
  377. }
  378. /**
  379. \brief Get FPSCR
  380. \details Returns the current value of the Floating Point Status/Control register.
  381. \return Floating Point Status/Control register value
  382. */
  383. #define __get_FPSCR __builtin_arm_get_fpscr
  384. /**
  385. \brief Set FPSCR
  386. \details Assigns the given value to the Floating Point Status/Control register.
  387. \param [in] fpscr Floating Point Status/Control value to set
  388. */
  389. #define __set_FPSCR __builtin_arm_set_fpscr
  390. /** \brief Get CPSR Register
  391. \return CPSR Register value
  392. */
  393. __STATIC_FORCEINLINE uint32_t __get_CPSR(void)
  394. {
  395. uint32_t result;
  396. __ASM volatile("MRS %0, cpsr" : "=r" (result) );
  397. return(result);
  398. }
  399. /** \brief Set CPSR Register
  400. \param [in] cpsr CPSR value to set
  401. */
  402. __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr)
  403. {
  404. __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory");
  405. }
  406. /** \brief Get Mode
  407. \return Processor Mode
  408. */
  409. __STATIC_FORCEINLINE uint32_t __get_mode(void)
  410. {
  411. return (__get_CPSR() & 0x1FU);
  412. }
  413. /** \brief Set Mode
  414. \param [in] mode Mode value to set
  415. */
  416. __STATIC_FORCEINLINE void __set_mode(uint32_t mode)
  417. {
  418. __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
  419. }
  420. /** \brief Get Stack Pointer
  421. \return Stack Pointer value
  422. */
  423. __STATIC_FORCEINLINE uint32_t __get_SP(void)
  424. {
  425. uint32_t result;
  426. __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory");
  427. return result;
  428. }
  429. /** \brief Set Stack Pointer
  430. \param [in] stack Stack Pointer value to set
  431. */
  432. __STATIC_FORCEINLINE void __set_SP(uint32_t stack)
  433. {
  434. __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
  435. }
  436. /** \brief Get USR/SYS Stack Pointer
  437. \return USR/SYS Stack Pointer value
  438. */
  439. __STATIC_FORCEINLINE uint32_t __get_SP_usr(void)
  440. {
  441. uint32_t cpsr;
  442. uint32_t result;
  443. __ASM volatile(
  444. "MRS %0, cpsr \n"
  445. "CPS #0x1F \n" // no effect in USR mode
  446. "MOV %1, sp \n"
  447. "MSR cpsr_c, %0 \n" // no effect in USR mode
  448. "ISB" : "=r"(cpsr), "=r"(result) : : "memory"
  449. );
  450. return result;
  451. }
  452. /** \brief Set USR/SYS Stack Pointer
  453. \param [in] topOfProcStack USR/SYS Stack Pointer value to set
  454. */
  455. __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack)
  456. {
  457. uint32_t cpsr;
  458. __ASM volatile(
  459. "MRS %0, cpsr \n"
  460. "CPS #0x1F \n" // no effect in USR mode
  461. "MOV sp, %1 \n"
  462. "MSR cpsr_c, %0 \n" // no effect in USR mode
  463. "ISB" : "=r"(cpsr) : "r" (topOfProcStack) : "memory"
  464. );
  465. }
  466. /** \brief Get FPEXC
  467. \return Floating Point Exception Control register value
  468. */
  469. __STATIC_FORCEINLINE uint32_t __get_FPEXC(void)
  470. {
  471. #if (__FPU_PRESENT == 1)
  472. uint32_t result;
  473. __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
  474. return(result);
  475. #else
  476. return(0);
  477. #endif
  478. }
  479. /** \brief Set FPEXC
  480. \param [in] fpexc Floating Point Exception Control value to set
  481. */
  482. __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc)
  483. {
  484. #if (__FPU_PRESENT == 1)
  485. __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
  486. #endif
  487. }
  488. /*
  489. * Include common core functions to access Coprocessor 15 registers
  490. */
  491. #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
  492. #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
  493. #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
  494. #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
  495. #include "cmsis_cp15.h"
  496. /** \brief Enable Floating Point Unit
  497. Critical section, called from undef handler, so systick is disabled
  498. */
  499. __STATIC_INLINE void __FPU_Enable(void)
  500. {
  501. __ASM volatile(
  502. //Permit access to VFP/NEON, registers by modifying CPACR
  503. " MRC p15,0,R1,c1,c0,2 \n"
  504. " ORR R1,R1,#0x00F00000 \n"
  505. " MCR p15,0,R1,c1,c0,2 \n"
  506. //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
  507. " ISB \n"
  508. //Enable VFP/NEON
  509. " VMRS R1,FPEXC \n"
  510. " ORR R1,R1,#0x40000000 \n"
  511. " VMSR FPEXC,R1 \n"
  512. //Initialise VFP/NEON registers to 0
  513. " MOV R2,#0 \n"
  514. //Initialise D16 registers to 0
  515. " VMOV D0, R2,R2 \n"
  516. " VMOV D1, R2,R2 \n"
  517. " VMOV D2, R2,R2 \n"
  518. " VMOV D3, R2,R2 \n"
  519. " VMOV D4, R2,R2 \n"
  520. " VMOV D5, R2,R2 \n"
  521. " VMOV D6, R2,R2 \n"
  522. " VMOV D7, R2,R2 \n"
  523. " VMOV D8, R2,R2 \n"
  524. " VMOV D9, R2,R2 \n"
  525. " VMOV D10,R2,R2 \n"
  526. " VMOV D11,R2,R2 \n"
  527. " VMOV D12,R2,R2 \n"
  528. " VMOV D13,R2,R2 \n"
  529. " VMOV D14,R2,R2 \n"
  530. " VMOV D15,R2,R2 \n"
  531. #if (defined(__ARM_NEON) && (__ARM_NEON == 1))
  532. //Initialise D32 registers to 0
  533. " VMOV D16,R2,R2 \n"
  534. " VMOV D17,R2,R2 \n"
  535. " VMOV D18,R2,R2 \n"
  536. " VMOV D19,R2,R2 \n"
  537. " VMOV D20,R2,R2 \n"
  538. " VMOV D21,R2,R2 \n"
  539. " VMOV D22,R2,R2 \n"
  540. " VMOV D23,R2,R2 \n"
  541. " VMOV D24,R2,R2 \n"
  542. " VMOV D25,R2,R2 \n"
  543. " VMOV D26,R2,R2 \n"
  544. " VMOV D27,R2,R2 \n"
  545. " VMOV D28,R2,R2 \n"
  546. " VMOV D29,R2,R2 \n"
  547. " VMOV D30,R2,R2 \n"
  548. " VMOV D31,R2,R2 \n"
  549. #endif
  550. //Initialise FPSCR to a known state
  551. " VMRS R1,FPSCR \n"
  552. " LDR R2,=0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
  553. " AND R1,R1,R2 \n"
  554. " VMSR FPSCR,R1 "
  555. : : : "cc", "r1", "r2"
  556. );
  557. }
  558. #endif /* __CMSIS_ARMCLANG_H */