I/O Systems & Device Management

memory-mapped I/O

Suppose that instead of giving each office machine its own special mailbox on a separate wall, you simply reserved a few drawers of the ordinary filing cabinet for them. 'Drawer 5000 is the photocopier's command slot; write to it and the copier runs.' Now you operate the machine with the very same gestures you use for any drawer. Memory-mapped I/O does exactly this: a device controller's registers are wired to look like ordinary memory addresses, so the CPU controls the device using plain load and store instructions.

Concretely, certain ranges of the address space are carved out and routed not to RAM but to device controllers. Writing to address 0xB8000, for example, might place a character on a text screen; reading address 0x... might return a network card's status. When the CPU executes a normal store to such an address, the bus hardware recognises the range and steers the access to the controller instead of memory. The benefit is that the full, rich instruction set works on devices — you can read, write, even do compound operations — without any special IN/OUT instructions, and the driver code looks like ordinary pointer code. The drawback is that those addresses are stolen from the memory map, and the compiler must be told not to optimise such accesses away (in C, the register pointer is marked volatile) because reading the same status address twice can legitimately give two different answers.

Why it matters: memory-mapped I/O is the dominant scheme on modern hardware, the only scheme on architectures like ARM, and what makes high-bandwidth devices practical — a graphics card's framebuffer is simply a large region of mapped memory the CPU (or GPU) writes pixels into. The OS must map these device regions only into the kernel's address space, never carelessly into a user program, or any process could drive hardware directly and bypass all protection.

On the classic PC text screen, the bytes at memory addresses starting at 0xB8000 are the screen. Store the character code for 'A' there and an A appears at the top-left corner — no special I/O instruction needed, just a normal write.

The device's registers live in the memory address space, driven by ordinary load/store.

A memory-mapped register is not RAM: it has side effects and may change on its own, so reads and writes must not be reordered or cached like ordinary memory — hence the volatile marking and special care in drivers.

Also called
MMIO記憶體對映輸入輸出