From: acevest Date: Mon, 29 May 2023 15:14:59 +0000 (+0800) Subject: 修复在启动分页前的输出看不见的问题 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=6aa54b5d69db6604b75ed7f9cc66b1dae212d078;p=kernel.git 修复在启动分页前的输出看不见的问题 --- diff --git a/boot/boot.c b/boot/boot.c index 62bc897..e7510a0 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -136,6 +136,7 @@ void check_kernel(unsigned long addr, unsigned long magic) { extern void *kernel_begin; extern void *kernel_end; extern void *bootmem_bitmap_begin; +extern void init_default_tty_before_paging(); void init_system_info() { system.kernel_begin = &kernel_begin; system.kernel_end = &kernel_end; @@ -147,6 +148,4 @@ void init_system_info() { printk("boot device: bios dev %x partition %x sub partition %x\n", boot_params.biosdev, boot_params.partition, boot_params.sub_partition); printk("mem lower %uKB upper %uKB\n", boot_params.mem_lower >> 10, boot_params.mem_upper >> 10); - // while (1) - // ; } diff --git a/boot/multiboot.S b/boot/multiboot.S index 8c44dfe..6616ee8 100644 --- a/boot/multiboot.S +++ b/boot/multiboot.S @@ -1,16 +1,16 @@ /* *-------------------------------------------------------------------------- * File Name: multiboot.S - * + * * Description: none - * - * + * + * * Author: Zhao Yanbai [zhaoyanbai@126.com] - * + * * Version: 1.0 * Create Date: Mon Nov 10 15:58:46 2008 * Last Update: Tue Feb 10 22:39:24 2009 - * + * *-------------------------------------------------------------------------- */ #define ASM @@ -19,7 +19,8 @@ #include "task.h" .global kernel_entry .global main -.extern check_kernel +.extern check_kernel +.extern init_default_tty_before_paging .extern init_system_info .extern setup_kernel .extern init_pgd @@ -99,7 +100,7 @@ main: stosl addl $0x1000,%eax loop 2b - + # 初始化页表 # 直接线性映射BOOT_INIT_PAGETBL_CNT*4M物理内存 movl $init_pgt-KRNLADDR,%ebx @@ -129,6 +130,7 @@ Label: addl $8, %esp movl $root_task + TASK_SIZE, %esp + call init_default_tty_before_paging call init_system_info call setup_kernel diff --git a/gdbscript b/gdbscript index c8c2218..7c763a7 100644 --- a/gdbscript +++ b/gdbscript @@ -1,3 +1,5 @@ target remote localhost:1234 -b setup_kernel +b init_system_info +#b setup_kernel +#b e820_init_bootmem_data c diff --git a/include/printk.h b/include/printk.h index f142ebe..e8f1c6f 100644 --- a/include/printk.h +++ b/include/printk.h @@ -27,7 +27,6 @@ int printlo(unsigned int line, unsigned int offset, const char *fmtstr, ...); // monitor print line enum { MPL_TITLE, - MPL_ROOTDEV, MPL_CLOCK, MPL_KEYBOARD, MPL_IDE, diff --git a/kernel/setup.c b/kernel/setup.c index cd8802b..016d433 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -35,7 +35,6 @@ extern void setup_ext2(); extern void reboot(); extern void cnsl_init(); -extern void init_ttys(); #define VERSION "0.3.1" const char *version = "Kernel version " VERSION " @ " BUILDER @@ -46,8 +45,6 @@ const char *version = "Kernel version " VERSION " @ " BUILDER "\n"; void setup_kernel() { - init_ttys(); - printk("sysenter esp mode: %s\n", #if FIX_SYSENTER_ESP_MODE "fixed to &tss.esp0" @@ -72,7 +69,6 @@ void setup_kernel() { cnsl_init(); printl(MPL_TITLE, " KERNEL MONITOR"); - printl(MPL_ROOTDEV, "root device %08x", system.root_dev); setup_tasks(); @@ -97,4 +93,4 @@ void setup_under_irq() { ata_init(); return; setup_fs(); -} \ No newline at end of file +} diff --git a/kernel/tty.c b/kernel/tty.c index f10f569..11a23f5 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -18,7 +18,8 @@ // 而一屏所需要的显存为 80*25*2 = 4000 约为4K // 所以大致可以分出8个tty // 每个的起始地址以0x1000对齐 -#define VADDR ((unsigned long)pa2va(0xB8000)) +const uint32_t PHY_VADDR = 0xB8000; +#define VADDR ((uint32_t)pa2va(PHY_VADDR)) #define TTY_VRAM_SIZE (0x1000) #define MAX_X 80 @@ -61,6 +62,14 @@ void __tty_set_next_pos_color(tty_t *tty, char color) { } } +void init_default_tty_before_paging() { + default_tty.fg_color = TTY_FG_HIGHLIGHT | TTY_GREEN; // 高亮 + default_tty.bg_color = TTY_BLACK; // 不闪 + default_tty.base_addr = PHY_VADDR; + default_tty.xpos = 0; + default_tty.ypos = 0; +} + void init_tty(tty_t *tty, const char *name, unsigned long base) { assert(0 != tty); @@ -75,19 +84,30 @@ void init_tty(tty_t *tty, const char *name, unsigned long base) { } void init_ttys() { + assert(irq_disabled()); + + // 先备份default_tty在分页前用到的xpos, ypos + unsigned int xpos = default_tty.xpos; + unsigned int ypos = default_tty.ypos; + init_tty(&default_tty, "tty.default", VADDR + 0 * TTY_VRAM_SIZE); init_tty(&monitor_tty, "tty.monitor", VADDR + 1 * TTY_VRAM_SIZE); + init_tty(&debug_tty, "tty.debug", VADDR + 7 * TTY_VRAM_SIZE); monitor_tty.fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE; monitor_tty.bg_color = TTY_BLUE; - tty_clear(&monitor_tty); - - current_tty = &default_tty; - init_tty(&debug_tty, "tty.debug", VADDR + 7 * TTY_VRAM_SIZE); debug_tty.fg_color = TTY_FG_HIGHLIGHT | TTY_WHITE; debug_tty.bg_color = TTY_CYAN; + + tty_clear(&monitor_tty); tty_clear(&debug_tty); + + // 恢复在分页前的输出位置 + default_tty.xpos = xpos; + default_tty.ypos = ypos; + + current_tty = &default_tty; } void tty_do_scroll_up(tty_t *tty) { @@ -240,4 +260,4 @@ void tty_switch(tty_t *tty) { tty_set_cursor(current_tty); } -tty_t *current_tty; \ No newline at end of file +tty_t *current_tty; diff --git a/mm/bootmem.c b/mm/bootmem.c index 92e9f7a..a4f09d7 100644 --- a/mm/bootmem.c +++ b/mm/bootmem.c @@ -15,19 +15,19 @@ static void e820_print_type(unsigned long type) { switch (type) { case E820_RAM: - printk("usable"); + printk("RAM"); break; case E820_RESERVED: - printk("reserved"); + printk("RESERVED"); break; case E820_ACPI: - printk("ACPI data"); + printk("ACPI"); break; case E820_NVS: - printk("ACPI NVS"); + printk("NVS"); break; case E820_UNUSABLE: - printk("unusable"); + printk("UNUSABLE"); break; default: printk("type %x", type); @@ -203,7 +203,6 @@ void init_bootmem() { e820_print_map(); e820_init_bootmem_data(); init_bootmem_allocator(); - // asm("cli;hlt;"); } // 由于只有在构建buddy system的时候才会用到 diff --git a/mm/mm.c b/mm/mm.c index 1626bb6..7d06373 100644 --- a/mm/mm.c +++ b/mm/mm.c @@ -119,6 +119,8 @@ void init_paging() { // } } +extern void init_ttys(); + void init_mm() { printk("init bootmem alloc...\n"); extern void init_bootmem(); @@ -126,6 +128,11 @@ void init_mm() { printk("init global paging...\n"); init_paging(); + // 只能将这个调用放在此处 + // 在这之前是没开启页映射用的是物理地址 + // 在这之后需要用到线性地址来定位显存 + init_ttys(); + printk("init buddy system...\n"); extern void init_buddy_system(); init_buddy_system();