16#ifndef ZEPHYR_INCLUDE_ARCH_ARC_ARCH_H_
17#define ZEPHYR_INCLUDE_ARCH_ARC_ARCH_H_
35#ifdef CONFIG_ARC_CONNECT
39#ifdef CONFIG_ISA_ARCV2
41#ifdef CONFIG_ARC_HAS_SECURE
46#if defined(CONFIG_ARC_FIRQ) && defined(CONFIG_ISA_ARCV3)
47#error "Unsupported configuration: ARC_FIRQ and ISA_ARCV3"
55#if defined(CONFIG_ARC_FIRQ) && CONFIG_NUM_IRQ_PRIO_LEVELS < 2
56#error "Unsupported configuration: ARC_FIRQ and (NUM_IRQ_PRIO_LEVELS < 2)"
59#if CONFIG_RGF_NUM_BANKS > 1 && !defined(CONFIG_ARC_FIRQ)
60#error "Unsupported configuration: (RGF_NUM_BANKS > 1) and !ARC_FIRQ"
68#if CONFIG_RGF_NUM_BANKS > 1 && CONFIG_NUM_IRQ_PRIO_LEVELS < 2
69#error "Unsupported configuration: (RGF_NUM_BANKS > 1) and (NUM_IRQ_PRIO_LEVELS < 2)"
72#if defined(CONFIG_ARC_FIRQ_STACK) && !defined(CONFIG_ARC_FIRQ)
73#error "Unsupported configuration: ARC_FIRQ_STACK and !ARC_FIRQ"
76#if defined(CONFIG_ARC_FIRQ_STACK) && CONFIG_RGF_NUM_BANKS < 2
77#error "Unsupported configuration: ARC_FIRQ_STACK and (RGF_NUM_BANKS < 2)"
81#if defined(CONFIG_ARC_FIRQ) && defined(CONFIG_ARC_HAS_SECURE)
82#error "Unsupported configuration: ARC_FIRQ and ARC_HAS_SECURE"
85#if defined(CONFIG_SMP) && !defined(CONFIG_MULTITHREADING)
86#error "Non-multithreading mode isn't supported on SMP targets"
96#define ARCH_STACK_PTR_ALIGN 8
98#define ARCH_STACK_PTR_ALIGN 4
102 "CONFIG_ISR_STACK_SIZE must be a multiple of ARCH_STACK_PTR_ALIGN");
105 "CONFIG_ARC_EXCEPTION_STACK_SIZE must be a multiple of ARCH_STACK_PTR_ALIGN");
115#ifdef CONFIG_ARC_CORE_MPU
116#if CONFIG_ARC_MPU_VER == 2
117#define Z_ARC_MPU_ALIGN 2048
118#elif (CONFIG_ARC_MPU_VER == 3) || (CONFIG_ARC_MPU_VER == 4) || (CONFIG_ARC_MPU_VER == 6)
119#define Z_ARC_MPU_ALIGN 32
121#error "Unsupported MPU version"
125#ifdef CONFIG_MPU_STACK_GUARD
126#define Z_ARC_STACK_GUARD_SIZE Z_ARC_MPU_ALIGN
128#define Z_ARC_STACK_GUARD_SIZE 0
143#ifdef CONFIG_MPU_STACK_GUARD
144#define ARCH_KERNEL_STACK_RESERVED Z_ARC_STACK_GUARD_SIZE
145#define ARCH_KERNEL_STACK_OBJ_ALIGN Z_ARC_MPU_ALIGN
148#ifdef CONFIG_USERSPACE
156#ifdef CONFIG_MPU_STACK_GUARD
173#define ARCH_THREAD_STACK_RESERVED (Z_ARC_STACK_GUARD_SIZE + \
174 CONFIG_PRIVILEGED_STACK_SIZE)
175#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_ARC_MPU_ALIGN
179#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
180 (ROUND_UP((size), Z_ARC_MPU_ALIGN))
181BUILD_ASSERT(CONFIG_PRIVILEGED_STACK_SIZE % Z_ARC_MPU_ALIGN == 0,
182 "improper privilege stack size");
185#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
201#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
202 Z_POW2_CEIL(ROUND_UP((size), Z_ARC_MPU_ALIGN))
203#define ARCH_THREAD_STACK_OBJ_ALIGN(size) \
204 ARCH_THREAD_STACK_SIZE_ADJUST(size)
205#define ARCH_THREAD_STACK_RESERVED 0
219#define ARCH_THREAD_STACK_RESERVED CONFIG_PRIVILEGED_STACK_SIZE
220#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
221 (ROUND_UP((size), Z_ARC_MPU_ALIGN))
222#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_ARC_MPU_ALIGN
224BUILD_ASSERT(CONFIG_PRIVILEGED_STACK_SIZE % Z_ARC_MPU_ALIGN == 0,
225 "improper privilege stack size");
231#ifdef CONFIG_MPU_STACK_GUARD
246#define ARCH_THREAD_STACK_RESERVED Z_ARC_STACK_GUARD_SIZE
247#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_ARC_MPU_ALIGN
259#define K_MEM_PARTITION_P_NA_U_NA AUX_MPU_ATTR_N
260#define K_MEM_PARTITION_P_RW_U_RW (AUX_MPU_ATTR_UW | AUX_MPU_ATTR_UR | \
261 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
262#define K_MEM_PARTITION_P_RW_U_RO (AUX_MPU_ATTR_UR | \
263 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
264#define K_MEM_PARTITION_P_RW_U_NA (AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
265#define K_MEM_PARTITION_P_RO_U_RO (AUX_MPU_ATTR_UR | AUX_MPU_ATTR_KR)
266#define K_MEM_PARTITION_P_RO_U_NA (AUX_MPU_ATTR_KR)
269#define K_MEM_PARTITION_P_RWX_U_RWX (AUX_MPU_ATTR_UW | AUX_MPU_ATTR_UR | \
270 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR | \
271 AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE)
272#define K_MEM_PARTITION_P_RWX_U_RX (AUX_MPU_ATTR_UR | \
273 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR | \
274 AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE)
275#define K_MEM_PARTITION_P_RX_U_RX (AUX_MPU_ATTR_UR | \
277 AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE)
279#define K_MEM_PARTITION_IS_WRITABLE(attr) \
281 int __is_writable__; \
282 switch (attr & (AUX_MPU_ATTR_UW | AUX_MPU_ATTR_KW)) { \
283 case (AUX_MPU_ATTR_UW | AUX_MPU_ATTR_KW): \
284 case AUX_MPU_ATTR_UW: \
285 case AUX_MPU_ATTR_KW: \
286 __is_writable__ = 1; \
289 __is_writable__ = 0; \
294#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
295 ((attr) & (AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE))
304#define IS_BUILTIN_MWDT(val) __builtin_constant_p((uintptr_t)(val))
305#if CONFIG_ARC_MPU_VER == 2 || CONFIG_ARC_MPU_VER == 3 || CONFIG_ARC_MPU_VER == 6
306#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
307 BUILD_ASSERT(IS_BUILTIN_MWDT(size) ? !((size) & ((size) - 1)) : 1, \
308 "partition size must be power of 2"); \
309 BUILD_ASSERT(IS_BUILTIN_MWDT(size) ? (size) >= Z_ARC_MPU_ALIGN : 1, \
310 "partition size must be >= mpu address alignment."); \
311 BUILD_ASSERT(IS_BUILTIN_MWDT(size) ? IS_BUILTIN_MWDT(start) ? \
312 !((uintptr_t)(start) & ((size) - 1)) : 1 : 1, \
313 "partition start address must align with size.")
314#elif CONFIG_ARC_MPU_VER == 4
315#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
316 BUILD_ASSERT(IS_BUILTIN_MWDT(size) ? (size) % Z_ARC_MPU_ALIGN == 0 : 1, \
317 "partition size must align with " STRINGIFY(Z_ARC_MPU_ALIGN)); \
318 BUILD_ASSERT(IS_BUILTIN_MWDT(size) ? (size) >= Z_ARC_MPU_ALIGN : 1, \
319 "partition size must be >= " STRINGIFY(Z_ARC_MPU_ALIGN)); \
320 BUILD_ASSERT(IS_BUILTIN_MWDT(start) ? (uintptr_t)(start) % Z_ARC_MPU_ALIGN == 0 : 1, \
321 "partition start address must align with " STRINGIFY(Z_ARC_MPU_ALIGN))
324#if CONFIG_ARC_MPU_VER == 2 || CONFIG_ARC_MPU_VER == 3 || CONFIG_ARC_MPU_VER == 6
325#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
326 BUILD_ASSERT(!((size) & ((size) - 1)), \
327 "partition size must be power of 2"); \
328 BUILD_ASSERT((size) >= Z_ARC_MPU_ALIGN, \
329 "partition size must be >= mpu address alignment."); \
330 BUILD_ASSERT(!((uintptr_t)(start) & ((size) - 1)), \
331 "partition start address must align with size.")
332#elif CONFIG_ARC_MPU_VER == 4
333#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
334 BUILD_ASSERT((size) % Z_ARC_MPU_ALIGN == 0, \
335 "partition size must align with " STRINGIFY(Z_ARC_MPU_ALIGN)); \
336 BUILD_ASSERT((size) >= Z_ARC_MPU_ALIGN, \
337 "partition size must be >= " STRINGIFY(Z_ARC_MPU_ALIGN)); \
338 BUILD_ASSERT((uintptr_t)(start) % Z_ARC_MPU_ALIGN == 0, \
339 "partition start address must align with " STRINGIFY(Z_ARC_MPU_ALIGN))
353extern char __arc_rw_sram_size[];
static ALWAYS_INLINE void arch_nop(void)
Definition: arch.h:347
uint32_t k_mem_partition_attr_t
Definition: arch.h:225
#define ARCH_STACK_PTR_ALIGN
Definition: arch.h:98
ARCv2 public error handling.
ARCv2 public exception handling.
ARCv2 public kernel miscellaneous.
ARCv2 ARC Connect driver.
Per-arch thread definition.
ARCv2 public interrupt handling.
ARCv2 auxiliary registers definitions.
#define ALWAYS_INLINE
Definition: common.h:124
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Software-managed ISR table.