NOFAULT(3spp)
NAME
nofault − fault handling for standalone programs
SYNOPSIS
#include <saio/saioctl.h>
int *nofault;
DESCRIPTION
Nofault is a global variable that may be assigned the address of a jmp_buf (see setjmp(3spp)). If nofault is not zero, a longjmp will be made via the jmp_buf pointed to by nofault should a fault occur. Nofault is typically used in code sequences like:
#include <saio/setjmp.h>
#include <saio/saioctl.h>
jmp_buf jb;
extern int *nofault;
if (setjmp(jb)) {
/*
* control is transferred here after a fault,
* place fault handling code here
*/
} else {
/*
* setting nofault to address on jmp_buf enables
* longjmp to fault handler above, should fault
* occur
*/
nofault = jb;
/*
* code that may cause a fault goes here
*/
}
/* cancel special fault handling */
nofault = NULL;
Nofault is cleared while performing the longjmp, so once a fault has been taken, if necessary, the fault handler must be re-enabled by again assigning a value to the global variable nofault. When a fault is taken the standalone library switches to a second stack referred to as the "fault stack" and always saves a small amount of state for the fault handler to examine. The following global integer variables may be examined by the fault handler to determine the nature of the fault:
_epc_savepc at time of fault
_exc_saveexception vector type
Indicates if exception was via "utlbmiss", or
general exception.
Literals EXCEPT_UTLB, and EXCEPT_NORM are
defined in <saio/saioctl.h>
_badvaddr_saveR2000 system coproc. badvaddr register
_cause_saveR2000 system coproc. cause register
_sp_savestack pointer at time of exception
_sr_saveR2000 system coproc. status register
_stack_modestack in use at time of exception
Literals MODE_NORMAL and MODE_FAULT are
defined in <saio/saioctl.h>
Additional state beyond that shown above is saved, if the global variable _stack_mode is equal to MODE_NORMAL at the time of a fault. In this case, the contents of the R2000 registers are saved into the global integer array _regs and _stack_mode is changed to MODE_FAULT. If the floating point coprocessor was marked as usable in the R2000 status register at the time of a fault on the normal stack, it’s state is also saved into _regs. Further faults will not alter the array _regs until _stack_mode is reassigned to MODE_NORMAL. _stack_mode is initialized to MODE_NORMAL when a program is started. The _regs array may be subscripted with the literals R_R0 .. R_R31. These literals, and literals for offsets to other R2000 registers saved in the _regs array, are defined in <saio/saioctl.h>. The context that is represented by the contents of _regs may be resumed by calling the routine _resume(3spp). Resume restores all R2000 registers from the contents of _regs; floating point coprocessor registers will be restored if the coprocessor is marked usable in the status register saved in _regs. Calling _resume resets _stack_mode to MODE_NORMAL.