From 2dacec156a8cf1f39c56bfb056e493f36aba50cf Mon Sep 17 00:00:00 2001 From: Philip Gladstone Date: Thu, 26 May 2016 22:14:02 -0400 Subject: [PATCH] Ensure that load_store exceptions trigger the exception handler (#1307) Chain unhandled load_store exceptions to SDK exception handler --- app/user/user_exceptions.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/user/user_exceptions.c b/app/user/user_exceptions.c index 74cb9097..d95c84d8 100644 --- a/app/user/user_exceptions.c +++ b/app/user/user_exceptions.c @@ -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; }