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
27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ enable_language(ASM_NASM)
# Module Path & Includes
# ============================================================================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

include(cache)
include(ccache)
include(features)
include(variable)
include(dependencies)
Expand All @@ -38,7 +40,17 @@ else()
endif()

if(NOT CMAKE_TOOLCHAIN_FILE)
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE is not set. Please provide a toolchain file.")
message(WARNING "CMAKE_TOOLCHAIN_FILE is not set. Automatically selecting toolchain file...")
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchains/linux-x64.cmake" CACHE PATH "Toolchain file" FORCE)
message(STATUS "Defaulting to Linux x86_64 toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchains/macos-x64.cmake" CACHE PATH "Toolchain file" FORCE)
message(STATUS "Defaulting to macOS x86_64 toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchains/windows-x64.cmake" CACHE PATH "Toolchain file" FORCE)
message(STATUS "Defaulting to Windows x86_64 toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
endif()
else()
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
endif()
Expand All @@ -48,19 +60,14 @@ if(NOT CMAKE_BUILD_TYPE)
message(WARNING "CMAKE_BUILD_TYPE not set. Defaulting to Release.")
endif()

if(CMAKE_GENERATOR STREQUAL "Ninja")
message(STATUS "CMake: Generator: ${CMAKE_GENERATOR}")
else()
message(WARNING "CMake: Non-Ninja generator detected: ${CMAKE_GENERATOR}. Ninja is recommended.")
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
message(STATUS "CMake: Target Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "CMake Target Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
set(Rust_CARGO_TARGET "x86_64-unknown-none")
else()
message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()

message(STATUS "CMake Generator: ${CMAKE_GENERATOR}")
message(STATUS "CMake Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMake Source Directory: ${CMAKE_SOURCE_DIR}")
message(STATUS "CMake Binary Directory: ${CMAKE_BINARY_DIR}")
Expand Down Expand Up @@ -106,10 +113,6 @@ if (SILENT_BUILD)
corrosion_add_target_rustflags(voidframe_spinlock "-A" "warnings" "-C" "link-arg=-s")
endif()

# ============================================================================
# Flags setup
# ============================================================================

# ============================================================================
# Kernel Linking
# ============================================================================
Expand Down
34 changes: 34 additions & 0 deletions cmake/ccache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ============================================================================
# CCache Configuration for Faster Builds
# ============================================================================

option(VF_ENABLE_CCACHE "Enable ccache for faster compilation" ON)

if(VF_ENABLE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
# Configure ccache
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})

# Set ccache options for kernel development
set(ENV{CCACHE_SLOPPINESS} "file_macro,locale,time_macros")
set(ENV{CCACHE_MAXSIZE} "2G")
set(ENV{CCACHE_COMPRESS} "true")
set(ENV{CCACHE_COMPRESSLEVEL} "6")

message(STATUS "ccache enabled: ${CCACHE_PROGRAM}")

# Show ccache stats
execute_process(
COMMAND ${CCACHE_PROGRAM} -s
OUTPUT_VARIABLE CCACHE_STATS
ERROR_QUIET
)
if(CCACHE_STATS)
message(STATUS "ccache statistics:\n${CCACHE_STATS}")
endif()
else()
message(WARNING "ccache requested but not found")
endif()
endif()
30 changes: 30 additions & 0 deletions cmake/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,33 @@ option(AUTOMATIC_POST "Run POST automatically on boot" OFF)
option(DEBUG_SYMBOLS "Enable debug symbols" ON)
option(STACK_PROTECTION "Enable stack protection" ON)
option(SILENT_BUILD "Enable silent build (suppress warnings)" OFF)

option(VF_CONFIG_ENABLE_VMWARE_SVGA_II "Enable VMware SVGA II support" OFF)
option(VF_CONFIG_ENABLE_CERBERUS_VFS_LOGGING "Enable Cerberus VFS logging" OFF)
option(VF_CONFIG_CERBERUS_THREAT_REPORTING "Enable Cerberus threat reporting" OFF)
option(VF_CONFIG_PANIC_OVERRIDE "Enable panic override" OFF)
option(VF_CONFIG_LOAD_MB_MODULES "Enable multiboot module loading" OFF)

option(VF_CONFIG_ENABLE_XHCI "Enable XHCI support" ON)
option(VF_CONFIG_ENABLE_VIRTIO "Enable VirtIO support" ON)
option(VF_CONFIG_ENABLE_ISA "Enable ISA support" ON)
option(VF_CONFIG_ENABLE_LPT "Enable LPT support" ON)
option(VF_CONFIG_ENABLE_PCI "Enable PCI support" ON)
option(VF_CONFIG_ENABLE_PS2 "Enable PS/2 support" ON)
option(VF_CONFIG_ENABLE_IDE "Enable IDE support" ON)
option(VF_CONFIG_ENABLE_VFCOMPOSITOR "Enable VFCompositor support" ON)
option(VF_CONFIG_ENABLE_AHCI "Enable AHCI support" ON)
option(VF_CONFIG_ENABLE_NVME "Enable NVMe support" ON)
option(VF_CONFIG_ENABLE_GENERIC_SOUND "Enable Generic Sound support" ON)
option(VF_CONFIG_RTC_CENTURY "Enable RTC Century support" ON)
option(VF_CONFIG_ENFORCE_MEMORY_PROTECTION "Enforce memory protection" ON)
option(VF_CONFIG_VM_HOST "Enable VM host optimizations" ON)
option(VF_CONFIG_SNOOZE_ON_BOOT "Enable snooze on boot" ON)
option(VF_CONFIG_USE_VFSHELL "Use VFShell as the default shell" ON)
option(VF_CONFIG_USE_DYNAMOX "Use Dynamox" ON)
option(VF_CONFIG_USE_ASTRA "Use Astra" ON)
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)
121 changes: 87 additions & 34 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
@@ -1,40 +1,93 @@
# ============================================================================
# VoidFrame Feature Configuration Flags
# ============================================================================
add_compile_definitions(
VF_CONFIG_ENABLE_XHCI
VF_CONFIG_ENABLE_VIRTIO
VF_CONFIG_ENABLE_ISA
VF_CONFIG_ENABLE_LPT
VF_CONFIG_ENABLE_PCI
VF_CONFIG_ENABLE_PS2
VF_CONFIG_ENABLE_IDE
VF_CONFIG_ENABLE_VFCOMPOSITOR
VF_CONFIG_ENABLE_AHCI
VF_CONFIG_ENABLE_NVME
VF_CONFIG_ENABLE_GENERIC_SOUND
VF_CONFIG_RTC_CENTURY
VF_CONFIG_ENFORCE_MEMORY_PROTECTION
VF_CONFIG_VM_HOST
VF_CONFIG_SNOOZE_ON_BOOT
VF_CONFIG_PROCINFO_CREATE_DEFAULT
VF_CONFIG_USE_VFSHELL
VF_CONFIG_USE_DYNAMOX
VF_CONFIG_USE_ASTRA
VF_CONFIG_USE_CERBERUS
VF_CONFIG_CERBERUS_STACK_PROTECTION
VF_CONFIG_INTEL
VF_CONFIG_ENABLE_OPIC
)

add_compile_definitions(
# VF_CONFIG_ENABLE_VMWARE_SVGA_II
# VF_CONFIG_ENABLE_CERBERUS_VFS_LOGGING
# VF_CONFIG_CERBERUS_THREAT_REPORTING
# VF_CONFIG_PROCINFO_AUTO_CLEANUP
# VF_CONFIG_PANIC_OVERRIDE
# VF_CONFIG_LOAD_MB_MODULES
)

if(VF_CONFIG_ENABLE_XHCI)
add_compile_definitions(VF_CONFIG_ENABLE_XHCI)
endif()
if(VF_CONFIG_ENABLE_VIRTIO)
add_compile_definitions(VF_CONFIG_ENABLE_VIRTIO)
endif()
if(VF_CONFIG_ENABLE_ISA)
add_compile_definitions(VF_CONFIG_ENABLE_ISA)
endif()
if(VF_CONFIG_ENABLE_LPT)
add_compile_definitions(VF_CONFIG_ENABLE_LPT)
endif()
if(VF_CONFIG_ENABLE_PCI)
add_compile_definitions(VF_CONFIG_ENABLE_PCI)
endif()
if(VF_CONFIG_ENABLE_PS2)
add_compile_definitions(VF_CONFIG_ENABLE_PS2)
endif()
if(VF_CONFIG_ENABLE_IDE)
add_compile_definitions(VF_CONFIG_ENABLE_IDE)
endif()
if(VF_CONFIG_ENABLE_VFCOMPOSITOR)
add_compile_definitions(VF_CONFIG_ENABLE_VFCOMPOSITOR)
endif()
if(VF_CONFIG_ENABLE_AHCI)
add_compile_definitions(VF_CONFIG_ENABLE_AHCI)
endif()
if(VF_CONFIG_ENABLE_NVME)
add_compile_definitions(VF_CONFIG_ENABLE_NVME)
endif()
if(VF_CONFIG_ENABLE_GENERIC_SOUND)
add_compile_definitions(VF_CONFIG_ENABLE_GENERIC_SOUND)
endif()
if(VF_CONFIG_RTC_CENTURY)
add_compile_definitions(VF_CONFIG_RTC_CENTURY)
endif()
if(VF_CONFIG_ENFORCE_MEMORY_PROTECTION)
add_compile_definitions(VF_CONFIG_ENFORCE_MEMORY_PROTECTION)
endif()
if(VF_CONFIG_VM_HOST)
add_compile_definitions(VF_CONFIG_VM_HOST)
endif()
if(VF_CONFIG_SNOOZE_ON_BOOT)
add_compile_definitions(VF_CONFIG_SNOOZE_ON_BOOT)
endif()
if(VF_CONFIG_USE_VFSHELL)
add_compile_definitions(VF_CONFIG_USE_VFSHELL)
endif()
if(VF_CONFIG_USE_DYNAMOX)
add_compile_definitions(VF_CONFIG_USE_DYNAMOX)
endif()
if(VF_CONFIG_USE_ASTRA)
add_compile_definitions(VF_CONFIG_USE_ASTRA)
endif()
if(VF_CONFIG_USE_CERBERUS)
add_compile_definitions(VF_CONFIG_USE_CERBERUS)
endif()
if(VF_CONFIG_CERBERUS_STACK_PROTECTION)
add_compile_definitions(VF_CONFIG_CERBERUS_STACK_PROTECTION)
endif()
if(VF_CONFIG_INTEL)
add_compile_definitions(VF_CONFIG_INTEL)
endif()
if(VF_CONFIG_ENABLE_OPIC)
add_compile_definitions(VF_CONFIG_ENABLE_OPIC)
endif()

if(VF_CONFIG_ENABLE_VMWARE_SVGA_II)
add_compile_definitions(VF_CONFIG_ENABLE_VMWARE_SVGA_II)
endif()

if(VF_CONFIG_ENABLE_CERBERUS_VFS_LOGGING)
add_compile_definitions(VF_CONFIG_ENABLE_CERBERUS_VFS_LOGGING)
endif()

if(VF_CONFIG_CERBERUS_THREAT_REPORTING)
add_compile_definitions(VF_CONFIG_CERBERUS_THREAT_REPORTING)
endif()

if(VF_CONFIG_PANIC_OVERRIDE)
add_compile_definitions(VF_CONFIG_PANIC_OVERRIDE)
endif()

if(VF_CONFIG_LOAD_MB_MODULES)
add_compile_definitions(VF_CONFIG_LOAD_MB_MODULES)
endif()

if(EXCLUDE_EXTRA_OBJECTS)
add_compile_definitions(VF_CONFIG_EXCLUDE_EXTRA_OBJECTS)
Expand Down
7 changes: 6 additions & 1 deletion cmake/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ endif()

set(CMAKE_C_FLAGS "${C_FLAGS}")
set(CMAKE_CXX_FLAGS "${C_FLAGS} -fno-exceptions -fno-rtti -fno-threadsafe-statics")
set(CMAKE_ASM_NASM_FLAGS "-f elf64 -DVF_CONFIG_VESA_FB")

set(ASM_NASM_FLAGS "-f elf64")
if(VF_CONFIG_VESA_FB)
string(APPEND ASM_NASM_FLAGS " -DVF_CONFIG_VESA_FB")
endif()
set(CMAKE_ASM_NASM_FLAGS "${ASM_NASM_FLAGS}")
10 changes: 5 additions & 5 deletions fs/DriveNaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ void GenerateDriveNameInto(BlockDeviceType type, char* out_name) {
else rust_spinlock_lock(dn_lock);
switch (type) {
case DEVICE_TYPE_IDE:
FormatA(out_name, 16, "hd%c", 'a' + ide_count++);
snprintf(out_name, 16, "hd%c", 'a' + ide_count++);
break;
case DEVICE_TYPE_AHCI:
FormatA(out_name, 16, "sd%c", 'a' + ahci_count++);
snprintf(out_name, 16, "sd%c", 'a' + ahci_count++);
break;
case DEVICE_TYPE_NVME:
FormatA(out_name, 16, "nvme%d", nvme_count++);
snprintf(out_name, 16, "nvme%d", nvme_count++);
break;
case DEVICE_TYPE_VIRTIO:
FormatA(out_name, 16, "vd%c", 'a' + virtio_count++);
snprintf(out_name, 16, "vd%c", 'a' + virtio_count++);
break;
default:
FormatA(out_name, 16, "unk%d", 0);
snprintf(out_name, 16, "unk%d", 0);
break;
}
rust_spinlock_unlock(dn_lock);
Expand Down
2 changes: 1 addition & 1 deletion fs/FileSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void FileSystemAutoMount() {
PrintKernel("\n");
// Simple mount point naming for now
char mount_point[64];
FormatA(mount_point, sizeof(mount_point), "%s/%s", RuntimeMounts, dev->name);
snprintf(mount_point, sizeof(mount_point), "%s/%s", RuntimeMounts, dev->name);
PrintKernel("FS: Mounting at ");
PrintKernel(mount_point);
PrintKernel("\n");
Expand Down
4 changes: 2 additions & 2 deletions fs/Iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ int Iso9660Copy(const char* iso_path, const char* vfs_path) {
char vfs_filepath[256];
char iso_filepath[256];

FormatA(vfs_filepath, sizeof(vfs_filepath), "%s/%s", vfs_path, filename);
FormatA(iso_filepath, sizeof(iso_filepath), "%s/%s", iso_path, filename);
snprintf(vfs_filepath, sizeof(vfs_filepath), "%s/%s", vfs_path, filename);
snprintf(iso_filepath, sizeof(iso_filepath), "%s/%s", iso_path, filename);

if (entries[i]->file_flags & 2) { // Directory
Iso9660Copy(iso_filepath, vfs_filepath);
Expand Down
2 changes: 1 addition & 1 deletion fs/MBR.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void ParseMBR(BlockDevice* device) {

if (p->type != 0 && p->num_sectors > 0) {
char part_name[32];
FormatA(part_name, sizeof(part_name), "%s-p%d", device->name, i + 1);
snprintf(part_name, sizeof(part_name), "%s-p%d", device->name, i + 1);

PrintKernel("MBR: Registering partition ");
PrintKernel(part_name);
Expand Down
2 changes: 1 addition & 1 deletion fs/procfs/ProcFS.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int ProcfsReadFile(const char* path, void* buffer, uint32_t max_size) {
char local_buffer[1024];

if (FastStrCmp(filename, "info") == 0) {
int len = FormatA(local_buffer, sizeof(local_buffer),
int len = snprintf(local_buffer, sizeof(local_buffer),
"Name: %s\n"
"PID: %u\n"
"State: %d\n"
Expand Down
50 changes: 50 additions & 0 deletions kernel/atomic/rust/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,47 @@ pub extern "C" fn rust_spinlock_try_lock(lock: *mut SpinLock) -> bool {
}
}

#[no_mangle]
pub extern "C" fn rust_spinlock_contention_level(lock: *mut SpinLock) -> u32 {
if !lock.is_null() {
unsafe { (*lock).contention_level() }
} else {
0
}
}

#[no_mangle]
pub extern "C" fn rust_spinlock_lock_order(lock: *mut SpinLock) -> u32 {
if !lock.is_null() {
unsafe { (*lock).lock_order() }
} else {
0
}
}

#[no_mangle]
pub extern "C" fn rust_spinlock_owner_cpu(lock: *mut SpinLock) -> u32 {
if !lock.is_null() {
unsafe { (*lock).owner_cpu() }
} else {
u32::MAX
}
}

#[no_mangle]
pub extern "C" fn rust_spinlock_new_with_order(order: u32) -> *mut SpinLock {
unsafe {
for i in 0..64 {
if !SPINLOCK_USED[i] {
SPINLOCK_USED[i] = true;
SPINLOCK_STORAGE[i] = SpinLock::new_with_order(order);
return &mut SPINLOCK_STORAGE[i] as *mut SpinLock;
}
}
}
core::ptr::null_mut()
}

// Static storage for MCS locks and nodes
static mut MCS_LOCK_STORAGE: [McsLock; 32] = [const { McsLock::new() }; 32];
static mut MCS_LOCK_USED: [bool; 32] = [false; 32];
Expand Down Expand Up @@ -147,6 +188,15 @@ pub extern "C" fn rust_mcs_unlock(lock: *mut McsLock, node: *mut McsNode) {
}
}

#[no_mangle]
pub extern "C" fn rust_mcs_try_lock(lock: *mut McsLock, node: *mut McsNode) -> bool {
if !lock.is_null() && !node.is_null() {
unsafe { (*lock).try_lock(&mut *node) }
} else {
false
}
}

// Static storage for RwLocks
static mut RWLOCK_STORAGE: [RwLock; 32] = [const { RwLock::new() }; 32];
static mut RWLOCK_USED: [bool; 32] = [false; 32];
Expand Down
Loading