Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,26 @@ add_custom_target(run
-vga vmware
-enable-kvm
-cdrom ${CMAKE_CURRENT_BINARY_DIR}/VoidFrame.iso
-debugcon file:bootstrap.log
-serial stdio
-no-reboot -no-shutdown
-m 4G
-drive file=VoidFrameDisk.img,if=ide
-drive file=SataDisk.img,if=none,id=sata0
-device ahci,id=ahci
-device ide-hd,drive=sata0,bus=ahci.0
-boot d
-device rtl8139
-device e1000
# Debug console and serial output
-debugcon file:bootstrap.log
-serial stdio
-parallel file:printer.out
# Network configuration
-netdev user,id=net0 -device rtl8139,netdev=net0
# USB controller and tablet
-device nec-usb-xhci,id=xhci
-device ich9-intel-hda
-usb -device usb-tablet
# Audio device
-audio pa,id=myaudio
# Disks configuration
-drive file=VoidFrameDisk.img,if=ide
-drive file=SataDisk.img,if=none,id=sata0
-device ahci,id=ahci
-device ide-hd,drive=sata0,bus=ahci.0
-device sb16,iobase=0x220,irq=5,dma=1,dma16=5
-parallel file:printer.out
-drive file=VirtioDisk.img,format=raw,id=virtio_disk,if=none
-device virtio-blk-pci,drive=virtio_disk,disable-legacy=on
-drive file=NVMeDisk.img,format=raw,id=nvme_disk,if=none
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/linux-x64.cmake \
-G Ninja \
-DVF_SCHEDULER=EEVDF
-G Ninja
ccmake . # Optinal, tune as needed
ninja -j$(nproc)
ninja run
Expand Down
11 changes: 10 additions & 1 deletion arch/x86_64/features/x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,24 @@ void CpuInit(void) {
// Most importantly, check if the CPU supports OSXSAVE (bit 27 of ECX).
// If this is not set, the OS is not allowed to set XCR0 to enable AVX.
cpu_features.osxsave = (ecx >> 27) & 1;
#ifndef VF_CONFIG_VM_HOST
if (!cpu_features.osxsave) {
PrintKernelWarning("System: CPU: OSXSAVE not supported. AVX/2/512F will be disabled.\n");
PrintKernel("System: CPU: OSXSAVE not supported. AVX/2/512F will be disabled.\n");
cpu_features.avx = false;
cpu_features.avx2 = false;
cpu_features.avx512f = false;
CPUFeatureValidation();
return;
}
PrintKernelSuccess("System: CPU: OSXSAVE supported.\n");
#else
PrintKernel("System: CPU: OSXSAVE not supported. AVX/2/512F will be disabled.\n");
cpu_features.avx = false;
cpu_features.avx2 = false;
cpu_features.avx512f = false;
CPUFeatureValidation();
return;
#endif
Comment on lines +65 to +82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Reduce code duplication in AVX disabling logic.

Both branches of the VF_CONFIG_VM_HOST conditional contain identical AVX/AVX2/AVX512F disabling code and validation calls. Consider extracting this into a helper function or consolidating the logic.

Apply this diff to reduce duplication:

+    bool should_disable_avx = false;
 #ifndef VF_CONFIG_VM_HOST
     if (!cpu_features.osxsave) {
         PrintKernel("System: CPU: OSXSAVE not supported. AVX/2/512F will be disabled.\n");
-        cpu_features.avx = false;
-        cpu_features.avx2 = false;
-        cpu_features.avx512f = false;
-        CPUFeatureValidation();
-        return;
+        should_disable_avx = true;
     }
     PrintKernelSuccess("System: CPU: OSXSAVE supported.\n");
 #else
     PrintKernel("System: CPU: OSXSAVE not supported. AVX/2/512F will be disabled.\n");
+    should_disable_avx = true;
+#endif
+
+    if (should_disable_avx) {
+        cpu_features.avx = false;
+        cpu_features.avx2 = false;
+        cpu_features.avx512f = false;
+        CPUFeatureValidation();
+        return;
+    }
+
+#ifndef VF_CONFIG_VM_HOST
-    cpu_features.avx = false;
-    cpu_features.avx2 = false;
-    cpu_features.avx512f = false;
-    CPUFeatureValidation();
-    return;
-#endif

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In arch/x86_64/features/x64.c around lines 65 to 82, the AVX/AVX2/AVX512F
disabling and CPUFeatureValidation calls are duplicated in both branches of the
VF_CONFIG_VM_HOST #ifdef; extract that repeated block into a single helper
function (e.g., DisableAVXFeatures or ConsolidateAVXFallback) or move the shared
logic after the #endif so it runs from one place, then replace both duplicated
blocks with a single call to the helper (ensure any necessary
includes/prototypes are added and preserve the existing
PrintKernel/PrintKernelSuccess messages semantics).


// --- Step 3: Enable AVX by setting the XCR0 Control Register ---
// The OS must set bits 1 (SSE state) and 2 (AVX state) in XCR0.
Expand Down
3 changes: 2 additions & 1 deletion cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ option(VF_CONFIG_USE_CERBERUS "Use Cerberus" ON)
option(VF_CONFIG_CERBERUS_STACK_PROTECTION "Enable Cerberus stack protection" ON)
option(VF_CONFIG_INTEL "Enable Intel-specific optimizations" ON)
option(VF_CONFIG_ENABLE_OPIC "Enable OPIC support" ON)
option(VF_CONFIG_VESA_FB "Enable VESA framebuffer support" ON)
option(VF_CONFIG_VESA_FB "Enable VESA framebuffer support" ON)
option(VF_CONFIG_MEMCPY_NT "Enable non-temporal memcpy optimizations" OFF)
4 changes: 4 additions & 0 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ if(AUTOMATIC_POST)
add_compile_definitions(VF_CONFIG_AUTOMATIC_POST)
endif()

if(VF_CONFIG_MEMCPY_NT)
add_compile_definitions(VF_CONFIG_MEMCPY_NT)
endif()

if(VF_SCHEDULER STREQUAL "MLFQ")
add_compile_definitions(VF_CONFIG_SCHED_MLFQ)
elseif(VF_SCHEDULER STREQUAL "EEVDF")
Expand Down
15 changes: 6 additions & 9 deletions drivers/ethernet/Network.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Network.h"
#include "Console.h"
#include "StringOps.h"
#include "intel/E1000.h"
#include "interface/Arp.h"
#include "realtek/RTL8139.h"
Expand All @@ -12,7 +13,6 @@ void Net_Initialize(void) {
g_device_count = 0;
ArpInit();


// Try to initialize E1000
if (E1000_Init() == 0) {
Net_RegisterDevice("E1000", (send_packet_t)E1000_SendPacket, (get_mac_t)E1000_GetDevice, E1000_HandleReceive);
Expand All @@ -29,14 +29,7 @@ void Net_Initialize(void) {
void Net_RegisterDevice(const char* name, send_packet_t sender, get_mac_t mac_getter, poll_receive_t poller) {
if (g_device_count < MAX_NETWORK_DEVICES) {
NetworkDevice* dev = &g_network_devices[g_device_count++];
// Simple string copy
int i = 0;
while(name[i] != '\0' && i < 31) {
dev->name[i] = name[i];
i++;
}
dev->name[i] = '\0';

FastStrCopy(dev->name, name, 256);
dev->send_packet = sender;
dev->get_mac_address = mac_getter;
dev->poll_receive = poller;
Expand All @@ -48,6 +41,10 @@ void Net_RegisterDevice(const char* name, send_packet_t sender, get_mac_t mac_ge
}
}

void Net_UnregisterDevice() {

}

NetworkDevice* Net_GetDevice(int index) {
if (index < g_device_count) {
return &g_network_devices[index];
Expand Down
8 changes: 4 additions & 4 deletions drivers/ethernet/interface/Ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ static uint16_t IpChecksum(const void* data, size_t length) {
}

void IpSend(uint8_t dest_ip[4], uint8_t protocol, const void* data, uint16_t len) {
NetworkDevice* net_dev = Net_GetDevice(0);
if (!net_dev) {
PrintKernel("IP: No network device found.\n");
return;
NetworkDevice* net_dev = NULL;
for (int i = 0; i < MAX_NETWORK_DEVICES; i++) {
net_dev = Net_GetDevice(i);
if (net_dev) break;
}

uint8_t dest_mac[6];
Expand Down
2 changes: 1 addition & 1 deletion kernel/core/Kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static InitResultT PXS2(void) {
// Load multiboot modules
PrintKernel("Info: Loading multiboot modules...\n");
InitRDLoad();
PrintKernelSuccess("System: Multiboot modules loaded\n");
PrintKernelSuccess("System: Multiboot modules loadded\n");
#endif

PrintKernel("Info: Initializing CRC32...\n");
Expand Down
10 changes: 10 additions & 0 deletions mm/MemOps.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ extern void* memcpy_internal_sse2(void* restrict dest, const void* restrict src,
extern void* memcpy_internal_avx2(void* restrict dest, const void* restrict src, uint64_t size);
extern void* memcpy_internal_avx512(void* restrict dest, const void* restrict src, uint64_t size);

extern void* memcpy_internal_sse2_wc(void* restrict dest, const void* restrict src, uint64_t size);
extern void* memcpy_internal_avx2_wc(void* restrict dest, const void* restrict src, uint64_t size);
extern void* memcpy_internal_avx512_wc(void* restrict dest, const void* restrict src, uint64_t size);

extern void* memset_internal_sse2(void* restrict dest, int value, uint64_t size);
extern void* memset_internal_avx2(void* restrict dest, int value, uint64_t size);
extern void* memset_internal_avx512(void* restrict dest, int value, uint64_t size);
Expand Down Expand Up @@ -60,9 +64,15 @@ void* FastMemcpy(void* restrict dest, const void* restrict src, uint64_t size) {

const CpuFeatures * features = GetCpuFeatures();

#ifdef VF_CONFIG_MEMCPY_NT
if (features->avx512f) return memcpy_internal_avx512(d, s, size);
if (features->avx2) return memcpy_internal_avx2(d, s, size);
if (features->sse2) return memcpy_internal_sse2(d, s, size);
#else
if (features->avx512f) return memcpy_internal_avx512_wc(d, s, size);
if (features->avx2) return memcpy_internal_avx2_wc(d, s, size);
if (features->sse2) return memcpy_internal_sse2_wc(d, s, size);
#endif

while (size--) *d++ = *s++;

Expand Down
Loading