Can anyone explain what's the difference between port mapping and memory mapping, and what having both accomplishes? Why is there port mapped, how does it differ in structure from memory maps, and is there any reason many architectures use both? Also, what is a "port" in this sense, because port can mean different things in different contexts?
Example: Port forwarding, port as a communications endpoint, "port mapping".
Say I write OUT to port 400h (fictive; just for example) (like in x86-64, etc.).
What or where am I writing to if it's not in memory? How is a "port" mapped, and what is it in this sense?
Best Answer
Memory-mapped I/O and port-mapped I/O are two complementary methods for I/O.
Memory-Mapped I/O
In memory-mapped systems, the I/O device is accessed like it is a part of the memory.
Load
andStore
commands are executed for reading from and writing to I/O devices, just like they are used for the memory (port-mapped has special commands for I/O). This means I/O devices use the same address bus as memory, meaning that CPU can refer to memory or the I/O device based on the value of the address. This approach requires isolation in the address space: that is, addresses reserved for I/O should not be available to physical memory.Below is an image of a simple, basic computer system. The case is much more complicated in contemporary systems.
Port-Mapped I/O
According to Wikipedia
As for the advantages and disadvantages: since the peripheral devices are slower than the memory, sharing data and address buses may slow the memory access. On the other hand, by the I/O simplicity memory-mapped systems provide, CPU requires less internal logic and this helps for faster, cheaper, less power consuming CPUs to be implemented. The logic is similar to that of RISC systems: reduce the complexity, get a more dedicated and a robust system which comes quite handy for embedded systems, for example.
On the contrary (again from Wiki):
I strongly recommend that you read that wiki article for further information.
To answer one of your questions:
You are writing to the registers of the I/O interface through the data bus, which later (when ready) sends the data to the actual I/O device. Below is an image of an example I/O device interface.