From 577d28cd2ec003d0d094c15640c4833d672e5c93 Mon Sep 17 00:00:00 2001 From: "Pierre-Emmanuel Gob." Date: Thu, 17 Sep 2026 22:44:16 +0200 Subject: [PATCH] Added documentation to console.c --- .gitignore | 2 ++ kernel/arch/x86_64/console.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index c34569c..1a169c1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ compile_commands.json .vscode/ .idea/ *~ +.pyc +*.pyc # QEMU / debug *.log diff --git a/kernel/arch/x86_64/console.c b/kernel/arch/x86_64/console.c index 054da5a..3d4decd 100644 --- a/kernel/arch/x86_64/console.c +++ b/kernel/arch/x86_64/console.c @@ -13,8 +13,13 @@ static uint8_t cursor_row; static uint8_t cursor_col; +/* Text buffer: one 16-bit cell per character, low byte is the ASCII code, + * high byte is the color attribute. `volatile` so the compiler keeps every + * store in order: this is memory-mapped I/O, and dropped or reordered + * writes would corrupt the screen. */ static volatile uint16_t *const vga = (uint16_t *)VGA_ADDR; +/* Move every line one row up and blank the last line */ static void scroll(void) { for (uint8_t row = 1; row < VGA_HEIGHT; row++) { @@ -47,10 +52,12 @@ void console_putchar(char c) (uint16_t)((COLOR_DEFAULT << 8) | c); cursor_col++; if (cursor_col >= VGA_WIDTH) { + /* Past the right edge: wrap to the next line. */ cursor_col = 0; cursor_row++; } } + /* Past the bottom line: scroll and stay on the last line. */ if (cursor_row >= VGA_HEIGHT) { scroll(); cursor_row = VGA_HEIGHT - 1; @@ -70,6 +77,7 @@ void console_puthex64(uint64_t value) static const char digits[] = "0123456789ABCDEF"; console_puts("0x"); + /* Print 16 nibbles, most significant first (shifts 60, 56, …, 0). */ for (int shift = 60; shift >= 0; shift -= 4) { console_putchar(digits[(value >> shift) & 0xFU]); }