What’s the difference between a hardware register and a memory-mapped register

buscpu-architecturedata transfermemoryregister

This has been puzzling, so I'll lay it all out here. Apparently, through MMIO, you can access external devices using a certain memory-mapped address, which would then be re-routed to that device itself(through a write, command packet, etc.). However, I've been hearing mixed descriptions of both hardware registers(e.g. like a CPU/GPU register, or even sound chips), and memory-mapped registers used interchangeably. Are they the same thing?

When you say a "memory-mapped register", aren't you referring to the address from which a data byte is re-routed to a specific address inside that device(e.g. theoretical: GPU's 0x500 address is for register TEXTURE_BUFFER). However, a memory-mapped device can't map a physical register inside RAM.

So basically, what is the difference between a memory-mapped register and just a hardware register?

Best Answer

Memory mapped hardware registers are accessed like RAM. All CPUs have specific instructions for reading/writing RAM and these same instructions are used to access memory-mapped registers.

Hardware registers in general do not have to be memory mapped, this is simply a common convention.

x86 provides two address spaces in which two separate groups of instructions are used to read and write - the first is RAM or memory space (all the MOV instructions), the second is I/O space (using the IN and OUT instructions). On x86, hardware registers may appear in either space.

You also may need to go through a level of indirection to really reach a hardware register. A device may only expose a "port" in memory or I/O space. You then need to write a register number to the address, and then the data you want to actually write to another address. The write then occurs. The old 8563 VDC in the Commodore 128 worked like this. The CMOS RAM and some PCI registers also work like this.

CPU hardware registers are of course not memory mapped (not on x86 or any common CPU anyway), that is another example of a hardware register.

Modern CPU's have "model specific registers" (MSRs) and these are read/written using their own instructions (RDMSR, WRMSR). Other CPU registers have their own instruction (LGDT, MOV xx, CR2, the basic EAX/RAX, etc.)