AMX 68000 Target Guide
K
DAK
9
2. Program Coding Specifications
2.1 Task Trap Handler
AMX 68000 supports task traps for the M68000 zero divide, bounds check and overflow
faults. A zero divide fault occurs if any M68000 instruction attempts an integer division
by zero. A bounds check fault occurs if the M68000
CHK instruction detects an array
bound violation. An overflow fault occurs if the overflow flag (V) is set in the status
register (SR) at the time an M68000 TRAPV instruction is executed.
The Task Trap Handler can be written as a C procedure with formal parameters.
#include "CJZZZ.H" /* AMX Headers */
void CJ_CCPP traphandler(
struct cjxregs *regp, /* A(Register Structure) */
void *faultfp) /* A(Fault frame) */
{
:
Process the error
:
}
The zero divide, bounds check and overflow exceptions are serviced by AMX. The state
of each register at the time of the fault is stored on the stack in an AMX register structure
cjxregs. Parameter regp is a pointer to that structure. Structure cjxregs is defined in
AMX header file CJ532KT.H.
Interrupts are enabled upon entry to the task trap handler. Note that the SR register copy
in the register array reflects the state of the status register after the exception occurred.
A pointer to the M68000 fault frame is provided as parameter faultfp. This pointer is
the M68000 stack pointer (SP) after the fault has occurred. Fault frame members can be
referenced as described in Chapter 3.1.
The register values in structure
regs can be examined and, in rare circumstances,
modified. If necessary, the fault frame at *faultfp can be modified, with extreme care,
to force resumption at some other location in the task code. If the task trap handler
returns to AMX, execution will resume at the location determined by the fault frame at
*faultfp with registers set according to the values in the structure referenced by regp.
Note that the
SR register will be restored according to the value returned in the fault frame
referenced by faultfp.
Since the task trap handler executes in the context of the task in which the exception
occurred, it is free to use all AMX services normally available to tasks. In particular, the
handler can call
cjtkend to end task execution if so desired.
Comments to this Manuals