exc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2013-2014 Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief ARM AArch32 public exception handling
  9. *
  10. * ARM AArch32-specific kernel exception handling interface. Included by
  11. * arm/arch.h.
  12. */
  13. #ifndef ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_EXC_H_
  14. #define ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_EXC_H_
  15. #if defined(CONFIG_CPU_CORTEX_M)
  16. #include <devicetree.h>
  17. #include <arch/arm/aarch32/cortex_m/nvic.h>
  18. /* for assembler, only works with constants */
  19. #define Z_EXC_PRIO(pri) (((pri) << (8 - NUM_IRQ_PRIO_BITS)) & 0xff)
  20. /*
  21. * In architecture variants with non-programmable fault exceptions
  22. * (e.g. Cortex-M Baseline variants), hardware ensures processor faults
  23. * are given the highest interrupt priority level. SVCalls are assigned
  24. * the highest configurable priority level (level 0); note, however, that
  25. * this interrupt level may be shared with HW interrupts.
  26. *
  27. * In Cortex variants with programmable fault exception priorities we
  28. * assign the highest interrupt priority level (level 0) to processor faults
  29. * with configurable priority.
  30. * The highest priority level may be shared with either Zero-Latency IRQs (if
  31. * support for the feature is enabled) or with SVCall priority level.
  32. * Regular HW IRQs are always assigned priority levels lower than the priority
  33. * levels for SVCalls, Zero-Latency IRQs and processor faults.
  34. *
  35. * PendSV IRQ (which is used in Cortex-M variants to implement thread
  36. * context-switching) is assigned the lowest IRQ priority level.
  37. */
  38. #if defined(CONFIG_CPU_CORTEX_M_HAS_PROGRAMMABLE_FAULT_PRIOS)
  39. #define _EXCEPTION_RESERVED_PRIO 1
  40. #else
  41. #define _EXCEPTION_RESERVED_PRIO 0
  42. #endif
  43. #define _EXC_FAULT_PRIO 0
  44. #define _EXC_ZERO_LATENCY_IRQS_PRIO 0
  45. #define _EXC_SVC_PRIO COND_CODE_1(CONFIG_ZERO_LATENCY_IRQS, (1), (0))
  46. #define _IRQ_PRIO_OFFSET (_EXCEPTION_RESERVED_PRIO + _EXC_SVC_PRIO)
  47. #define IRQ_PRIO_LOWEST (BIT(NUM_IRQ_PRIO_BITS) - (_IRQ_PRIO_OFFSET) - 1)
  48. #define _EXC_IRQ_DEFAULT_PRIO Z_EXC_PRIO(_IRQ_PRIO_OFFSET)
  49. /* Use lowest possible priority level for PendSV */
  50. #define _EXC_PENDSV_PRIO 0xff
  51. #define _EXC_PENDSV_PRIO_MASK Z_EXC_PRIO(_EXC_PENDSV_PRIO)
  52. #endif /* CONFIG_CPU_CORTEX_M */
  53. #ifdef _ASMLANGUAGE
  54. GTEXT(z_arm_exc_exit);
  55. #else
  56. #include <zephyr/types.h>
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. /* Additional register state that is not stacked by hardware on exception
  61. * entry.
  62. *
  63. * These fields are ONLY valid in the ESF copy passed into z_arm_fatal_error().
  64. * When information for a member is unavailable, the field is set to zero.
  65. */
  66. #if defined(CONFIG_EXTRA_EXCEPTION_INFO)
  67. struct __extra_esf_info {
  68. _callee_saved_t *callee;
  69. uint32_t msp;
  70. uint32_t exc_return;
  71. };
  72. #endif /* CONFIG_EXTRA_EXCEPTION_INFO */
  73. struct __esf {
  74. struct __basic_sf {
  75. sys_define_gpr_with_alias(a1, r0);
  76. sys_define_gpr_with_alias(a2, r1);
  77. sys_define_gpr_with_alias(a3, r2);
  78. sys_define_gpr_with_alias(a4, r3);
  79. sys_define_gpr_with_alias(ip, r12);
  80. sys_define_gpr_with_alias(lr, r14);
  81. sys_define_gpr_with_alias(pc, r15);
  82. uint32_t xpsr;
  83. } basic;
  84. #if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
  85. float s[16];
  86. uint32_t fpscr;
  87. uint32_t undefined;
  88. #endif
  89. #if defined(CONFIG_EXTRA_EXCEPTION_INFO)
  90. struct __extra_esf_info extra_info;
  91. #endif
  92. };
  93. extern uint32_t z_arm_coredump_fault_sp;
  94. typedef struct __esf z_arch_esf_t;
  95. #ifdef CONFIG_CPU_CORTEX_M
  96. extern void z_arm_exc_exit(void);
  97. #else
  98. extern void z_arm_exc_exit(bool fatal);
  99. #endif
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* _ASMLANGUAGE */
  104. #endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_EXC_H_ */