diff --git a/arch/arm/core/aarch32/cortex_m/Kconfig b/arch/arm/core/aarch32/cortex_m/Kconfig index 69ef8ee2b0..2a52d924a9 100644 --- a/arch/arm/core/aarch32/cortex_m/Kconfig +++ b/arch/arm/core/aarch32/cortex_m/Kconfig @@ -305,6 +305,95 @@ config TEST_EXTRA_STACKSIZE endmenu +# Implement the null pointer detection using either the Data Watchpoint and +# Trace Unit and the Debug Monitor Exception, or the Memory Protection Unit. + +choice CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION + bool "Enable and use null-pointer exception" + help + There are 2 implementations available, one based + on DWT and the other based on MPU. Use this choice + symbol to select one of the options. By default the + feature is disabled. In the test suite the feature + is enabled and the DWT-based solution is preferred. + +config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_NONE + bool "Do not enable null pointer exception detection" + help + Null pointer exception detection feature is not + enabled. + +config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_DWT + bool "Use DWT for null pointer exception detection" + depends on CPU_CORTEX_M_HAS_DWT + depends on !TRUSTED_EXECUTION_NONSECURE + select CORTEX_M_DWT + select CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + help + Null pointer dereference detection implemented + using the DWT unit functionality. + Notes: + - Not enabled for Non-Secure FW images, where + null-pointer dereferencing is likely caught as + a SecureFault. + - Requires DWT functionality in the Cortex-M SoC + implementation (1 comparator for ARMv7-M, 2 comparators + for ARMv8-M). + +config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_DETECTION_MPU + bool "Use MPU for null pointer exception detection" + depends on !TRUSTED_EXECUTION_NONSECURE + depends on ARM_MPU + select CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + help + Null pointer dereference detection implemented + using MPU functionality. + Notes: + - Mutually exclusive to the DWT-based solution + - Not enabled for Non-Secure FW images, where + null-pointer dereferencing is likely caught as + a SecureFault. + - Requires MPU functionality to be present and + enabled. The implementation consumes 1 MPU region. + - In ARMv8-M, explicit null-pointer dereference + detection with MPU requires, additionally, that + the area: [0x0, + CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE) + is not unmapped (covered by an MPU region already). + If it is unmapped null-pointer dereferencing may + still be idirectly detected (e.g. via a precise + Bus access fault), but this is not guaranteed. A + build-time message warns the user of this scenario. + +endchoice + +config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + bool + help + Enable and use the null pointer exception option. + This is a debug feature in Cortex-M, allowing for + detecting null pointer dereferencing (raising a + CPU fault). Supporting the feature results in an + increased code footprint, determined by option + CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE. + + Note: this hidden option is selected by the choice + symbols corresponding to the DWT-based or to the + MPU-based solution. + +if CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + +config CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE + hex "Size of paged unmapped to implement null pointer detection" + default 0x400 + help + Size of the page reserved for detecting null pointer + dereferencing. Must be a power of two. A large value + offers enhanced detection performance to the cost of + wasting a large flash area that code may not use. + +endif # CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION + rsource "mpu/Kconfig" rsource "tz/Kconfig"