From f8e8f2aaae81041f4942f6e9815dee723f3d5c1b Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Fri, 9 Aug 2024 08:53:01 +0000 Subject: [PATCH 01/24] refactor: rename std:: with sk_std Signed-off-by: Zone.N --- src/kernel/arch/README.md | 4 +-- src/kernel/arch/aarch64/arch_main.cpp | 2 +- src/kernel/arch/aarch64/backtrace.cpp | 4 +-- src/kernel/arch/aarch64/include/cpu.hpp | 4 +-- src/kernel/arch/riscv64/arch_main.cpp | 4 +-- src/kernel/arch/riscv64/backtrace.cpp | 4 +-- src/kernel/arch/riscv64/include/cpu.hpp | 4 +-- src/kernel/arch/x86_64/arch_main.cpp | 4 +-- src/kernel/arch/x86_64/backtrace.cpp | 4 +-- src/kernel/arch/x86_64/include/cpu.hpp | 4 +-- src/kernel/include/basic_info.hpp | 4 +-- src/kernel/include/kernel_elf.hpp | 2 +- src/kernel/include/kernel_fdt.hpp | 2 +- src/kernel/include/kernel_log.hpp | 4 +-- src/kernel/libc/CMakeLists.txt | 6 ++--- src/kernel/libc/include/{libc.h => sk_libc.h} | 10 +++---- .../libc/include/{stdio.h => sk_stdio.h} | 10 +++---- .../libc/include/{string.h => sk_string.h} | 10 +++---- src/kernel/libc/{libc.c => sk_libc.c} | 9 +++---- src/kernel/libc/{stdio.c => sk_stdio.c} | 6 ++--- src/kernel/libc/{string.c => sk_string.c} | 6 ++--- src/kernel/libcxx/CMakeLists.txt | 6 ++--- .../libcxx/include/{cstdio => sk_cstdio} | 12 ++++----- .../libcxx/include/{cstring => sk_cstring} | 10 +++---- .../libcxx/include/{iostream => sk_iostream} | 8 +++--- .../libcxx/include/{libcxx.h => sk_libcxx.h} | 10 +++---- src/kernel/libcxx/include/{new => sk_new} | 8 +++--- .../libcxx/{iostream.cpp => sk_iostream.cpp} | 6 ++--- .../libcxx/{libcxx.cpp => sk_libcxx.cpp} | 26 +++++-------------- src/kernel/libcxx/{new.cpp => sk_new.cpp} | 4 +-- src/kernel/main.cpp | 6 ++--- test/system_test/cxx_init_test/main.cpp | 6 ++--- test/system_test/gnu_efi_test/main.cpp | 6 ++--- test/system_test/opensbi_test/main.cpp | 2 +- test/unit_test/CMakeLists.txt | 2 ++ 35 files changed, 103 insertions(+), 116 deletions(-) rename src/kernel/libc/include/{libc.h => sk_libc.h} (59%) rename src/kernel/libc/include/{stdio.h => sk_stdio.h} (62%) rename src/kernel/libc/include/{string.h => sk_string.h} (86%) rename src/kernel/libc/{libc.c => sk_libc.c} (81%) rename src/kernel/libc/{stdio.c => sk_stdio.c} (83%) rename src/kernel/libc/{string.c => sk_string.c} (97%) rename src/kernel/libcxx/include/{cstdio => sk_cstdio} (57%) rename src/kernel/libcxx/include/{cstring => sk_cstring} (70%) rename src/kernel/libcxx/include/{iostream => sk_iostream} (87%) rename src/kernel/libcxx/include/{libcxx.h => sk_libcxx.h} (65%) rename src/kernel/libcxx/include/{new => sk_new} (77%) rename src/kernel/libcxx/{iostream.cpp => sk_iostream.cpp} (95%) rename src/kernel/libcxx/{libcxx.cpp => sk_libcxx.cpp} (94%) rename src/kernel/libcxx/{new.cpp => sk_new.cpp} (95%) 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/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 78f631a34..0741af11b 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/x86_64/arch_main.cpp b/src/kernel/arch/x86_64/arch_main.cpp index 1fffd8ab8..ecc4aec2e 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 c87a9e668..e30fe565d 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/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 f0d572be5..66dd6a2a5 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 dd1bfb139..3bb4aa08d 100644 --- a/src/kernel/libc/CMakeLists.txt +++ b/src/kernel/libc/CMakeLists.txt @@ -14,9 +14,9 @@ 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}/sk_libc.c + ${PROJECT_SOURCE_DIR}/sk_string.c + ${PROJECT_SOURCE_DIR}/sk_stdio.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..d2533eb5d 100644 --- a/src/kernel/libcxx/CMakeLists.txt +++ b/src/kernel/libcxx/CMakeLists.txt @@ -14,9 +14,9 @@ enable_language(CXX) # 生成对象库 add_library(${PROJECT_NAME} OBJECT - ${PROJECT_SOURCE_DIR}/libcxx.cpp - ${PROJECT_SOURCE_DIR}/new.cpp - ${PROJECT_SOURCE_DIR}/iostream.cpp + ${PROJECT_SOURCE_DIR}/sk_libcxx.cpp + ${PROJECT_SOURCE_DIR}/sk_new.cpp + ${PROJECT_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 8b32b47c6..d03aa65ca 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/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/main.cpp b/test/system_test/gnu_efi_test/main.cpp index 3018c2ba7..4170a5512 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); @@ -51,7 +51,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/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 d72b3fcb3..5695090b2 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -23,6 +23,8 @@ add_executable(${PROJECT_NAME} add_header_arch(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) +add_header_libc(${PROJECT_NAME}) +add_header_libcxx(${PROJECT_NAME}) target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_TEST_COMPILE_OPTIONS} From 4a9b4a34cb7d15c8de6e6926ef0872e76aa555ce Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Fri, 9 Aug 2024 09:20:07 +0000 Subject: [PATCH 02/24] refactor: COMMON_COMPILE_OPTIONS INTERFACE Signed-off-by: Zone.N --- cmake/compile_config.cmake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 8cb3395a7..01deeb75c 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -6,7 +6,8 @@ # 配置信息 # 通用编译选项 -list(APPEND COMMON_COMPILE_OPTIONS +add_library(COMMON_COMPILE_OPTIONS INTERFACE) +target_compile_options(COMMON_COMPILE_OPTIONS INTERFACE # 如果 CMAKE_BUILD_TYPE 为 Release 则使用 -O3 -Werror,否则使用 -O0 -ggdb # -g 在 Debug 模式下由 cmake 自动添加 $<$:-O3;-Werror> @@ -83,7 +84,6 @@ list(APPEND DEFAULT_BOOT_DEFINITIONS ) list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS - ${COMMON_COMPILE_OPTIONS} # 使用 2 字节 wchar_t -fshort-wchar # 允许 wchar_t @@ -155,8 +155,6 @@ list(APPEND DEFAULT_KERNEL_DEFINITIONS ) list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS - ${COMMON_COMPILE_OPTIONS} - $<$: # 使用 kernel 内存模型 -mcmodel=large @@ -196,6 +194,7 @@ list(APPEND DEFAULT_KERNEL_LINK_LIB printf_bare_metal ${dtc_BINARY_DIR}/libfdt/libfdt.a + COMMON_COMPILE_OPTIONS $<$: opensbi_interface From ef70b8a8c0e64c504139dc5374731e34dd9dede0 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Fri, 9 Aug 2024 09:26:14 +0000 Subject: [PATCH 03/24] refactor: COMMON_LINK_OPTIONS INTERFACE Signed-off-by: Zone.N --- cmake/compile_config.cmake | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 01deeb75c..7ddb97bbd 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -61,13 +61,15 @@ target_compile_options(COMMON_COMPILE_OPTIONS INTERFACE ) # 通用链接选项 -list(APPEND COMMON_LINK_OPTIONS +add_library(COMMON_LINK_OPTIONS INTERFACE) +target_link_options(COMMON_LINK_OPTIONS INTERFACE # 不链接 ctr0 等启动代码 -nostartfiles ) # 通用库选项 list(APPEND COMMON_LINK_LIB + COMMON_LINK_OPTIONS ) # 通用宏定义 @@ -98,8 +100,6 @@ list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS ) list(APPEND DEFAULT_BOOT_LINK_OPTIONS - ${COMMON_LINK_OPTIONS} - $<$: # 编译为共享库 -shared @@ -168,8 +168,6 @@ list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS ) list(APPEND DEFAULT_KERNEL_LINK_OPTIONS - ${COMMON_LINK_OPTIONS} - # 链接脚本 -T ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/link.ld From 59daceb456fdd200932b05c1e3ab28092211fee8 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Fri, 9 Aug 2024 09:31:14 +0000 Subject: [PATCH 04/24] refactor: COMMON_LINK_LIB INTERFACE Signed-off-by: Zone.N --- cmake/compile_config.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 7ddb97bbd..b445e0d5a 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -68,7 +68,8 @@ target_link_options(COMMON_LINK_OPTIONS INTERFACE ) # 通用库选项 -list(APPEND COMMON_LINK_LIB +add_library(COMMON_LINK_LIB INTERFACE) +target_link_libraries(COMMON_LINK_LIB INTERFACE COMMON_LINK_OPTIONS ) @@ -121,7 +122,7 @@ list(APPEND DEFAULT_BOOT_LINK_OPTIONS ) list(APPEND DEFAULT_BOOT_LINK_LIB - ${COMMON_LINK_LIB} + COMMON_LINK_LIB # 目标平台编译选项 $<$: # 链接 gnu-efi @@ -188,7 +189,7 @@ list(APPEND DEFAULT_KERNEL_LINK_OPTIONS ) list(APPEND DEFAULT_KERNEL_LINK_LIB - ${COMMON_LINK_LIB} + COMMON_LINK_LIB printf_bare_metal ${dtc_BINARY_DIR}/libfdt/libfdt.a From 0d55f2bded6d8aea31d0c9796927cb6161747cf6 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Fri, 9 Aug 2024 09:49:02 +0000 Subject: [PATCH 05/24] refactor: replace with INTERFACE, not finished Signed-off-by: Zone.N --- cmake/compile_config.cmake | 38 +++++++++++++++++++++++++------------- src/boot/CMakeLists.txt | 15 --------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index b445e0d5a..e94714816 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -74,19 +74,20 @@ target_link_libraries(COMMON_LINK_LIB INTERFACE ) # 通用宏定义 -list(APPEND COMMON_DEFINITIONS +add_library(COMMON_DEFINITIONS INTERFACE) +target_compile_definitions(COMMON_DEFINITIONS INTERFACE $<$:SIMPLEKERNEL_RELEASE> $<$:SIMPLEKERNEL_DEBUG> ) -list(APPEND DEFAULT_BOOT_DEFINITIONS - ${COMMON_DEFINITIONS} - +add_library(DEFAULT_BOOT_DEFINITIONS INTERFACE) +target_compile_definitions(DEFAULT_BOOT_DEFINITIONS INTERFACE # 使用 gnu-efi GNU_EFI_USE_MS_ABI ) -list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS +add_library(DEFAULT_BOOT_COMPILE_OPTIONS INTERFACE) +target_compile_options(DEFAULT_BOOT_COMPILE_OPTIONS INTERFACE # 使用 2 字节 wchar_t -fshort-wchar # 允许 wchar_t @@ -100,7 +101,8 @@ list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS > ) -list(APPEND DEFAULT_BOOT_LINK_OPTIONS +add_library(DEFAULT_BOOT_LINK_OPTIONS INTERFACE) +target_link_options(DEFAULT_BOOT_LINK_OPTIONS INTERFACE $<$: # 编译为共享库 -shared @@ -121,8 +123,16 @@ list(APPEND DEFAULT_BOOT_LINK_OPTIONS > ) -list(APPEND DEFAULT_BOOT_LINK_LIB +add_library(DEFAULT_BOOT_LINK_LIB INTERFACE) +target_link_libraries(DEFAULT_BOOT_LINK_LIB INTERFACE + COMMON_COMPILE_OPTIONS + COMMON_LINK_OPTIONS COMMON_LINK_LIB + COMMON_DEFINITIONS + DEFAULT_BOOT_DEFINITIONS + DEFAULT_BOOT_COMPILE_OPTIONS + DEFAULT_BOOT_LINK_OPTIONS + # 目标平台编译选项 $<$: # 链接 gnu-efi @@ -149,13 +159,13 @@ list(APPEND DEFAULT_BOOT_LINK_LIB > ) -list(APPEND DEFAULT_KERNEL_DEFINITIONS - ${COMMON_DEFINITIONS} - +add_library(DEFAULT_KERNEL_DEFINITIONS INTERFACE) +target_compile_definitions(DEFAULT_KERNEL_DEFINITIONS INTERFACE USE_NO_RELAX=$ ) -list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS +add_library(DEFAULT_KERNEL_COMPILE_OPTIONS INTERFACE) +target_compile_options(DEFAULT_KERNEL_COMPILE_OPTIONS INTERFACE $<$: # 使用 kernel 内存模型 -mcmodel=large @@ -168,7 +178,8 @@ list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS > ) -list(APPEND DEFAULT_KERNEL_LINK_OPTIONS +add_library(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE) +target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE # 链接脚本 -T ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/link.ld @@ -188,7 +199,8 @@ list(APPEND DEFAULT_KERNEL_LINK_OPTIONS > ) -list(APPEND DEFAULT_KERNEL_LINK_LIB +add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) +target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE COMMON_LINK_LIB printf_bare_metal diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index f3caf6c81..6731a8270 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -24,21 +24,6 @@ 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_link_libraries(${PROJECT_NAME} PRIVATE ${DEFAULT_BOOT_LINK_LIB} From 6a319b26bdf5b9d3aedcef43fa1678e26de800f1 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Tue, 13 Aug 2024 11:37:27 +0000 Subject: [PATCH 06/24] refactor: replace with INTERFACE, not finished Signed-off-by: Zone.N --- CMakePresets.json | 2 +- cmake/compile_config.cmake | 1 + src/boot/CMakeLists.txt | 2 +- src/kernel/CMakeLists.txt | 2 +- src/kernel/arch/CMakeLists.txt | 2 +- src/kernel/libc/CMakeLists.txt | 2 +- src/kernel/libcxx/CMakeLists.txt | 2 +- test/system_test/cxx_init_test/CMakeLists.txt | 2 +- test/system_test/gnu_efi_test/CMakeLists.txt | 2 +- test/system_test/opensbi_test/CMakeLists.txt | 2 +- 10 files changed, 10 insertions(+), 9 deletions(-) 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/compile_config.cmake b/cmake/compile_config.cmake index e94714816..342004229 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -202,6 +202,7 @@ target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE COMMON_LINK_LIB + DEFAULT_KERNEL_LINK_OPTIONS printf_bare_metal ${dtc_BINARY_DIR}/libfdt/libfdt.a diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index 6731a8270..159d89a86 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -26,7 +26,7 @@ add_header_3rd(${PROJECT_NAME}) # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_BOOT_LINK_LIB} + DEFAULT_BOOT_LINK_LIB ) # 添加依赖 diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index e7d4008ac..697c47298 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -46,7 +46,7 @@ target_link_options(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB libc libcxx arch diff --git a/src/kernel/arch/CMakeLists.txt b/src/kernel/arch/CMakeLists.txt index 9e81bec68..3602bfe97 100644 --- a/src/kernel/arch/CMakeLists.txt +++ b/src/kernel/arch/CMakeLists.txt @@ -48,5 +48,5 @@ target_link_options(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB ) diff --git a/src/kernel/libc/CMakeLists.txt b/src/kernel/libc/CMakeLists.txt index 3bb4aa08d..d4145a305 100644 --- a/src/kernel/libc/CMakeLists.txt +++ b/src/kernel/libc/CMakeLists.txt @@ -39,5 +39,5 @@ target_link_options(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB ) diff --git a/src/kernel/libcxx/CMakeLists.txt b/src/kernel/libcxx/CMakeLists.txt index d2533eb5d..90af60391 100644 --- a/src/kernel/libcxx/CMakeLists.txt +++ b/src/kernel/libcxx/CMakeLists.txt @@ -40,5 +40,5 @@ target_link_options(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB ) diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index b2b723741..b1cc9bacb 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -35,7 +35,7 @@ target_link_options(${PROJECT_NAME} PRIVATE ) target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB libc libcxx ) diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index e860c2374..c293e595b 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -30,7 +30,7 @@ target_link_options(${PROJECT_NAME} PRIVATE ) target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB libc libcxx ) diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index ae3b21118..4d95a0240 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_options(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - ${DEFAULT_KERNEL_LINK_LIB} + DEFAULT_KERNEL_LINK_LIB libc libcxx ) From 8003763ea569df0bd4c304b3998aac696a5e3c42 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 03:05:46 +0000 Subject: [PATCH 07/24] refactor: replace with INTERFACE, arch Signed-off-by: Zone.N --- src/kernel/CMakeLists.txt | 2 ++ src/kernel/arch/CMakeLists.txt | 48 +++++----------------------------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 697c47298..85f27c46b 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) diff --git a/src/kernel/arch/CMakeLists.txt b/src/kernel/arch/CMakeLists.txt index 3602bfe97..745a402eb 100644 --- a/src/kernel/arch/CMakeLists.txt +++ b/src/kernel/arch/CMakeLists.txt @@ -4,49 +4,13 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - arch - VERSION 0.0.1 -) - -enable_language(ASM) -enable_language(CXX) - # 生成对象库 -add_library(${PROJECT_NAME} OBJECT +add_library(arch INTERFACE) +target_sources(arch INTERFACE $<$: - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/macro.S - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/boot.S + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/macro.S + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/boot.S > - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/arch_main.cpp - ${PROJECT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/backtrace.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}/arch_main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/backtrace.cpp ) From 5d9d62ece6584a02dd4a39efbd1bb38ed8a57515 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 03:08:14 +0000 Subject: [PATCH 08/24] refactor: replace with INTERFACE, arch Signed-off-by: Zone.N --- cmake/add_header.cmake | 4 ---- src/kernel/arch/CMakeLists.txt | 7 ++++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 61970b9a2..0c6b598c2 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -26,10 +26,6 @@ function(add_header_libcxx _target) 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) diff --git a/src/kernel/arch/CMakeLists.txt b/src/kernel/arch/CMakeLists.txt index 745a402eb..f1c93ebaa 100644 --- a/src/kernel/arch/CMakeLists.txt +++ b/src/kernel/arch/CMakeLists.txt @@ -4,8 +4,13 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 生成对象库 add_library(arch INTERFACE) + +target_include_directories(arch INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/include +) + target_sources(arch INTERFACE $<$: ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_PROCESSOR}/macro.S From 34b68fbb456e5ddf5d4149392334732a3aa48ee2 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 03:10:31 +0000 Subject: [PATCH 09/24] refactor: replace with INTERFACE, arch Signed-off-by: Zone.N --- cmake/add_header.cmake | 3 --- src/kernel/CMakeLists.txt | 1 - test/system_test/cxx_init_test/CMakeLists.txt | 6 +++++- test/system_test/gnu_efi_test/CMakeLists.txt | 1 - test/system_test/opensbi_test/CMakeLists.txt | 1 - test/unit_test/CMakeLists.txt | 1 - 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 0c6b598c2..844aeec26 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -25,9 +25,6 @@ function(add_header_libcxx _target) ${CMAKE_SOURCE_DIR}/src/kernel/libcxx/include) endfunction() -function(add_header_arch _target) -endfunction() - function(add_header_kernel _target) target_include_directories(${_target} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/include) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 85f27c46b..42b4be079 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -26,7 +26,6 @@ add_executable(${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}) diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index b1cc9bacb..9eece5582 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -23,9 +23,13 @@ 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_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/src/kernel/arch + ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include +) + target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_KERNEL_COMPILE_OPTIONS} ) diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index c293e595b..ef0f410bb 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -18,7 +18,6 @@ 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 diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 4d95a0240..90ea75661 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -20,7 +20,6 @@ add_executable(${PROJECT_NAME} 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}) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 5695090b2..9d0d416ff 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -20,7 +20,6 @@ add_executable(${PROJECT_NAME} kernel_fdt_test.cpp ) -add_header_arch(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) add_header_libc(${PROJECT_NAME}) From 039ba0e726a455e80891db11946a29229f6dc7fc Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 03:18:30 +0000 Subject: [PATCH 10/24] refactor: replace with INTERFACE, driver Signed-off-by: Zone.N --- cmake/add_header.cmake | 9 ------ src/kernel/CMakeLists.txt | 1 - src/kernel/driver/CMakeLists.txt | 35 +++++------------------ src/kernel/driver/ns16550a/CMakeLists.txt | 35 ++++------------------- 4 files changed, 12 insertions(+), 68 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 844aeec26..5beb99b25 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -30,15 +30,6 @@ function(add_header_kernel _target) ${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) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 42b4be079..a78db34ca 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -27,7 +27,6 @@ add_executable(${PROJECT_NAME} add_header_libc(${PROJECT_NAME}) add_header_libcxx(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) -add_header_driver(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) # 添加定义 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 ) From ad61a6f4a132a134cc9df5c362bd6279c60123b8 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 03:27:00 +0000 Subject: [PATCH 11/24] refactor: replace with INTERFACE, libc/libcxx Signed-off-by: Zone.N --- cmake/add_header.cmake | 10 ----- src/kernel/CMakeLists.txt | 2 - src/kernel/libc/CMakeLists.txt | 40 ++++-------------- src/kernel/libcxx/CMakeLists.txt | 41 ++++--------------- test/system_test/cxx_init_test/CMakeLists.txt | 2 - test/system_test/opensbi_test/CMakeLists.txt | 2 - 6 files changed, 14 insertions(+), 83 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 5beb99b25..a7c1d60f1 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -15,16 +15,6 @@ function(add_header_boot _target) ${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_kernel _target) target_include_directories(${_target} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/include) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index a78db34ca..bc297e791 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -24,8 +24,6 @@ add_executable(${PROJECT_NAME} ) # 添加头文件 -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) diff --git a/src/kernel/libc/CMakeLists.txt b/src/kernel/libc/CMakeLists.txt index d4145a305..f6a5cc915 100644 --- a/src/kernel/libc/CMakeLists.txt +++ b/src/kernel/libc/CMakeLists.txt @@ -4,40 +4,14 @@ # # CMakeLists.txt for Simple-XX/SimpleKernel. -# 设置项目名与版本 -project( - libc - VERSION 0.0.1 -) - -enable_language(C) - -# 生成对象库 -add_library(${PROJECT_NAME} OBJECT - ${PROJECT_SOURCE_DIR}/sk_libc.c - ${PROJECT_SOURCE_DIR}/sk_string.c - ${PROJECT_SOURCE_DIR}/sk_stdio.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 ) diff --git a/src/kernel/libcxx/CMakeLists.txt b/src/kernel/libcxx/CMakeLists.txt index 90af60391..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}/sk_libcxx.cpp - ${PROJECT_SOURCE_DIR}/sk_new.cpp - ${PROJECT_SOURCE_DIR}/sk_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/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index 9eece5582..14c775bd0 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -21,8 +21,6 @@ add_executable(${PROJECT_NAME} > ) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 90ea75661..6c4fa2168 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -18,8 +18,6 @@ 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_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) From 6db87e852a100db60813dc3584f2320e160e2674 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:07:11 +0000 Subject: [PATCH 12/24] refactor: replace with INTERFACE, boot Signed-off-by: Zone.N --- cmake/add_header.cmake | 5 ----- src/boot/CMakeLists.txt | 5 ++++- test/system_test/gnu_efi_test/CMakeLists.txt | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index a7c1d60f1..6e231cd19 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -10,11 +10,6 @@ function(add_header_project _target) ${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_kernel _target) target_include_directories(${_target} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/include) diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index 159d89a86..ddb346a86 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -21,9 +21,12 @@ add_executable(${PROJECT_NAME} # 添加头文件 add_header_project(${PROJECT_NAME}) -add_header_boot(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) +target_include_directories(${PROJECT_NAME} PRIVATE + include +) + # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE DEFAULT_BOOT_LINK_LIB diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index ef0f410bb..d38e993d2 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -16,8 +16,6 @@ add_executable(${PROJECT_NAME} main.cpp ) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) add_header_kernel(${PROJECT_NAME}) target_compile_options(${PROJECT_NAME} PRIVATE From bbbada7fbc1c76ef1def96ccc213f20f2dbc4231 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:14:55 +0000 Subject: [PATCH 13/24] refactor: replace with INTERFACE, kernel Signed-off-by: Zone.N --- cmake/add_header.cmake | 5 ----- src/kernel/CMakeLists.txt | 4 +++- test/system_test/cxx_init_test/CMakeLists.txt | 3 +-- test/system_test/gnu_efi_test/CMakeLists.txt | 6 +++++- test/system_test/opensbi_test/CMakeLists.txt | 1 - test/unit_test/CMakeLists.txt | 3 --- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 6e231cd19..eb83c529b 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -10,11 +10,6 @@ function(add_header_project _target) ${CMAKE_SOURCE_DIR}/src) endfunction() -function(add_header_kernel _target) - target_include_directories(${_target} PRIVATE - ${CMAKE_SOURCE_DIR}/src/kernel/include) -endfunction() - function(add_header_3rd _target) target_include_directories(${_target} PRIVATE ${gnu-efi_BINARY_DIR}/inc) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index bc297e791..9f1cf63d5 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -24,8 +24,10 @@ add_executable(${PROJECT_NAME} ) # 添加头文件 -add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) +target_include_directories(kernel PRIVATE + include +) # 添加定义 target_compile_definitions(${PROJECT_NAME} PRIVATE diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index 14c775bd0..b573b6cda 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -21,9 +21,8 @@ add_executable(${PROJECT_NAME} > ) -add_header_kernel(${PROJECT_NAME}) - 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 ) diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index d38e993d2..fd64aeabb 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -16,7 +16,11 @@ add_executable(${PROJECT_NAME} main.cpp ) -add_header_kernel(${PROJECT_NAME}) +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_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_KERNEL_COMPILE_OPTIONS} diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 6c4fa2168..941e2a72a 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -18,7 +18,6 @@ add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/boot.S ) -add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) target_compile_options(${PROJECT_NAME} PRIVATE diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 9d0d416ff..5923059a0 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -20,10 +20,7 @@ add_executable(${PROJECT_NAME} kernel_fdt_test.cpp ) -add_header_kernel(${PROJECT_NAME}) add_header_3rd(${PROJECT_NAME}) -add_header_libc(${PROJECT_NAME}) -add_header_libcxx(${PROJECT_NAME}) target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_TEST_COMPILE_OPTIONS} From cdb2000d7bd4e4f474328b8a8b1515d0bf06999b Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:23:00 +0000 Subject: [PATCH 14/24] refactor: replace with INTERFACE, ut, not finished Signed-off-by: Zone.N --- test/unit_test/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 5923059a0..913d7dfb0 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -21,6 +21,10 @@ add_executable(${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} From 70327ce6045bd3df0a634fb01aea71c4b5c33941 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:36:51 +0000 Subject: [PATCH 15/24] refactor: replace with INTERFACE, gnu-efi Signed-off-by: Zone.N --- cmake/3rd.cmake | 13 +++++++++++++ cmake/add_header.cmake | 6 ------ cmake/compile_config.cmake | 16 +++------------- src/boot/boot.cpp | 1 + test/system_test/gnu_efi_test/main.cpp | 5 +++++ 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cmake/3rd.cmake b/cmake/3rd.cmake index 8b1ae981c..567025bbb 100644 --- a/cmake/3rd.cmake +++ b/cmake/3rd.cmake @@ -189,6 +189,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 index eb83c529b..1820623ad 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -11,12 +11,6 @@ function(add_header_project _target) 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 342004229..9f6f8f2fa 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -136,26 +136,17 @@ target_link_libraries(DEFAULT_BOOT_LINK_LIB INTERFACE # 目标平台编译选项 $<$: # 链接 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 > ) @@ -219,7 +210,6 @@ target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE # 编译依赖 list(APPEND COMPILE_DEPENDS ovmf - gnu-efi dtc printf_bare_metal ) 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/test/system_test/gnu_efi_test/main.cpp b/test/system_test/gnu_efi_test/main.cpp index 4170a5512..c937366fc 100644 --- a/test/system_test/gnu_efi_test/main.cpp +++ b/test/system_test/gnu_efi_test/main.cpp @@ -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) { From da41f45bb435b6bad88d5916dcd824a53165bb39 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:39:15 +0000 Subject: [PATCH 16/24] refactor: replace with INTERFACE, dtc Signed-off-by: Zone.N --- cmake/3rd.cmake | 8 ++++++++ cmake/add_header.cmake | 2 -- cmake/compile_config.cmake | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmake/3rd.cmake b/cmake/3rd.cmake index 567025bbb..cc5c916fb 100644 --- a/cmake/3rd.cmake +++ b/cmake/3rd.cmake @@ -152,6 +152,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) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index 1820623ad..cadfce0dc 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -11,6 +11,4 @@ function(add_header_project _target) endfunction() function(add_header_3rd _target) - target_include_directories(${_target} PRIVATE - ${dtc_BINARY_DIR}/libfdt) endfunction() diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 9f6f8f2fa..f7fe8f65d 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -196,7 +196,7 @@ target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE DEFAULT_KERNEL_LINK_OPTIONS printf_bare_metal - ${dtc_BINARY_DIR}/libfdt/libfdt.a + dtc-lib COMMON_COMPILE_OPTIONS $<$: @@ -210,7 +210,6 @@ target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE # 编译依赖 list(APPEND COMPILE_DEPENDS ovmf - dtc printf_bare_metal ) if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") From 9c44d9f8818beb44fb267f46fb3f6658de4832fe Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:40:44 +0000 Subject: [PATCH 17/24] refactor: replace with INTERFACE, printf_bare_metal Signed-off-by: Zone.N --- cmake/compile_config.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index f7fe8f65d..ba7956462 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -210,7 +210,6 @@ target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE # 编译依赖 list(APPEND COMPILE_DEPENDS ovmf - printf_bare_metal ) if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64") From 845ee616db89f16a602c69f9d044f0519ef294e9 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:41:31 +0000 Subject: [PATCH 18/24] refactor: replace with INTERFACE, 3rd Signed-off-by: Zone.N --- cmake/add_header.cmake | 3 --- src/boot/CMakeLists.txt | 1 - src/kernel/CMakeLists.txt | 1 - test/system_test/opensbi_test/CMakeLists.txt | 2 -- test/unit_test/CMakeLists.txt | 1 - 5 files changed, 8 deletions(-) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake index cadfce0dc..63a4883da 100644 --- a/cmake/add_header.cmake +++ b/cmake/add_header.cmake @@ -9,6 +9,3 @@ function(add_header_project _target) target_include_directories(${_target} PRIVATE ${CMAKE_SOURCE_DIR}/src) endfunction() - -function(add_header_3rd _target) -endfunction() diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index ddb346a86..677c8187c 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -21,7 +21,6 @@ add_executable(${PROJECT_NAME} # 添加头文件 add_header_project(${PROJECT_NAME}) -add_header_3rd(${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 9f1cf63d5..1fed0a78b 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -24,7 +24,6 @@ add_executable(${PROJECT_NAME} ) # 添加头文件 -add_header_3rd(${PROJECT_NAME}) target_include_directories(kernel PRIVATE include ) diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 941e2a72a..32d90b7bb 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -18,8 +18,6 @@ add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/boot.S ) -add_header_3rd(${PROJECT_NAME}) - target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_KERNEL_COMPILE_OPTIONS} ) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 913d7dfb0..b2b8d3e4f 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -20,7 +20,6 @@ add_executable(${PROJECT_NAME} kernel_fdt_test.cpp ) -add_header_3rd(${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/include ${CMAKE_SOURCE_DIR}/src/kernel/arch From 9817d429b9a06d0f1b276394555f2be4a6f6588d Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:43:39 +0000 Subject: [PATCH 19/24] refactor: replace with INTERFACE, add_header Signed-off-by: Zone.N --- CMakeLists.txt | 2 -- cmake/add_header.cmake | 11 ----------- src/boot/CMakeLists.txt | 3 +-- 3 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 cmake/add_header.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 185044d56..f155585aa 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) diff --git a/cmake/add_header.cmake b/cmake/add_header.cmake deleted file mode 100644 index 63a4883da..000000000 --- a/cmake/add_header.cmake +++ /dev/null @@ -1,11 +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() diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index 677c8187c..a62c94a19 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -20,10 +20,9 @@ add_executable(${PROJECT_NAME} ) # 添加头文件 -add_header_project(${PROJECT_NAME}) - target_include_directories(${PROJECT_NAME} PRIVATE include + ${CMAKE_SOURCE_DIR}/src ) # 添加要链接的库 From 1b2c862e216f0923eaeaf912d1d3927b4983e567 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 05:51:07 +0000 Subject: [PATCH 20/24] refactor: replace with INTERFACE, DEPENDS Signed-off-by: Zone.N --- CMakeLists.txt | 2 +- cmake/3rd.cmake | 8 ++++++++ cmake/compile_config.cmake | 13 ------------- src/boot/CMakeLists.txt | 5 ----- src/kernel/CMakeLists.txt | 5 ----- test/system_test/cxx_init_test/CMakeLists.txt | 4 ---- test/system_test/gnu_efi_test/CMakeLists.txt | 4 ---- test/system_test/opensbi_test/CMakeLists.txt | 4 ---- test/unit_test/CMakeLists.txt | 4 ---- 9 files changed, 9 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f155585aa..b6d65f1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,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/cmake/3rd.cmake b/cmake/3rd.cmake index cc5c916fb..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) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index ba7956462..6bda192fe 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -206,16 +206,3 @@ target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE $<$: > ) - -# 编译依赖 -list(APPEND COMPILE_DEPENDS - ovmf - ) -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 a62c94a19..8a32dfba7 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -30,11 +30,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE DEFAULT_BOOT_LINK_LIB ) -# 添加依赖 -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${BOOT_ELF_OUTPUT_NAME}) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 1fed0a78b..a3b8ce30d 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -52,11 +52,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE 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/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index b573b6cda..bba08d8bc 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -41,10 +41,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE 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/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index fd64aeabb..69baa728b 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -36,10 +36,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE 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/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 32d90b7bb..927cdc3bd 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -33,10 +33,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE 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/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index b2b8d3e4f..9646735c8 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -38,8 +38,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${dtc_BINARY_DIR}/libfdt/libfdt.a ) -add_dependencies(${PROJECT_NAME} - ${COMPILE_DEPENDS} -) - gtest_discover_tests(${PROJECT_NAME}) From 1166ea497b1415579fbf0cd0144a4218a8dd99cf Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 06:01:32 +0000 Subject: [PATCH 21/24] refactor: replace with INTERFACE, DEFAULT_KERNEL_LINK_LIB Signed-off-by: Zone.N --- cmake/compile_config.cmake | 6 +++++- src/kernel/CMakeLists.txt | 15 --------------- test/system_test/cxx_init_test/CMakeLists.txt | 8 -------- test/system_test/gnu_efi_test/CMakeLists.txt | 8 -------- test/system_test/opensbi_test/CMakeLists.txt | 8 -------- 5 files changed, 5 insertions(+), 40 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 6bda192fe..e30362e3e 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -192,12 +192,16 @@ target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE + COMMON_COMPILE_OPTIONS + COMMON_LINK_OPTIONS COMMON_LINK_LIB + COMMON_DEFINITIONS + DEFAULT_KERNEL_DEFINITIONS + DEFAULT_KERNEL_COMPILE_OPTIONS DEFAULT_KERNEL_LINK_OPTIONS printf_bare_metal dtc-lib - COMMON_COMPILE_OPTIONS $<$: opensbi_interface diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index a3b8ce30d..8125a8b17 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -28,21 +28,6 @@ target_include_directories(kernel PRIVATE include ) -# 添加定义 -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_link_libraries(${PROJECT_NAME} PRIVATE DEFAULT_KERNEL_LINK_LIB diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index bba08d8bc..b6462a190 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -27,14 +27,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include ) -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 libc diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index 69baa728b..1b0398cd0 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -22,14 +22,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/include ) -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 libc diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 927cdc3bd..837f9cd61 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -18,14 +18,6 @@ add_executable(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/boot.S ) -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 From 0795c2914a90ac3c086e40406b5c59a68ea30d64 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 06:08:15 +0000 Subject: [PATCH 22/24] refactor: replace with INTERFACE, DEFAULT_KERNEL_LINK_LIB Signed-off-by: Zone.N --- cmake/compile_config.cmake | 62 ++++++++++++++++++-------------------- src/boot/CMakeLists.txt | 2 +- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index e30362e3e..dff075fba 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -5,9 +5,16 @@ # compile_config.cmake for Simple-XX/SimpleKernel. # 配置信息 +# 通用宏定义 +add_library(compile_definitions INTERFACE) +target_compile_definitions(compile_definitions INTERFACE + $<$:SIMPLEKERNEL_RELEASE> + $<$:SIMPLEKERNEL_DEBUG> +) + # 通用编译选项 -add_library(COMMON_COMPILE_OPTIONS INTERFACE) -target_compile_options(COMMON_COMPILE_OPTIONS INTERFACE +add_library(compile_options INTERFACE) +target_compile_options(compile_options INTERFACE # 如果 CMAKE_BUILD_TYPE 为 Release 则使用 -O3 -Werror,否则使用 -O0 -ggdb # -g 在 Debug 模式下由 cmake 自动添加 $<$:-O3;-Werror> @@ -61,33 +68,28 @@ target_compile_options(COMMON_COMPILE_OPTIONS INTERFACE ) # 通用链接选项 -add_library(COMMON_LINK_OPTIONS INTERFACE) -target_link_options(COMMON_LINK_OPTIONS INTERFACE +add_library(link_options INTERFACE) +target_link_options(link_options INTERFACE # 不链接 ctr0 等启动代码 -nostartfiles ) # 通用库选项 -add_library(COMMON_LINK_LIB INTERFACE) -target_link_libraries(COMMON_LINK_LIB INTERFACE - COMMON_LINK_OPTIONS -) - -# 通用宏定义 -add_library(COMMON_DEFINITIONS INTERFACE) -target_compile_definitions(COMMON_DEFINITIONS INTERFACE - $<$:SIMPLEKERNEL_RELEASE> - $<$:SIMPLEKERNEL_DEBUG> +add_library(link_libraries INTERFACE) +target_link_libraries(link_libraries INTERFACE + compile_definitions + compile_options + link_options ) -add_library(DEFAULT_BOOT_DEFINITIONS INTERFACE) -target_compile_definitions(DEFAULT_BOOT_DEFINITIONS INTERFACE +add_library(boot_compile_definitions INTERFACE) +target_compile_definitions(boot_compile_definitions INTERFACE # 使用 gnu-efi GNU_EFI_USE_MS_ABI ) -add_library(DEFAULT_BOOT_COMPILE_OPTIONS INTERFACE) -target_compile_options(DEFAULT_BOOT_COMPILE_OPTIONS INTERFACE +add_library(boot_compile_options INTERFACE) +target_compile_options(boot_compile_options INTERFACE # 使用 2 字节 wchar_t -fshort-wchar # 允许 wchar_t @@ -101,8 +103,8 @@ target_compile_options(DEFAULT_BOOT_COMPILE_OPTIONS INTERFACE > ) -add_library(DEFAULT_BOOT_LINK_OPTIONS INTERFACE) -target_link_options(DEFAULT_BOOT_LINK_OPTIONS INTERFACE +add_library(boot_link_options INTERFACE) +target_link_options(boot_link_options INTERFACE $<$: # 编译为共享库 -shared @@ -123,15 +125,12 @@ target_link_options(DEFAULT_BOOT_LINK_OPTIONS INTERFACE > ) -add_library(DEFAULT_BOOT_LINK_LIB INTERFACE) -target_link_libraries(DEFAULT_BOOT_LINK_LIB INTERFACE - COMMON_COMPILE_OPTIONS - COMMON_LINK_OPTIONS - COMMON_LINK_LIB - COMMON_DEFINITIONS - DEFAULT_BOOT_DEFINITIONS - DEFAULT_BOOT_COMPILE_OPTIONS - DEFAULT_BOOT_LINK_OPTIONS +add_library(boot_link_libraries INTERFACE) +target_link_libraries(boot_link_libraries INTERFACE + link_libraries + boot_compile_definitions + boot_compile_options + boot_link_options # 目标平台编译选项 $<$: @@ -192,10 +191,7 @@ target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE - COMMON_COMPILE_OPTIONS - COMMON_LINK_OPTIONS - COMMON_LINK_LIB - COMMON_DEFINITIONS + link_libraries DEFAULT_KERNEL_DEFINITIONS DEFAULT_KERNEL_COMPILE_OPTIONS DEFAULT_KERNEL_LINK_OPTIONS diff --git a/src/boot/CMakeLists.txt b/src/boot/CMakeLists.txt index 8a32dfba7..87bd8c9fa 100644 --- a/src/boot/CMakeLists.txt +++ b/src/boot/CMakeLists.txt @@ -27,7 +27,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - DEFAULT_BOOT_LINK_LIB + boot_link_libraries ) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") From 9111882fb325c93b00a8a2f1e694a70a4424b383 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 09:05:57 +0000 Subject: [PATCH 23/24] refactor: replace with INTERFACE, boot_link_libraries Signed-off-by: Zone.N --- cmake/compile_config.cmake | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index dff075fba..687673dea 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -149,13 +149,13 @@ target_link_libraries(boot_link_libraries INTERFACE > ) -add_library(DEFAULT_KERNEL_DEFINITIONS INTERFACE) -target_compile_definitions(DEFAULT_KERNEL_DEFINITIONS INTERFACE +add_library(kernel_compile_definitions INTERFACE) +target_compile_definitions(kernel_compile_definitions INTERFACE USE_NO_RELAX=$ ) -add_library(DEFAULT_KERNEL_COMPILE_OPTIONS INTERFACE) -target_compile_options(DEFAULT_KERNEL_COMPILE_OPTIONS INTERFACE +add_library(kernel_compile_options INTERFACE) +target_compile_options(kernel_compile_options INTERFACE $<$: # 使用 kernel 内存模型 -mcmodel=large @@ -168,8 +168,8 @@ target_compile_options(DEFAULT_KERNEL_COMPILE_OPTIONS INTERFACE > ) -add_library(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE) -target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE +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 @@ -192,9 +192,9 @@ target_link_options(DEFAULT_KERNEL_LINK_OPTIONS INTERFACE add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE link_libraries - DEFAULT_KERNEL_DEFINITIONS - DEFAULT_KERNEL_COMPILE_OPTIONS - DEFAULT_KERNEL_LINK_OPTIONS + kernel_compile_definitions + kernel_compile_options + kernel_link_options printf_bare_metal dtc-lib From 0792d6ec3408035fd3aee99c339b6bc3d28e3862 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Mon, 26 Aug 2024 09:09:11 +0000 Subject: [PATCH 24/24] refactor: replace with INTERFACE, boot_link_libraries Signed-off-by: Zone.N --- cmake/compile_config.cmake | 4 ++-- src/kernel/CMakeLists.txt | 2 +- test/system_test/cxx_init_test/CMakeLists.txt | 2 +- test/system_test/gnu_efi_test/CMakeLists.txt | 2 +- test/system_test/opensbi_test/CMakeLists.txt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/compile_config.cmake b/cmake/compile_config.cmake index 687673dea..b189a3275 100644 --- a/cmake/compile_config.cmake +++ b/cmake/compile_config.cmake @@ -189,8 +189,8 @@ target_link_options(kernel_link_options INTERFACE > ) -add_library(DEFAULT_KERNEL_LINK_LIB INTERFACE) -target_link_libraries(DEFAULT_KERNEL_LINK_LIB INTERFACE +add_library(kernel_link_libraries INTERFACE) +target_link_libraries(kernel_link_libraries INTERFACE link_libraries kernel_compile_definitions kernel_compile_options diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 8125a8b17..bbc0f4ba9 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -30,7 +30,7 @@ target_include_directories(kernel PRIVATE # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - DEFAULT_KERNEL_LINK_LIB + kernel_link_libraries libc libcxx arch diff --git a/test/system_test/cxx_init_test/CMakeLists.txt b/test/system_test/cxx_init_test/CMakeLists.txt index b6462a190..52facc372 100644 --- a/test/system_test/cxx_init_test/CMakeLists.txt +++ b/test/system_test/cxx_init_test/CMakeLists.txt @@ -28,7 +28,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ) target_link_libraries(${PROJECT_NAME} PRIVATE - DEFAULT_KERNEL_LINK_LIB + kernel_link_libraries libc libcxx ) diff --git a/test/system_test/gnu_efi_test/CMakeLists.txt b/test/system_test/gnu_efi_test/CMakeLists.txt index 1b0398cd0..04834f858 100644 --- a/test/system_test/gnu_efi_test/CMakeLists.txt +++ b/test/system_test/gnu_efi_test/CMakeLists.txt @@ -23,7 +23,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ) target_link_libraries(${PROJECT_NAME} PRIVATE - DEFAULT_KERNEL_LINK_LIB + kernel_link_libraries libc libcxx ) diff --git a/test/system_test/opensbi_test/CMakeLists.txt b/test/system_test/opensbi_test/CMakeLists.txt index 837f9cd61..0c0788d8a 100644 --- a/test/system_test/opensbi_test/CMakeLists.txt +++ b/test/system_test/opensbi_test/CMakeLists.txt @@ -20,7 +20,7 @@ add_executable(${PROJECT_NAME} # 添加要链接的库 target_link_libraries(${PROJECT_NAME} PRIVATE - DEFAULT_KERNEL_LINK_LIB + kernel_link_libraries libc libcxx )