哪些真实平台将硬件端口映射到内存地址?

发布于 2024-10-05 09:38:51 字数 184 浏览 8 评论 0原文

我有时会看到这样的语句:在某些平台上,以下 C 或 C++ 代码:

int* ptr;
*ptr = 0;

如果 ptr 恰好存储了该端口映射到的地址,则可能会导致写入硬件输入输出端口。通常它们被称为“嵌入式平台”。

此类平台的真实例子有哪些?

I sometimes see statements that on some platforms the following C or C++ code:

int* ptr;
*ptr = 0;

can result in writing to a hardware input-output port if ptr happens to store the address to which that port is mapped. Usually they are called "embedded platforms".

What are real examples of such platforms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

时光倒影 2024-10-12 09:38:52

游戏机。这就是我们如何获得对系统低级图形(和其他)功能的直接优化访问。

PlayStation. That was how we got some direct optimized access to low-level graphics (and other) features of the system.

捶死心动 2024-10-12 09:38:52

Windows 上的 NDIS 驱动程序就是一个示例。这称为内存映射 I/O,这样做的好处是性能。

An NDIS driver on Windows is an example. This is called memory mapped I/O and the benefit of this is performance.

┾廆蒐ゝ 2024-10-12 09:38:52

请参阅嵌入式系统,了解使用内存映射 I/O 的设备示例,例如路由器、adsl-调制解调器、微控制器等

See Embedded-Systems for examples of devices that use Memory-mapped I/O e.g. routers,adsl-modems, microcontroller etc.

最单纯的乌龟 2024-10-12 09:38:52

它主要在编写驱动程序时使用,因为大多数外围设备通过内存映射寄存器与主 CPU 通信。

It is mostly used when writing drivers, since most peripheral devices communicate with the main CPU through memory mapped registers.

浮云落日 2024-10-12 09:38:52

摩托罗拉 68k 系列和 PowerPC 是其中的佼佼者。

Motorola 68k series and PowerPC are the big ones.

提笔书几行 2024-10-12 09:38:52

您可以在现代 Windows 中执行此操作(我很确定 Linux 也提供了它)。它称为内存映射文件。您可以将文件加载到 Windows 上的内存中,然后仅通过操作指针来写入/更改它。

You can do this in modern Windows (and I'm pretty sure Linux offers it too). It's called memory mapped files. You can load a file into memory on Windows and then write/alter it just by manipulating pointers.

请别遗忘我 2024-10-12 09:38:51

根据我的经验,大多数系统都使用内存映射 I/O。 x86 平台具有独立的、非内存映射的 I/O 地址空间(使用处理器操作码的in/out系列),但 PC 架构还广泛使用设备 I/O 的标准内存地址空间,它具有更大的地址空间、更快的访问(通常)和更容易的编程(通常)。

我认为最初使用单独的 I/O 地址空间是因为处理器的内存地址空间有时非常有限,使用其中的一部分进行设备访问没有什么意义。一旦内存地址空间开放到兆字节或更多,将 I/O 地址与内存地址分开的原因就变得不那么重要了。

我不确定有多少处理器像 x86 那样提供单独的 I/O 地址空间。作为单独 I/O 地址空间如何失宠的一个迹象,当 x86 架构进入 32 位领域时,没有采取任何措施将 I/O 地址空间从 64KB 增加(尽管他们确实增加了能力)在一条指令中移动 32 位数据块)。当 x86 进入 64 位领域时,I/O 地址空间仍保持在 64KB,甚至没有添加以 64 位单元移动数据的能力……

另请注意,现代桌面和服务器平台(或其他系统)使用虚拟内存的应用程序)通常不允许应用程序访问 I/O 端口,无论它们是否是内存映射的。该访问仅限于设备驱动程序,甚至设备驱动程序也会有一些操作系统接口来处理物理地址的虚拟内存映射和/或设置 DMA 访问。

在较小的系统(如嵌入式系统)上,I/O 地址通常由应用程序直接访问。对于使用内存映射地址的系统,通常只需使用设备 I/O 端口的物理地址设置一个指针,然后像使用其他指针一样使用该指针即可完成此操作。但是,为了确保访问发生并且以正确的顺序发生,必须将指针声明为指向 易失性 对象。

要访问使用内存映射 I/O 端口以外的设备(例如 x86 的 I/O 地址空间),编译器通常会提供一个扩展,允许您读取或写入该地址空间。如果没有这样的扩展,您需要调用汇编语言函数来执行 I/O。

Most systems in my experience use memory-mapped I/O. The x86 platform has a separate, non-memory-mapped I/O address space (that uses the in/out family of processor op-codes), but the PC architecture also extensively uses the standard memory address space for device I/O, which has a larger address space, faster access (generally), and easier programming (generally).

I think that the separate I/O address space was used initially because the memory address space of processors was sometimes quite limited and it made little sense to use a portion of it for device access. Once the memory address space was opened up to megabytes or more, that reason to separate I/O addresses from memory addresses became less important.

I'm not sure how many processors provide a separate I/O address space like the x86 does. As an indication of how the separate I/O address space has fallen out of favor, when the x86 architecture moved into the 32-bit realm, nothing was done to increase the I/O address space from 64KB (though they did add the ability to move 32-bit chunks of data in one instruction). When x86 moved into the 64-realm, the I/O address space remained at 64KB and they didn't even add the ability to move data in 64-bit units...

Also note that modern desktop and server platforms (or other systems that use virtual memory) generally don't permit an application to access I/O ports, whether they're memory-mapped or not. That access is restricted to device drivers, and even device drivers will have some OS interface to deal with virtual memory mappings of the physical address and/or to set up DMA access.

On smaller systems, like embedded systems, I/O addresses are often accessed directly by the application. For systems that use memory-mapped addresses, that will usually be done by simply setting a pointer with the physical address of the device's I/O port and using that pointer like any other. However, to ensure that the access occurs and occurs in the right order, the pointer must be declared as pointing to a volatile object.

To access a device that uses something other than a memory-mapped I/O port (like the x86's I/O address space), a compiler will generally provide an extension that allows you to read or write to that address space. In the absence of such an extension, you'd need to call an assembly language function to perform the I/O.

姐不稀罕 2024-10-12 09:38:51

这称为内存映射 I/O,维基百科文章

现代操作系统通常会保护您免受这种情况的影响,除非您正在编写驱动程序,但这种技术甚至在 PC 架构上也适用。还记得 DOS 640Kb 限制吗?这是因为 640K 到 1Mb 的内存地址被分配给 I/O。

This is called Memory-mapped I/O, and a good place to start is the Wikipedia article.

Modern operating systems usually protect you from this unless you're writing drivers, but this technique is relevant even on PC architectures. Remember the DOS 640Kb limit? That's because memory addresses from 640K to 1Mb were allocated for I/O.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文