NOFAULT(3spp) RISC/os Reference Manual NOFAULT(3spp)
NAME
nofault - fault handling for standalone programs
SYNOPSIS
#include <saio/saioctl.h>
int *nofault;
DESCRIPTION
Nofault is a global variable that can be assigned the
address of a jmpbuf (see setjmp(3spp)). If nofault is not
zero, a longjmp will be made via the jmp_buf pointed to by
nofault. 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. Once a
fault has been taken, the fault handler must be re-enabled
by 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 can be examined by the
fault handler to determine the nature of the fault:
_epc_save pc at time of fault
_exc_save exception vector type
Indicates if exception was via "utlbmiss", or
general exception.
Literals EXCEPTUTLB, and EXCEPTNORM are
Printed 1/6/92 Page 1
NOFAULT(3spp) RISC/os Reference Manual NOFAULT(3spp)
defined in <saio/saioctl.h>
_badvaddr_save system coproc. badvaddr register
_cause_save system coproc. cause register
_sp_save stack pointer at time of exception
_sr_save system coproc. status register
_stack_mode stack in use at time of exception
Literals MODENORMAL and MODEFAULT are
defined in <saio/saioctl.h>
Additional state beyond that shown above is saved, if the
global variable _stack_mode is equal to MODENORMAL at the
time of a fault. In this case, the contents of the regis-
ters are saved into the global integer array _regs and
_stack_mode is changed to MODEFAULT. If the floating point
coprocessor was marked as usable in the status register at
the time of a fault on the normal stack, its state is also
saved into _regs. Further faults will not alter the array
_regs until _stack_mode is reassigned to MODENORMAL.
_stack_mode is initialized to MODENORMAL when a program is
started. The _regs array can be subscripted with the
literals RR0 .. RR31. These literals, and literals for
offsets to other registers saved in the _regs array, are
defined in <saio/saioctl.h>. The context that is
represented by the contents of _regs can be resumed by cal-
ling the routine _resume(3spp). Resume restores all regis-
ters 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 MODENORMAL.
SEE ALSO
setjmp(3spp)
Page 2 Printed 1/6/92