aboutsummaryrefslogtreecommitdiffstats
path: root/src/kernel/pci.asm
blob: 63ff3df0b9f6e88df8383ffaddc8328de9ee5b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; pci.asm
;; PCI Bus

%define PCI_ENABLE 0x80000000
%define PCI_CONFIG_ADDR_1 0xcf8
%define PCI_CONFIG_ADDR_2 0xcfc
%define PCI_SLOT_EMPTY 0xffff
%define PCI_SLOT_COUNT 32
        
pci_config_read_word:   
        enter
        movzx ebx, word [ebp + 8]          ; bus
        movzx edx, word [ebp + 12]         ; slot
        movzx ecx, word [ebp + 16]         ; func
        movzx eax, word [ebp + 20]         ; offset
        
        shl ebx, 16
        shl edx, 11
        shl ecx, 8
        and eax, 0xfc

        or eax, ecx
        or eax, edx
        or eax, ebx
        or eax, 0x80000000

        mov dx, PCI_CONFIG_ADDR_1 ; write address
        out dx, eax

        mov dx, PCI_CONFIG_ADDR_2 ; read data
        in dx, eax

        movzx ecx, word [ebp + 20] ; offset
        and ecx, 2
        imul ecx, ecx, 8
        shr eax, cl
        and ax, 0xffff

        leave
        ret

pci_config_get_vendor:
        enter
        movzx ebx, word [ebp + 8] ; bus
        movzx edx, word [ebp + 12] ; device
        movzx ecx, word [ebp + 16] ; func
        
        push 0
        push ecx
        push edx
        push ebx
        call pci_config_read_word

        leave
        ret

pci_config_get_device:
        enter
        movzx ebx, word [ebp + 8] ; bus
        movzx edx, word [ebp + 12] ; device
        movzx ecx, word [ebp + 16] ; func
        
        push 2
        push ecx
        push edx
        push ebx

        call pci_config_read_word
        leave
        ret

pci_config_get_class:
        enter
        movzx ebx, word [ebp + 8] ; bus
        movzx edx, word [ebp + 12] ; device
        movzx ecx, word [ebp + 16] ; func
        
        push 0xa
        push ecx
        push edx
        push ebx
        call pci_config_read_word

        xor esi, esi
        not esi, 0xff00
        and eax, esi

        leave
        ret