“输入/输出”如何实现端口映射到内存?
我一直在尝试了解 I/O 端口及其与内存和内存的映射。 I/O 地址空间。我读到了“内存映射 I/O”,并且想知道操作系统/硬件是如何实现这一点的。操作系统/硬件是否使用某种表将指令中指定的地址映射到相应的端口?
I have been trying to understand I/O ports and their mappings with the memory & I/O address space. I read about 'Memory Mapped I/O' and was wondering how this is accomplished by OS/Hardware. Does OS/Hardware uses some kind of table to map address specified in the instruction to respective port ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实施方式在很多方面都有所不同。但基本思想是,当对内存地址进行读取或写入时,微处理器会在其总线上输出该地址。硬件(称为“地址解码器”)检测该地址是否用于特定的内存映射 I/O 设备,并启用该设备作为操作的目标。
通常,操作系统不会执行任何特殊操作。在某些平台上,BIOS 或操作系统可能必须配置某些参数才能使硬件正常工作。
例如,该范围可能必须设置为不可缓存,以防止缓存逻辑对关心事件发生顺序的设备的操作进行重新排序。 (想象一下,如果一次写入告诉硬件要执行什么操作,而另一次写入则告诉硬件启动。重新排序可能会造成灾难性的后果。)
在某些平台上,操作系统或 BIOS 可能必须将某些内存映射 I/O 范围设置为通过添加等待状态来“慢”。这是因为作为操作目标的硬件可能不如系统内存快。
某些设备可能允许操作系统选择在内存中映射设备的位置。这是 PC 平台上较新的即插即用设备的典型特征。
在某些设备中,例如微控制器,这一切都完全在单个芯片内完成。对特定地址的写入在硬件中路由到特定端口或寄存器。这可以包括与芯片上的引脚连接的通用 I/O 寄存器。
Implementations differ in many ways. But the basic idea is that when a read or write occurs for a memory address, the microprocessor outputs the address on its bus. Hardware (called an 'address decoder') detects that the address is for a particular memory-mapped I/O device and enables that device as the target of the operation.
Typically, the OS doesn't do anything special. On some platforms, the BIOS or operating system may have to configure certain parameters for the hardware to work properly.
For example, the range may have to be set as uncacheable to prevent the caching logic from reordering operations to devices that care about the order in which things happen. (Imagine if one write tells the hardware what operation to do and another write tells the hardware to start. Reordering those could be disastrous.)
On some platforms, the operating system or BIOS may have to set certain memory-mapped I/O ranges as 'slow' by adding wait states. This is because the hardware that's the target of the operation may not be as fast as the system memory is.
Some devices may allow the operating system to choose where in memory to map the device. This is typical of newer plug-and-play devices on the PC platform.
In some devices, such as microcontrollers, this is all done entirely inside a single chip. A write to a particular address is routed in hardware to a particular port or register. This can include general-purpose I/O registers which interface to pins on the chip.