From: acevest Date: Tue, 24 Sep 2024 15:47:05 +0000 (+0800) Subject: 修复在default tty最顶上显示内核版本及编译信息造成的tty坐标错误的问题 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=3b236d4daf4e3981dc7328b14f4e59ba2314cfd1;p=kernel.git 修复在default tty最顶上显示内核版本及编译信息造成的tty坐标错误的问题 --- diff --git a/include/tty.h b/include/tty.h index 1a69558..3d81ec0 100644 --- a/include/tty.h +++ b/include/tty.h @@ -31,6 +31,10 @@ typedef struct tty { unsigned int fg_color; unsigned int bg_color; + // 最大字符数 + int max_x; + int max_y; + // 记录对应的显存起始位置 unsigned long base_addr; } tty_t; diff --git a/kernel/setup.c b/kernel/setup.c index adffa9d..e5aa761 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -48,7 +48,29 @@ const char *version = "KERNEL v" VERSION " @" BUILDER void print_kernel_version() { // extern tty_t *const default_tty; - tty_write_at(default_tty, 0, 0, version, (size_t)strlen(version)); + tty_t *const tty = default_tty; + + int len = strlen(version); + + for (int i = 0; i < tty->max_x; i++) { + char c = i < len ? version[i] : ' '; + c = c != '\n' ? c : ' '; + c = c != '\t' ? c : ' '; + + // + uint32_t fg_color = tty->fg_color; + uint32_t bg_color = tty->bg_color; + + fg_color = TTY_WHITE | TTY_FG_HIGHLIGHT; + bg_color = TTY_CYAN; + + // + char *dst = (char *)tty->base_addr; + + // + dst[i * 2 + 0] = c; + dst[i * 2 + 1] = ((bg_color) << 4) | (fg_color); + } // printk(version); diff --git a/kernel/tty.c b/kernel/tty.c index 370c2f9..132d02c 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -75,6 +75,9 @@ void init_tty(tty_t *tty, const char *name, unsigned long base) { tty->fg_color = TTY_FG_HIGHLIGHT | TTY_GREEN; // 高亮 tty->bg_color = TTY_BLACK; // 不闪 + tty->max_x = MAX_X; + tty->max_y = MAX_Y; + tty->base_addr = base; for (int i = 0; i < TTY_VRAM_SIZE; i += 2) {