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 e92b0313a..aef672c97 100644 --- a/src/kernel/arch/riscv64/include/cpu.hpp +++ b/src/kernel/arch/riscv64/include/cpu.hpp @@ -1149,7 +1149,7 @@ class ReadWriteField : public ReadOnlyField, // 第三部分:寄存器实例 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 27fdbafc9..8ceee3d6a 100644 --- a/src/kernel/arch/x86_64/arch_main.cpp +++ b/src/kernel/arch/x86_64/arch_main.cpp @@ -98,7 +98,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 086206868..630f510dc 100644 --- a/src/kernel/arch/x86_64/include/cpu.hpp +++ b/src/kernel/arch/x86_64/include/cpu.hpp @@ -1670,7 +1670,7 @@ class ReadWriteField : public ReadOnlyField, // 第三部分:寄存器实例 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 03e6f8e6f..b08e33dee 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; InterruptInit(argc, argv); 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