diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..19d2fa4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +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 -g -O2 -Wall -Wextra") +set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32 -nostdlib") + +# 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) +# add_subdirectory(libs) +# add_subdirectory(apps) diff --git a/README.md b/README.md index 0fbd2d6..5ce8e8c 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ The git commit should describe what is done and why certain choices were made. The title of the commit should always end with (AI), to indicate that it was written by an AI. Once a task is completed, it should be checked off. -- [ ] Create directory structure -- [ ] Create initial build system +- [x] Create directory structure +- [x] Create initial build system - [ ] Setup a simple kernel that writes `Hello, world` to Qemu debug port - [ ] Update the build system to create both ISO and Floppy images. Verify these work using a test script. The standard CMake build target should automatically generate both images. - [ ] Update the kernel to correctly setup the GDT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..fe3e222 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.16) + +add_executable(kernel + kernel.c +) + +# Use our custom linker script +target_link_options(kernel PRIVATE -T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld) + +target_include_directories(kernel PRIVATE + ${CMAKE_SOURCE_DIR}/vendor + ${CMAKE_SOURCE_DIR}/include # If created later +) diff --git a/src/kernel.c b/src/kernel.c new file mode 100644 index 0000000..147888a --- /dev/null +++ b/src/kernel.c @@ -0,0 +1,3 @@ +void _start() { + while(1) {} +} diff --git a/src/linker.ld b/src/linker.ld new file mode 100644 index 0000000..678c08f --- /dev/null +++ b/src/linker.ld @@ -0,0 +1,28 @@ +ENTRY(_start) + +SECTIONS +{ + . = 1M; + + .text BLOCK(4K) : ALIGN(4K) + { + KEEP(*(.multiboot)) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +}