This article has been archived. It is offered "as is" and will no longer be updated.
Attempting to use the port I/O (input/output) functions such as inp() andoutp() from within an application for Windows NT running in user modecauses a privileged instruction exception to occur. The sample codeprovided in the OUTP.C online help sample for the outp() function andrelated functions can be used to illustrate this behavior.
The documentation regarding the compatibility of the port I/O functions isincomplete. Win32-based applications that call inp(), outp(), and so forthcan be successfully compiled and linked. However, these applications willgenerate the privileged instruction exception because the port I/Ofunctions cannot be called from code running in user mode.
Do not call the following functions from within a Win32-based applicationexecuting in user mode:
_inp() _inpw() _inpd() _outp() _outpw() _outpd()
NOTE: This documentation error has been corrected for the Visual C++ 4.0Books Online. The descriptions of the various port I/O functions do notlist "Win NT" in the Compatibility section.
According to the documentation provided with Visual C++ 32-bit Edition,inp(), outp(), and the other port I/O related functions are Win32 andWin32s compatible. However, executing code that uses these functionscauses a privileged instruction exception on Win32 on Windows NT. The codethat uses inp(), outp(), and so forth will execute correctly on Win32s.
The inp(), outp(), and other I/O port related functions map to privilegedprocessor instructions. For example, on Intel processors, the inp() andoutp() functions end up calling the IN and OUT instructions. The privilegedinstruction exception occurs when these instructions are executed becausetypical Windows NT applications execute in a nonprivileged (user) mode.Only code executing in kernel mode has the necessary rights to executeprivileged instructions. Kernel mode code is typically found in devicedrivers.
For more information on user mode and kernel mode in Windows NT, refer tothe Microsoft Press book "Inside Windows NT" by Helen Custer. For anexample of a kernel mode Windows NT device driver that allows user modeapplications to access hardware ports, refer to the GENPORT sample providedwith the Microsoft Windows NT Device Driver Kit (DDK).
The Online help for _inp, _inpw, _inpd, _outp, _outpw, and _outpd. The Microsoft Press book "Inside Windows NT" by Helen Custer. The Microsoft Press book "Microsoft's 80386/80486 Programming Guide"by Ross P. Nelson. The "Kernel-Mode Device Driver Guide" provided with the MicrosoftWindows NT DDK.