From 8ccd6e9c6d4d825287532f5a1c3a040879f4c11b Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Sun, 12 Jun 2022 15:25:30 -0400 Subject: [PATCH] undo pt2 --- CMakeLists.txt | 25 +++++++++++++++++++++++++ include/shade/terminal.h | 6 ++++++ include/shade/version.h.in | 11 +++++++++++ shade-build/checkbin.sh | 5 +++++ shade-build/mkiso.sh | 7 +++++++ shade-build/run_qemu.sh | 2 ++ src/kernel/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ src/libc/CMakeLists.txt | 10 ++++++++++ 8 files changed, 101 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 include/shade/terminal.h create mode 100644 include/shade/version.h.in create mode 100755 shade-build/checkbin.sh create mode 100755 shade-build/mkiso.sh create mode 100755 shade-build/run_qemu.sh create mode 100644 src/kernel/CMakeLists.txt create mode 100644 src/libc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2736c0b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) +project(shadeOS LANGUAGES C ASM_NASM) + +# Configure CFLAGS +set(CMAKE_C_FLAGS -ffreestanding) +set(CMAKE_LINKER x86_64-elf-ld) +set(CMAKE_C_COMPILER x86_64-elf-gcc) +set(CMAKE_ASM_NASM_LINK_EXECUTABLE " -o ") +set(CMAKE_C_LINK_EXECUTABLE " -n -o ") + +# Configure versioning info +set(SHADE_KERNEL_VERSION "0.1.1-alpha") +set(SHADE_RELEASE_STREAM "shade-development") +execute_process(COMMAND "git rev-parse --short HEAD | tr -d '\n'" SHADE_GIT_BUILD) +execute_process(COMMAND "date | tr -d '\n'" OUTPUT_VARIABLE SHADE_COMPILE_DATE) +set(SHADE_CODENAME willow) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/libc) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/kernel) + +# Generate the iso +#add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.iso COMMAND ${CMAKE_SOURCE_DIR}/shade-build/mkiso.sh ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.bin ${CMAKE_CURRENT_SOURCE_DIR}/../iso/ ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.iso ${CMAKE_SOURCE_DIR}/shade-build/checkbin.sh) + +# Add target to run the file +#add_custom_target(run COMMAND ${CMAKE_SOURCE_DIR}/shade-build/run_qemu.sh DEPENDS shadeOS.iso WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/include/shade/terminal.h b/include/shade/terminal.h new file mode 100644 index 0000000..a130bb2 --- /dev/null +++ b/include/shade/terminal.h @@ -0,0 +1,6 @@ +#ifndef SHADE_TERMINAL_H +#define SHADE_TERMINAL_H + + + +#endif \ No newline at end of file diff --git a/include/shade/version.h.in b/include/shade/version.h.in new file mode 100644 index 0000000..afa3e35 --- /dev/null +++ b/include/shade/version.h.in @@ -0,0 +1,11 @@ +#ifndef SHADE_VERSION_H +#define SHADE_VERSION_H +// This file was autogenerated by the shadeOS build system. +// It should not be modified by hand. +// To change these values, modify them in CMakeLists.txt. +#define SHADE_OS_KERNEL_VERSION "${SHADE_KERNEL_VERSION}" +#define SHADE_OS_KERNEL "${SHADE_RELEASE_STREAM}" +#define SHADE_OS_BUILD "${SHADE_GIT_BUILD}" +#define SHADE_OS_COMPILE_DATE "${SHADE_COMPILE_DATE}" +#define SHADE_OS_CODENAME "${SHADE_CODENAME}" +#endif diff --git a/shade-build/checkbin.sh b/shade-build/checkbin.sh new file mode 100755 index 0000000..16423de --- /dev/null +++ b/shade-build/checkbin.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +echo "Checking binary $1" +grub-file --is-x86-multiboot2 $1 +echo "$1 is a valid mb2 binary" \ No newline at end of file diff --git a/shade-build/mkiso.sh b/shade-build/mkiso.sh new file mode 100755 index 0000000..dbad36b --- /dev/null +++ b/shade-build/mkiso.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +$4 $1 +echo "Packaging $1 into shadeOS ISO $3" +# mkiso.sh build/src/kernel/shadeOS.bin src/iso/ build/shade.iso check_command +cp $1 $2/boot/shade.bin +grub-mkrescue $2 -o $3 \ No newline at end of file diff --git a/shade-build/run_qemu.sh b/shade-build/run_qemu.sh new file mode 100755 index 0000000..83e12d3 --- /dev/null +++ b/shade-build/run_qemu.sh @@ -0,0 +1,2 @@ +#!/bin/bash +qemu-system-x86_64 -drive file=build/src/kernel/shade.iso,index=0,media=disk,format=raw -no-reboot \ No newline at end of file diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt new file mode 100644 index 0000000..f664272 --- /dev/null +++ b/src/kernel/CMakeLists.txt @@ -0,0 +1,35 @@ +# Define ASM source files +set(KERNEL_ASM_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/int.asm) + +# Define C source files +set(KERNEL_C_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/platform/drivers/keyboard.c + ${CMAKE_CURRENT_SOURCE_DIR}/platform/drivers/vga_text_mode.c + ${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/idt.c + ${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/isr.c + ${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/pic.c + ${CMAKE_CURRENT_SOURCE_DIR}/platform/ports.c + ${CMAKE_CURRENT_SOURCE_DIR}/cansid.c + ${CMAKE_CURRENT_SOURCE_DIR}/kernel.c + ${CMAKE_CURRENT_SOURCE_DIR}/kmsg.c + ${CMAKE_CURRENT_SOURCE_DIR}/util.c) + +set(SBOOT_ASM_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/../boot/entry.asm + ${CMAKE_CURRENT_SOURCE_DIR}/../boot/entry64.asm + ${CMAKE_CURRENT_SOURCE_DIR}/../boot/mb2_header.asm) + +set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../linker.ld) +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}") + +configure_file(${CMAKE_SOURCE_DIR}/include/shade/version.h.in ${CMAKE_SOURCE_DIR}/include/shade/version.h) + +add_executable(shadeOS.bin ${SBOOT_ASM_SOURCE_FILES} ${KERNEL_ASM_SOURCE_FILES} ${KERNEL_C_SOURCE_FILES}) +target_link_libraries(shadeOS.bin LINK_PUBLIC shadeOS_libc) # Link the kernel to libc + +# Generate the iso +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shade.iso COMMAND ${CMAKE_SOURCE_DIR}/shade-build/mkiso.sh ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.bin ${CMAKE_CURRENT_SOURCE_DIR}/../iso/ ${CMAKE_CURRENT_BINARY_DIR}/shade.iso ${CMAKE_SOURCE_DIR}/shade-build/checkbin.sh DEPENDS shadeOS.bin) + +# Add target to run the file +add_custom_target(run COMMAND ${CMAKE_SOURCE_DIR}/shade-build/run_qemu.sh DEPENDS shade.iso WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/src/libc/CMakeLists.txt b/src/libc/CMakeLists.txt new file mode 100644 index 0000000..76c24ee --- /dev/null +++ b/src/libc/CMakeLists.txt @@ -0,0 +1,10 @@ +# Define C source files +set(LIBC_C_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/printf.c + ${CMAKE_CURRENT_SOURCE_DIR}/strings.c) + +# Define ASM source files +# none currently + +add_library(shadeOS_libc ${LIBC_C_SOURCE_FILES}) # Create the libc library +target_include_directories(shadeOS_libc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) # Set the include dir \ No newline at end of file