如何通过pci功能标识识别设备?这是我的密码:
我尝试访问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
“”“
发布于 2022-03-30 06:19:14
编写这个答案的前提是,该代码正在寻找PCI功能。
这段代码有几个问题。
在capability.
al
而不是ah
来确定pointer功能的第一个first
功能ID的偏移量是10小时,而不是10。在读取每个能力标头之后,al
包含能力id,ah
包含下一个指针。所以cmp ah, 10
应该是cmp al, 10h
。nextreg
标签上,它应该使用ah
而不是al
来确定下一个nextreg
迭代的偏移量,它在不移除前一个偏移量的情况下将bx
添加到di
中。< code >H 222H 123
初始化到什么d24,但是如果它没有设置位31,那么这段代码根本就不会读取PCI配置空间。H 225G 226
这应该是可行的:
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 al,10h
jne nextreg
jmp ispcie
first:
cmp al,0
je ending
sub edi,52
movzx bx,al
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 ah,0
je ending
sub di, bx
movzx bx,ah
add di,bx
loop lopreg
ending:
更好的方法是将原始地址保留在edi中而不更改它,并对每个新的偏移量使用lea eax, [edi+ebx]。
没有必要使用ecx作为循环计数器,逻辑也有点复杂。它可以变得更清晰一些。--
我会这样写:
lea eax,[edi+34h]
mov dx,0cf8h
out dx,eax
mov dx,0cfch
in al,dx ; read offset of first capability
cmp al,0
je ending
movzx ebx,al
lopreg:
lea eax,[edi+ebx] ; offset of next capability is in ebx
mov dx,0cf8h
out dx,eax
mov dx,0cfch
in eax,dx ; read capability header
cmp al,10h ; check if it is the PCI Express capability
je ispcie
nextreg:
cmp ah,0 ; check if it is the end of the capability list
je ending
movzx ebx, ah ; set up ebx with the offset of the next capability
jmp lopreg
ispcie:
; base of device PCI config space is in edi
; offset of PCI Express Capability is in ebx
...
ending:
(我不知道set_cur和regmem是什么,所以我没有尝试编写这部分代码。)
https://stackoverflow.com/questions/71655343
复制相似问题