Build system changes: - scripts/gen_initrd.sh packs all files from apps/ into a newc-format CPIO archive at build/isodir/boot/initrd.cpio. - CMakeLists.txt adds 'initrd' target as ISO dependency. GRUB loads the archive as a Multiboot2 module via 'module2 /boot/initrd.cpio'. - apps/README added as placeholder file for initial ramdisk content. Kernel changes: - kernel.c scans Multiboot2 tags for MULTIBOOT_TAG_TYPE_MODULE to find the initrd's physical address range, then passes it to cpio_init(). - cpio.c/h implements a parser for the SVR4/newc CPIO format: - cpio_init(): lists archive contents on startup - cpio_find(): look up a file by name (handles ./ prefix) - cpio_next(): iterate through all entries - cpio_count(): count files in archive - The initrd lives in identity-mapped physical memory, so no additional mapping is needed to access it. Verified in QEMU: GRUB loads the module at 0x0014A000, CPIO parser finds the README file (38 bytes). All existing functionality (Ring 3 processes, syscalls) continues to work.
52 lines
2.0 KiB
CMake
52 lines
2.0 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(ClaudeOS C ASM)
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
# We are building a kernel, so we don't want standard libraries
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffreestanding -m32 -fno-pie -fno-pic -fno-builtin -fno-stack-protector -mno-sse -mno-mmx -g -O2 -Wall -Wextra")
|
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32 -fno-pie -fno-pic")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32 -nostdlib -no-pie")
|
|
|
|
# Define build output directory
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
add_subdirectory(src)
|
|
|
|
# Create output directories
|
|
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/release)
|
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/isodir/boot/grub)
|
|
|
|
# Generate CPIO initial ramdisk from apps directory.
|
|
# All files in apps/ are packed into a newc-format CPIO archive.
|
|
set(INITRD_FILE ${CMAKE_BINARY_DIR}/isodir/boot/initrd.cpio)
|
|
add_custom_command(
|
|
OUTPUT ${INITRD_FILE}
|
|
COMMAND ${CMAKE_SOURCE_DIR}/scripts/gen_initrd.sh ${CMAKE_SOURCE_DIR}/apps ${INITRD_FILE}
|
|
DEPENDS ${CMAKE_SOURCE_DIR}/apps
|
|
COMMENT "Generating CPIO initial ramdisk"
|
|
)
|
|
add_custom_target(initrd DEPENDS ${INITRD_FILE})
|
|
|
|
# Create grub.cfg for ISO - includes module2 for the initrd
|
|
file(WRITE ${CMAKE_BINARY_DIR}/isodir/boot/grub/grub.cfg "set timeout=0\nset default=0\nsearch --set=root --file /boot/kernel.bin\nmenuentry \"ClaudeOS\" { multiboot2 /boot/kernel.bin\n module2 /boot/initrd.cpio }")
|
|
|
|
|
|
# ISO Generation
|
|
add_custom_target(iso ALL
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/kernel ${CMAKE_BINARY_DIR}/isodir/boot/kernel.bin
|
|
COMMAND grub-mkrescue -o ${CMAKE_SOURCE_DIR}/release/claude-os.iso ${CMAKE_BINARY_DIR}/isodir
|
|
DEPENDS kernel initrd
|
|
COMMENT "Generating bootable ISO image"
|
|
)
|
|
|
|
# Test target
|
|
add_custom_target(test_images
|
|
COMMAND sh ${CMAKE_SOURCE_DIR}/test_images.sh
|
|
DEPENDS iso
|
|
COMMENT "Testing generated images in QEMU"
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
)
|