Skip to content

Commit 8bdc835

Browse files
author
Ian Seyler
committed
Interrupt fires on packet receive
1 parent d4d3a2d commit 8bdc835

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

src/drivers/msi.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ msix_init_enable:
7676

7777
; Configure MSI-X Table
7878
add cx, 1 ; Table Size is 0-indexed
79-
mov ebx, 0x00004000 ; Trigger Mode (15), Level (14), Delivery Mode (10:8), Vector (7:0)
79+
xor ebx, ebx ; Trigger Mode (15), Level (14), Delivery Mode (10:8), Vector (7:0)
8080
mov bl, r8b ; Store start vector
8181
msix_init_create_entry:
8282
mov rax, [os_LocalAPICAddress] ; 0xFEE for bits 31:20, Dest (19:12), RH (3), DM (2)

src/drivers/net/virtio-net.asm

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ net_virtio_init:
1717
push rbx
1818
push rax
1919

20-
push rdx ; Save packed bus address
20+
; push rdx ; Save packed bus address
2121

2222
mov rdi, net_table
2323
xor eax, eax
@@ -42,9 +42,36 @@ net_virtio_init:
4242
mov dl, 0x01 ; Read Status/Command
4343
call os_bus_read
4444
bts eax, 10 ; Set Interrupt Disable
45+
bts eax, 2 ; Enable Bus Master
4546
bts eax, 1 ; Enable Memory Space
4647
call os_bus_write
4748

49+
; Configure MSI-X (if available)
50+
mov al, 0xB0
51+
call msix_init
52+
jc net_virtio_init_skip_int
53+
54+
; Create gate(s) in the IDT
55+
push rdi
56+
sub rdi, 0x1C
57+
mov ax, 0x0001 ; Set flag for nt_interrupt
58+
stosw
59+
mov edi, 0xB0
60+
mov rax, net_virtio_int
61+
call create_gate
62+
mov edi, 0xB1
63+
mov rax, net_virtio_int
64+
call create_gate
65+
; mov edi, 0xB2
66+
; mov rax, net_virtio_int
67+
; call create_gate
68+
; mov edi, 0xB3
69+
; mov rax, net_virtio_int
70+
; call create_gate
71+
pop rdi
72+
73+
net_virtio_init_skip_int:
74+
4875
; Get required values from PCI Capabilities
4976
mov dl, 1
5077
call os_bus_read ; Read register 1 for Status/Command
@@ -148,30 +175,6 @@ virtio_net_init_cap_end:
148175
mov dl, [os_net_icount]
149176
call net_virtio_reset
150177

151-
; Enable interrupts
152-
pop rdx ; Restore packed bus address
153-
mov al, 0xB0
154-
call msix_init
155-
jc virtio_net_init_no_int
156-
157-
; Create gate(s) in the IDT
158-
push rdi
159-
mov edi, 0xB0
160-
mov rax, net_virtio_int
161-
call create_gate
162-
mov edi, 0xB1
163-
mov rax, net_virtio_int
164-
call create_gate
165-
; mov edi, 0xB2
166-
; mov rax, net_virtio_int
167-
; call create_gate
168-
; mov edi, 0xB3
169-
; mov rax, net_virtio_int
170-
; call create_gate
171-
pop rdi
172-
173-
virtio_net_init_no_int:
174-
175178
; Store call addresses
176179
sub rdi, 0x28
177180
mov eax, net_virtio_config
@@ -555,7 +558,7 @@ align 8
555558
net_virtio_int:
556559
push rcx
557560
push rax
558-
jmp $
561+
559562
; Clear pending interrupt (if set)
560563
mov al, 0xab
561564
call os_debug_dump_al

0 commit comments

Comments
 (0)