Skip to content
EXPERIMENTAL

x86 port I/O

The std.port module — the x86 in and out instructions as functions, for freestanding programs that talk to a device through an I/O port.

Last verified

import std.port. The in and out instructions name their registers, so they cannot be written as assembly text; here each is a function. They are x86 instructions and are refused on any other target, with an error that names the function and the target, rather than assembled into something the assembler rejects.

prismio
import std.port

portOutU8(0x3F8, 65)             // a byte to the first serial port
let status = portInU8(0x3FD)     // its line status register
FunctionInstruction
portOutU8(port: U16, value: U8), portOutU16, portOutU32outb, outw, outl
portInU8(port: U16) -> U8, portInU16, portInU32inb, inw, inl

Meant for --freestanding programs, where a kernel talks to the hardware directly; an ordinary process is not allowed to execute either instruction. The module calls nothing in the C runtime.