The address returned in CX is a segment, not a
selector. Therefore you should not attempt to
place the value returned in CX into a segment
register in protected mode or a general protection
fault may occur.

Note all 100h (256 decimal) interrupt vectors must
be supported by the DPMI host.

10.2 Set Real Mode Interrupt Vector

This function sets the value of the current task's real
mode interrupt vector for the specified interrupt.

If function was successful:
Carry flag is clear.
If function was not successful:
Carry flag is set.

Programmer's Notes

The address passed in CX must be a real mode
segment, not a selector.

If the interrupt being hooked is a hardware
interrupt then you must lock the segment that the
interrupt handler runs in as well as any memory
the handler may touch at interrupt time.

The address contained in CX:DX must be a real mode
segment:offset, not a selector:offset. This means
that the code for the interrupt handler must
either reside in DOS addressable memory or you
must use a real mode call-back address. Refer to
the section on DOS memory management services
in section 9.1
for information on allocating memory below
1 megabyte. Information on real mode call back
addresses can be found in section 11.4.

10.3 Get Processor Exception Handler Vector

This function returns the CS:(E)IP of the current
protected mode exception handler for the specified
exception number.

To Call

AX = 0202h
BL = Exception/fault number (00h-1Fh)

Returns

If function was successful:
Carry flag is clear.
CX:(E)DX = Selector:Offset of exception handler
If function was not successful:
Carry flag is set.
The value passed in BL was invalid.

Programmer's Notes

The value returned in CX is a valid protected mode
selector, not a real mode segment.

32-bit mode programs will be returned a 32-bit
offset in the EDX register.

10.4 Set Processor Exception Handler Vector

This function allows protected mode applications to
intercept processor exceptions that are not handled by
the DPMI environment. Programs may wish to handle
exceptions such as not present segment faults which
would otherwise generate a fatal error.

Every exception is first examined by the protected mode
operating system. If it can not handle the exception
it then reflects it through the protected mode
exception handler chain. The final handler in the
chain may either reflect the exception as an interrupt
(as would happen in real mode) or it may terminate the
current program.

If function was successful:
Carry flag is clear.
If function was not successful:
Carry flag is set.
The value passed in BL was invalid.

Programmer's Notes

The value passed in CX must be a valid protected
mode code selector, not a real mode segment.

32-bit mode programs must supply a 32-bit offset
in the EDX register. If your handler chains to
the next exception handler it must do so using a
32-bit interrupt stack frame.

The handler should return using a far return
instruction. The original SS:(E)SP, CS:(E)IP and
flags on the stack, including the interrupt flag,
will be restored.

All fault stack frames have an error code.
However, the error code is only valid for
exceptions 08h, 0Ah, 0Bh, 0Ch, 0Dh, and 0Eh.

The handler must preserve and restore all
registers.

The exception handler will be called on a locked
stack with interrupts disabled. The original SS,
(E)SP, CS, and (E)IP will be pushed on the
exception handler stack frame.

The handler must either return from the call by
executing a far return or jump to the next handler
in the chain (which will execute a far return or
chain to the next handler).

The procedure can modify any of the values on the
stack pertaining to the exception before
returning. This can be used, for example, to jump
to a procedure by modifying the CS:IP on the
stack. Note that the procedure must not modify
the far return address on the stack -- it must
return to the original caller. The caller will
then restore the flags, CS:(E)IP and SS:(E)SP from
the stack frame.

If the DPMI client does not handle an exception,
or jumps to the default exception handler, the
host will reflect the exception as an interrupt
for exceptions 0, 1, 2, 3, 4, 5, and 7.
Exceptions 6, and 8-1Fh will be treated as fatal
errors and the client will be terminated.

Exception handlers will only be called for
exceptions that occur in protected mode.

Call-Back Stack Frames

Stack frame for 16-bit programs:

15 0
SS
SP
Flags
CS
IP
Err Code
Return
CS
Return
IP
<-- SS:SP

Stack frame for 32-bit programs:

31 0
SS
ESP
EFlags
CS
EIP
Error Code
Ret CS
Return EIP
<-- SS:ESP

Shaded fields should not be modified. Other fields can
be modified before returning from the exception
handler.

10.5 Get Protected Mode Interrupt Vector

This function returns the CS:(E)IP of the current
protected mode interrupt handler for the specified
interrupt number.

To Call

AX = 0204h
BL = Interrupt number

Returns

Carry flag is clear.
CX:(E)DX = Selector:Offset of exception handler

Programmer's Notes

The value returned in CX is a valid protected mode
selector, not a real mode segment.

32-bit mode programs will be returned a 32-bit
offset in the EDX register.

All 100h (256 decimal) interrupt vectors must be
supported by the DPMI host.

10.6 Set Protected Mode Interrupt Vector

This function sets the address of the specified
protected mode interrupt vector.