1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2012 Return Infinity -- see LICENSE.TXT
6 ; =============================================================================
14 ; Search for a supported NIC
15 mov rsi
, NIC_DeviceVendor_ID
18 lodsd ; Load a driver ID - Low half must be 0xFFFF
19 init_net_probe_next_driver:
20 mov rdx
, rax
; Save the driver ID
21 init_net_probe_next_device:
22 lodsd ; Load a device and vendor ID from our list of supported NICs
23 cmp eax, 0x00000000 ; 0x00000000 means we have reached the end of the list
24 je init_net_probe_not_found
; No suported NIC found
25 cmp ax, 0xFFFF ; New driver ID?
26 je init_net_probe_next_driver
; We found the next driver type
27 call os_pci_find_device
; Returns BL = Bus number (8-bit value) and CL = Device/Slot number (5-bit value) if NIC was found
28 jnc init_net_probe_found
; If Carry is clear then we found a supported NIC
29 jmp init_net_probe_next_device
; Check the next device
33 je init_net_probe_found_rtl8169
35 je init_net_probe_found_i8254x
36 jmp init_net_probe_not_found
38 init_net_probe_found_rtl8169:
39 call os_net_rtl8169_init
40 mov rdi
, os_net_transmit
41 mov rax
, os_net_rtl8169_transmit
43 mov rax
, os_net_rtl8169_poll
45 mov rax
, os_net_rtl8169_ack_int
47 jmp init_net_probe_found_finish
49 init_net_probe_found_i8254x:
50 call os_net_i8254x_init
51 mov rdi
, os_net_transmit
52 mov rax
, os_net_i8254x_transmit
54 mov rax
, os_net_i8254x_poll
56 mov rax
, os_net_i8254x_ack_int
58 jmp init_net_probe_found_finish
60 init_net_probe_found_finish:
63 push rax
; Save the IRQ
68 pop rax
; Restore the IRQ
71 bts rax
, 13 ; 1=Low active
72 bts rax
, 15 ; 1=Level sensitive
73 call ioapic_entry_write
75 mov byte [os_NetEnabled
], 1 ; A supported NIC was found. Signal to the OS that networking is enabled
76 call os_ethernet_ack_int
; Call the driver function to acknowledge the interrupt internally
78 init_net_probe_not_found:
83 ; =============================================================================