]> Zhao Yanbai Git Server - kernel.git/commitdiff
default tty最顶上一行保留用来显示内核的版本及编译时间等信息
authoracevest <zhaoyanbai@126.com>
Tue, 24 Sep 2024 15:25:13 +0000 (23:25 +0800)
committeracevest <zhaoyanbai@126.com>
Tue, 24 Sep 2024 15:25:13 +0000 (23:25 +0800)
kernel/setup.c
kernel/tty.c

index 6bf2142e40e9b7b2c48fa6da28780b9fb53746fb..adffa9d23e8afe7d4fdea50124efd867b27dd775 100644 (file)
@@ -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;
index f574aeb9c7cd6042afa403fec2eafc72cbbc7c82..370c2f9f9bbefbf158f2622a8d816f60fac52269 100644 (file)
@@ -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;