@@ -17,6 +17,8 @@ net_virtio_init:
1717 push rbx
1818 push rax
1919
20+ push rdx ; Save packed bus address
21+
2022 mov rdi , net_table
2123 xor eax , eax
2224 mov al , [ os_net_icount ]
@@ -25,7 +27,7 @@ net_virtio_init:
2527
2628 mov ax , 0x1AF4 ; Driver tag for virtio-net
2729 stosw
28- push rdi ; Used in msi-x init
30+ push rdi ; Save offset into net_table
2931 add rdi , 14
3032
3133 ; Get the Base Memory Address of the device
@@ -58,60 +60,9 @@ virtio_net_init_cap_next:
5860 call os_bus_read
5961 cmp al , VIRTIO_PCI_CAP_VENDOR_CFG
6062 je virtio_net_init_cap
61- cmp al , 0x11
62- je virtio_net_init_msix
6363 shr eax , 8
6464 jmp virtio_net_init_cap_next_offset
6565
66- virtio_net_init_msix:
67- push rdx
68-
69- ; Enable MSI-X, Mask it, Get Table Size
70- call os_bus_read
71- mov ecx , eax ; Save for Table Size
72- bts eax , 31 ; Enable MSIX
73- bts eax , 30 ; Set Function Mask
74- call os_bus_write
75- shr ecx , 16 ; Shift Message Control to low 16-bits
76- and cx , 0x7FF ; Keep bits 10:0
77-
78- ; Read the BIR and Table Offset
79- push rdx
80- add dl , 1
81- call os_bus_read
82- mov ebx , eax ; EBX for the Table Offset
83- and ebx , 0xFFFFFFF8 ; Clear bits 2:0
84- and eax , 0x00000007 ; Keep bits 2:0 for the BIR
85- add al , 0x04 ; Add offset to start of BARs
86- mov dl , al
87- call os_bus_read ; Read the BAR address
88- add rax , rbx ; Add offset to base
89- mov rdi , rax
90- pop rdx
91-
92- ; Configure MSI-X Table
93- add cx , 1 ; Table Size is 0-indexed
94- virtio_net_init_msix_entry:
95- mov rax , [ os_LocalAPICAddress ] ; 0xFEE for bits 31:20, Dest (19:12), RH (3), DM (2)
96- stosd ; Store Message Address Low
97- shr rax , 32 ; Rotate the high bits to EAX
98- stosd ; Store Message Address High
99- mov eax , 0x000040AB ; Trigger Mode (15), Level (14), Delivery Mode (10:8), Vector (7:0)
100- stosd ; Store Message Data
101- xor eax , eax ; Bits 31:1 are reserved, Masked (0) - 1 for masked
102- stosd ; Store Vector Control
103- dec cx
104- cmp cx , 0
105- jne virtio_net_init_msix_entry
106- pop rdx
107-
108- ; Unmask MSI-X
109- call os_bus_read
110- btc eax , 30 ; Clear Function Mask
111- call os_bus_write
112-
113- jmp virtio_net_init_cap_next_offset
114-
11566virtio_net_init_cap:
11667 rol eax , 8 ; Move Virtio cfg_type to AL
11768 cmp al , VIRTIO_PCI_CAP_COMMON_CFG
@@ -197,6 +148,27 @@ virtio_net_init_cap_end:
197148 mov dl , [ os_net_icount ]
198149 call net_virtio_reset
199150
151+ ; Enable interrupts
152+ pop rdx ; Restore packed bus address
153+ ; mov al, 0x40
154+ ; call msix_init
155+ ; jc virtio_net_init_no_int
156+ ; Create a gate in the IDT
157+ ; mov edi, 0x40
158+ ; mov rax, net_virtio_int
159+ ; call create_gate
160+ ; mov edi, 0x41
161+ ; mov rax, net_virtio_int
162+ ; call create_gate
163+ ; mov edi, 0x42
164+ ; mov rax, net_virtio_int
165+ ; call create_gate
166+ ; mov edi, 0x43
167+ ; mov rax, net_virtio_int
168+ ; call create_gate
169+
170+ virtio_net_init_no_int:
171+
200172 ; Store call addresses
201173 sub rdi , 0x28
202174 mov eax , net_virtio_config
@@ -583,6 +555,8 @@ net_virtio_int:
583555 push rax
584556
585557 ; Clear pending interrupt (if set)
558+ mov al , 0xab
559+ call os_debug_dump_al
586560
587561 ; Acknowledge the interrupt
588562 mov ecx , APIC_EOI
0 commit comments