It needs to be written in Assembly as the rest of the OS is in Assembly.
I would have thought it to be more important to get the funding before announcing the bounty. The money will be returned if there are no takers. Paypal stated that it could be refunded within 60 days without penalty.
Another thing to note is that the core functionality will need to translate to BSD sockets at the C/C++ application level. So functions like send, recv, accept, bind, listen, and connect will need to be implemented. UDP is not required at the moment. BareMetal OS already has functionality to send and receive raw Ethernet frames:
Code:
; os_ethernet_tx -- Transmit a packet via Ethernet
; IN: RSI = Memory location where data is stored
; RDI = Pointer to 48 bit destination address
; BX = Type of packet (If set to 0 then the EtherType will be set to the length of data)
; CX = Length of data
; OUT: Nothing. All registers preserved
The TCP handler would need split the data into Ethernet packets (as well as reassemble them) and handle the SYN/ACK communication.
I'm thinking of functions like:
os_tcp_open
os_tcp_close
os_tcp_send
os_tcp_recv
os_tcp_listen
os_tcp_accept
This should be a pretty good challenge and I'm interested to see what someone else can do. I wrote the incoming ICMP handler but TCP is a bit beyond me at the moment with all the handshakes and error correction.
Here is my ICMP code:
Code:
; -----------------------------------------------------------------------------
; os_icmp_handler -- Handle an incoming ICMP packet
; IN: RCX = packet length
; RSI = location of received ICMP packet
os_icmp_handler:
push rsi
push rax
; Check if reply or request
; Swap the MAC addresses
mov rax, [rsi] ; Grab the Destination MAC as 8 bytes even though the MAC is 6 bytes
mov ax, [rsi+0x0C] ; Store the EtherType in the low 16-bits of RAX
push rax ; Save the new Source MAC (with EtherType) to the stack
mov rax, [rsi+0x06] ; Grab the Source MAC as 8 bytes (the last two bytes will be overwritten)
mov [rsi], rax ; Store the new Destination MAC in the packet
pop rax ; Restore the new Source MAC + EtherType
mov [rsi+0x06], rax ; Write it to the packet
; Swap the IP addresses
mov eax, [rsi+0x1A] ; Grab the Source IP
push rax
mov eax, [rsi+0x1E] ; Grab the Destination IP
mov dword [rsi+0x1A], eax ; Overwrite the 'old' Source with the 'new' Source
pop rax
mov dword [rsi+0x1E], eax ; Overwrite the 'old' Destination with the 'new' Destination
; Set to Echo Reply
mov byte [rsi+0x22], 0x00 ; Set to 0 for Echo Reply (Was originally 8 for Echo Request)
; Adjust the checksum
mov ax, [rsi+0x24]
add ax, 8 ; Add 8 since we removed 8 (by clearing the Echo Request)
mov word [rsi+0x24], ax
call os_ethernet_tx_raw ; Send the packet
pop rax
pop rsi
ret
; -----------------------------------------------------------------------------
Best regards,
Ian Seyler