写入端口0cf8h失败,出现segfault [英] Write to port 0cf8h fails with segfault
问题描述
我有一个e2-2000模型的AMD处理器.这是家庭0fh. 根据0fh BKDG系列,我有以下代码可以读取设备和供应商ID:
I have an AMD processor of e2-2000 model. THis is family 0fh. According to family 0fh BKDG I have this code to read device and vendor ID:
ReadPCIConfiguration:
movq $0x80000100, %rax
movq $0x0cf8, %rdx
outl %eax, %dx # sigsegv caught here
movq $0x0cfc, %rdx
inl %dx, %eax
ret
据我所知,读写PCI配置的算法如下:
As far as I know the algorithm to read/write PCI configuration is as follows:
- 将目标总线号,设备号功能号和偏移量或寄存器号写入配置地址端口
- 从/到配置数据端口执行1字节,2字节或4字节的读/写操作
端口0xcf8..0xcfb-配置地址端口(双字)
Ports 0xcf8..0xcfb - configuration address port (doubleword)
位含义:
- 31-EnReg-启用交易(读/写)
- 24..31-保留(R/O)
- 16..23-BusNum(R/W)
- 11..15-DevNum(R/W)
- 8..10-FuncNum(R/W)
- 2..7-RegNum(R/W)
- 0..1-保留(R/O)
所以,我写到bus-0,dev-0,func-1,reg-00
So, I write to bus - 0, dev - 0, func - 1, reg - 00
我做错什么了吗?
(我从用户空间GNU/Debian"Wheezy" Linux 3.11.6运行已编译和链接的应用程序)
(I run the compiled and linked application from userspace, GNU/Debian "Wheezy" Linux 3.11.6)
推荐答案
Linux默认情况下不允许用户区代码写入I/O端口. (从安全角度来看,这样做非常危险.)如果您希望Linux允许您的进程访问I/O端口,则有两种选择:
Linux does not, by default, allow userland code to write to I/O ports. (Doing so can be quite dangerous from a security perspective.) If you’d like Linux to give your process access to the I/O ports, you have two options:
-
您可以使用
ioperm
系统调用.但是,ioperm
已经过时了一段时间,Josh Triplett最近推出了补丁程序允许用户将其从内核中删除.如果您希望代码在可预见的将来继续工作,请避免使用ioperm
.
You can use the
ioperm
system call. However,ioperm
has been deprecated for some time, and Josh Triplett recently pushed a patch that allows users to remove it from the kernel. Avoidioperm
if you want your code to continue working for the forseeable future.
您可以读写/dev/port.参见 mem(4).显然,您的进程将需要对/dev/mem的读写权限;在Wheezy上,这意味着它需要以root用户身份运行,除非您更改设备的权限.
You can read from and write to /dev/port. See mem(4). Your process will, obviously, need read and write permissions for /dev/mem; on Wheezy, that means it needs to run as root, unless you change the permissions on the device.
这篇关于写入端口0cf8h失败,出现segfault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!