Zephyr Project API  3.3.0
A Scalable Open Source RTOS
arch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2014 Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
16#ifndef ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ARCH_H_
17#define ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ARCH_H_
18
19/* Add include for DTS generated information */
20#include <zephyr/devicetree.h>
21
22/* ARM GPRs are often designated by two different names */
23#define sys_define_gpr_with_alias(name1, name2) union { uint32_t name1, name2; }
24
35
36#ifdef CONFIG_CPU_CORTEX_M
40#elif defined(CONFIG_CPU_AARCH32_CORTEX_R) || defined(CONFIG_CPU_AARCH32_CORTEX_A)
43#if defined(CONFIG_AARCH32_ARMV8_R)
46#else
48#endif
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#ifndef _ASMLANGUAGE
56
57#include <zephyr/fatal_types.h>
58
60 /* Cortex-M MEMFAULT exceptions */
67
68 /* Cortex-M BUSFAULT exceptions */
76
77 /* Cortex-M USAGEFAULT exceptions */
86
87 /* Cortex-M SECURE exceptions */
96
97 /* Cortex-A/R exceptions*/
108
109#endif /* _ASMLANGUAGE */
110
118#ifdef CONFIG_STACK_ALIGN_DOUBLE_WORD
119#define ARCH_STACK_PTR_ALIGN 8
120#else
121#define ARCH_STACK_PTR_ALIGN 4
122#endif
123
133#if defined(CONFIG_USERSPACE)
134#define Z_THREAD_MIN_STACK_ALIGN CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
135#elif defined(CONFIG_ARM_AARCH32_MMU)
136#define Z_THREAD_MIN_STACK_ALIGN CONFIG_ARM_MMU_REGION_MIN_ALIGN_AND_SIZE
137#else
138#define Z_THREAD_MIN_STACK_ALIGN ARCH_STACK_PTR_ALIGN
139#endif
140
188#if defined(CONFIG_MPU_STACK_GUARD)
189/* make sure there's more than enough space for an exception frame */
190#if CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE <= 0x20
191#define MPU_GUARD_ALIGN_AND_SIZE 0x40
192#else
193#define MPU_GUARD_ALIGN_AND_SIZE CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
194#endif
195#else
196#define MPU_GUARD_ALIGN_AND_SIZE 0
197#endif
198
209#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING) \
210 && defined(CONFIG_MPU_STACK_GUARD)
211#if CONFIG_MPU_STACK_GUARD_MIN_SIZE_FLOAT <= 0x20
212#define MPU_GUARD_ALIGN_AND_SIZE_FLOAT 0x40
213#else
214#define MPU_GUARD_ALIGN_AND_SIZE_FLOAT CONFIG_MPU_STACK_GUARD_MIN_SIZE_FLOAT
215#endif
216#else
217#define MPU_GUARD_ALIGN_AND_SIZE_FLOAT 0
218#endif
219
227#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
228#define Z_MPU_GUARD_ALIGN (MAX(MPU_GUARD_ALIGN_AND_SIZE, \
229 MPU_GUARD_ALIGN_AND_SIZE_FLOAT))
230#else
231#define Z_MPU_GUARD_ALIGN MPU_GUARD_ALIGN_AND_SIZE
232#endif
233
234#if defined(CONFIG_USERSPACE) && \
235 defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
236/* This MPU requires regions to be sized to a power of two, and aligned to
237 * their own size. Since an MPU region must be able to cover the entire
238 * user-accessible stack buffer, we size/align to match. The privilege
239 * mode stack is generated elsewhere in memory.
240 */
241#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_POW2_CEIL(size)
242#define ARCH_THREAD_STACK_SIZE_ADJUST(size) Z_POW2_CEIL(size)
243#else
244#define ARCH_THREAD_STACK_OBJ_ALIGN(size) MAX(Z_THREAD_MIN_STACK_ALIGN, \
245 Z_MPU_GUARD_ALIGN)
246#ifdef CONFIG_USERSPACE
247#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
248 ROUND_UP(size, CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE)
249#endif
250#endif
251
252#ifdef CONFIG_MPU_STACK_GUARD
253/* Kernel-only stacks need an MPU guard region programmed at the beginning of
254 * the stack object, so align the object appropriately.
255 */
256#define ARCH_KERNEL_STACK_RESERVED MPU_GUARD_ALIGN_AND_SIZE
257#define ARCH_KERNEL_STACK_OBJ_ALIGN Z_MPU_GUARD_ALIGN
258#endif
259
260/* On arm, all MPU guards are carve-outs. */
261#define ARCH_THREAD_STACK_RESERVED 0
262
263/* Legacy case: retain containing extern "C" with C++ */
264#ifdef CONFIG_ARM_MPU
265#ifdef CONFIG_CPU_HAS_ARM_MPU
267#endif /* CONFIG_CPU_HAS_ARM_MPU */
268#ifdef CONFIG_CPU_HAS_NXP_MPU
270#endif /* CONFIG_CPU_HAS_NXP_MPU */
271#endif /* CONFIG_ARM_MPU */
272#ifdef CONFIG_ARM_AARCH32_MMU
274#endif /* CONFIG_ARM_AARCH32_MMU */
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ARCH_H_ */
ARM AArch32 public interrupt handling.
Per-arch thread definition.
k_fatal_error_reason_arch
Definition: arch.h:59
@ K_ERR_ARM_BUS_FP_LAZY_STATE_PRESERVATION
Definition: arch.h:75
@ K_ERR_ARM_MEM_UNSTACKING
Definition: arch.h:63
@ K_ERR_ARM_BACKGROUND_FAULT
Definition: arch.h:100
@ K_ERR_ARM_SYNC_EXTERNAL_ABORT
Definition: arch.h:102
@ K_ERR_ARM_SECURE_LAZY_STATE_PRESERVATION
Definition: arch.h:94
@ K_ERR_ARM_SECURE_GENERIC
Definition: arch.h:88
@ K_ERR_ARM_MEM_STACKING
Definition: arch.h:62
@ K_ERR_ARM_SYNC_PARITY_ERROR
Definition: arch.h:104
@ K_ERR_ARM_SECURE_ENTRY_POINT
Definition: arch.h:89
@ K_ERR_ARM_USAGE_ILLEGAL_EXC_RETURN
Definition: arch.h:83
@ K_ERR_ARM_USAGE_NO_COPROCESSOR
Definition: arch.h:82
@ K_ERR_ARM_SECURE_INTEGRITY_SIGNATURE
Definition: arch.h:90
@ K_ERR_ARM_ASYNC_EXTERNAL_ABORT
Definition: arch.h:103
@ K_ERR_ARM_MEM_FP_LAZY_STATE_PRESERVATION
Definition: arch.h:66
@ K_ERR_ARM_ALIGNMENT_FAULT
Definition: arch.h:99
@ K_ERR_ARM_USAGE_UNALIGNED_ACCESS
Definition: arch.h:80
@ K_ERR_ARM_USAGE_ILLEGAL_EPSR
Definition: arch.h:84
@ K_ERR_ARM_MEM_INSTRUCTION_ACCESS
Definition: arch.h:65
@ K_ERR_ARM_SECURE_EXCEPTION_RETURN
Definition: arch.h:91
@ K_ERR_ARM_BUS_UNSTACKING
Definition: arch.h:71
@ K_ERR_ARM_MEM_GENERIC
Definition: arch.h:61
@ K_ERR_ARM_BUS_STACKING
Definition: arch.h:70
@ K_ERR_ARM_USAGE_DIV_0
Definition: arch.h:79
@ K_ERR_ARM_BUS_GENERIC
Definition: arch.h:69
@ K_ERR_ARM_BUS_IMPRECISE_DATA_BUS
Definition: arch.h:73
@ K_ERR_ARM_BUS_INSTRUCTION_BUS
Definition: arch.h:74
@ K_ERR_ARM_UNDEFINED_INSTRUCTION
Definition: arch.h:98
@ K_ERR_ARM_USAGE_UNDEFINED_INSTRUCTION
Definition: arch.h:85
@ K_ERR_ARM_ASYNC_PARITY_ERROR
Definition: arch.h:105
@ K_ERR_ARM_DEBUG_EVENT
Definition: arch.h:106
@ K_ERR_ARM_SECURE_ATTRIBUTION_UNIT
Definition: arch.h:92
@ K_ERR_ARM_SECURE_TRANSITION
Definition: arch.h:93
@ K_ERR_ARM_SECURE_LAZY_STATE_ERROR
Definition: arch.h:95
@ K_ERR_ARM_USAGE_STACK_OVERFLOW
Definition: arch.h:81
@ K_ERR_ARM_BUS_PRECISE_DATA_BUS
Definition: arch.h:72
@ K_ERR_ARM_MEM_DATA_ACCESS
Definition: arch.h:64
@ K_ERR_ARM_PERMISSION_FAULT
Definition: arch.h:101
@ K_ERR_ARM_USAGE_GENERIC
Definition: arch.h:78
ARM AArch32 public error handling.
ARM AArch32 public exception handling.
ARM AArch32 public kernel miscellaneous.
Devicetree main header.
Fatal base type definitions.
@ K_ERR_ARCH_START
Definition: fatal_types.h:41
ARM CORTEX-M memory map.
ARM AArch32 NMI routines.