Intel 80286 Computer Accessories User Manual


 
inter
SYSTEM-LEVEL NUMERIC PROGRAMMING
As described previously, whenever the 80286
CPU
encounters an
ESC
instruction,
and
its
MP
and
EM
status
bits
are
set appropriately
(MP=O,
EM
= I), the 80286 will automatically
trap
to
interrupt
#7, the Processor Extension
Not
Available exception. The return link stored
on
the
stack
points to the
first byte of the
ESC
instruction, including the prefix byte(s), if any. The exception handler can use
this
return
link to examine the
ESC
instruction and proceed to emulate the numeric instruction in
software.
The
emulator
must step the return pointer so that, upon return from the exception handler, execution
can
resume
at
the
first instruction following the
ESC
instruction.
To an application program, execution on
an
80286 system with 80287 emulation
is
almost indistin-
guishable from execution on an
80287 system, except for the difference in execution speeds.
There
are
several important considerations when using emulation on an 80286 system:
When
operating in Protected-Address mode, numeric applications using the emulator must be
executed in execute-readable code segments.
Numeric
software cannot be emulated
if
it
is
executed
in execute-only code segments. This
is
because the emulator must be able to examine the
particular
numeric instruction
that
caused the Emulation trap.
Only privileged tasks can place the 80286 in emulation mode.
The
instructions necessary to place
the
80286 in Emulatio,n mode are privileged instructions, and are not typically accessible to an
application.
\
An
emulator package (E80287)
that
runs on 80286 systems
is
available from Intel in the 8086 Software
Toolbox,
Order
Number
122203. This emulation package operates in both Real and Protected mode,
providing a complete functional equivalent for the
80287 emulated in software.
When
using the E80287 emulator, writers of numeric exception handlers should be aware of one slight
difference between the emulated
80287 and the 80287 hardware:
On
the 80287 hardware, exception handlers
are
invoked by the 80286
at
the first
WAIT
or
ESC
instruction following the instruction causing the exception.
The
return
link, stored on the 80286
stack, points to this second
WAIT
or
ESC
instruction where execution will resume following a
retu~n
from
the
exception
handler.
Using the E80287 emulator, numeric exception handlers are invoked from within the emulator itself.
The
return link stored on the
stack
when the exception handler is invoked will therefore point back
to the
E80287 emulator,
rather
than
to the program code actually being executed (emulated). An
IRET
return from the exception handler returns
to
the emulator, which then returns immediately
to the
emulated
program. This added layer
of
indirection should not cause confusion, however,
because
the
instruction causing the exception
can
always be identified from the 80287's instruction
and
data
pointers.
Handling Numeric Processing Exceptions
Once
the 80287 has been initialized
and
normal execution of applications has been commenced,
the
80287
NPX
may occasionally require attention in order to recover from numeric processing errors.
This section provides details for writing software exception handlers for numeric exceptions.
Numeric
processing exceptions have already been introduced in previous sections of this manual.
3-6