When GRUB is configured with multiboot2, it may provide a graphical
(RGB) framebuffer instead of legacy VGA text mode. This happens on
UTM/QEMU on macOS and other configurations where the bootloader
switches to a pixel-based display.
- Parse multiboot2 framebuffer tag in kernel_main to detect display mode
- Identity-map the framebuffer address (often at 0xFD000000+) after
paging is enabled, with write-through caching
- Add framebuffer.h describing the boot-time display info
- Embed 8x16 VGA bitmap font (font8x16.h) for pixel-mode rendering
- Rewrite VGA driver to support both text mode and pixel mode:
- Text mode: unchanged behavior writing to 0xB8000
- Pixel mode: renders characters using the bitmap font to the
GRUB-provided framebuffer, with proper VGA color palette mapping
- Auto-detects mode from fb_info at init time
- Multiboot2 header now requests text mode via framebuffer tag, but
gracefully falls back to pixel rendering if GRUB provides RGB
- Reverted grub.cfg gfxpayload=text (caused display issues on UTM)
Tested: boots in both text mode and graphical framebuffer mode.
59 lines
2.2 KiB
CMake
59 lines
2.2 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)
|
|
|
|
# Build user-mode applications as flat binaries.
|
|
set(APPS_BIN_DIR ${CMAKE_BINARY_DIR}/apps_bin)
|
|
file(MAKE_DIRECTORY ${APPS_BIN_DIR})
|
|
add_custom_target(apps
|
|
COMMAND ${CMAKE_SOURCE_DIR}/scripts/build_apps.sh ${CMAKE_SOURCE_DIR}/apps ${APPS_BIN_DIR}
|
|
COMMENT "Building user-mode applications"
|
|
)
|
|
|
|
# Generate CPIO initial ramdisk from built app binaries.
|
|
set(INITRD_FILE ${CMAKE_BINARY_DIR}/isodir/boot/initrd.cpio)
|
|
add_custom_command(
|
|
OUTPUT ${INITRD_FILE}
|
|
COMMAND ${CMAKE_SOURCE_DIR}/scripts/gen_initrd.sh ${APPS_BIN_DIR} ${INITRD_FILE}
|
|
DEPENDS 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\" {\n multiboot2 /boot/kernel.bin\n module2 /boot/initrd.cpio\n}")
|
|
|
|
|
|
# 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}
|
|
)
|