* remove "\r" nonsense
[mascara-docs.git] / amd64 / bareMetalOS-0.5.3 / os / init_net.asm
blob756e21879b8e612b67f84073c177b12f65ce16c7
1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2012 Return Infinity -- see LICENSE.TXT
5 ; INIT_NET
6 ; =============================================================================
8 align 16
9 db 'DEBUG: INIT_NET '
10 align 16
13 init_net:
14 ; Search for a supported NIC
15 mov rsi, NIC_DeviceVendor_ID
17 init_net_probe_next:
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
31 init_net_probe_found:
32 cmp edx, 0x8169FFFF
33 je init_net_probe_found_rtl8169
34 cmp edx, 0x8254FFFF
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
42 stosq
43 mov rax, os_net_rtl8169_poll
44 stosq
45 mov rax, os_net_rtl8169_ack_int
46 stosq
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
53 stosq
54 mov rax, os_net_i8254x_poll
55 stosq
56 mov rax, os_net_i8254x_ack_int
57 stosq
58 jmp init_net_probe_found_finish
60 init_net_probe_found_finish:
61 xor eax, eax
62 mov al, [os_NetIRQ]
63 push rax ; Save the IRQ
64 add al, 0x20
65 mov rdi, rax
66 mov rax, network
67 call create_gate
68 pop rax ; Restore the IRQ
69 mov rcx, rax
70 add rax, 0x20
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:
80 ret
83 ; =============================================================================
84 ; EOF