diff --git a/arch/nios2/core/fatal.c b/arch/nios2/core/fatal.c index 951c9492203..99a21caf00d 100644 --- a/arch/nios2/core/fatal.c +++ b/arch/nios2/core/fatal.c @@ -17,18 +17,77 @@ #include #include #include +#include +/* TODO initialize with sentinel values */ const NANO_ESF _default_esf; + +/** + * + * @brief Nanokernel fatal error handler + * + * This routine is called when a fatal error condition is detected by either + * hardware or software. + * + * The caller is expected to always provide a usable ESF. In the event that the + * fatal error does not have a hardware generated ESF, the caller should either + * create its own or call _Fault instead. + * + * @param reason the reason that the handler was called + * @param pEsf pointer to the exception stack frame + * + * @return This function does not return. + */ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *esf) { - ARG_UNUSED(reason); - ARG_UNUSED(esf); + /* STUB TODO: dump out reason for the error and any interesting + * info in esf + */ + + _SysFatalErrorHandler(reason, esf); +} + + + +FUNC_NORETURN void _Fault(void) +{ + /* STUB TODO dump out reason for this exception */ + + _NanoFatalErrorHandler(_NANO_ERR_HW_EXCEPTION, &_default_esf); +} + +/** + * + * @brief Fatal error handler + * + * This routine implements the corrective action to be taken when the system + * detects a fatal error. + * + * This sample implementation attempts to abort the current thread and allow + * the system to continue executing, which may permit the system to continue + * functioning with degraded capabilities. + * + * System designers may wish to enhance or substitute this sample + * implementation to take other actions, such as logging error (or debug) + * information to a persistent repository and/or rebooting the system. + * + * @param reason the fatal error reason + * @param pEsf the pointer to the exception stack frame + * + * @return This function does not return. + */ +FUNC_NORETURN void _SysFatalErrorHandler(unsigned int reason, + const NANO_ESF *esf) +{ + /* STUB TODO try to abort task/fibers like in the x86 implementation */ + printk("Fatal error!\n"); - /* STUB */ while (1) { /* whee! */ } } + + diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index c7ccfa0ba58..488de3c5596 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -70,6 +70,9 @@ struct __esf { typedef struct __esf NANO_ESF; extern const NANO_ESF _default_esf; +FUNC_NORETURN void _SysFatalErrorHandler(unsigned int reason, + const NANO_ESF *esf); + #endif /* _ASMLANGUAGE */ #ifdef __cplusplus