60
K
A
DAK
Interrupt Service Procedures
4.5 Task Error Traps
The 80x86 processor automatically detects the occurrence of execution errors such as
division by zero, arithmetic overflow or an array bound violation. These errors, by their
very nature, must be handled by the application in the context of the task in which they
occur.
AMX offers tasks a convenient method of trapping such errors. For each task, AMX
maintains a pointer to a task trap handler for each detectable error.
Normally, when a task is running, AMX treats these errors as fatal if they occur. A task
can specify a trap handler for a particular error trap by calling AMX service procedure
ajitrp or AAITRP. Thereafter, if the error occurs while running in the context of the
task, the task automatically branches to its trap handler.
Note that the actual processor error exception is completely serviced by AMX. The task
simply appears to have suddenly jumped to its trap handler.
Divide errors cannot be disabled. Once a task specifies a divide error trap handler, any
subsequent divide error which occurs when that task is executing will cause an immediate
jump to the task's divide error trap handler.
Overflow error exceptions do not occur automatically. The task must execute an
interrupt on overflow (INTO) instruction to cause the overflow exception if the overflow
flag (OF) is set. If the exception occurs and the task has specified an overflow error trap
handler, then AMX will cause the task to jump to that handler.
Bound error exceptions do not occur automatically. The task must execute a bound
check (BOUND) instruction to cause the bound error exception if specific array bounds are
violated. If the exception occurs and the task has specified a bound error trap handler,
then AMX will cause the task to jump to that handler.
AMX maintains unique divide, overflow and bound error trap handlers for each task. If a
task is suspended and another task executes, AMX selects the divide, overflow and bound
trap handlers for the new task. When the suspended task resumes, its unique trap
handlers are reinstated.
A task trap handler for a particular error trap is reset (cancelled) with a request to AMX
to set the pointer to NULL (0L).
When a task is first created, AMX sets the task's trap handlers to NULL forcing errors to be
fatal until the task specifies its own trap handlers. Once a task defines its trap handlers,
they remain defined even if the task ends execution. If the task is subsequently executed
again, its previously defined trap handlers remain in effect unless altered by the task.
If a trapped error exception occurs in a task with no trap handler or in a Restart
Procedure, an ISP or a Timer Procedure, AMX initiates a fatal exit as described in
Chapter 13.1.