Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

armv8-m: make the securefault handled by non-securefult #5845

Merged
merged 2 commits into from Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions arch/arm/src/armv8-m/arm_securefault.c
Expand Up @@ -41,6 +41,38 @@

#ifdef CONFIG_DEBUG_SECUREFAULT
# define sfalert(format, ...) _alert(format, ##__VA_ARGS__)

# define OFFSET_R0 (0 * 4) /* R0 */
# define OFFSET_R1 (1 * 4) /* R1 */
# define OFFSET_R2 (2 * 4) /* R2 */
# define OFFSET_R3 (3 * 4) /* R3 */
# define OFFSET_R12 (4 * 4) /* R12 */
# define OFFSET_R14 (5 * 4) /* R14 = LR */
# define OFFSET_R15 (6 * 4) /* R15 = PC */
# define OFFSET_XPSR (7 * 4) /* xPSR */

/****************************************************************************
* Private Functions
****************************************************************************/

static void generate_nonsecure_busfault(void)
{
uint32_t nsp;

/* Get non-secure SP */

__asm__ __volatile__ ("mrs %0, msp_ns" : "=r" (nsp));

sfalert("Non-sec sp %08" PRIx32 "\n", nsp);
syslog_flush();

/* Force set return ReturnAddress to 0, then non-secure cpu will crash.
* Also, the ReturnAddress is very important, so move it to R12.
*/

putreg32(getreg32(nsp + OFFSET_R15), nsp + OFFSET_R12);
putreg32(0, nsp + OFFSET_R15);
}
#else
# define sfalert(...)
#endif
Expand All @@ -49,6 +81,19 @@
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: arm_securefault_should_generate
*
* Description:
* Check whether should generate non-secure IRQ from securefault
*
****************************************************************************/

bool weak_function arm_should_generate_nonsecure_busfault(void)
{
return true;
}

/****************************************************************************
* Name: arm_securefault
*
Expand Down Expand Up @@ -112,7 +157,16 @@ int arm_securefault(int irq, FAR void *context, FAR void *arg)

putreg32(0xff, SAU_SFSR);

#ifdef CONFIG_DEBUG_SECUREFAULT
if (arm_should_generate_nonsecure_busfault())
{
generate_nonsecure_busfault();
return OK;
}
#endif

up_irq_save();
PANIC();

return OK;
}