2022-07-21 07:39:21 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-10-07 23:19:23 -04:00
|
|
|
|
2023-10-27 06:10:47 -04:00
|
|
|
#include "xtensa_context.h"
|
2020-10-07 23:19:23 -04:00
|
|
|
#include "esp_private/panic_internal.h"
|
|
|
|
|
|
|
|
extern void esp_panic_handler(panic_info_t *info);
|
|
|
|
extern volatile bool g_override_illegal_instruction;
|
|
|
|
|
|
|
|
void __real_esp_panic_handler(panic_info_t *info);
|
2022-07-21 07:39:21 -04:00
|
|
|
void __real_esp_cpu_stall(int core_id);
|
2020-10-07 23:19:23 -04:00
|
|
|
|
|
|
|
/* Memprot test specific IllegalInstruction exception handler:
|
|
|
|
* when testing the protection against a code execution, sample code
|
|
|
|
* is being injected into various memory regions which produces
|
|
|
|
* EXCCAUSE_ILLEGAL on execution attempt. Such a result is expected
|
|
|
|
* but it causes system reboot in the standard panic handler.
|
|
|
|
* The following variant of panic handling simply returns back to the
|
|
|
|
* next instruction and continues normal execution.
|
|
|
|
*
|
|
|
|
* NOTE: if EXCCAUSE_ILLEGAL comes from a different source than the testing code
|
|
|
|
* the behavior is undefined
|
|
|
|
* */
|
|
|
|
void __wrap_esp_panic_handler(panic_info_t *info)
|
|
|
|
{
|
|
|
|
XtExcFrame *frm = (XtExcFrame *)info->frame;
|
2022-07-21 07:41:54 -04:00
|
|
|
if (frm->exccause == EXCCAUSE_ILLEGAL && g_override_illegal_instruction == true) {
|
2020-10-07 23:19:23 -04:00
|
|
|
frm->pc = frm->a0;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
__real_esp_panic_handler(info);
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 07:39:21 -04:00
|
|
|
|
|
|
|
void __wrap_esp_cpu_stall(int core_id)
|
|
|
|
{
|
2022-07-21 07:41:54 -04:00
|
|
|
if (g_override_illegal_instruction == true) {
|
2022-07-21 07:39:21 -04:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
__real_esp_cpu_stall(core_id);
|
|
|
|
}
|
|
|
|
}
|