📄 pcibus.asm
字号:
;* On Return: BX: Handle
;*
;******************************************************************************
SearchPCIClassCodeM2 proc near
push cx
push dx
mov cx, ax ;store the class code
mov dl, (PCI_CONFIG_BASE_ADDRESS shr 8) ;search from C0-CF
mov dh, 0 ;forward bus #
@spccm2_loop:
READ_PCI_CONFIG_WORD dx, Pci_ClassCode
cmp ax, cx
jz @spccm2_found_device
@spccm2_next_search:
inc dl
cmp dl, 0CFh
jbe @spccm2_loop
mov dl, 0C0h
inc dh
cmp dh, 0FFh ;Bus# 255 is not implemented
jne @spccm2_loop
mov dx, -1 ;not found any device
jmp @spccm2_exit
@spccm2_found_device:
cmp si, 0
jz @spccm2_exit
dec si
jmp @spccm2_next_search
@spccm2_exit:
;DX hold the device handle
;-------------------------
mov bx, dx
pop dx
pop cx
ret
SearchPCIClassCodeM2 endp
;******************************************************************************
;* SearchPCIDeviceM2()
;*
;* On Entry: EAX: Device ID + Vendor ID
;* SI: Index
;*
;* On Return: BX: Handle
;*
;******************************************************************************
SearchPCIDeviceM2 proc near
push ecx
push dx
mov ecx, eax ;store the Device ID
mov dl, (PCI_CONFIG_BASE_ADDRESS shr 8) ;search from C0-CF
mov dh, 0 ;forward bus #
@spdm2_loop:
READ_PCI_CONFIG_WORD dx, Pci_VendorID
cmp eax, ecx
jz @spdm2_found_device
@spdm2_next_search:
inc dl
cmp dl, 0CFh
jbe @spdm2_loop
mov dl, 0C0h
inc dh
cmp dh, 0FFh ;Bus# 255 is not implemented
jne @spdm2_loop
mov dx, -1 ;not found any device
jmp @spdm2_exit
@spdm2_found_device:
cmp si, 0
jz @spdm2_exit
dec si
jmp @spdm2_next_search
@spdm2_exit:
;DX hold the device handle
;-------------------------
mov bx, dx
pop dx
pop ecx
ret
SearchPCIDeviceM2 endp
;******************************************************************************
;* find_device_using_class_code(unsigned char, unsigned char *)
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
find_device_using_class_code proc near C, \
classcode: Word,
H_handle: NEAR PTR
push ax
push bx
push cx
mov ax, classcode ;class code
SEARCH_PCI_CLASS_CODE ax, 0
;BX hold the PCI access hanlde
;-----------------------------
mov ax, bx
mov bx, H_handle
mov Word Ptr [bx], ax
pop cx
pop bx
pop ax
ret
find_device_using_class_code endp
;******************************************************************************
;* open_bridge_card()
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
open_bridge_card proc near C, \
C_handle: Word,
context: NEAR PTR
push eax
push bx
mov bx, context
READ_PCI_CONFIG_WORD C_handle, Pci_Command
mov Word Ptr [bx].bcommand, ax
READ_PCI_CONFIG_WORD C_handle, Pci_CacheLineSize
mov Word Ptr [bx].blatency, ax
READ_PCI_CONFIG_DWORD C_handle, Pci_BusNumber
mov Dword Ptr [bx].bbus_number, eax
READ_PCI_CONFIG_WORD C_handle, Pci_BridgeIoBase
mov Word Ptr [bx].bio, ax
READ_PCI_CONFIG_DWORD C_handle, Pci_BridgeMemory
mov DWord Ptr [bx].bmemory, eax
READ_PCI_CONFIG_DWORD C_handle, Pci_BridgePrefetchMemory
mov DWord Ptr [bx].bpmemory, eax
READ_PCI_CONFIG_WORD C_handle, Pci_BridgeControl
mov Word Ptr [bx].bcontrol, ax
pop bx
pop eax
ret
open_bridge_card endp
;******************************************************************************
;* enable_bridge_card()
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
enable_bridge_card proc near C, \
C_handle: Word,
context: NEAR PTR
push eax
push edx
push bx
mov bx, context
mov dx, Word Ptr [bx].blatency
WRITE_PCI_CONFIG_WORD C_handle, Pci_CacheLineSize, dx
mov edx, Dword Ptr [bx].bbus_number
WRITE_PCI_CONFIG_DWORD C_handle, Pci_BusNumber, edx
mov dx, Word Ptr [bx].bio
WRITE_PCI_CONFIG_WORD C_handle, Pci_BridgeIoBase, dx
mov edx, DWord Ptr [bx].bmemory
WRITE_PCI_CONFIG_DWORD C_handle, Pci_BridgeMemory, edx
mov edx, DWord Ptr [bx].bpmemory
WRITE_PCI_CONFIG_DWORD C_handle, Pci_BridgePrefetchMemory, edx
;Reset the secondary bus
mov dx, Word Ptr [bx].bcontrol
or dx, 40h
WRITE_PCI_CONFIG_WORD C_handle, Pci_BridgeControl, dx
call Delay1us
;Reset complete
mov dx, Word Ptr [bx].bcontrol
WRITE_PCI_CONFIG_WORD C_handle, Pci_BridgeControl, dx
mov dx, Word Ptr [bx].bcommand
WRITE_PCI_CONFIG_WORD C_handle, Pci_Command, dx
pop bx
pop edx
pop eax
ret
enable_bridge_card endp
;******************************************************************************
;* find_en1207_card()
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
find_en1207_card proc near C, \
index: Word,
C_handle: NEAR PTR
push eax
push bx
push cx
mov cx, index
SEARCH_PCI_CLASS_CODE PCI_ETHERNET_CARD_CLASS_CODE, cx
;BX hold the PCI Access Hanlde
;-----------------------------
@fec_exit:
mov ax, bx
mov bx, C_handle
mov Word Ptr [bx], ax
pop cx
pop bx
pop eax
ret
find_en1207_card endp
;******************************************************************************
;* open_en1207_card()
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
open_en1207_card proc near C, \
C_handle: Word,
context: NEAR PTR
push eax
push bx
mov bx, context
READ_PCI_CONFIG_WORD C_handle, Pci_Command
mov Word Ptr [bx].pcommand, ax
READ_PCI_CONFIG_WORD C_handle, Pci_CacheLineSize
mov Word Ptr [bx].platency, ax
READ_PCI_CONFIG_DWORD C_handle, Pci_CBIO
and eax, 0FFF0h
mov Dword Ptr [bx].pio, eax
READ_PCI_CONFIG_BYTE C_handle, Pci_InterruptLine
mov Byte Ptr [bx].pirq, al
pop bx
pop eax
ret
open_en1207_card endp
;******************************************************************************
;* enable_en1207_card()
;*
;* On Entry:
;*
;* On Return: all regsiter reserved
;*
;******************************************************************************
enable_en1207_card proc near C, \
C_handle: Word,
context: NEAR PTR
push eax
push edx
push bx
mov bx, context
mov dx, Word Ptr [bx].platency
WRITE_PCI_CONFIG_WORD C_handle, Pci_CacheLineSize, dx
mov edx, Dword Ptr [bx].pio
or edx, 1
WRITE_PCI_CONFIG_DWORD C_handle, Pci_CBIO, edx
mov dl, Byte Ptr [bx].pirq
WRITE_PCI_CONFIG_BYTE C_handle, Pci_InterruptLine, dl
mov dx, Word Ptr [bx].pcommand
WRITE_PCI_CONFIG_WORD C_handle, Pci_Command, dx
pop bx
pop edx
pop eax
ret
enable_en1207_card endp
;;************************************************************************
find_nic proc near C, \
C_handle: NEAR PTR
push ax
push bx
push ecx
push si
push di
xor si,si
s_nic:
mov ah,0B1h
mov al,003h
mov ecx,20000h
int 01Ah
cmp ah,0
jz lb1
mov bx,C_handle
mov Word ptr [bx],0ffffh
jmp exit1
lb1: mov ax,0B10Ah
xor di,di
int 01Ah
cmp ecx,00091011h
je chk
cmp ecx,00191011h
jnz lb2
chk:
inc si
jmp s_nic
lb2:
mov ax,bx
mov bx,C_handle
mov Word ptr [bx],ax
exit1:
pop di
pop si
pop ecx
pop bx
pop ax
ret
find_nic endp
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -