如何通过pci能力id识别设备
如何通过PCI功能ID识别设备? 这是我的代码:
我尝试访问34h并检查第一个循环中的功能ID是否存在 如果存在,它指向下一个指针,但是在获取指针并放置地址的步骤中似乎存在一些问题。
'''
push eax
push edi
push esi
mov cx,100
;mov edi,[esi]
add edi,52 ;access 34h
lopreg:
mov eax,edi ;read
mov dx,0cf8h
out dx,eax
mov dx,0cfch
in eax,dx
cmp cx,100 ;first time
je first
cmp ah,10
jne nextreg
jmp ispcie
first:
cmp ah,0
je ending
sub edi,52
movzx bx,ah
add di,bx
loop lopreg
jmp ending
ispcie:
call set_cur
mov ah,09h
lea dx,regmem ;print pcie
int 21h
jmp ending
nextreg:
cmp al,0
je ending
movzx bx,al ;
add di,bx
loop lopreg
ending:
pop esi
pop edi
pop eax
ret
'''
How to identify the device by pci capability id?
this is my code:
I try to access 34h and check if the capability id exists on the first loop
If it exists, it points to the next pointer, But there seems to be some problems in the steps of getting the pointer and putting the address.
'''
push eax
push edi
push esi
mov cx,100
;mov edi,[esi]
add edi,52 ;access 34h
lopreg:
mov eax,edi ;read
mov dx,0cf8h
out dx,eax
mov dx,0cfch
in eax,dx
cmp cx,100 ;first time
je first
cmp ah,10
jne nextreg
jmp ispcie
first:
cmp ah,0
je ending
sub edi,52
movzx bx,ah
add di,bx
loop lopreg
jmp ending
ispcie:
call set_cur
mov ah,09h
lea dx,regmem ;print pcie
int 21h
jmp ending
nextreg:
cmp al,0
je ending
movzx bx,al ;
add di,bx
loop lopreg
ending:
pop esi
pop edi
pop eax
ret
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案是在假设该代码正在寻找 PCI Express 功能的情况下编写的。
这段代码有几个问题。
first
标签处,应该使用al
而不是ah
来确定第一个能力的偏移量。al
包含功能 id,ah
包含下一个指针。所以cmp ah, 10
应该是cmp al, 10h
。nextreg
标签处,应该使用ah
而不是al
来确定下一个功能的偏移量。bx
添加到di
中,而不删除先前的偏移量。这应该可行:
更好的方法是将原始地址保留在
edi
中而不更改它,并为每个新偏移量使用lea eax, [edi+ebx]
.没有必要使用
ecx
作为循环计数器,而且逻辑有点复杂。可以将其拉直一点,以便更清晰地流动。这是我的编写方式:(
我不知道
set_cur
和regmem
是什么,所以我没有尝试编写这部分代码。)This answer is written with the assumption that this code is looking for the PCI Express Capability.
There are several problems in this code.
first
label, it should useal
instead ofah
to determine the offset of the first capability.al
contains the capability id andah
contains the next pointer. Socmp ah, 10
should becmp al, 10h
.nextreg
label, it should useah
instead ofal
to determine the offset of the next capability.bx
todi
without removing the previous offset.edi
is initialized to, but if it does not have bit 31 set, then this code won't be reading PCI config space at all.This should work:
A better approach is to keep the original address in
edi
without changing it, and uselea eax, [edi+ebx]
for each new offset.There's no need to use
ecx
as a loop counter and the logic is a bit convoluted. It can be straightened out a bit to flow more clearly.Here's how I would write it:
(I don't know what
set_cur
andregmem
are so I didn't attempt to write that part of the code.)