Linux用户态程序读写IO端口方法总结

来源:互联网 发布:淘宝哪家弹弓好 编辑:程序博客网 时间:2024/06/09 20:28

从ELDD上看到的,人家总结的很全很好很强大,这里拿来用了
1、使用ioperm() and iopl()来获得权限,然后To write data to an I/O port, use outb(), outw(), outl(), or their cousins. To read data from a port, use inb(), inw(), inl(), or their relatives.这种方法只在x86上有效
附带一个例子,读取pc兼容机上的rtc时钟(属于cmos的一部分)的秒


2、使用/dev/port 这个由内核提供的驱动,这比前一种方式会损失一些性能,好处是比ioperm() and iopl()得到更加有效的权限管理

原创粉丝点击