Port IO

From OSDev Wiki
(Redirected from User:Combuster/Port IO)
Jump to: navigation, search

The x86 architecture separates the address space in two programmatically distinct groups: memory and ports. In ancient history, memory was used as the storage of data where reads and writes would not have side-effects, and ports were used to control external hardware, which needed different timings to work. Which is also why accessing ports is so much slower than accessing memory. Many other common architectures have a unified space, where devices run at the same speed as memory, or where the address space is divided into blocks with separately configurable properties.

Modern x86 hardware tends more and more toward the unified space, but still contains the port for legacy reasons.

How to access ports

The x86 contains four opcodes that read from port space: IN, INS*, OUT and OUTS*, each come in a 8-bit and 16-bit version, as well as 32-bit for 386s and later.

Which ports belong to this device

There are three groups of devices, each requiring a different approach. The first group contains all PC-AT hardware, devices like timers, interrupt controllers, PS/2 ports, serial and parallel port, floppy and disk drive, and the VGA. Back in the old days devices were attached to fixed addresses, and they remained there for backwards compatibility. The programming information will tell you the ports used.

The second group is plug-and-play hardware. Most modern cards and optional features are PCI, AGP or PCI express. At boot, their requirements are checked, and the BIOS will assign port ranges to each device. Enumerating the PCI bus will list all these devices, and can also tell you what ports (and memory mapped ranges) they use.

The third group is old non-plug-and-play compatible hardware. They have jumpers or fixed addresses that physically select the ports in use. Most ISA cards behave this way. You will have to probe the port range for possible locations to see if the device in question exists. Alternatively, you can ask the user to enter the details (like the soundblaster configurations seen in DOS games). The problem is, it is very hard to list all devices, which makes mapping other devices without conflicts a potential problem.

What device belongs to this port

The only real way is to find all devices on the system, then look up your favourite port among all devices. But there is hardly any use for this kind of query.

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox