Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
exception.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
11
12#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXCEPTION_H_
13#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXCEPTION_H_
14
15#include <zephyr/devicetree.h>
16
18
19/* for assembler, only works with constants */
20#define Z_EXC_PRIO(pri) (((pri) << (8 - NUM_IRQ_PRIO_BITS)) & 0xff)
21
22/*
23 * In architecture variants with non-programmable fault exceptions
24 * (e.g. Cortex-M Baseline variants), hardware ensures processor faults
25 * are given the highest interrupt priority level. SVCalls are assigned
26 * the highest configurable priority level (level 0); note, however, that
27 * this interrupt level may be shared with HW interrupts.
28 *
29 * In Cortex variants with programmable fault exception priorities we
30 * assign the highest interrupt priority level (level 0) to processor faults
31 * with configurable priority.
32 * The highest priority level may be shared with either Zero-Latency IRQs (if
33 * support for the feature is enabled) or with SVCall priority level.
34 * Regular HW IRQs are always assigned priority levels lower than the priority
35 * levels for SVCalls, Zero-Latency IRQs and processor faults.
36 *
37 * PendSV IRQ (which is used in Cortex-M variants to implement thread
38 * context-switching) is assigned the lowest IRQ priority level.
39 */
40#if defined(CONFIG_CPU_CORTEX_M_HAS_PROGRAMMABLE_FAULT_PRIOS)
41#define _EXCEPTION_RESERVED_PRIO 1
42#else
43#define _EXCEPTION_RESERVED_PRIO 0
44#endif
45
46#define _EXC_FAULT_PRIO 0
47#define _EXC_ZERO_LATENCY_IRQS_PRIO 0
48#define _EXC_SVC_PRIO COND_CODE_1(CONFIG_ZERO_LATENCY_IRQS, \
49 (CONFIG_ZERO_LATENCY_LEVELS), (0))
50#define _IRQ_PRIO_OFFSET (_EXCEPTION_RESERVED_PRIO + _EXC_SVC_PRIO)
51#define IRQ_PRIO_LOWEST (BIT(NUM_IRQ_PRIO_BITS) - (_IRQ_PRIO_OFFSET) - 1)
52
53#define _EXC_IRQ_DEFAULT_PRIO Z_EXC_PRIO(_IRQ_PRIO_OFFSET)
54
55/* Use lowest possible priority level for PendSV */
56#define _EXC_PENDSV_PRIO 0xff
57#define _EXC_PENDSV_PRIO_MASK Z_EXC_PRIO(_EXC_PENDSV_PRIO)
58
59#ifdef _ASMLANGUAGE
60#ifndef CONFIG_USE_SWITCH
61GTEXT(z_arm_exc_exit);
62#endif
63#else
64#include <zephyr/types.h>
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
72
73/* Registers s16-s31 (d8-d15, q4-q7) must be preserved across subroutine calls.
74 *
75 * Registers s0-s15 (d0-d7, q0-q3) do not have to be preserved (and can be used
76 * for passing arguments or returning results in standard procedure-call variants).
77 *
78 * Registers d16-d31 (q8-q15), do not have to be preserved.
79 */
80struct __fpu_sf {
81 uint32_t s[16]; /* s0~s15 (d0-d7) */
82#ifdef CONFIG_VFP_FEATURE_REGS_S64_D32
83 uint64_t d[16]; /* d16~d31 */
84#endif
85 uint32_t fpscr;
86 uint32_t undefined;
87};
88#endif
89
90/* Additional register state that is not stacked by hardware on exception
91 * entry.
92 *
93 * These fields are ONLY valid in the ESF copy passed into z_arm_fatal_error().
94 * When information for a member is unavailable, the field is set to zero.
95 */
96#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
97struct __extra_esf_info {
98 _callee_saved_t *callee;
99 uint32_t msp;
100 uint32_t exc_return;
101};
102#endif /* CONFIG_EXTRA_EXCEPTION_INFO */
103
104/* ARM GPRs are often designated by two different names */
105#define sys_define_gpr_with_alias(name1, name2) \
106 union { \
107 uint32_t name1, name2; \
108 }
109
110struct arch_esf {
111 struct __basic_sf {
120 } basic;
121#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
122 struct __fpu_sf fpu;
123#endif
124#if defined(CONFIG_EXTRA_EXCEPTION_INFO)
125 struct __extra_esf_info extra_info;
126#endif
127};
128
129extern uint32_t z_arm_coredump_fault_sp;
130
131#ifdef CONFIG_USE_SWITCH
132static inline void z_arm_exc_exit(void)
133{
135}
136#else
137extern void z_arm_exc_exit(void);
138#endif
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* _ASMLANGUAGE */
145
146#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXCEPTION_H_ */
Cortex-M context-switch support helpers.
static void arm_m_exc_tail(void)
ISR-tail helper that patches the stacked LR for deferred switch fixup.
Definition arm-m-switch.h:156
#define sys_define_gpr_with_alias(name1, name2)
Definition exception.h:58
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa s
Definition asm-macro-32-bit-gnu.h:17
irp nz macro MOVR cc d
Definition asm-macro-32-bit-gnu.h:11
Devicetree main header.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
uint32_t r14
Definition exception.h:73
uint32_t xpsr
Definition exception.h:75
uint32_t r3
Definition exception.h:71
uint32_t lr
Definition exception.h:73
uint32_t r2
Definition exception.h:70
uint32_t r1
Definition exception.h:69
uint32_t a2
Definition exception.h:69
uint32_t pc
Definition exception.h:74
uint32_t a3
Definition exception.h:70
uint32_t r0
Definition exception.h:68
uint32_t ip
Definition exception.h:72
uint32_t a1
Definition exception.h:68
uint32_t a4
Definition exception.h:71
uint32_t r12
Definition exception.h:72
uint32_t r15
Definition exception.h:74
Exception Stack Frame.
Definition exception.h:60
struct arch_esf::__basic_sf basic
struct __fpu_sf fpu
Definition exception.h:65