You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
4.9KB

  1. /* ARMv8-M Secure Extensions intrinsics include file.
  2. Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. Contributed by ARM Ltd.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published
  7. by the Free Software Foundation; either version 3, or (at your
  8. option) any later version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #ifndef _GCC_ARM_CMSE_H
  21. #define _GCC_ARM_CMSE_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if __ARM_FEATURE_CMSE & 1
  26. #include <stddef.h>
  27. #ifdef __ARM_BIG_ENDIAN
  28. typedef union {
  29. struct cmse_address_info {
  30. #if __ARM_FEATURE_CMSE & 2
  31. unsigned idau_region:8;
  32. unsigned idau_region_valid:1;
  33. unsigned secure:1;
  34. unsigned nonsecure_readwrite_ok:1;
  35. unsigned nonsecure_read_ok:1;
  36. #else
  37. unsigned :12;
  38. #endif
  39. unsigned readwrite_ok:1;
  40. unsigned read_ok:1;
  41. #if __ARM_FEATURE_CMSE & 2
  42. unsigned sau_region_valid:1;
  43. #else
  44. unsigned :1;
  45. #endif
  46. unsigned mpu_region_valid:1;
  47. #if __ARM_FEATURE_CMSE & 2
  48. unsigned sau_region:8;
  49. #else
  50. unsigned :8;
  51. #endif
  52. unsigned mpu_region:8;
  53. } flags;
  54. unsigned value;
  55. } cmse_address_info_t;
  56. #else
  57. typedef union {
  58. struct cmse_address_info {
  59. unsigned mpu_region:8;
  60. #if __ARM_FEATURE_CMSE & 2
  61. unsigned sau_region:8;
  62. #else
  63. unsigned :8;
  64. #endif
  65. unsigned mpu_region_valid:1;
  66. #if __ARM_FEATURE_CMSE & 2
  67. unsigned sau_region_valid:1;
  68. #else
  69. unsigned :1;
  70. #endif
  71. unsigned read_ok:1;
  72. unsigned readwrite_ok:1;
  73. #if __ARM_FEATURE_CMSE & 2
  74. unsigned nonsecure_read_ok:1;
  75. unsigned nonsecure_readwrite_ok:1;
  76. unsigned secure:1;
  77. unsigned idau_region_valid:1;
  78. unsigned idau_region:8;
  79. #else
  80. unsigned :12;
  81. #endif
  82. } flags;
  83. unsigned value;
  84. } cmse_address_info_t;
  85. #endif /* __ARM_BIG_ENDIAN */
  86. #define cmse_TT_fptr(p) (__cmse_TT_fptr ((__cmse_fptr)(p)))
  87. typedef void (*__cmse_fptr)(void);
  88. #define __CMSE_TT_ASM(flags) \
  89. { \
  90. cmse_address_info_t __result; \
  91. __asm__ ("tt" # flags " %0,%1" \
  92. : "=r"(__result) \
  93. : "r"(__p) \
  94. : "memory"); \
  95. return __result; \
  96. }
  97. __extension__ static __inline __attribute__ ((__always_inline__))
  98. cmse_address_info_t
  99. __cmse_TT_fptr (__cmse_fptr __p)
  100. __CMSE_TT_ASM ()
  101. __extension__ static __inline __attribute__ ((__always_inline__))
  102. cmse_address_info_t
  103. cmse_TT (void *__p)
  104. __CMSE_TT_ASM ()
  105. #define cmse_TTT_fptr(p) (__cmse_TTT_fptr ((__cmse_fptr)(p)))
  106. __extension__ static __inline __attribute__ ((__always_inline__))
  107. cmse_address_info_t
  108. __cmse_TTT_fptr (__cmse_fptr __p)
  109. __CMSE_TT_ASM (t)
  110. __extension__ static __inline __attribute__ ((__always_inline__))
  111. cmse_address_info_t
  112. cmse_TTT (void *__p)
  113. __CMSE_TT_ASM (t)
  114. #if __ARM_FEATURE_CMSE & 2
  115. #define cmse_TTA_fptr(p) (__cmse_TTA_fptr ((__cmse_fptr)(p)))
  116. __extension__ static __inline __attribute__ ((__always_inline__))
  117. cmse_address_info_t
  118. __cmse_TTA_fptr (__cmse_fptr __p)
  119. __CMSE_TT_ASM (a)
  120. __extension__ static __inline __attribute__ ((__always_inline__))
  121. cmse_address_info_t
  122. cmse_TTA (void *__p)
  123. __CMSE_TT_ASM (a)
  124. #define cmse_TTAT_fptr(p) (__cmse_TTAT_fptr ((__cmse_fptr)(p)))
  125. __extension__ static __inline cmse_address_info_t
  126. __attribute__ ((__always_inline__))
  127. __cmse_TTAT_fptr (__cmse_fptr __p)
  128. __CMSE_TT_ASM (at)
  129. __extension__ static __inline cmse_address_info_t
  130. __attribute__ ((__always_inline__))
  131. cmse_TTAT (void *__p)
  132. __CMSE_TT_ASM (at)
  133. /* FIXME: diagnose use outside cmse_nonsecure_entry functions. */
  134. __extension__ static __inline int __attribute__ ((__always_inline__))
  135. __attribute__ ((warn_unused_result))
  136. cmse_nonsecure_caller (void)
  137. {
  138. return __builtin_arm_cmse_nonsecure_caller ();
  139. }
  140. #define CMSE_AU_NONSECURE 2
  141. #define CMSE_MPU_NONSECURE 16
  142. #define CMSE_NONSECURE 18
  143. #define cmse_nsfptr_create(p) ((__typeof__ ((p))) ((__INTPTR_TYPE__) (p) & ~1))
  144. #define cmse_is_nsfptr(p) (!((__INTPTR_TYPE__) (p) & 1))
  145. #endif /* __ARM_FEATURE_CMSE & 2 */
  146. #define CMSE_MPU_UNPRIV 4
  147. #define CMSE_MPU_READWRITE 1
  148. #define CMSE_MPU_READ 8
  149. __extension__ void *
  150. __attribute__ ((warn_unused_result))
  151. cmse_check_address_range (void *, size_t, int);
  152. #define cmse_check_pointed_object(p, f) \
  153. ((__typeof__ ((p))) cmse_check_address_range ((p), sizeof (*(p)), (f)))
  154. #endif /* __ARM_FEATURE_CMSE & 1 */
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif /* _GCC_ARM_CMSE_H */