


EFLAGS IOPL field controls the I/O ports address space restricting machine instruction access to such ports.

EFLAGS is stored into TSS when a task is suspended and it is replaced with the one contained in the new executing task's TSS. X86 processors use an algorithm to validate a port I/O access based on two permission checks ():Ĭhecking the I/O Privilege Level (IOPL) of EFLAGS registerĬhecking I/O permission bit map (IOPM) of a process task state segment (TSS)įor the memory mapped devices other MMU related specific mechanisms are provided (but they are out of scope, see for more details on this).ĮFLAGS register is the 32 bit status register of processor. I/O permission level and I/O permission bit map Sometimes this is not possible because the performances are compromised by the Kernel / User context switch overhead.Īnd finally, although we cannot replace a KMD anytime we have to deal with interrupts and other bunch of low level stuff, knowing how to access I/O from user space can still be useful in many other cases. Often a better way is combining UMD and KMD for providing a solution where the KMD provides access to I/O and the UMD implements stuff 'too' complex to be implemented easily in the KMD. We are talking about User Mode Drivers (UMD).Īn UMD is a simple user space application since it can be built, executed and debugged as any other user space application while a Kernel mode driver (KMD) requires specific tools and a very specific knowledge to be designed, implemented, deployed and debugged.Įven taking into account that an UMD might represent a violation of modern operating systems architecture which splits user space and kernel space domains, an UMD might still represent a pragmatic temporary solution for experimenting low level stuff without dealing with KMD complexity. While in kernel space any privileged instruction can be executed, in user space this can only be allowed through a specific interface provided by operating system.Įven if user space applications normally don't access directly the I/O a specific class of applications can violate such rule. Only two of four privilege levels (rings) of x86 processors are typically used by Linux and Windows: ring 0 for kernel space and ring 3 for user space. Such instructions are checked by system to guarantee processes and kernel space isolation where only (Linux and Windows) Kernel privileged code is allowed to address the I/O directly.

Intel x86 processors in addition to memory mapped devices support also so called I/O ports mapped devices via a 'privileged' set of machine instructions. A Windows kernel driver which uses undocumented internal API is also described. This article describes the direct I/O access techniques in Linux and Windows user space applications. 153 - Gennaio 2006 Enabling direct I/O ports access in user space Sample code related to the following article published on Computer Programming - n.
