From: acevest Date: Tue, 24 Sep 2024 15:25:13 +0000 (+0800) Subject: default tty最顶上一行保留用来显示内核的版本及编译时间等信息 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=5447eca29c66d2283f536b8b0c3b94c5a73a8801;p=kernel.git default tty最顶上一行保留用来显示内核的版本及编译时间等信息 --- diff --git a/kernel/setup.c b/kernel/setup.c index 6bf2142..adffa9d 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -45,6 +45,15 @@ const char *version = "KERNEL v" VERSION " @" BUILDER "]" "\n\n"; +void print_kernel_version() { + // + extern tty_t *const default_tty; + tty_write_at(default_tty, 0, 0, version, (size_t)strlen(version)); + + // + printk(version); +} + void setup_kernel() { printk("sysenter esp mode: %s\n", #if FIXED_SYSENTER_ESP_MODE @@ -87,7 +96,7 @@ void setup_kernel() { detect_cpu(); boot_delay(DEFAULT_BOOT_DELAY_TICKS); - printk(version); + print_kernel_version(); boot_delay(DEFAULT_BOOT_DELAY_TICKS); extern tty_t *const monitor_tty; diff --git a/kernel/tty.c b/kernel/tty.c index f574aeb..370c2f9 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -129,9 +129,11 @@ void tty_do_scroll_up(tty_t *tty) { return; } - // - char *dst = (char *)tty->base_addr; - for (int src = BYTES_PER_LINE; src < (MAX_Y * BYTES_PER_LINE); src++) { + // 如果是default_tty则保留用来显示内核版本及编译时间信息 + const int keep = tty != default_tty ? 0 : BYTES_PER_LINE; + + char *dst = (char *)tty->base_addr + keep; + for (int src = BYTES_PER_LINE + keep; src < (MAX_Y * BYTES_PER_LINE); src++) { *dst++ = *(char *)(tty->base_addr + src); } @@ -260,7 +262,7 @@ void tty_switch(tty_t *tty) { outb(VGA_CRTC_START_ADDR_H, VGA_CRTC_ADDR); outb((offset >> 8) & 0xFF, VGA_CRTC_DATA); outb(VGA_CRTC_START_ADDR_L, VGA_CRTC_ADDR); - outb((offset)&0xFF, VGA_CRTC_DATA); + outb((offset) & 0xFF, VGA_CRTC_DATA); irq_restore(flags); current_tty = tty;