INF: Accessing I/O Ports Under OS/2 Protected Mode

ID Number: Q39973

5.10 6.00 6.00a

OS/2

Summary:

In Microsoft C versions 5.1, 6.0, and 6.0a for OS/2, you must have a

.DEF module-definition file that gives IOPL to the _IOSEG segment in

order to use the inp(), inpw(), outp(), and outpw() routines from the

Microsoft C run-time library. Failure to do this will result in the

following message:

SYS1943: A program caused a protection violation.

More Information:

To read from or write to ports under OS/2 protected mode, you must

have a .DEF module-definition file that gives IOPL (input/output

privilege) to the _IOSEG segment. Also, if the intrinsic (/Oi) switch

is used during compilation, the segments that contain the port

functions must be given IOPL. You can check the .MAP file for the

associated segment name or compile with the /NT switch to manually

name the segment.

The following must be in your .DEF file if /Oi is not used:

SEGMENTS

_IOSEG CLASS 'IOSEG_CODE' IOPL

If /Oi is used, the following must be in your .DEF file:

SEGMENTS

(segment name) IOPL

Note: Segments that have IOPL cannot make system calls. If you do, you

will generate a GP-fault (a general protection violation). This

behavior is discussed on page 239 of Gordon Letwin's "Inside OS/2."

Additional reference words: 5.10 6.00 6.00a COM1 COM2 serial communication