diff --git a/build/build-iso.sh b/build/build-iso.sh index 2868c9db..3535c830 100755 --- a/build/build-iso.sh +++ b/build/build-iso.sh @@ -64,7 +64,7 @@ umount_tempdisk echo "Rebuilding kernel headers, kernel, OS, and building Distro ISO ..." $QEMU_BIN_PATH/qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -smp 4 -device isa-debug-exit -LIMINE_BINARY_BRANCH="v5.x-branch-binary" +LIMINE_BINARY_BRANCH="v6.x-branch-binary" if [ -d "limine" ] then diff --git a/src/Home/Net/Drivers/PCNet.ZC b/src/Home/Net/Drivers/PCNet.ZC index d3c7c344..7ca8b800 100755 --- a/src/Home/Net/Drivers/PCNet.ZC +++ b/src/Home/Net/Drivers/PCNet.ZC @@ -563,6 +563,11 @@ I64 PCNetTransmitPacketAllocate(U8 **packet_buffer_out, I64 length) return de_index; } +U8 *EthernetMACGet() +{ + return pcnet.mac_address; +} + U0 PCNetTransmitPacketFinish(I64 de_index) {/* Release ownership of the packet to the PCNet card by setting the OWN bit to 1. */ @@ -574,11 +579,23 @@ U0 PCNetTransmitPacketFinish(I64 de_index) de_index, PCIBt(&entry->status1, PCNET_DESCRIPTORf_OWN)); } -U0 EthernetFrameFinish(I64 de_index) -{//Alias for driver Finish TX function. +U0 NetDriverTransmitPacketFinish(I64 de_index) +{//Alias for driver-specific Finish TX function. PCNetTransmitPacketFinish(de_index); } +I64 NetDriverPacketBufferGet(I64 de_index) +{ + return pcnet.tx_buffer_addr_phys + de_index * ETHERNET_FRAME_SIZE; +} + +I64 NetDriverPacketLengthGet(I64 de_index) +{ + CPCNetDescriptorEntry *entry = &pcnet.tx_de_buffer[de_index * sizeof(CPCNetDescriptorEntry)]; + + return U16_MAX - (entry->status1 & 0xFFFF) + 1; +} + I64 PCNetPacketReceive(U8 **packet_buffer_out, U16 *packet_length_out) {/* Receives the packet at the current RX DE index. Parameters are both pointers, since we modify the value at the packet_buffer_out, @@ -809,11 +826,6 @@ I64 EthernetFrameAllocate(U8 **packet_buffer_out, return de_index; } -U8 *EthernetMACGet() -{ - return pcnet.mac_address; -} - U0 NetStop() { // Halt network activity by setting STOP bit on Status CSR. U32 csr = PCNetCSRRead(PCNET_CSR_CTRLSTATUS); diff --git a/src/Home/Net/Drivers/VirtIONet.ZC b/src/Home/Net/Drivers/VirtIONet.ZC index 31541648..c858eaf9 100755 --- a/src/Home/Net/Drivers/VirtIONet.ZC +++ b/src/Home/Net/Drivers/VirtIONet.ZC @@ -167,15 +167,15 @@ I64 EthernetFrameAllocate(U8 **buffer_out, U8 *src_addr, U8 *dst_addr, I64 index; - if (!MemCompare(dst_addr, &VirtioNet.mac, 6)) { - frame = loopback_frame; - loopback_length = length; - index = I64_MAX; - } else { +// if (!MemCompare(dst_addr, &VirtioNet.mac, 6)) { +// frame = loopback_frame; +// loopback_length = length; +// index = I64_MAX; +// } else { index = @virtio_net_alloc_tx_packet(&frame, 14 + length/*, flags*/); if (index < 0) return index; - } +// } MemCopy(frame + 0, dst_addr, 6); MemCopy(frame + 6, src_addr, 6); @@ -186,15 +186,26 @@ I64 EthernetFrameAllocate(U8 **buffer_out, U8 *src_addr, U8 *dst_addr, return index; } -I64 EthernetFrameFinish(I64 index) { - if (index == I64_MAX && loopback_frame && loopback_length) { - NetQueuePush(loopback_frame, loopback_length); - loopback_length = 0; - return 0; - } +//I64 EthernetFrameFinish(I64 index) { +I64 NetDriverTransmitPacketFinish(I64 index) { +// if (index == I64_MAX && loopback_frame && loopback_length) { +// NetQueuePush(loopback_frame, loopback_length); +// loopback_length = 0; +// return 0; +// } return @virtio_net_finish_tx_packet(index); } +I64 NetDriverPacketBufferGet(I64 de_index) +{ + return tx_buffers + de_index * ETHERNET_FRAME_SIZE; +} + +I64 NetDriverPacketLengthGet(I64 de_index) +{ // TODO: ... de_index in Alec's VirtIO-Net driver don't match up to any way to get packet length... + return ETHERNET_FRAME_SIZE; +} + U8 *EthernetMACGet() { return &VirtioNet.mac; } I64 @virtio_net_init() { diff --git a/src/Home/Net/Programs/TCPChatClient.ZC b/src/Home/Net/Programs/TCPChatClient.ZC index 2d8d6a68..4ae33e9f 100755 --- a/src/Home/Net/Programs/TCPChatClient.ZC +++ b/src/Home/Net/Programs/TCPChatClient.ZC @@ -24,8 +24,8 @@ U0 ChatMessageTask(I64) while (message = StrGet("> ",, SGF_SHIFT_ESC_EXIT)) { DocBottom(chat_display_task->put_doc); - DocPrint(chat_display_task->put_doc, - "$$BG,BLUE$$$$BLACK$$$$FG$$$$BG$$ %s\n", message); +// DocPrint(chat_display_task->put_doc, +// "$$BG,BLUE$$$$BLACK$$$$FG$$$$BG$$ %s\n", message); TCPSocketSendString(tcp, message); diff --git a/src/Home/Net/Programs/TCPChatServer.ZC b/src/Home/Net/Programs/TCPChatServer.ZC index db21e363..f7c2935c 100755 --- a/src/Home/Net/Programs/TCPChatServer.ZC +++ b/src/Home/Net/Programs/TCPChatServer.ZC @@ -37,7 +37,7 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length) { dest_socket = conn->socket; - if (dest_socket != tcp_socket) +// if (dest_socket != tcp_socket) { addr.address = EndianU32(dest_socket->destination_address(CSocketAddressIPV4).address.address); @@ -51,7 +51,10 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length) ip_string = NetworkToPresentation(AF_INET, &addr); // TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ? - message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s>$$FG$$$$BG$$ %%0%dts", ip_string, length); + if (dest_socket == tcp_socket) + message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s (you)>$$FG$$$$BG$$ %%0%dts", ip_string, length); + else + message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s>$$FG$$$$BG$$ %%0%dts", ip_string, length); message = MStrPrint(message_prefix, buffer); diff --git a/src/Home/Net/Protocols/ARP.ZC b/src/Home/Net/Protocols/ARP.ZC index 1a80cfb7..347b470c 100755 --- a/src/Home/Net/Protocols/ARP.ZC +++ b/src/Home/Net/Protocols/ARP.ZC @@ -127,9 +127,11 @@ CARPHash *ARPCachePut(U32 ip_address, U8 *mac_address) } U0 ARPLocalIPV4Set(U32 ip_address) -{ // takes in little endian IP, stores into globals as Big Endian +{ // takes in little endian IP, stores into arp_globals as Big Endian and into ARP cache as Little Endian arp_globals.local_ipv4 = EndianU32(ip_address); + ARPCachePut(ip_address, EthernetMACGet); + ARPSend(ARP_REPLY, ethernet_globals.ethernet_broadcast, EthernetMACGet, diff --git a/src/Home/Net/Protocols/Ethernet.ZC b/src/Home/Net/Protocols/Ethernet.ZC index 801ac2aa..3a4de9f0 100755 --- a/src/Home/Net/Protocols/Ethernet.ZC +++ b/src/Home/Net/Protocols/Ethernet.ZC @@ -1,8 +1,8 @@ class CEthernetFrame { - U8 source_address[6]; + U8 source_address[MAC_ADDRESS_LENGTH]; U8 padding[2]; - U8 destination_address[6]; + U8 destination_address[MAC_ADDRESS_LENGTH]; U16 ethertype; U8 *data; @@ -12,15 +12,15 @@ class CEthernetFrame class CEthernetGlobals { - U8 ethernet_null[6]; - U8 ethernet_broadcast[6]; + U8 ethernet_null[MAC_ADDRESS_LENGTH]; + U8 ethernet_broadcast[MAC_ADDRESS_LENGTH]; } ethernet_globals; U0 EthernetGlobalsInit() { I64 i; - for (i = 0; i < 6; i++) + for (i = 0; i < MAC_ADDRESS_LENGTH; i++) { ethernet_globals.ethernet_null[i] = 0; ethernet_globals.ethernet_broadcast[i] = 0xFF; @@ -52,4 +52,19 @@ U0 EthernetFrameParse(CEthernetFrame *frame_out, U8 *frame, U16 length) frame_out->length = length - ETHERNET_MAC_HEADER_LENGTH - 4; // He has a comment literally just saying "??". + or - 4? } -EthernetGlobalsInit; \ No newline at end of file +U0 EthernetFrameFinish(I64 de_index) +{//Alias for generic driver Finish TX function. + U8 *data = NetDriverPacketBufferGet(de_index); + I64 length = NetDriverPacketLengthGet(de_index); + U8 *mac = EthernetMACGet(); + Bool is_loopback = !MemCompare(mac, data, MAC_ADDRESS_LENGTH); // check the TX packet MAC against local MAC + + // software loopback the TX packet to RX NetQueue if it's loopback + if (is_loopback) + NetQueueLazyPush(data, length); + + NetDriverTransmitPacketFinish(de_index); + +} + +EthernetGlobalsInit; diff --git a/src/Home/Net/Utilities/NetQueue.ZC b/src/Home/Net/Utilities/NetQueue.ZC index 1e709dda..c6eddb41 100755 --- a/src/Home/Net/Utilities/NetQueue.ZC +++ b/src/Home/Net/Utilities/NetQueue.ZC @@ -68,5 +68,32 @@ U0 NetQueuePush(U8 *data, I64 length) MPInt(I_NETHANDLER, INT_DEST_CPU); } +U0 NetQueueLazyPull() +{ + PUSHFD + CLI + + if (net_queue->next != net_queue) + { + NetLog("NETQUEUE LAZY PULL: Generating NetHandler interrupt."); + MPInt(I_NETHANDLER, INT_DEST_CPU); + } + + POPFD +} + +U0 NetQueueLazyPush(U8 *data, I64 length) +{ // Push into NetQueue, don't trigger interrupt in this func. + // Trigger interrupt by Spawn-ing another Task to check queue. + + CNetQueueEntry *entry = CAlloc(sizeof(CNetQueueEntry)); + + entry->packet_length = length; + MemCopy(entry->frame, data, length); + QueueInsert(entry, net_queue->last); + + Spawn(&NetQueueLazyPull,, "NetQueueLazyPull"); +} + +NetQueueInit; -NetQueueInit; \ No newline at end of file diff --git a/src/Kernel/KGlobals.ZC b/src/Kernel/KGlobals.ZC index c372e793..bc646ec1 100755 --- a/src/Kernel/KGlobals.ZC +++ b/src/Kernel/KGlobals.ZC @@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed CDate local_time_offset; F64 *pow10_I64, sys_os_version = 2.03; -U64 sys_os_version_sub = 107; +U64 sys_os_version_sub = 108; U8 *sys_os_version_str; U8 *sys_os_version_full; U8 *sys_os_version_nice; diff --git a/src/System/Define.ZC b/src/System/Define.ZC index 901ce1bc..d9411781 100755 --- a/src/System/Define.ZC +++ b/src/System/Define.ZC @@ -15,7 +15,7 @@ U0 LoadDocDefines() //$LK,"DD_BOOT_HIGH_LOC_DVD",A="FF:::/System/Boot/BootDVD.ZC,DD_BOOT_HIGH_LOC_DVD"$ $TR,"LineRep"$ -$ID,2$DefinePrint("DD_ZEALOS_LOC","98,756"); +$ID,2$DefinePrint("DD_ZEALOS_LOC","99,737"); $ID,-2$ DefinePrint("DD_MP_VECT", "%08X", MP_VECT_ADDR); DefinePrint("DD_MP_VECT_END", "%08X", MP_VECT_ADDR + COREAP_16BIT_INIT_END - COREAP_16BIT_INIT - 1);