Ensure that load_store exceptions trigger the exception handler (#1307)

Chain unhandled load_store exceptions to SDK exception handler
This commit is contained in:
Philip Gladstone 2016-05-26 22:14:02 -04:00 committed by Johny Mattsson
parent 56b4a3ec33
commit 2dacec156a

View File

@ -38,6 +38,8 @@
#define L16UI_MATCH 0x001002u
#define L16SI_MATCH 0x009002u
static exception_handler_fn load_store_handler;
void load_non_32_wide_handler (struct exception_frame *ef, uint32_t cause)
{
@ -70,9 +72,13 @@ void load_non_32_wide_handler (struct exception_frame *ef, uint32_t cause)
else
{
die:
/* Turns out we couldn't fix this, trigger a system break instead
/* Turns out we couldn't fix this, so try and chain to the handler
* that was set by the SDK. If none then trigger a system break instead
* and hang if the break doesn't get handled. This is effectively
* what would happen if the default handler was installed. */
if (load_store_handler) {
load_store_handler(ef, cause);
}
asm ("break 1, 1");
while (1) {}
}
@ -102,11 +108,14 @@ die:
* of whether there's a proper handler installed for EXCCAUSE_LOAD_STORE_ERROR,
* which of course breaks everything if we allow that to go through. As such,
* we use the linker to wrap that call and stop the SDK from shooting itself in
* its proverbial foot.
* its proverbial foot. We do save the EXCCAUSE_LOAD_STORE_ERROR handler so that
* we can chain to it above.
*/
exception_handler_fn TEXT_SECTION_ATTR
__wrap__xtos_set_exception_handler (uint32_t cause, exception_handler_fn fn)
{
if (cause != EXCCAUSE_LOAD_STORE_ERROR)
__real__xtos_set_exception_handler (cause, fn);
else
load_store_handler = fn;
}