cmsis_gcc_m.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /*
  19. * CMSIS-Core(M) Compiler GCC Header File
  20. */
  21. #ifndef __CMSIS_GCC_M_H
  22. #define __CMSIS_GCC_M_H
  23. #ifndef __CMSIS_GCC_H
  24. #error "This file must not be included directly"
  25. #endif
  26. #include <arm_acle.h>
  27. /* ######################### Startup and Lowlevel Init ######################## */
  28. #ifndef __PROGRAM_START
  29. /**
  30. \brief Initializes data and bss sections
  31. \details This default implementations initialized all data and additional bss
  32. sections relying on .copy.table and .zero.table specified properly
  33. in the used linker script.
  34. */
  35. __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
  36. {
  37. extern void _start(void) __NO_RETURN;
  38. typedef struct __copy_table {
  39. uint32_t const* src;
  40. uint32_t* dest;
  41. uint32_t wlen;
  42. } __copy_table_t;
  43. typedef struct __zero_table {
  44. uint32_t* dest;
  45. uint32_t wlen;
  46. } __zero_table_t;
  47. extern const __copy_table_t __copy_table_start__;
  48. extern const __copy_table_t __copy_table_end__;
  49. extern const __zero_table_t __zero_table_start__;
  50. extern const __zero_table_t __zero_table_end__;
  51. for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
  52. for(uint32_t i=0u; i<pTable->wlen; ++i) {
  53. pTable->dest[i] = pTable->src[i];
  54. }
  55. }
  56. for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
  57. for(uint32_t i=0u; i<pTable->wlen; ++i) {
  58. pTable->dest[i] = 0u;
  59. }
  60. }
  61. _start();
  62. }
  63. #define __PROGRAM_START __cmsis_start
  64. #endif
  65. #ifndef __INITIAL_SP
  66. #define __INITIAL_SP __StackTop
  67. #endif
  68. #ifndef __STACK_LIMIT
  69. #define __STACK_LIMIT __StackLimit
  70. #endif
  71. #ifndef __VECTOR_TABLE
  72. #define __VECTOR_TABLE __Vectors
  73. #endif
  74. #ifndef __VECTOR_TABLE_ATTRIBUTE
  75. #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
  76. #endif
  77. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  78. #ifndef __STACK_SEAL
  79. #define __STACK_SEAL __StackSeal
  80. #endif
  81. #ifndef __TZ_STACK_SEAL_SIZE
  82. #define __TZ_STACK_SEAL_SIZE 8U
  83. #endif
  84. #ifndef __TZ_STACK_SEAL_VALUE
  85. #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
  86. #endif
  87. __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
  88. *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
  89. }
  90. #endif
  91. /* ########################### Core Function Access ########################### */
  92. /** \ingroup CMSIS_Core_FunctionInterface
  93. \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
  94. @{
  95. */
  96. /**
  97. \brief Get Control Register
  98. \details Returns the content of the Control Register.
  99. \return Control Register value
  100. */
  101. __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
  102. {
  103. uint32_t result;
  104. __ASM volatile ("MRS %0, control" : "=r" (result) );
  105. return (result);
  106. }
  107. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  108. /**
  109. \brief Get Control Register (non-secure)
  110. \details Returns the content of the non-secure Control Register when in secure mode.
  111. \return non-secure Control Register value
  112. */
  113. __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
  114. {
  115. uint32_t result;
  116. __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
  117. return (result);
  118. }
  119. #endif
  120. /**
  121. \brief Set Control Register
  122. \details Writes the given value to the Control Register.
  123. \param [in] control Control Register value to set
  124. */
  125. __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
  126. {
  127. __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
  128. __ISB();
  129. }
  130. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  131. /**
  132. \brief Set Control Register (non-secure)
  133. \details Writes the given value to the non-secure Control Register when in secure state.
  134. \param [in] control Control Register value to set
  135. */
  136. __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
  137. {
  138. __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
  139. __ISB();
  140. }
  141. #endif
  142. /**
  143. \brief Get IPSR Register
  144. \details Returns the content of the IPSR Register.
  145. \return IPSR Register value
  146. */
  147. __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
  148. {
  149. uint32_t result;
  150. __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
  151. return (result);
  152. }
  153. /**
  154. \brief Get APSR Register
  155. \details Returns the content of the APSR Register.
  156. \return APSR Register value
  157. */
  158. __STATIC_FORCEINLINE uint32_t __get_APSR(void)
  159. {
  160. uint32_t result;
  161. __ASM volatile ("MRS %0, apsr" : "=r" (result) );
  162. return (result);
  163. }
  164. /**
  165. \brief Get xPSR Register
  166. \details Returns the content of the xPSR Register.
  167. \return xPSR Register value
  168. */
  169. __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
  170. {
  171. uint32_t result;
  172. __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
  173. return (result);
  174. }
  175. /**
  176. \brief Get Process Stack Pointer
  177. \details Returns the current value of the Process Stack Pointer (PSP).
  178. \return PSP Register value
  179. */
  180. __STATIC_FORCEINLINE uint32_t __get_PSP(void)
  181. {
  182. uint32_t result;
  183. __ASM volatile ("MRS %0, psp" : "=r" (result) );
  184. return (result);
  185. }
  186. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  187. /**
  188. \brief Get Process Stack Pointer (non-secure)
  189. \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
  190. \return PSP Register value
  191. */
  192. __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
  193. {
  194. uint32_t result;
  195. __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
  196. return (result);
  197. }
  198. #endif
  199. /**
  200. \brief Set Process Stack Pointer
  201. \details Assigns the given value to the Process Stack Pointer (PSP).
  202. \param [in] topOfProcStack Process Stack Pointer value to set
  203. */
  204. __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
  205. {
  206. __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
  207. }
  208. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  209. /**
  210. \brief Set Process Stack Pointer (non-secure)
  211. \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
  212. \param [in] topOfProcStack Process Stack Pointer value to set
  213. */
  214. __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
  215. {
  216. __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
  217. }
  218. #endif
  219. /**
  220. \brief Get Main Stack Pointer
  221. \details Returns the current value of the Main Stack Pointer (MSP).
  222. \return MSP Register value
  223. */
  224. __STATIC_FORCEINLINE uint32_t __get_MSP(void)
  225. {
  226. uint32_t result;
  227. __ASM volatile ("MRS %0, msp" : "=r" (result) );
  228. return (result);
  229. }
  230. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  231. /**
  232. \brief Get Main Stack Pointer (non-secure)
  233. \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
  234. \return MSP Register value
  235. */
  236. __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
  237. {
  238. uint32_t result;
  239. __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
  240. return (result);
  241. }
  242. #endif
  243. /**
  244. \brief Set Main Stack Pointer
  245. \details Assigns the given value to the Main Stack Pointer (MSP).
  246. \param [in] topOfMainStack Main Stack Pointer value to set
  247. */
  248. __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
  249. {
  250. __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
  251. }
  252. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  253. /**
  254. \brief Set Main Stack Pointer (non-secure)
  255. \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
  256. \param [in] topOfMainStack Main Stack Pointer value to set
  257. */
  258. __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
  259. {
  260. __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
  261. }
  262. #endif
  263. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  264. /**
  265. \brief Get Stack Pointer (non-secure)
  266. \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
  267. \return SP Register value
  268. */
  269. __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
  270. {
  271. uint32_t result;
  272. __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
  273. return (result);
  274. }
  275. /**
  276. \brief Set Stack Pointer (non-secure)
  277. \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
  278. \param [in] topOfStack Stack Pointer value to set
  279. */
  280. __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
  281. {
  282. __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
  283. }
  284. #endif
  285. /**
  286. \brief Get Priority Mask
  287. \details Returns the current state of the priority mask bit from the Priority Mask Register.
  288. \return Priority Mask value
  289. */
  290. __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
  291. {
  292. uint32_t result;
  293. __ASM volatile ("MRS %0, primask" : "=r" (result) );
  294. return (result);
  295. }
  296. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  297. /**
  298. \brief Get Priority Mask (non-secure)
  299. \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
  300. \return Priority Mask value
  301. */
  302. __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
  303. {
  304. uint32_t result;
  305. __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
  306. return (result);
  307. }
  308. #endif
  309. /**
  310. \brief Set Priority Mask
  311. \details Assigns the given value to the Priority Mask Register.
  312. \param [in] priMask Priority Mask
  313. */
  314. __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
  315. {
  316. __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
  317. }
  318. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  319. /**
  320. \brief Set Priority Mask (non-secure)
  321. \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
  322. \param [in] priMask Priority Mask
  323. */
  324. __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
  325. {
  326. __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
  327. }
  328. #endif
  329. #if (__ARM_ARCH_ISA_THUMB >= 2)
  330. /**
  331. \brief Get Base Priority
  332. \details Returns the current value of the Base Priority register.
  333. \return Base Priority register value
  334. */
  335. __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
  336. {
  337. uint32_t result;
  338. __ASM volatile ("MRS %0, basepri" : "=r" (result) );
  339. return (result);
  340. }
  341. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  342. /**
  343. \brief Get Base Priority (non-secure)
  344. \details Returns the current value of the non-secure Base Priority register when in secure state.
  345. \return Base Priority register value
  346. */
  347. __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
  348. {
  349. uint32_t result;
  350. __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
  351. return (result);
  352. }
  353. #endif
  354. /**
  355. \brief Set Base Priority
  356. \details Assigns the given value to the Base Priority register.
  357. \param [in] basePri Base Priority value to set
  358. */
  359. __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
  360. {
  361. __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
  362. }
  363. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  364. /**
  365. \brief Set Base Priority (non-secure)
  366. \details Assigns the given value to the non-secure Base Priority register when in secure state.
  367. \param [in] basePri Base Priority value to set
  368. */
  369. __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
  370. {
  371. __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
  372. }
  373. #endif
  374. /**
  375. \brief Set Base Priority with condition
  376. \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
  377. or the new value increases the BASEPRI priority level.
  378. \param [in] basePri Base Priority value to set
  379. */
  380. __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
  381. {
  382. __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
  383. }
  384. /**
  385. \brief Get Fault Mask
  386. \details Returns the current value of the Fault Mask register.
  387. \return Fault Mask register value
  388. */
  389. __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
  390. {
  391. uint32_t result;
  392. __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
  393. return (result);
  394. }
  395. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  396. /**
  397. \brief Get Fault Mask (non-secure)
  398. \details Returns the current value of the non-secure Fault Mask register when in secure state.
  399. \return Fault Mask register value
  400. */
  401. __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
  402. {
  403. uint32_t result;
  404. __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
  405. return (result);
  406. }
  407. #endif
  408. /**
  409. \brief Set Fault Mask
  410. \details Assigns the given value to the Fault Mask register.
  411. \param [in] faultMask Fault Mask value to set
  412. */
  413. __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
  414. {
  415. __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
  416. }
  417. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  418. /**
  419. \brief Set Fault Mask (non-secure)
  420. \details Assigns the given value to the non-secure Fault Mask register when in secure state.
  421. \param [in] faultMask Fault Mask value to set
  422. */
  423. __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
  424. {
  425. __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
  426. }
  427. #endif
  428. #endif /* (__ARM_ARCH_ISA_THUMB >= 2) */
  429. #if (__ARM_ARCH >= 8)
  430. /**
  431. \brief Get Process Stack Pointer Limit
  432. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  433. Stack Pointer Limit register hence zero is returned always in non-secure
  434. mode.
  435. \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
  436. \return PSPLIM Register value
  437. */
  438. __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
  439. {
  440. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  441. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) && \
  442. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  443. /* without main extensions, the non-secure PSPLIM is RAZ/WI */
  444. return (0U);
  445. #else
  446. uint32_t result;
  447. __ASM volatile ("MRS %0, psplim" : "=r" (result) );
  448. return (result);
  449. #endif
  450. }
  451. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  452. /**
  453. \brief Get Process Stack Pointer Limit (non-secure)
  454. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  455. Stack Pointer Limit register hence zero is returned always.
  456. \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  457. \return PSPLIM Register value
  458. */
  459. __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
  460. {
  461. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  462. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)))
  463. /* without main extensions, the non-secure PSPLIM is RAZ/WI */
  464. return (0U);
  465. #else
  466. uint32_t result;
  467. __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
  468. return (result);
  469. #endif
  470. }
  471. #endif
  472. /**
  473. \brief Set Process Stack Pointer Limit
  474. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  475. Stack Pointer Limit register hence the write is silently ignored in non-secure
  476. mode.
  477. \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
  478. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  479. */
  480. __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
  481. {
  482. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  483. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) && \
  484. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  485. /* without main extensions, the non-secure PSPLIM is RAZ/WI */
  486. (void)ProcStackPtrLimit;
  487. #else
  488. __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
  489. #endif
  490. }
  491. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  492. /**
  493. \brief Set Process Stack Pointer (non-secure)
  494. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  495. Stack Pointer Limit register hence the write is silently ignored.
  496. \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  497. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  498. */
  499. __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
  500. {
  501. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  502. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)))
  503. /* without main extensions, the non-secure PSPLIM is RAZ/WI */
  504. (void)ProcStackPtrLimit;
  505. #else
  506. __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
  507. #endif
  508. }
  509. #endif
  510. /**
  511. \brief Get Main Stack Pointer Limit
  512. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  513. Stack Pointer Limit register hence zero is returned always.
  514. \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
  515. \return MSPLIM Register value
  516. */
  517. __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
  518. {
  519. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  520. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) && \
  521. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  522. /* without main extensions, the non-secure MSPLIM is RAZ/WI */
  523. return (0U);
  524. #else
  525. uint32_t result;
  526. __ASM volatile ("MRS %0, msplim" : "=r" (result) );
  527. return (result);
  528. #endif
  529. }
  530. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  531. /**
  532. \brief Get Main Stack Pointer Limit (non-secure)
  533. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  534. Stack Pointer Limit register hence zero is returned always.
  535. \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
  536. \return MSPLIM Register value
  537. */
  538. __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
  539. {
  540. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  541. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)))
  542. /* without main extensions, the non-secure MSPLIM is RAZ/WI */
  543. return (0U);
  544. #else
  545. uint32_t result;
  546. __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
  547. return (result);
  548. #endif
  549. }
  550. #endif
  551. /**
  552. \brief Set Main Stack Pointer Limit
  553. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  554. Stack Pointer Limit register hence the write is silently ignored.
  555. \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
  556. \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
  557. */
  558. __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
  559. {
  560. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  561. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) && \
  562. (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
  563. /* without main extensions, the non-secure MSPLIM is RAZ/WI */
  564. (void)MainStackPtrLimit;
  565. #else
  566. __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
  567. #endif
  568. }
  569. #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
  570. /**
  571. \brief Set Main Stack Pointer Limit (non-secure)
  572. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  573. Stack Pointer Limit register hence the write is silently ignored.
  574. \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
  575. \param [in] MainStackPtrLimit Main Stack Pointer value to set
  576. */
  577. __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
  578. {
  579. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  580. !(defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)))
  581. /* without main extensions, the non-secure MSPLIM is RAZ/WI */
  582. (void)MainStackPtrLimit;
  583. #else
  584. __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
  585. #endif
  586. }
  587. #endif
  588. #endif /* (__ARM_ARCH >= 8) */
  589. /*@} end of CMSIS_Core_RegAccFunctions */
  590. #endif /* __CMSIS_GCC_M_H */