Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jun 14, 2024
1 parent 3a85209 commit 20adc71
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/kernel/arch/riscv64/arch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) {
// 解析内核 elf 信息
kKernelElf.GetInstance() = KernelElf();

info("Hello riscv64 ArchInit\n");
Info("Hello riscv64 ArchInit\n");

return 0;
}
4 changes: 2 additions & 2 deletions src/kernel/arch/x86_64/arch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void Fillrect(uint8_t *vram, uint32_t pitch, uint8_t r, uint8_t g,

uint32_t ArchInit(uint32_t argc, uint8_t *argv) {
if (argc != 1) {
err("argc != 1 [%d]\n", argc);
Err("argc != 1 [%d]\n", argc);
throw;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) {
kKernelElf.GetInstance() = KernelElf(kBasicInfo.GetInstance().elf_addr,
kBasicInfo.GetInstance().elf_size);

info("Hello x8_64 ArchInit\n");
Info("Hello x8_64 ArchInit\n");

return 0;
}
10 changes: 5 additions & 5 deletions src/kernel/include/kernel_elf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class KernelElf {
*/
explicit KernelElf(uint64_t elf_addr, size_t elf_size = 64) {
if (!elf_addr || !elf_size) {
err("Fatal Error: Invalid elf_addr or elf_size.\n");
Err("Fatal Error: Invalid elf_addr or elf_size.\n");
throw;
}

Expand All @@ -53,7 +53,7 @@ class KernelElf {
// 检查 elf 头数据
auto check_elf_identity_ret = CheckElfIdentity();
if (!check_elf_identity_ret) {
err("KernelElf NOT valid ELF file.\n");
Err("KernelElf NOT valid ELF file.\n");
throw;
}

Expand Down Expand Up @@ -106,15 +106,15 @@ class KernelElf {
[[nodiscard]] bool CheckElfIdentity() const {
if ((elf_[EI_MAG0] != ELFMAG0) || (elf_[EI_MAG1] != ELFMAG1) ||
(elf_[EI_MAG2] != ELFMAG2) || (elf_[EI_MAG3] != ELFMAG3)) {
err("Fatal Error: Invalid ELF header.\n");
Err("Fatal Error: Invalid ELF header.\n");
throw;
}
if (elf_[EI_CLASS] == ELFCLASS32) {
err("Found 32bit executable but NOT SUPPORT.\n");
Err("Found 32bit executable but NOT SUPPORT.\n");
throw;
}
if (elf_[EI_CLASS] != ELFCLASS64) {
err("Fatal Error: Invalid executable.\n");
Err("Fatal Error: Invalid executable.\n");
throw;
}
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/kernel/include/kernel_fdt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class KernelFdt {
*/
explicit KernelFdt(uint64_t fdt_addr) : fdt_addr_((void *)fdt_addr) {
if (!fdt_addr_) {
err("Fatal Error: Invalid fdt_addr.\n");
Err("Fatal Error: Invalid fdt_addr.\n");
throw;
}

// 检查 fdt 头数据
if (fdt_check_header(fdt_addr_) != 0) {
err("Invalid device tree blob\n");
Err("Invalid device tree blob\n");
throw;
}
}
Expand Down Expand Up @@ -82,14 +82,14 @@ class KernelFdt {
// 找到 /memory 节点
auto offset = fdt_path_offset(fdt_addr_, "/memory");
if (offset < 0) {
err("Error finding /memory node: %s\n", fdt_strerror(offset));
Err("Error finding /memory node: %s\n", fdt_strerror(offset));
throw;
}

// 获取 reg 属性
auto prop = fdt_get_property(fdt_addr_, offset, "reg", &len);
if (!prop) {
err("Error finding reg property: %s\n", fdt_strerror(len));
Err("Error finding reg property: %s\n", fdt_strerror(len));
throw;
}

Expand All @@ -115,14 +115,14 @@ class KernelFdt {
// 找到 /memory 节点
auto offset = fdt_path_offset(fdt_addr_, "/soc/serial");
if (offset < 0) {
err("Error finding /soc/serial node: %s\n", fdt_strerror(offset));
Err("Error finding /soc/serial node: %s\n", fdt_strerror(offset));
throw;
}

// 获取 reg 属性
auto prop = fdt_get_property(fdt_addr_, offset, "reg", &len);
if (!prop) {
err("Error finding reg property: %s\n", fdt_strerror(len));
Err("Error finding reg property: %s\n", fdt_strerror(len));
throw;
}

Expand Down
6 changes: 3 additions & 3 deletions src/kernel/include/kernel_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static constexpr const auto kWhite = "\033[37m";
/**
* @brief 与 printf 类似,只是颜色不同
*/
extern "C" inline void info(const char* format, ...) {
extern "C" inline void Info(const char* format, ...) {
va_list args;
va_start(args, format);
printf("%s", kCyan);
Expand All @@ -47,7 +47,7 @@ extern "C" inline void info(const char* format, ...) {
va_end(args);
}

extern "C" inline void warn(const char* format, ...) {
extern "C" inline void Warn(const char* format, ...) {
va_list args;
va_start(args, format);
printf("%s", kYellow);
Expand All @@ -56,7 +56,7 @@ extern "C" inline void warn(const char* format, ...) {
va_end(args);
}

extern "C" inline void err(const char* format, ...) {
extern "C" inline void Err(const char* format, ...) {
va_list args;
va_start(args, format);
printf("%s", kRed);
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/libc/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include <stdint.h>

// 声明内核提供的函数
extern void err(const char* format, ...);
extern void Err(const char* format, ...);

/// 栈保护
uint64_t __stack_chk_guard = 0x595E9FBD94FDA766;

/// 栈保护检查失败后进入死循环
__attribute__((noreturn)) void __stack_chk_fail() {
err("Error: Stack smashing detected!\n");
Err("Error: Stack smashing detected!\n");
while (1);
}
6 changes: 3 additions & 3 deletions src/kernel/libcxx/libcxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// 声明内核提供的函数
extern void DumpStack();
extern "C" void err(const char* format, ...);
extern "C" void Err(const char* format, ...);

/// 全局构造函数函数指针
typedef void (*function_t)(void);
Expand Down Expand Up @@ -166,9 +166,9 @@ extern "C" void __cxa_pure_virtual() { while (1); }
* @note 这里只能处理 throw,无法处理异常类型
*/
extern "C" void __cxa_rethrow() {
err("----__cxa_rethrow----\n");
Err("----__cxa_rethrow----\n");
DumpStack();
err("--__cxa_rethrow End--\n");
Err("--__cxa_rethrow End--\n");
while (1);
}

Expand Down
9 changes: 4 additions & 5 deletions src/kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ uint32_t main(uint32_t argc, uint8_t *argv) {
// 架构相关初始化
[[maybe_unused]] auto arch_init_ret = ArchInit(argc, argv);

info("Hello printf\n");

info("Hello info\n");
warn("Hello warn\n");
err("Hello err\n");
printf("Hello SimpleKernel\n");
Info("Hello SimpleKernel\n");
Warn("Hello SimpleKernel\n");
Err("Hello SimpleKernel\n");

DumpStack();

Expand Down

0 comments on commit 20adc71

Please sign in to comment.