📄 pcibus.asm
字号:
mov dx, PCI_CONFIG_DATA_REGISTER
mov ax, cx
and ax, 03h
add dx, ax
pop ax ;restore the value
out dx, ax
pop edx
ret
WritePCIConfigWordM1 endp
;******************************************************************************
;* WritePCIConfigByteM1()
;*
;* On Entry: AL: value
;* BX: bus number + device number + function number
;* ---------- ------------- ---------------
;* bit 15:8 bit 7:3 bit 2:0
;*
;* CL: register offset (should be WORD alignment)
;*
;* On Return:
;*
;******************************************************************************
WritePCIConfigByteM1 proc near
push edx
push ax ;reserved the value
movzx eax, bx
shl eax, 8 ;specify bus, device, function #
or al, cl ;specify the register #
and al, 0FCh ;make it 4-byte alignment
or eax, 80000000h ;enable configuration cycle
mov dx, PCI_CONFIG_ADDRESS_REGISTER
out dx, eax
mov dx, PCI_CONFIG_DATA_REGISTER
mov ax, cx
and ax, 03h
add dx, ax
pop ax ;restore the value
out dx, al
pop edx
ret
WritePCIConfigByteM1 endp
;******************************************************************************
;* SearchPCIClassCodeM1()
;*
;* On Entry: AX: Class Code
;* SI: Index
;*
;* On Return: BX: Handle
;*
;******************************************************************************
SearchPCIClassCodeM1 proc near
push cx
push dx
mov cx, ax ;store the class code
xor dx, dx ;PCI handle
@spccm1_loop:
READ_PCI_CONFIG_WORD dx, Pci_ClassCode
cmp ax, cx
jz @spccm1_found_device
@spccm1_next_search:
inc dx
cmp dx, 0FF00h ;Bus# 255 is not implemented
jne @spccm1_loop
mov dx, -1 ;not found any device
jmp @spccm1_exit
@spccm1_found_device:
cmp si, 0
jz @spccm1_exit
dec si
jmp @spccm1_next_search
@spccm1_exit:
;DX hold the device handle
;-------------------------
mov bx, dx
pop dx
pop cx
ret
SearchPCIClassCodeM1 endp
;******************************************************************************
;* SearchPCIDeviceM1()
;*
;* On Entry: EAX: DeviceID+VendorID
;* SI: Index
;*
;* On Return: BX: Handle
;*
;******************************************************************************
SearchPCIDeviceM1 proc near
push ecx
push dx
mov ecx, eax ;store the Device ID
xor dx, dx ;PCI handle
@spdm1_loop:
READ_PCI_CONFIG_DWORD dx, Pci_VendorID
cmp eax, ecx
jz @spdm1_found_device
@spdm1_next_search:
inc dx
cmp dx, 0FF00h ;Bus# 255 is not implemented
jne @spdm1_loop
mov dx, -1 ;not found any device
jmp @spdm1_exit
@spdm1_found_device:
cmp si, 0
jz @spdm1_exit
dec si
jmp @spdm1_next_search
@spdm1_exit:
;DX hold the device handle
;-------------------------
mov bx, dx
pop dx
pop ecx
ret
ret
SearchPCIDeviceM1 endp
;******************************************************************************
;* ReadPCIConfigDwordM2()
;*
;* On Entry: BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset (should be DWORD alignment)
;*
;* On Return: EAX hold the value
;*
;******************************************************************************
ReadPCIConfigDwordM2 proc near
push edx
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
and dl, 0FCh ;make it 4-byte alignment
in eax, dx
pop edx
ret
ReadPCIConfigDwordM2 endp
;******************************************************************************
;* ReadPCIConfigWordM2()
;*
;* On Entry: BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset (should be WORD alignment)
;*
;* On Return: AX hold the value
;*
;******************************************************************************
ReadPCIConfigWordM2 proc near
push edx
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
in ax, dx
pop edx
ret
ReadPCIConfigWordM2 endp
;******************************************************************************
;* ReadPCIConfigByteM2()
;*
;* On Entry: BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset
;*
;* On Return: AL hold the value
;*
;******************************************************************************
ReadPCIConfigByteM2 proc near
push edx
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
in al, dx
pop edx
ret
ReadPCIConfigByteM2 endp
;******************************************************************************
;* WritePCIConfigDwordM2()
;*
;* On Entry: EAX: the value
;*
;* BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset (should be DWORD alignment)
;*
;* On Return: all registers are preserved
;*
;******************************************************************************
WritePCIConfigDwordM2 proc near
push edx
push eax
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
and dl, 0FCh ;make it 4-byte alignment
pop eax
out dx, eax
pop edx
ret
WritePCIConfigDwordM2 endp
;******************************************************************************
;* WritePCIConfigWordM2()
;*
;* On Entry: AX: the value
;*
;* BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset (should be DWORD alignment)
;*
;* On Return: all registers are preserved
;*
;******************************************************************************
WritePCIConfigWordM2 proc near
push edx
push ax
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
pop ax
out dx, ax
pop edx
ret
WritePCIConfigWordM2 endp
;******************************************************************************
;* WritePCIConfigByteM2()
;*
;* On Entry: AL: the value
;*
;* BX: bus number + forword register value (15:8)
;* ---------- -------------------------------
;* bit 15:8 bit 7:0
;*
;* CL: register offset (should be DWORD alignment)
;*
;* On Return: all registers are preserved
;*
;******************************************************************************
WritePCIConfigByteM2 proc near
push edx
push ax
mov al, 0F0h
mov dx, PCI_ENABLE_REGISTER
out dx, al
mov al, bh ;bus #
mov dx, PCI_FORWARD_REGISTER
out dx, al
movzx dx, bl
shl dx, 8
or dl, cl ;specify the register #
pop ax
out dx, al
pop edx
ret
WritePCIConfigByteM2 endp
;******************************************************************************
;* SearchPCIClassCodeM2()
;*
;* On Entry: AX: Class Code
;* SI: Index
;*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -