PCI enumerator; save ebx/esi in pci_{read,write}_reg

git-svn-id: svn://kolibrios.org@3393 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2013-03-19 21:41:56 +00:00
parent 75ae4a827a
commit 8c506bcc45
3 changed files with 89 additions and 12 deletions

View File

@ -155,12 +155,12 @@ pci_make_config_cmd:
align 4 align 4
pci_read_reg: pci_read_reg:
push ebx esi
cmp byte [BOOT_VAR+0x9020], 2;what mechanism will we use? cmp byte [BOOT_VAR+0x9020], 2;what mechanism will we use?
je pci_read_reg_2 je pci_read_reg_2
; mechanism 1 ; mechanism 1
push esi ; save register size into ESI mov esi, eax ; save register size into ESI
mov esi, eax
and esi, 3 and esi, 3
call pci_make_config_cmd call pci_make_config_cmd
@ -202,15 +202,14 @@ pci_fin_read1:
out dx, eax out dx, eax
pop eax pop eax
pop esi pop esi ebx
ret ret
pci_read_reg_2: pci_read_reg_2:
test bh, 128 ;mech#2 only supports 16 devices per bus test bh, 128 ;mech#2 only supports 16 devices per bus
jnz pci_read_reg_err jnz pci_read_reg_err
push esi; save register size into ESI mov esi, eax ; save register size into ESI
mov esi, eax
and esi, 3 and esi, 3
push eax push eax
@ -262,12 +261,13 @@ pci_fin_read2:
out dx, al out dx, al
pop eax pop eax
pop esi pop esi ebx
ret ret
pci_read_reg_err: pci_read_reg_err:
xor eax, eax xor eax, eax
dec eax dec eax
pop esi ebx
ret ret
@ -286,12 +286,12 @@ pci_read_reg_err:
align 4 align 4
pci_write_reg: pci_write_reg:
push esi ebx
cmp byte [BOOT_VAR+0x9020], 2;what mechanism will we use? cmp byte [BOOT_VAR+0x9020], 2;what mechanism will we use?
je pci_write_reg_2 je pci_write_reg_2
; mechanism 1 ; mechanism 1
push esi ; save register size into ESI mov esi, eax ; save register size into ESI
mov esi, eax
and esi, 3 and esi, 3
call pci_make_config_cmd call pci_make_config_cmd
@ -335,7 +335,7 @@ pci_fin_write1:
out dx, eax out dx, eax
xor eax, eax xor eax, eax
pop esi pop ebx esi
ret ret
pci_write_reg_2: pci_write_reg_2:
@ -344,8 +344,7 @@ pci_write_reg_2:
jnz pci_write_reg_err jnz pci_write_reg_err
push esi; save register size into ESI mov esi, eax ; save register size into ESI
mov esi, eax
and esi, 3 and esi, 3
push eax push eax
@ -397,12 +396,13 @@ pci_fin_write2:
out dx, al out dx, al
xor eax, eax xor eax, eax
pop esi pop ebx esi
ret ret
pci_write_reg_err: pci_write_reg_err:
xor eax, eax xor eax, eax
dec eax dec eax
pop ebx esi
ret ret
if defined mmio_pci_addr ; must be set above if defined mmio_pci_addr ; must be set above
@ -658,3 +658,67 @@ sys_pcibios:
.return_a: .return_a:
mov dword[esp + 32], eax mov dword[esp + 32], eax
ret ret
proc pci_enum
push ebp
mov ebp, esp
push 0
virtual at ebp-4
.devfn db ?
.bus db ?
end virtual
.loop:
mov ah, [.bus]
mov al, 2
mov bh, [.devfn]
mov bl, 0
call pci_read_reg
cmp eax, 0xFFFFFFFF
jnz .has_device
test byte [.devfn], 7
jnz .next_func
jmp .no_device
.has_device:
push eax
push sizeof.PCIDEV
pop eax
call malloc
pop ecx
test eax, eax
jz .nomemory
mov edi, eax
mov [edi+PCIDEV.vendor_device_id], ecx
mov eax, pcidev_list
mov ecx, [eax+PCIDEV.bk]
mov [edi+PCIDEV.bk], ecx
mov [edi+PCIDEV.fd], eax
mov [ecx+PCIDEV.fd], edi
mov [eax+PCIDEV.bk], edi
mov eax, dword [.devfn]
mov word [edi+PCIDEV.devfn], ax
mov bh, al
mov al, 2
mov bl, 8
call pci_read_reg
shr eax, 8
mov [edi+PCIDEV.class], eax
test byte [.devfn], 7
jnz .next_func
mov ah, [.bus]
mov al, 0
mov bh, [.devfn]
mov bl, 0Eh
call pci_read_reg
test al, al
js .next_func
.no_device:
or byte [.devfn], 7
.next_func:
inc dword [.devfn]
mov ah, [.bus]
cmp ah, [BOOT_VAR+0x9021]
jbe .loop
.nomemory:
leave
ret
endp

View File

@ -570,6 +570,15 @@ struct MUTEX
count dd ? count dd ?
ends ends
struct PCIDEV
bk dd ?
fd dd ?
vendor_device_id dd ?
class dd ?
devfn db ?
bus db ?
ends
struct MEM_STATE struct MEM_STATE
mutex MUTEX mutex MUTEX
smallmap dd ? smallmap dd ?

View File

@ -181,6 +181,10 @@ dll_list:
.bk dd dll_list .bk dd dll_list
.fd dd dll_list .fd dd dll_list
pcidev_list:
.bk dd pcidev_list
.fd dd pcidev_list
MAX_DEFAULT_DLL_ADDR = 0x80000000 MAX_DEFAULT_DLL_ADDR = 0x80000000
MIN_DEFAULT_DLL_ADDR = 0x70000000 MIN_DEFAULT_DLL_ADDR = 0x70000000
dll_cur_addr dd MIN_DEFAULT_DLL_ADDR dll_cur_addr dd MIN_DEFAULT_DLL_ADDR