From 58bb3db64be1a0d216445dc0c5fe67e8c960663e Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Wed, 7 Aug 2024 09:35:12 +0000 Subject: [PATCH 1/2] fix: aarch64 test Signed-off-by: Zone.N --- test/system_test/cxx_init_test/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/system_test/cxx_init_test/main.cpp b/test/system_test/cxx_init_test/main.cpp index 34e46efd0..6c3143f15 100644 --- a/test/system_test/cxx_init_test/main.cpp +++ b/test/system_test/cxx_init_test/main.cpp @@ -30,6 +30,8 @@ extern "C" void _putchar(char character) { serial.Write(character); } extern "C" void _putchar(char character) { sbi_debug_console_write_byte(character); } +#elif __aarch64__ +extern "C" void _putchar(char character) { (void)character; } #endif template From 071768e42ff47f9790e238bafd619a9ebfec2af7 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Wed, 7 Aug 2024 09:43:04 +0000 Subject: [PATCH 2/2] refactor: rename std::ostream with sk_std:: Signed-off-by: Zone.N --- src/kernel/arch/aarch64/include/cpu.hpp | 2 +- src/kernel/arch/riscv64/arch_main.cpp | 2 +- src/kernel/arch/riscv64/include/cpu.hpp | 2 +- src/kernel/arch/x86_64/arch_main.cpp | 2 +- src/kernel/arch/x86_64/include/cpu.hpp | 2 +- src/kernel/include/basic_info.hpp | 4 ++-- src/kernel/include/kernel_log.hpp | 2 +- src/kernel/libcxx/include/cstring | 4 ++-- src/kernel/libcxx/include/iostream | 4 ++-- src/kernel/libcxx/iostream.cpp | 4 ++-- src/kernel/main.cpp | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kernel/arch/aarch64/include/cpu.hpp b/src/kernel/arch/aarch64/include/cpu.hpp index c48d5ce38..73b6dbbcb 100644 --- a/src/kernel/arch/aarch64/include/cpu.hpp +++ b/src/kernel/arch/aarch64/include/cpu.hpp @@ -148,7 +148,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase, // 第三部分:寄存器实例 class X29 : public ReadWriteRegBase { public: - friend std::ostream &operator<<(std::ostream &os, const X29 &x29) { + friend sk_std::ostream &operator<<(sk_std::ostream &os, const X29 &x29) { printf("val: 0x%p", (void *)x29.Read()); return os; } diff --git a/src/kernel/arch/riscv64/arch_main.cpp b/src/kernel/arch/riscv64/arch_main.cpp index a53d751c5..1fe288c14 100644 --- a/src/kernel/arch/riscv64/arch_main.cpp +++ b/src/kernel/arch/riscv64/arch_main.cpp @@ -58,7 +58,7 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) { kKernelFdt.GetInstance() = KernelFdt((uint64_t)argv); kBasicInfo.GetInstance() = BasicInfo(argc, argv); - std::cout << kBasicInfo.GetInstance(); + sk_std::cout << kBasicInfo.GetInstance(); auto [serial_base, serial_size] = kKernelFdt.GetInstance().GetSerial(); auto uart = Ns16550a(serial_base); diff --git a/src/kernel/arch/riscv64/include/cpu.hpp b/src/kernel/arch/riscv64/include/cpu.hpp index 9bdc5be51..78f631a34 100644 --- a/src/kernel/arch/riscv64/include/cpu.hpp +++ b/src/kernel/arch/riscv64/include/cpu.hpp @@ -148,7 +148,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase, // 第三部分:寄存器实例 class Fp : public ReadWriteRegBase { public: - friend std::ostream &operator<<(std::ostream &os, const Fp &fp) { + friend sk_std::ostream &operator<<(sk_std::ostream &os, const Fp &fp) { printf("val: 0x%p", (void *)fp.Read()); return os; } diff --git a/src/kernel/arch/x86_64/arch_main.cpp b/src/kernel/arch/x86_64/arch_main.cpp index 9fcef176a..1fffd8ab8 100644 --- a/src/kernel/arch/x86_64/arch_main.cpp +++ b/src/kernel/arch/x86_64/arch_main.cpp @@ -59,7 +59,7 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) { } kBasicInfo.GetInstance() = BasicInfo(argc, argv); - std::cout << kBasicInfo.GetInstance(); + sk_std::cout << kBasicInfo.GetInstance(); // 解析内核 elf 信息 kKernelElf.GetInstance() = KernelElf(kBasicInfo.GetInstance().elf_addr, diff --git a/src/kernel/arch/x86_64/include/cpu.hpp b/src/kernel/arch/x86_64/include/cpu.hpp index 6c7c51c34..c87a9e668 100644 --- a/src/kernel/arch/x86_64/include/cpu.hpp +++ b/src/kernel/arch/x86_64/include/cpu.hpp @@ -298,7 +298,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase, // 第三部分:寄存器实例 class Rbp : public ReadWriteRegBase { public: - friend std::ostream &operator<<(std::ostream &os, const Rbp &rbp) { + friend sk_std::ostream &operator<<(sk_std::ostream &os, const Rbp &rbp) { printf("val: 0x%p", (void *)rbp.Read()); return os; } diff --git a/src/kernel/include/basic_info.hpp b/src/kernel/include/basic_info.hpp index 27badcbeb..97bee5945 100644 --- a/src/kernel/include/basic_info.hpp +++ b/src/kernel/include/basic_info.hpp @@ -60,8 +60,8 @@ struct BasicInfo { ~BasicInfo() = default; /// @} - friend std::ostream &operator<<(std::ostream &os, - const BasicInfo &basic_info) { + friend sk_std::ostream &operator<<(sk_std::ostream &os, + const BasicInfo &basic_info) { printf("physical_memory_addr: 0x%X, size 0x%X.\n", basic_info.physical_memory_addr, basic_info.physical_memory_size); printf("kernel_addr: 0x%X, size 0x%X.\n", basic_info.kernel_addr, diff --git a/src/kernel/include/kernel_log.hpp b/src/kernel/include/kernel_log.hpp index beb76bc8f..8f66a619b 100644 --- a/src/kernel/include/kernel_log.hpp +++ b/src/kernel/include/kernel_log.hpp @@ -36,7 +36,7 @@ static constexpr const auto kCyan = "\033[36m"; static constexpr const auto kWhite = "\033[37m"; template -class Logger : public std::ostream { +class Logger : public sk_std::ostream { public: Logger& operator<<(int8_t val) override { OutputFunction("%d", val); diff --git a/src/kernel/libcxx/include/cstring b/src/kernel/libcxx/include/cstring index 0a371aa32..e032d692b 100644 --- a/src/kernel/libcxx/include/cstring +++ b/src/kernel/libcxx/include/cstring @@ -19,7 +19,7 @@ #include "string.h" -namespace std { +namespace sk_std { using ::memcmp; using ::memcpy; @@ -34,6 +34,6 @@ using ::strncmp; using ::strncpy; using ::strnlen; -}; // namespace std +}; // namespace sk_std #endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_CSTRING_ */ diff --git a/src/kernel/libcxx/include/iostream b/src/kernel/libcxx/include/iostream index c8c87fc15..98177dbc3 100644 --- a/src/kernel/libcxx/include/iostream +++ b/src/kernel/libcxx/include/iostream @@ -20,7 +20,7 @@ #include -namespace std { +namespace sk_std { class ostream { public: enum openmode : uint8_t { @@ -57,6 +57,6 @@ inline ostream& endl(ostream& os) { return os << "\n"; } [[maybe_unused]] static ostream cout; -}; // namespace std +}; // namespace sk_std #endif /* SIMPLEKERNEL_SRC_KERNEL_LIBCXX_INCLUDE_IOSTREAM_ */ diff --git a/src/kernel/libcxx/iostream.cpp b/src/kernel/libcxx/iostream.cpp index 50f051d7c..755d3030d 100644 --- a/src/kernel/libcxx/iostream.cpp +++ b/src/kernel/libcxx/iostream.cpp @@ -21,7 +21,7 @@ #include "cstdio" -namespace std { +namespace sk_std { ostream& ostream::operator<<(int8_t val) { printf("%d", val); @@ -72,4 +72,4 @@ ostream& ostream::operator<<(ostream& (*manip)(ostream&)) { return manip(*this); } -}; // namespace std +}; // namespace sk_std diff --git a/src/kernel/main.cpp b/src/kernel/main.cpp index a38f0d625..8b32b47c6 100644 --- a/src/kernel/main.cpp +++ b/src/kernel/main.cpp @@ -49,7 +49,7 @@ uint32_t main(uint32_t argc, uint8_t *argv) { DumpStack(); - std::cout << "Hello ostream" << std::endl; + sk_std::cout << "Hello ostream" << sk_std::endl; return 0; }