/dev/port 与 /dev/mem
我需要一些澄清。我可以直接写入 /dev/port
以直接访问并行端口,并且它工作正常(我可以打开插入端口连接器的 LED)。但是,我想我可以对 /dev/mem
做同样的事情? (http://tldp.org/LDP/khg/HyperNews/get/devices/fake.html)。当我尝试读取和写入 /dev/mem
时,我没有收到任何错误,但写入似乎从未反映在外部连接器上。我这么问只是因为根据我所读到的有关写入 /dev/mem
的内容,这不是我所期望的。
无法通过/dev/mem
访问ioports吗?
I need some clarification. I can directly write to /dev/port
to get direct access to a parallel port and it works fine (I can turn on LEDs plugged into the port connector). However, I thought I could do the same with /dev/mem
? (http://tldp.org/LDP/khg/HyperNews/get/devices/fake.html). When I try to read and write to /dev/mem
I get no errors, but the writes never seem to be reflected on the external connector. I ask just because this isn't what I expected based on what I've read about writing to /dev/mem
.
Can you not access ioports via /dev/mem
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提出一些建议(未经测试)。可能是...
/dev/mem
的使用要求硬件已进行MMIO映射,并且还需要知道MMIO地址(通常不是0x378)。Throwing in a handful of suggestions (untested). It could be that...
/dev/mem
requires that the hardware has been MMIO-mapped, and you also need to know the MMIO address (which usually is not 0x378).编辑:这仅适用于 x86 处理器(也许还有其他一些处理器)。
内存映射 I/O 与 x86 处理器上的端口 I/O 不太一样。
jørgensen 的观点是正确的,即内存在保护模式下重新映射 - 然而,I/O 端口不能以这种方式重新映射。
/dev/port
直接引用 I/O 端口,而/dev/mem
映射到(我相信)物理内存(即未重新映射),所以在这种情况下,您想使用/dev/port
。至于您提供的链接,它使用
/dev/mem
进行内存映射 I/O(同样,与 I/O 端口不同)。EDIT: this only applies to x86 processors (and perhaps a few others).
Memory-mapped I/O is not quite the same as port I/O on x86 processors.
jørgensen is right in that memory is remapped in protected mode - however, I/O ports cannot be remapped in this manner.
/dev/port
refers directly to the I/O ports, whereas/dev/mem
maps to (I believe) physical ram (i.e. NOT remapped), so in this case, you want to use/dev/port
.As for the link you provided, it uses
/dev/mem
for memory-mapped I/O (again, not the same as I/O ports).