A.8 Interrupt, IRQ, and Callback Wrappers

A.8.1 Install_Int()

Usage

int Install_Int(int IntNum, unsigned int HandlerAddress);

Purpose

Installs a interrupt handler for the specified interrupt, allocating a wrapper function which will save registers and handle the stack switching. The passed function should return zero (in EAX) to exit the interrupt with an iret instruction, and non-zero to chain to the old handler.

Inputs

IntNum, the interrupt number to install the handler for.

HandlerAddress, the address of the handler function.

Outputs

Returns -1 on error (unable to allocate a wrapper), 0 on success.

Notes

A maximum of MAX_INTS interrupts may be hooked using this function.

A.8.2 Remove_Int()

Usage

void Remove_Int(int IntNum);

Purpose

Removes an interrupt handler installed by Install_Int(), restoring the old vector.

Inputs

IntNum, the interrupt number to uninstall the handler for.

Outputs

None

A.8.3 Init_IRQ()

Usage

void Init_IRQ(void);

Purpose

Saves the current IRQ masks as the default.

Inputs

None

Outputs

None

A.8.4 Exit_IRQ()

Usage

void Exit_IRQ(void);

Purpose

Restores the default IRQ masks (the masks at the time Init_IRQ() was called).

Inputs

None

Outputs

None

A.8.5 Restore_IRQ()

Usage

void Restore_IRQ(int IRQNum);

Purpose

Restores default masking for a single IRQ.

Inputs

IRQNum, the IRQ to restore to its original masking.

Outputs

None

A.8.6 Enable_IRQ()

Usage

void Enable_IRQ(int IRQNum);

Purpose

Enables (unmasks) a single IRQ.

Inputs

IRQNum, the IRQ to enable (unmask).

Outputs

None

A.8.7 Disable_IRQ()

Usage

void Disable_IRQ(int IRQNum);

Purpose

Disables (masks) a single IRQ.

Inputs

IRQNum, the IRQ to disable (mask).

Outputs

None

A.8.8 Get_RMCB()

Usage

bool Get_RMCB(unsigned short *RM_Segment, unsigned short *RM_Offset, unsigned int HandlerAddress, bool ReturnTypeRETF);

Purpose

Gets a real-mode callback handler for the specified protected mode callback handler, allocating a wrapper function which will save registers and handle the stack switching. The real-mode segment and offset to pass to the real-mode function (eg, the mouse interrupt) are returned into the variables pointed to by RM_Segment and RM_Offset.

Inputs

HandlerAddress, the address of the callback handler function.

ReturnTypeRETF, the return type of the handler (in real mode), 1=retf, 0=iret.

Outputs

RM_Segment, the real-mode segment of the real-mode callback.

RM_Offset, the real-mode offset of the real-mode callback.

Returns 1 on error (unable to allocate a wrapper), 0 on success.

Notes

A maximum of MAX_RMCB wrappers may be allocated using this function.

Callback procedure should use the C calling convention, compatible with the following C declaration:

void Callback(DPMI_Regs *Regs);

The Regs parameter is the starting address of a structure that's organized the same as the DPMI_Regs global structure (e.g., the same as the structure in DPMI function 0300h. However, it does not point at the global DPMI_Regs structure, so don't attempt to access the EAX value by looking at the DPMI_EAX global variable. Rather, use the DPMI_*_off constants (such as DPMI_EAX_off) to offset from the address in the Regs parameter within the ES selector, using code like the following:

proc _Callback
.Regs   arg     4

        mov     ebx, [ebp+.Regs]
        mov     eax, [es:ebx+DPMI_EAX_off] ; Get eax value
        ret
endproc

The values the DPMI_Regs structure pointed to by Regs contains are the real-mode register values set at the time the real mode side of the real mode callback was called (e.g., by the mouse driver).

Some outputs are passed as parameters; pass the address of a variable, and after a successful call, the variable will be filled with the output information.

A.8.9 Free_RMCB()

Usage

void Free_RMCB(short RM_Segment, short RM_Offset);

Purpose

Frees a real-mode callback wrapper allocated by Get_RMCB().

Inputs

RM_Segment, the real-mode segment of the real-mode callback.

RM_Offset, the real-mode offset of the real-mode callback.

Outputs

None