Skip to content

Commit

Permalink
feat: add Debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jul 31, 2024
1 parent 7aa7de0 commit 4b1797f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ list(APPEND COMMON_LINK_LIB

# 通用宏定义
list(APPEND COMMON_DEFINITIONS
$<$<CONFIG:Release>:RELEASE>
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:SIMPLEKERNEL_RELEASE>
$<$<CONFIG:Debug>:SIMPLEKERNEL_DEBUG>
)

list(APPEND DEFAULT_BOOT_DEFINITIONS
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/arch/x86_64/arch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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 x86_64 ArchInit\n");

return 0;
}
5 changes: 3 additions & 2 deletions src/kernel/include/kernel_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include <stdarg.h>

#include "cstdio"
#include "../../project_config.h"
#include "cstdio"

namespace {

Expand All @@ -40,7 +40,8 @@ static constexpr const auto kWhite = "\033[37m";
* @brief 与 printf 类似,只是颜色不同
*/
extern "C" inline void Debug(const char* format, ...) {
#ifdef DEBUG_LOG
(void)format;
#ifdef SIMPLEKERNEL_DEBUG_LOG
va_list args;
va_start(args, format);
printf("%s", kMagenta);
Expand Down
1 change: 1 addition & 0 deletions src/kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ uint32_t main(uint32_t argc, uint8_t *argv) {
[[maybe_unused]] auto arch_init_ret = ArchInit(argc, argv);

printf("Hello SimpleKernel\n");
Debug("Hello SimpleKernel\n");
Info("Hello SimpleKernel\n");
Warn("Hello SimpleKernel\n");
Err("Hello SimpleKernel\n");
Expand Down
4 changes: 2 additions & 2 deletions src/project_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#define KERNEL_NAME (wchar_t *)L"kernel.elf"

#ifdef DEBUG
#define DEBUG_LOG
#ifdef SIMPLEKERNEL_DEBUG
#define SIMPLEKERNEL_DEBUG_LOG
#endif

#endif /* SIMPLEKERNEL_SRC_PROJECT_CONFIG_H_ */
4 changes: 2 additions & 2 deletions tools/project_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#define KERNEL_NAME (wchar_t *)L"@KERNEL_ELF_OUTPUT_NAME@"

#ifdef DEBUG
#define DEBUG_LOG
#ifdef SIMPLEKERNEL_DEBUG
#define SIMPLEKERNEL_DEBUG_LOG
#endif

#endif /* SIMPLEKERNEL_SRC_PROJECT_CONFIG_H_ */

0 comments on commit 4b1797f

Please sign in to comment.