使用端口映射的I/O时是否使用虚拟内存? [英] Is virtual memory used when using Port-mapped I/O?

查看:73
本文介绍了使用端口映射的I/O时是否使用虚拟内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个内存映射的I/O设备,并且我想写入该设备的寄存器,该寄存器位于地址 0x16D34 ,则实际上 0x16D34 地址是一个虚拟地址,CPU会先将其转换为物理地址,然后将数据写入该物理地址.

If I have a Memory-mapped I/O device, and I want to write to a register for this device located at address 0x16D34, the 0x16D34 address is actually a virtual address, and the CPU will translate it to a physical address first, and then write the data to the physical address.

但是关于端口映射的I/O设备(例如:串行端口),因此,如果我要写入位于地址 0x3F8 的串行端口的寄存器,则 0x3F8 是物理地址还是虚拟地址?

But what about Port-mapped I/O devices (for example: a serial port), so if I want to write to a register for a serial port located at address 0x3F8, is the 0x3F8 address a physical address or a virtual address?

:我使用的是x86体系结构.

I am on x86 architecture.

推荐答案

x86/x86-64上的端口映射I/O(大多数其他现代体系结构甚至不支持它)发生在完全独立的地址空间中.此地址空间不受内存映射的影响,因此没有虚拟端口地址,只有物理地址.必须使用特殊的 in out 指令来执行端口I/O,简单的内存访问(例如,使用 mov )不能单独访问此端口地址空间.可以基于特权级别进行访问保护;默认情况下,大多数现代操作系统都会阻止用户空间进程访问I/O端口.

Port-mapped I/O on x86/x86-64 (most other modern architectures don't even support it) happens in an entirely separate address space. This address space is not subject to memory mapping, so there are no virtual port addresses, only physical ones. Special in and out instructions must be used to perform port I/O, simple memory access (e.g. with mov) can't access this separate address space. Access protection based on privilege level is possible; most modern OSes prevent user space processes from accessing I/O ports by default.

有关详细信息,例如,您可以查看英特尔的《英特尔®64和IA-32架构开发人员手册:第1卷》的输入/输出"一章./content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-vol-1-manual.html"rel =" noreferrer>(截至撰写本文时,第18章).

For details, you can for example check the chapter "INPUT/OUTPUT" of Intel's "Intel® 64 and IA-32 Architectures Developer's Manual: Vol. 1" (chapter 18 as of this writing).

请注意,在x86的早期,每个设备(包括ISA附加卡)中的端口地址都是硬连线的.如果您幸运的话,该卡具有一组 jumpers ,用于选择受限的一个设备的一组可能的端口范围,以避免设备之间的范围冲突.稍后,即插即用引入了Play ,可在系统启动过程中动态进行选择.PCI对此进行了进一步完善,因此,操作系统和/或固件几乎可以将I/O BAR映射到0x0000-0xffff地址空间内的任何位置.由于存在许多固有的局限性,现在在设计新硬件时强烈建议不要使用端口映射的I/O.

Note that in the early days of x86, port addresses were hardwired in each device, including ISA add-in cards. If you were lucky, the card had a set of jumpers for selecting one of a limited set of possible port ranges for the device, in order to avoid range clashes between devices. Later, Plug & Play was introduced to make the selection dynamically during system boot. PCI further refined this, so that I/O BARs can pretty much be mapped anywhere within the 0x0000-0xffff address space by the operating system and/or firmware. Port-mapped I/O is now strongly discouraged when designing new hardware due to its many inherent limitations.

这篇关于使用端口映射的I/O时是否使用虚拟内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆