12 #if (__ARM_FEATURE_CMSE & 0x1)
16 #define __ARM_CMSE_SECURE_MODE (__ARM_FEATURE_CMSE & 0x2)
17 #define CMSE_MPU_READWRITE 1
18 #define CMSE_AU_NONSECURE 2
19 #define CMSE_MPU_UNPRIV 4
20 #define CMSE_MPU_READ 8
21 #define CMSE_MPU_NONSECURE 16
22 #define CMSE_NONSECURE (CMSE_AU_NONSECURE | CMSE_MPU_NONSECURE)
24 #define cmse_check_pointed_object(p, f) \
25 cmse_check_address_range((p), sizeof(*(p)), (f))
27 #if defined(__cplusplus)
32 struct cmse_address_info {
33 #ifdef __ARM_BIG_ENDIAN
35 #if (__ARM_CMSE_SECURE_MODE)
36 unsigned idau_region : 8;
37 unsigned idau_region_valid : 1;
39 unsigned nonsecure_readwrite_ok : 1;
40 unsigned nonsecure_read_ok : 1;
44 unsigned readwrite_ok : 1;
46 #if (__ARM_CMSE_SECURE_MODE)
47 unsigned sau_region_valid : 1;
51 unsigned mpu_region_valid : 1;
52 #if (__ARM_CMSE_SECURE_MODE)
53 unsigned sau_region : 8;
57 unsigned mpu_region : 8;
60 unsigned mpu_region : 8;
61 #if (__ARM_CMSE_SECURE_MODE)
62 unsigned sau_region : 8;
66 unsigned mpu_region_valid : 1;
67 #if (__ARM_CMSE_SECURE_MODE)
68 unsigned sau_region_valid : 1;
73 unsigned readwrite_ok : 1;
74 #if (__ARM_CMSE_SECURE_MODE)
75 unsigned nonsecure_read_ok : 1;
76 unsigned nonsecure_readwrite_ok : 1;
78 unsigned idau_region_valid : 1;
79 unsigned idau_region : 8;
86 } cmse_address_info_t;
88 static cmse_address_info_t
__attribute__((__always_inline__, __nodebug__))
90 cmse_address_info_t __u;
91 __u.value = __builtin_arm_cmse_TT(
__p);
94 static cmse_address_info_t
__attribute__((__always_inline__, __nodebug__))
96 cmse_address_info_t __u;
97 __u.value = __builtin_arm_cmse_TTT(
__p);
101 #if __ARM_CMSE_SECURE_MODE
102 static cmse_address_info_t
__attribute__((__always_inline__, __nodebug__))
103 cmse_TTA(
void *
__p) {
104 cmse_address_info_t __u;
105 __u.value = __builtin_arm_cmse_TTA(
__p);
108 static cmse_address_info_t
__attribute__((__always_inline__, __nodebug__))
109 cmse_TTAT(
void *
__p) {
110 cmse_address_info_t __u;
111 __u.value = __builtin_arm_cmse_TTAT(
__p);
116 #define cmse_TT_fptr(p) cmse_TT(__builtin_bit_cast(void *, (p)))
117 #define cmse_TTT_fptr(p) cmse_TTT(__builtin_bit_cast(void *, (p)))
119 #if __ARM_CMSE_SECURE_MODE
120 #define cmse_TTA_fptr(p) cmse_TTA(__builtin_bit_cast(void *, (p)))
121 #define cmse_TTAT_fptr(p) cmse_TTAT(__builtin_bit_cast(void *, (p)))
125 cmse_check_address_range(
void *__pb,
size_t __s,
int __flags) {
133 const int __single_check = (__begin ^ __end) < 0x20u;
136 void *__pe = (
void *)__end;
137 cmse_address_info_t __permb, __perme;
138 switch (__flags & (CMSE_MPU_UNPRIV | CMSE_MPU_NONSECURE)) {
140 __permb = cmse_TT(__pb);
141 __perme = __single_check ? __permb : cmse_TT(__pe);
143 case CMSE_MPU_UNPRIV:
144 __permb = cmse_TTT(__pb);
145 __perme = __single_check ? __permb : cmse_TTT(__pe);
147 #if __ARM_CMSE_SECURE_MODE
148 case CMSE_MPU_NONSECURE:
149 __permb = cmse_TTA(__pb);
150 __perme = __single_check ? __permb : cmse_TTA(__pe);
152 case CMSE_MPU_UNPRIV | CMSE_MPU_NONSECURE:
153 __permb = cmse_TTAT(__pb);
154 __perme = __single_check ? __permb : cmse_TTAT(__pe);
163 if (__permb.value != __perme.value)
165 #if !(__ARM_CMSE_SECURE_MODE)
167 if (__flags & CMSE_AU_NONSECURE)
172 switch (__flags & ~(CMSE_MPU_UNPRIV | CMSE_MPU_NONSECURE)) {
173 #if (__ARM_CMSE_SECURE_MODE)
174 case CMSE_MPU_READ | CMSE_MPU_READWRITE | CMSE_AU_NONSECURE:
175 case CMSE_MPU_READWRITE | CMSE_AU_NONSECURE:
176 return __permb.flags.nonsecure_readwrite_ok ? __pb :
NULL;
178 case CMSE_MPU_READ | CMSE_AU_NONSECURE:
179 return __permb.flags.nonsecure_read_ok ? __pb :
NULL;
181 case CMSE_AU_NONSECURE:
182 return __permb.flags.secure ?
NULL : __pb;
184 case CMSE_MPU_READ | CMSE_MPU_READWRITE:
185 case CMSE_MPU_READWRITE:
186 return __permb.flags.readwrite_ok ? __pb :
NULL;
189 return __permb.flags.read_ok ? __pb :
NULL;
196 #if __ARM_CMSE_SECURE_MODE
198 cmse_nonsecure_caller(
void) {
199 return !((
uintptr_t)__builtin_return_address(0) & 1);
202 #define cmse_nsfptr_create(p) \
203 __builtin_bit_cast(__typeof__(p), \
204 (__builtin_bit_cast(uintptr_t, p) & ~(uintptr_t)1))
206 #define cmse_is_nsfptr(p) ((__builtin_bit_cast(uintptr_t, p) & 1) == 0)
211 #if defined(__cplusplus)
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
static __inline unsigned char unsigned int unsigned int unsigned int * __p
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...