* mikeOS 16 bit and amd64 baremetal
[mascara-docs.git] / amd64 / bareMetalOS-0.5.2 / baremetal0.5.2 / os / init_net.asm
blobca32c4890f1bd077a6bee832d37233240f40064d
1 ; =============================================================================
2 ; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2011 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 device and vendor ID from our list of supported NICs
19 cmp eax, 0x00000000 ; 0x00000000 means we have reached the end of the list
20 je init_net_probe_not_found ; No suported NIC found
21 call os_pci_find_device ; Returns BL = Bus number (8-bit value) and CL = Device/Slot number (5-bit value) if NIC was found
22 jnc init_net_probe_found ; If Carry is clear then we found a supported NIC
23 add rsi, 4 ; Skip the device type
24 jmp init_net_probe_next
26 init_net_probe_found:
27 lodsd ; Load the device type
28 cmp eax, 0x00008169
29 je init_net_probe_found_rtl8169
30 cmp eax, 0x00008254
31 je init_net_probe_found_i8254x
32 jmp init_net_probe_not_found
34 init_net_probe_found_rtl8169:
35 call os_net_rtl8169_init
36 mov rdi, os_net_transmit
37 mov rax, os_net_rtl8169_transmit
38 stosq
39 mov rax, os_net_rtl8169_poll
40 stosq
41 mov rax, os_net_rtl8169_ack_int
42 stosq
43 jmp init_net_probe_found_finish
45 init_net_probe_found_i8254x:
46 call os_net_i8254x_init
47 mov rdi, os_net_transmit
48 mov rax, os_net_i8254x_transmit
49 stosq
50 mov rax, os_net_i8254x_poll
51 stosq
52 mov rax, os_net_i8254x_ack_int
53 stosq
54 jmp init_net_probe_found_finish
56 init_net_probe_found_finish:
57 xor rax, rax
58 mov al, [os_NetIRQ]
59 add al, 0x20
60 mov rdi, rax
61 mov rax, network
62 call create_gate
63 mov byte [os_NetEnabled], 1 ; A supported NIC was found. Signal to the OS that networking is enabled
65 init_net_probe_not_found:
67 ret
70 ; =============================================================================
71 ; EOF