diff --git a/CMakeLists.txt b/CMakeLists.txt index 185044d56..b6d65f1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,6 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # 导入项目配置 include(project_config) -# 导入头文件处理 -include(add_header) # 导入函数 include(functions) @@ -85,7 +83,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/doc) # 添加 run 和 debug target add_run_target( - DEPENDS $<$:boot> $<$:boot> $<$:boot> kernel + DEPENDS ovmf $<$:opensbi-fw_jump> $<$:boot> $<$:boot> $<$:boot> kernel WORKING_DIRECTORY ${PROJECT_BINARY_DIR} TARGET ${CMAKE_SYSTEM_PROCESSOR} BOOT ${PROJECT_BINARY_DIR}/src/boot/boot.efi diff --git a/CMakePresets.json b/CMakePresets.json index 181cc5320..238257a92 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -45,7 +45,7 @@ "cacheVariables": { "CMAKE_VERBOSE_MAKEFILE": { "type": "BOOL", - "value": "FALSE" + "value": "TRUE" }, "CMAKE_EXPORT_COMPILE_COMMANDS": { "type": "BOOL", diff --git a/cmake/3rd.cmake b/cmake/3rd.cmake index 8b1ae981c..9cfcbbe79 100644 --- a/cmake/3rd.cmake +++ b/cmake/3rd.cmake @@ -116,6 +116,14 @@ if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64") ${opensbi_SOURCE_DIR}/include ${opensbi_BINARY_DIR}/include ) + add_library(opensbi-fw_jump INTERFACE) + add_dependencies(opensbi-fw_jump opensbi) + target_include_directories(opensbi-fw_jump INTERFACE + ${dtc_BINARY_DIR}/libfdt + ) + target_link_libraries(opensbi-fw_jump INTERFACE + ${dtc_BINARY_DIR}/libfdt/libfdt.a + ) # https://github.com/MRNIU/opensbi_interface.git add_subdirectory(3rd/opensbi_interface) @@ -152,6 +160,14 @@ add_custom_target(dtc COMMAND make clean ) +add_library(dtc-lib INTERFACE) +add_dependencies(dtc-lib dtc) +target_include_directories(dtc-lib INTERFACE + ${dtc_BINARY_DIR}/libfdt +) +target_link_libraries(dtc-lib INTERFACE + ${dtc_BINARY_DIR}/libfdt/libfdt.a +) # https://github.com/ncroxon/gnu-efi.git set(gnu-efi_SOURCE_DIR ${CMAKE_SOURCE_DIR}/3rd/gnu-efi) @@ -189,6 +205,19 @@ add_custom_target(gnu-efi ${gnu-efi_SOURCE_DIR}/inc ${gnu-efi_BINARY_DIR}/inc ) +add_library(gnu-efi-lib INTERFACE) +add_dependencies(gnu-efi-lib gnu-efi) +target_include_directories(gnu-efi-lib INTERFACE + ${gnu-efi_BINARY_DIR}/inc + ${gnu-efi_BINARY_DIR}/inc/${CMAKE_SYSTEM_PROCESSOR} + ${gnu-efi_BINARY_DIR}/inc/protocol +) +target_link_libraries(gnu-efi-lib INTERFACE + ${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o + ${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o + ${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a + ${gnu-efi_BINARY_DIR}/lib/libefi.a +) # ovmf # @todo 使用互联网连接或从 edk2 编译 diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake deleted file mode 100644 index 61970b9a2..000000000 --- a/cmake/add_header.cmake +++ /dev/null @@ -1,58 +0,0 @@ - -# This file is a part of Simple-XX/SimpleKernel -# (https://github.com/Simple-XX/SimpleKernel). -# -# add_header.cmake for Simple-XX/SimpleKernel. -# 将头文件路径添加到 _target 的搜索路径中 - -function(add_header_project _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src) -endfunction() - -function(add_header_boot _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/boot/include) -endfunction() - -function(add_header_libc _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/libc/include) -endfunction() - -function(add_header_libcxx _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/libcxx/include) -endfunction() - -function(add_header_arch _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/arch) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include) -endfunction() - -function(add_header_kernel _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/include) -endfunction() - -function(add_header_driver _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/driver/include) - if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64") - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/driver/ns16550a/include) - endif () -endfunction() - -function(add_header_3rd _target) - target_include_directories(${_target} PRIVATE - ${gnu-efi_BINARY_DIR}/inc) - target_include_directories(${_target} PRIVATE - ${gnu-efi_BINARY_DIR}/inc/${CMAKE_SYSTEM_PROCESSOR}) - target_include_directories(${_target} PRIVATE - ${gnu-efi_BINARY_DIR}/inc/protocol) - target_include_directories(${_target} PRIVATE - ${dtc_BINARY_DIR}/libfdt) -endfunction() diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 8cb3395a7..b189a3275 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -5,8 +5,16 @@ # compile_config.cmake for Simple-XX/SimpleKernel. # 配置信息 +# 通用宏定义 +add_library(compile_definitions INTERFACE) +target_compile_definitions(compile_definitions INTERFACE + $<$:SIMPLEKERNEL_RELEASE> + $<$:SIMPLEKERNEL_DEBUG> +) + # 通用编译选项 -list(APPEND COMMON_COMPILE_OPTIONS +add_library(compile_options INTERFACE) +target_compile_options(compile_options INTERFACE # 如果 CMAKE_BUILD_TYPE 为 Release 则使用 -O3 -Werror,否则使用 -O0 -ggdb # -g 在 Debug 模式下由 cmake 自动添加 $<$:-O3;-Werror> @@ -60,30 +68,28 @@ list(APPEND COMMON_COMPILE_OPTIONS ) # 通用链接选项 -list(APPEND COMMON_LINK_OPTIONS +add_library(link_options INTERFACE) +target_link_options(link_options INTERFACE # 不链接 ctr0 等启动代码 -nostartfiles ) # 通用库选项 -list(APPEND COMMON_LINK_LIB +add_library(link_libraries INTERFACE) +target_link_libraries(link_libraries INTERFACE + compile_definitions + compile_options + link_options ) -# 通用宏定义 -list(APPEND COMMON_DEFINITIONS - $<$:SIMPLEKERNEL_RELEASE> - $<$:SIMPLEKERNEL_DEBUG> -) - -list(APPEND DEFAULT_BOOT_DEFINITIONS - ${COMMON_DEFINITIONS} - +add_library(boot_compile_definitions INTERFACE) +target_compile_definitions(boot_compile_definitions INTERFACE # 使用 gnu-efi GNU_EFI_USE_MS_ABI ) -list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS - ${COMMON_COMPILE_OPTIONS} +add_library(boot_compile_options INTERFACE) +target_compile_options(boot_compile_options INTERFACE # 使用 2 字节 wchar_t -fshort-wchar # 允许 wchar_t @@ -97,9 +103,8 @@ list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS > ) -list(APPEND DEFAULT_BOOT_LINK_OPTIONS - ${COMMON_LINK_OPTIONS} - +add_library(boot_link_options INTERFACE) +target_link_options(boot_link_options INTERFACE $<$: # 编译为共享库 -shared @@ -120,43 +125,37 @@ list(APPEND DEFAULT_BOOT_LINK_OPTIONS > ) -list(APPEND DEFAULT_BOOT_LINK_LIB - ${COMMON_LINK_LIB} +add_library(boot_link_libraries INTERFACE) +target_link_libraries(boot_link_libraries INTERFACE + link_libraries + boot_compile_definitions + boot_compile_options + boot_link_options + # 目标平台编译选项 $<$: # 链接 gnu-efi - ${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a - ${gnu-efi_BINARY_DIR}/lib/libefi.a + gnu-efi-lib > $<$: # 链接 gnu-efi - ${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a - ${gnu-efi_BINARY_DIR}/lib/libefi.a + gnu-efi-lib > $<$: # 链接 gnu-efi - ${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o - ${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a - ${gnu-efi_BINARY_DIR}/lib/libefi.a + gnu-efi-lib > ) -list(APPEND DEFAULT_KERNEL_DEFINITIONS - ${COMMON_DEFINITIONS} - +add_library(kernel_compile_definitions INTERFACE) +target_compile_definitions(kernel_compile_definitions INTERFACE USE_NO_RELAX=$ ) -list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS - ${COMMON_COMPILE_OPTIONS} - +add_library(kernel_compile_options INTERFACE) +target_compile_options(kernel_compile_options INTERFACE $<$: # 使用 kernel 内存模型 -mcmodel=large @@ -169,9 +168,8 @@ list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS > ) -list(APPEND DEFAULT_KERNEL_LINK_OPTIONS - ${COMMON_LINK_OPTIONS} - +add_library(kernel_link_options INTERFACE) +target_link_options(kernel_link_options INTERFACE # 链接脚本 -T ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/link.ld @@ -191,11 +189,15 @@ list(APPEND DEFAULT_KERNEL_LINK_OPTIONS > ) -list(APPEND DEFAULT_KERNEL_LINK_LIB - ${COMMON_LINK_LIB} +add_library(kernel_link_libraries INTERFACE) +target_link_libraries(kernel_link_libraries INTERFACE + link_libraries + kernel_compile_definitions + kernel_compile_options + kernel_link_options printf_bare_metal - ${dtc_BINARY_DIR}/libfdt/libfdt.a + dtc-lib $<$: opensbi_interface @@ -204,19 +206,3 @@ list(APPEND DEFAULT_KERNEL_LINK_LIB $<$: > ) - -# 编译依赖 -list(APPEND COMPILE_DEPENDS - ovmf - gnu-efi - dtc - printf_bare_metal - ) -if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") -elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64") - list(APPEND COMPILE_DEPENDS - opensbi - opensbi_interface - ) -elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") -endif () diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index f3caf6c81..87bd8c9fa 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -20,33 +20,14 @@ add_executable(${PROJECT_NAME} ) # 添加头文件 -add_header_project(${PROJECT_NAME}) -add_header_boot(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_BOOT_DEFINITIONS} -) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_BOOT_COMPILE_OPTIONS} -) - -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_BOOT_LINK_OPTIONS} +target_include_directories(${PROJECT_NAME} PRIVATE + include + ${CMAKE_SOURCE_DIR}/src ) # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_BOOT_LINK_LIB} -) - -# 添加依赖 -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} + boot_link_libraries ) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") diff --git a/src/boot/boot.cpp b/src/boot/boot.cpp index 60a964800..d742b15fa 100644 --- a/src/boot/boot.cpp +++ b/src/boot/boot.cpp @@ -112,6 +112,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { uint64_t elf_addr; size_t elf_size; } basic_info; + std::fill_n(reinterpret_cast(&basic_info), sizeof(basic_info), 0); // 获取物理内存信息 auto [physical_memory_addr, physical_memory_size] = memory.GetMemory(); diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 6fa82505a..5f14d2ebc 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -10,6 +10,8 @@ project( VERSION 0.0.1 ) +enable_language(ASM) +enable_language(C) enable_language(CXX) add_subdirectory(${PROJECT_SOURCE_DIR}/libc) @@ -23,44 +25,20 @@ add_executable(${PROJECT_NAME} physical_memory_manager.cpp ) -# 添加头文件 -add_header_project(${PROJECT_NAME}) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) -add_header_driver(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) - -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(kernel PRIVATE + include + ../ ) # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + kernel_link_libraries libc libcxx arch driver ) -# 添加依赖 -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${KERNEL_ELF_OUTPUT_NAME}) diff --git a/src/kernel/arch/CMakeLists.txt b/src/kernel/arch/CMakeLists.txt index 8cb495ffb..e2ab2260a 100644 --- a/src/kernel/arch/CMakeLists.txt +++ b/src/kernel/arch/CMakeLists.txt @@ -4,50 +4,19 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - arch - VERSION 0.0.1 -) +add_library(arch INTERFACE) -enable_language(ASM) -enable_language(CXX) +target_include_directories(arch INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/include +) -# 生成对象库 -add_library(${PROJECT_NAME} OBJECT +target_sources(arch INTERFACE $<$: - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/boot.S + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/boot.S > - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/macro.S - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/arch_main.cpp - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/backtrace.cpp - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/interrupt.cpp -) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) - -# 添加头文件 -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) -add_header_driver(${PROJECT_NAME}) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) - -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} -) - -# 添加要链接的库 -target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/macro.S + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/arch_main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/backtrace.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/interrupt.cpp ) diff --git a/src/kernel/arch/README.md b/src/kernel/arch/README.md index 98032444c..a277ce464 100644 --- a/src/kernel/arch/README.md +++ b/src/kernel/arch/README.md @@ -70,8 +70,8 @@ arch 目录下放置了与架构强相关的内容 #include #include -#include "cstdio" -#include "iostream" +#include "sk_cstdio" +#include "sk_iostream" #include "kernel_log.hpp" /** diff --git a/src/kernel/arch/aarch64/arch_main.cpp b/src/kernel/arch/aarch64/arch_main.cpp index cc5c600ee..2e1e7f67a 100644 --- a/src/kernel/arch/aarch64/arch_main.cpp +++ b/src/kernel/arch/aarch64/arch_main.cpp @@ -15,7 +15,7 @@ */ #include "arch.h" -#include "cstdio" +#include "sk_cstdio" // printf_bare_metal 基本输出实现 extern "C" void _putchar(char character) { (void)character; } diff --git a/src/kernel/arch/aarch64/backtrace.cpp b/src/kernel/arch/aarch64/backtrace.cpp index d3882cdf9..30d1741cc 100644 --- a/src/kernel/arch/aarch64/backtrace.cpp +++ b/src/kernel/arch/aarch64/backtrace.cpp @@ -15,9 +15,9 @@ #include "arch.h" #include "cpu.hpp" -#include "cstdio" +#include "sk_cstdio" #include "kernel_elf.hpp" -#include "libc.h" +#include "sk_libc.h" int backtrace(void **buffer, int size) { uint64_t *x29 = (uint64_t *)cpu::kAllXreg.x29.Read(); diff --git a/src/kernel/arch/aarch64/include/cpu.hpp b/src/kernel/arch/aarch64/include/cpu.hpp index 73b6dbbcb..f0e740793 100644 --- a/src/kernel/arch/aarch64/include/cpu.hpp +++ b/src/kernel/arch/aarch64/include/cpu.hpp @@ -22,8 +22,8 @@ #include #include -#include "cstdio" -#include "iostream" +#include "sk_cstdio" +#include "sk_iostream" #include "kernel_log.hpp" /** diff --git a/src/kernel/arch/aarch64/interrupt.cpp b/src/kernel/arch/aarch64/interrupt.cpp index aad7ae143..92962eb6d 100644 --- a/src/kernel/arch/aarch64/interrupt.cpp +++ b/src/kernel/arch/aarch64/interrupt.cpp @@ -18,7 +18,7 @@ #include "cstdio" #include "kernel_log.hpp" -Interrupt::Interrupt() { Info("Interrupt init.\n"); } +Interrupt::Interrupt() { log::Info("Interrupt init.\n"); } void Interrupt::Do(uint64_t cause, uint8_t *context) { (void)cause; @@ -31,7 +31,7 @@ void Interrupt::RegisterInterruptFunc(uint64_t cause, InterruptFunc func) { } uint32_t InterruptInit(uint32_t, uint8_t *) { - Info("Hello InterruptInit\n"); + log::Info("Hello InterruptInit\n"); return 0; } diff --git a/src/kernel/arch/riscv64/arch_main.cpp b/src/kernel/arch/riscv64/arch_main.cpp index 1fe288c14..1cbe6e87f 100644 --- a/src/kernel/arch/riscv64/arch_main.cpp +++ b/src/kernel/arch/riscv64/arch_main.cpp @@ -17,11 +17,11 @@ #include "basic_info.hpp" #include "cpu.hpp" -#include "cstdio" #include "kernel_elf.hpp" #include "kernel_fdt.hpp" -#include "libc.h" #include "ns16550a.h" +#include "sk_cstdio" +#include "sk_libc.h" // printf_bare_metal 基本输出实现 extern "C" void _putchar(char character) { diff --git a/src/kernel/arch/riscv64/backtrace.cpp b/src/kernel/arch/riscv64/backtrace.cpp index bcbbcdf97..529188a9f 100644 --- a/src/kernel/arch/riscv64/backtrace.cpp +++ b/src/kernel/arch/riscv64/backtrace.cpp @@ -16,10 +16,10 @@ #include "arch.h" #include "cpu.hpp" -#include "cstdio" +#include "sk_cstdio" #include "kernel_elf.hpp" #include "kernel_fdt.hpp" -#include "libc.h" +#include "sk_libc.h" int backtrace(void **buffer, int size) { uint64_t *fp = (uint64_t *)cpu::kAllXreg.fp.Read(); diff --git a/src/kernel/arch/riscv64/include/cpu.hpp b/src/kernel/arch/riscv64/include/cpu.hpp index 3da8fc594..634f478bb 100644 --- a/src/kernel/arch/riscv64/include/cpu.hpp +++ b/src/kernel/arch/riscv64/include/cpu.hpp @@ -22,9 +22,9 @@ #include #include -#include "cstdio" -#include "iostream" #include "kernel_log.hpp" +#include "sk_cstdio" +#include "sk_iostream" /** * riscv64 cpu 相关定义 diff --git a/src/kernel/arch/riscv64/interrupt.cpp b/src/kernel/arch/riscv64/interrupt.cpp index d8a43e6d5..7a3a53993 100644 --- a/src/kernel/arch/riscv64/interrupt.cpp +++ b/src/kernel/arch/riscv64/interrupt.cpp @@ -16,11 +16,11 @@ #include "interrupt.h" #include "cpu.hpp" -#include "cstdio" -#include "iostream" #include "kernel_fdt.hpp" #include "kernel_log.hpp" #include "opensbi_interface.h" +#include "sk_cstdio" +#include "sk_iostream" Interrupt::InterruptFunc Interrupt::interrupt_handlers [cpu::reginfo::csr::ScauseInfo::kInterruptMaxCount]; diff --git a/src/kernel/arch/riscv64/interrupt.h b/src/kernel/arch/riscv64/interrupt.h index 70eb3a156..5f2b45a9e 100644 --- a/src/kernel/arch/riscv64/interrupt.h +++ b/src/kernel/arch/riscv64/interrupt.h @@ -22,7 +22,7 @@ #include "cpu.hpp" #include "interrupt_base.h" #include "singleton.hpp" -#include "stdio.h" +#include "sk_stdio.h" class Interrupt final : public InterruptBase { public: diff --git a/src/kernel/arch/x86_64/arch_main.cpp b/src/kernel/arch/x86_64/arch_main.cpp index 125f9d9e2..bda043302 100644 --- a/src/kernel/arch/x86_64/arch_main.cpp +++ b/src/kernel/arch/x86_64/arch_main.cpp @@ -18,8 +18,8 @@ #include "basic_info.hpp" #include "cpu.hpp" -#include "cstdio" -#include "cstring" +#include "sk_cstdio" +#include "sk_cstring" #include "kernel_elf.hpp" #include "kernel_log.hpp" diff --git a/src/kernel/arch/x86_64/backtrace.cpp b/src/kernel/arch/x86_64/backtrace.cpp index da30216f5..cb5f55b40 100644 --- a/src/kernel/arch/x86_64/backtrace.cpp +++ b/src/kernel/arch/x86_64/backtrace.cpp @@ -15,9 +15,9 @@ #include "arch.h" #include "cpu.hpp" -#include "cstdio" +#include "sk_cstdio" #include "kernel_elf.hpp" -#include "libc.h" +#include "sk_libc.h" int backtrace(void **buffer, int size) { uint64_t *rbp = (uint64_t *)cpu::kAllXreg.rbp.Read(); diff --git a/src/kernel/arch/x86_64/include/cpu.hpp b/src/kernel/arch/x86_64/include/cpu.hpp index 91cd917e6..f6c2e88b7 100644 --- a/src/kernel/arch/x86_64/include/cpu.hpp +++ b/src/kernel/arch/x86_64/include/cpu.hpp @@ -22,8 +22,8 @@ #include #include -#include "cstdio" -#include "iostream" +#include "sk_cstdio" +#include "sk_iostream" #include "kernel_log.hpp" /** diff --git a/src/kernel/arch/x86_64/interrupt.cpp b/src/kernel/arch/x86_64/interrupt.cpp index 31b8855cd..aff0a1dc1 100644 --- a/src/kernel/arch/x86_64/interrupt.cpp +++ b/src/kernel/arch/x86_64/interrupt.cpp @@ -17,9 +17,9 @@ #include "arch.h" #include "cpu.hpp" -#include "cstdio" -#include "iostream" #include "kernel_log.hpp" +#include "sk_cstdio" +#include "sk_iostream" Interrupt::InterruptFunc Interrupt::interrupt_handlers[cpu::reginfo::IdtrInfo::kInterruptMaxCount]; diff --git a/src/kernel/arch/x86_64/interrupt.h b/src/kernel/arch/x86_64/interrupt.h index 500d45ecd..90119afad 100644 --- a/src/kernel/arch/x86_64/interrupt.h +++ b/src/kernel/arch/x86_64/interrupt.h @@ -22,7 +22,7 @@ #include "cpu.hpp" #include "interrupt_base.h" #include "singleton.hpp" -#include "stdio.h" +#include "sk_stdio.h" class Interrupt final : public InterruptBase { public: diff --git a/src/kernel/driver/CMakeLists.txt b/src/kernel/driver/CMakeLists.txt index 7afa4b1a7..6b158f6b9 100644 --- a/src/kernel/driver/CMakeLists.txt +++ b/src/kernel/driver/CMakeLists.txt @@ -4,41 +4,20 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - driver - VERSION 0.0.1 -) - -enable_language(CXX) - -# 生成对象库 -add_library(${PROJECT_NAME} - ${PROJECT_SOURCE_DIR}/driver.cpp -) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) -# 添加头文件 -add_header_driver(${PROJECT_NAME}) +add_library(driver INTERFACE) -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} +target_include_directories(driver INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_sources(driver INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/driver.cpp ) -# 添加要链接的库 -target_link_libraries(${PROJECT_NAME} PRIVATE +target_link_libraries(driver INTERFACE $<$: - ns16550a + ns16550a > ) diff --git a/src/kernel/driver/ns16550a/CMakeLists.txt b/src/kernel/driver/ns16550a/CMakeLists.txt index 5214d9f16..04ebfae55 100644 --- a/src/kernel/driver/ns16550a/CMakeLists.txt +++ b/src/kernel/driver/ns16550a/CMakeLists.txt @@ -4,37 +4,12 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - ns16550a - VERSION 0.0.1 -) - -enable_language(CXX) - -# 生成对象库 -add_library(${PROJECT_NAME} - ${PROJECT_SOURCE_DIR}/ns16550a.cpp -) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) - -# 添加头文件 -add_header_driver(${PROJECT_NAME}) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) +add_library(ns16550a INTERFACE) -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(ns16550a INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# 添加要链接的库 -target_link_libraries(${PROJECT_NAME} PRIVATE +target_sources(ns16550a INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/ns16550a.cpp ) diff --git a/src/kernel/include/basic_info.hpp b/src/kernel/include/basic_info.hpp index 97bee5945..286f3df29 100644 --- a/src/kernel/include/basic_info.hpp +++ b/src/kernel/include/basic_info.hpp @@ -19,10 +19,10 @@ #include #include -#include -#include #include "singleton.hpp" +#include "sk_cstdio" +#include "sk_iostream" struct BasicInfo { /// physical_memory 地址 diff --git a/src/kernel/include/kernel_elf.hpp b/src/kernel/include/kernel_elf.hpp index 769d31732..5bfa84e89 100644 --- a/src/kernel/include/kernel_elf.hpp +++ b/src/kernel/include/kernel_elf.hpp @@ -23,7 +23,7 @@ #include #include -#include "cstring" +#include "sk_cstring" #include "kernel_log.hpp" #include "singleton.hpp" diff --git a/src/kernel/include/kernel_fdt.hpp b/src/kernel/include/kernel_fdt.hpp index a8373b32b..d1fb6dab4 100644 --- a/src/kernel/include/kernel_fdt.hpp +++ b/src/kernel/include/kernel_fdt.hpp @@ -33,7 +33,7 @@ #include #include -#include "cstring" +#include "sk_cstring" #include "kernel_log.hpp" #include "singleton.hpp" diff --git a/src/kernel/include/kernel_log.hpp b/src/kernel/include/kernel_log.hpp index 8f66a619b..34c017f14 100644 --- a/src/kernel/include/kernel_log.hpp +++ b/src/kernel/include/kernel_log.hpp @@ -20,8 +20,8 @@ #include #include "../../project_config.h" -#include "cstdio" -#include "iostream" +#include "sk_cstdio" +#include "sk_iostream" namespace { diff --git a/src/kernel/libc/CMakeLists.txt b/src/kernel/libc/CMakeLists.txt index d37f2559b..8cdd84f23 100644 --- a/src/kernel/libc/CMakeLists.txt +++ b/src/kernel/libc/CMakeLists.txt @@ -4,41 +4,15 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - libc - VERSION 0.0.1 -) - -enable_language(C) - -# 生成对象库 -add_library(${PROJECT_NAME} OBJECT - ${PROJECT_SOURCE_DIR}/libc.c - ${PROJECT_SOURCE_DIR}/string.c - ${PROJECT_SOURCE_DIR}/stdio.c - ${PROJECT_SOURCE_DIR}/bit.c -) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) - -# 添加头文件 -add_header_libc(${PROJECT_NAME}) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) +add_library(libc INTERFACE) -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(libc INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# 添加要链接的库 -target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} +target_sources(libc INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/sk_libc.c + ${CMAKE_CURRENT_SOURCE_DIR}/sk_string.c + ${CMAKE_CURRENT_SOURCE_DIR}/sk_stdio.c + ${CMAKE_CURRENT_SOURCE_DIR}/bit.c ) diff --git a/src/kernel/libc/include/libc.h b/src/kernel/libc/include/sk_libc.h similarity index 59% rename from src/kernel/libc/include/libc.h rename to src/kernel/libc/include/sk_libc.h index 060510a51..12c22a19f 100644 --- a/src/kernel/libc/include/libc.h +++ b/src/kernel/libc/include/sk_libc.h @@ -1,7 +1,7 @@ /** - * @file libc.h - * @brief libc 头文件 + * @file sk_libc.h + * @brief sk_libc 头文件 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-07-15 @@ -14,7 +14,7 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_LIBC_H_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_LIBC_H_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_LIBC_H_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_LIBC_H_ -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_LIBC_H_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_LIBC_H_ */ diff --git a/src/kernel/libc/include/stdio.h b/src/kernel/libc/include/sk_stdio.h similarity index 62% rename from src/kernel/libc/include/stdio.h rename to src/kernel/libc/include/sk_stdio.h index 71aa584e3..352b24b75 100644 --- a/src/kernel/libc/include/stdio.h +++ b/src/kernel/libc/include/sk_stdio.h @@ -1,7 +1,7 @@ /** - * @file stdio.h - * @brief stdio 定义 + * @file sk_stdio.h + * @brief sk_stdio 定义 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-03-31 @@ -15,9 +15,9 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STDIO_H_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STDIO_H_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STDIO_H_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STDIO_H_ #include -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STDIO_H_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STDIO_H_ */ diff --git a/src/kernel/libc/include/string.h b/src/kernel/libc/include/sk_string.h similarity index 86% rename from src/kernel/libc/include/string.h rename to src/kernel/libc/include/sk_string.h index 141c04f45..0a9f9fa2c 100644 --- a/src/kernel/libc/include/string.h +++ b/src/kernel/libc/include/sk_string.h @@ -1,7 +1,7 @@ /** - * @file string.h - * @brief string 定义 + * @file sk_string.h + * @brief sk_string 定义 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-05-08 @@ -14,8 +14,8 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STRING_H_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STRING_H_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STRING_H_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STRING_H_ #include @@ -69,4 +69,4 @@ char *strrchr(const char *s, int c); } #endif -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_STRING_H_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBC_INCLUDE_SK_STRING_H_ */ diff --git a/src/kernel/libc/libc.c b/src/kernel/libc/sk_libc.c similarity index 81% rename from src/kernel/libc/libc.c rename to src/kernel/libc/sk_libc.c index c5ffda3c8..bc110a72a 100644 --- a/src/kernel/libc/libc.c +++ b/src/kernel/libc/sk_libc.c @@ -1,6 +1,6 @@ /** - * @file libc.c + * @file sk_libc.c * @brief c 运行时支持 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 @@ -14,7 +14,7 @@ * */ -#include "libc.h" +#include "sk_libc.h" #include @@ -22,7 +22,4 @@ uint64_t __stack_chk_guard = 0x595E9FBD94FDA766; /// 栈保护检查失败后进入死循环 -__attribute__((noreturn)) void __stack_chk_fail() { - while (1) - ; -} +__attribute__((noreturn)) void __stack_chk_fail() { while (1); } diff --git a/src/kernel/libc/stdio.c b/src/kernel/libc/sk_stdio.c similarity index 83% rename from src/kernel/libc/stdio.c rename to src/kernel/libc/sk_stdio.c index 15440fe56..08d145290 100644 --- a/src/kernel/libc/stdio.c +++ b/src/kernel/libc/sk_stdio.c @@ -1,7 +1,7 @@ /** - * @file stdio.h - * @brief stdio 定义 + * @file sk_stdio.h + * @brief sk_stdio 定义 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-03-31 @@ -15,4 +15,4 @@ * */ -#include "stdio.h" +#include "sk_stdio.h" diff --git a/src/kernel/libc/string.c b/src/kernel/libc/sk_string.c similarity index 97% rename from src/kernel/libc/string.c rename to src/kernel/libc/sk_string.c index 48d5d5562..d1cf041c4 100644 --- a/src/kernel/libc/string.c +++ b/src/kernel/libc/sk_string.c @@ -1,7 +1,7 @@ /** - * @file string.c - * @brief string 实现 + * @file sk_string.c + * @brief sk_string 实现 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-05-08 @@ -14,7 +14,7 @@ * */ -#include "string.h" +#include "sk_string.h" #ifdef __cplusplus extern "C" { diff --git a/src/kernel/libcxx/CMakeLists.txt b/src/kernel/libcxx/CMakeLists.txt index 9bea23315..2c0a451b8 100644 --- a/src/kernel/libcxx/CMakeLists.txt +++ b/src/kernel/libcxx/CMakeLists.txt @@ -4,41 +4,14 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - libcxx - VERSION 0.0.1 -) - -enable_language(CXX) - -# 生成对象库 -add_library(${PROJECT_NAME} OBJECT - ${PROJECT_SOURCE_DIR}/libcxx.cpp - ${PROJECT_SOURCE_DIR}/new.cpp - ${PROJECT_SOURCE_DIR}/iostream.cpp -) - -# 添加定义 -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_DEFINITIONS} -) - -# 添加头文件 -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) - -# 添加编译参数 -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) +add_library(libcxx INTERFACE) -# 添加链接参数 -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(libcxx INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# 添加要链接的库 -target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} +target_sources(libcxx INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/sk_libcxx.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sk_new.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sk_iostream.cpp ) diff --git a/src/kernel/libcxx/include/cstdio b/src/kernel/libcxx/include/sk_cstdio similarity index 57% rename from src/kernel/libcxx/include/cstdio rename to src/kernel/libcxx/include/sk_cstdio index c01f4c9f1..83985921a 100644 --- a/src/kernel/libcxx/include/cstdio +++ b/src/kernel/libcxx/include/sk_cstdio @@ -1,7 +1,7 @@ /** - * @file cstdio - * @brief cstdio 定义 + * @file sk_cstdio + * @brief sk_cstdio 定义 * @author Zone.N (Zone.Niuzh@hotmail.com) * Based on https://github.com/mpaland/printf * @version 1.0 @@ -15,9 +15,9 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTDIO_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTDIO_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTDIO_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTDIO_ -#include "stdio.h" +#include "sk_stdio.h" -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTDIO_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTDIO_ */ diff --git a/src/kernel/libcxx/include/cstring b/src/kernel/libcxx/include/sk_cstring similarity index 70% rename from src/kernel/libcxx/include/cstring rename to src/kernel/libcxx/include/sk_cstring index e032d692b..822b7474e 100644 --- a/src/kernel/libcxx/include/cstring +++ b/src/kernel/libcxx/include/sk_cstring @@ -1,7 +1,7 @@ /** - * @file cstring - * @brief cstring 定义 + * @file sk_cstring + * @brief sk_cstring 定义 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-05-08 @@ -14,8 +14,8 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTRING_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTRING_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTRING_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTRING_ #include "string.h" @@ -36,4 +36,4 @@ using ::strnlen; }; // namespace sk_std -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTRING_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_CSTRING_ */ diff --git a/src/kernel/libcxx/include/iostream b/src/kernel/libcxx/include/sk_iostream similarity index 87% rename from src/kernel/libcxx/include/iostream rename to src/kernel/libcxx/include/sk_iostream index 98177dbc3..09261137c 100644 --- a/src/kernel/libcxx/include/iostream +++ b/src/kernel/libcxx/include/sk_iostream @@ -1,6 +1,6 @@ /** - * @file iostream + * @file sk_iostream * @brief C++ 输入输出 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 @@ -15,8 +15,8 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_IOSTREAM_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_IOSTREAM_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_IOSTREAM_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_IOSTREAM_ #include @@ -59,4 +59,4 @@ inline ostream& endl(ostream& os) { return os << "\n"; } }; // namespace sk_std -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_IOSTREAM_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_IOSTREAM_ */ diff --git a/src/kernel/libcxx/include/libcxx.h b/src/kernel/libcxx/include/sk_libcxx.h similarity index 65% rename from src/kernel/libcxx/include/libcxx.h rename to src/kernel/libcxx/include/sk_libcxx.h index 4ed2591c2..92296cea6 100644 --- a/src/kernel/libcxx/include/libcxx.h +++ b/src/kernel/libcxx/include/sk_libcxx.h @@ -1,7 +1,7 @@ /** - * @file libcxx.h - * @brief libcxx 头文件 + * @file sk_libcxx.h + * @brief sk_libcxx 头文件 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-07-15 @@ -14,8 +14,8 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_LIBCXX_H_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_LIBCXX_H_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_LIBCXX_H_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_LIBCXX_H_ #include @@ -29,4 +29,4 @@ void CppInit(); */ void CppDeInit(); -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_LIBCXX_H_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_LIBCXX_H_ */ diff --git a/src/kernel/libcxx/include/new b/src/kernel/libcxx/include/sk_new similarity index 77% rename from src/kernel/libcxx/include/new rename to src/kernel/libcxx/include/sk_new index 50de9ede1..489baf66e 100644 --- a/src/kernel/libcxx/include/new +++ b/src/kernel/libcxx/include/sk_new @@ -1,6 +1,6 @@ /** - * @file new + * @file sk_new * @brief 内存分配 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 @@ -14,8 +14,8 @@ * */ -#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_NEW_ -#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_NEW_ +#ifndef SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_NEW_ +#define SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_NEW_ #include @@ -35,4 +35,4 @@ void operator delete[](void*); void operator delete[](void*, size_t); -#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_NEW_ */ +#endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_SK_NEW_ */ diff --git a/src/kernel/libcxx/iostream.cpp b/src/kernel/libcxx/sk_iostream.cpp similarity index 95% rename from src/kernel/libcxx/iostream.cpp rename to src/kernel/libcxx/sk_iostream.cpp index 755d3030d..d94d69326 100644 --- a/src/kernel/libcxx/iostream.cpp +++ b/src/kernel/libcxx/sk_iostream.cpp @@ -1,6 +1,6 @@ /** - * @file iostream + * @file sk_iostream * @brief C++ 输入输出 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 @@ -15,11 +15,11 @@ * */ -#include "iostream" +#include "sk_iostream" #include -#include "cstdio" +#include "sk_cstdio" namespace sk_std { diff --git a/src/kernel/libcxx/libcxx.cpp b/src/kernel/libcxx/sk_libcxx.cpp similarity index 94% rename from src/kernel/libcxx/libcxx.cpp rename to src/kernel/libcxx/sk_libcxx.cpp index e3ec4818b..6712de839 100644 --- a/src/kernel/libcxx/libcxx.cpp +++ b/src/kernel/libcxx/sk_libcxx.cpp @@ -1,7 +1,7 @@ /** - * @file libcxx.cpp - * @brief libcxx cpp + * @file sk_libcxx.cpp + * @brief sk_libcxx cpp * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 * @date 2023-07-15 @@ -14,7 +14,7 @@ * */ -#include "libcxx.h" +#include "sk_libcxx.h" #include @@ -155,27 +155,15 @@ extern "C" void __cxa_guard_abort(GuardType* guard) { /** * 纯虚函数调用处理 */ -extern "C" void __cxa_pure_virtual() { - while (1) - ; -} +extern "C" void __cxa_pure_virtual() { while (1); } /** * 异常处理 * @note 这里只能处理 throw,无法处理异常类型 */ -extern "C" void __cxa_rethrow() { - while (1) - ; -} -extern "C" void _Unwind_Resume() { - while (1) - ; -} -extern "C" void __gxx_personality_v0() { - while (1) - ; -} +extern "C" void __cxa_rethrow() { while (1); } +extern "C" void _Unwind_Resume() { while (1); } +extern "C" void __gxx_personality_v0() { while (1); } /** * c++ 全局对象构造 diff --git a/src/kernel/libcxx/new.cpp b/src/kernel/libcxx/sk_new.cpp similarity index 95% rename from src/kernel/libcxx/new.cpp rename to src/kernel/libcxx/sk_new.cpp index 4ab820549..4bfe04e90 100644 --- a/src/kernel/libcxx/new.cpp +++ b/src/kernel/libcxx/sk_new.cpp @@ -1,6 +1,6 @@ /** - * @file new.cpp + * @file sk_new.cpp * @brief 内存分配实现 * @author Zone.N (Zone.Niuzh@hotmail.com) * @version 1.0 @@ -14,7 +14,7 @@ * */ -#include "new" +#include "sk_new" #include diff --git a/src/kernel/main.cpp b/src/kernel/main.cpp index b08e33dee..55121dec4 100644 --- a/src/kernel/main.cpp +++ b/src/kernel/main.cpp @@ -16,11 +16,11 @@ #include #include "arch.h" -#include "cstdio" -#include "iostream" +#include "sk_cstdio" +#include "sk_iostream" #include "kernel.h" #include "kernel_log.hpp" -#include "libcxx.h" +#include "sk_libcxx.h" void _start(uint32_t argc, uint8_t *argv) { CppInit(); diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index b2b723741..52facc372 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -21,29 +21,18 @@ add_executable(${PROJECT_NAME} > ) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) - -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) - -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/src/kernel/include + ${CMAKE_SOURCE_DIR}/src/kernel/arch + ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include ) target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + kernel_link_libraries libc libcxx ) -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${KERNEL_ELF_OUTPUT_NAME}) diff --git a/test/system_test/cxx_init_test/main.cpp b/test/system_test/cxx_init_test/main.cpp index 6c3143f15..e1296e891 100644 --- a/test/system_test/cxx_init_test/main.cpp +++ b/test/system_test/cxx_init_test/main.cpp @@ -15,12 +15,12 @@ */ #include -#include -#include #include "basic_info.hpp" #include "cpu.hpp" -#include "libcxx.h" +#include "sk_cstdio" +#include "sk_cstring" +#include "sk_libcxx.h" #ifdef __x86_64__ static auto serial = cpu::Serial(cpu::kCom1); diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index e860c2374..04834f858 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -16,29 +16,18 @@ add_executable(${PROJECT_NAME} main.cpp ) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) - -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) - -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/src/kernel/include + ${CMAKE_SOURCE_DIR}/src/kernel/arch + ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include ) target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + kernel_link_libraries libc libcxx ) -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${KERNEL_ELF_OUTPUT_NAME}) diff --git a/test/system_test/gnu_efi_test/main.cpp b/test/system_test/gnu_efi_test/main.cpp index 3018c2ba7..c937366fc 100644 --- a/test/system_test/gnu_efi_test/main.cpp +++ b/test/system_test/gnu_efi_test/main.cpp @@ -15,11 +15,11 @@ */ #include -#include -#include #include "basic_info.hpp" #include "cpu.hpp" +#include "sk_cstdio" +#include "sk_cstring" extern "C" void _putchar(char character) { auto serial = cpu::Serial(cpu::kCom1); @@ -34,14 +34,19 @@ extern "C" void *__executable_start[]; extern "C" void *end[]; BasicInfo::BasicInfo(uint32_t argc, uint8_t *argv) { (void)argc; + auto basic_info = *reinterpret_cast(argv); physical_memory_addr = basic_info.physical_memory_addr; physical_memory_size = basic_info.physical_memory_size; + kernel_addr = reinterpret_cast(__executable_start); kernel_size = reinterpret_cast(end) - reinterpret_cast(__executable_start); + elf_addr = basic_info.elf_addr; elf_size = basic_info.elf_size; + + fdt_addr = 0; } uint32_t main(uint32_t argc, uint8_t *argv) { @@ -51,7 +56,7 @@ uint32_t main(uint32_t argc, uint8_t *argv) { } kBasicInfo.GetInstance() = BasicInfo(argc, argv); - std::cout << kBasicInfo.GetInstance(); + sk_std::cout << kBasicInfo.GetInstance(); printf("Hello Test\n"); diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index ae3b21118..0c0788d8a 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -18,31 +18,13 @@ add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/boot.S ) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) - -target_compile_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_COMPILE_OPTIONS} -) - -target_link_options(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_OPTIONS} -) - # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + kernel_link_libraries libc libcxx ) -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${KERNEL_ELF_OUTPUT_NAME}) diff --git a/test/system_test/opensbi_test/main.cpp b/test/system_test/opensbi_test/main.cpp index 83fbb8ab8..d06a2bb1e 100644 --- a/test/system_test/opensbi_test/main.cpp +++ b/test/system_test/opensbi_test/main.cpp @@ -18,7 +18,7 @@ #include -#include "cstdio" +#include "sk_cstdio" // printf_bare_metal 基本输出实现 extern "C" void _putchar(char character) { diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 13073b8c6..0ccc2647d 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -24,9 +24,10 @@ add_executable(${PROJECT_NAME} firstfit_allocator_test.cpp ) -add_header_arch(${PROJECT_NAME}) -add_header_kernel(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/src/kernel/include + ${CMAKE_SOURCE_DIR}/src/kernel/arch +) target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_TEST_COMPILE_OPTIONS} @@ -42,8 +43,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE libc ) -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - gtest_discover_tests(${PROJECT_NAME})