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;
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)
- // ;
}
/*
*--------------------------------------------------------------------------
* 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
#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
stosl
addl $0x1000,%eax
loop 2b
-
+
# 初始化页表
# 直接线性映射BOOT_INIT_PAGETBL_CNT*4M物理内存
movl $init_pgt-KRNLADDR,%ebx
addl $8, %esp
movl $root_task + TASK_SIZE, %esp
+ call init_default_tty_before_paging
call init_system_info
call setup_kernel
target remote localhost:1234
-b setup_kernel
+b init_system_info
+#b setup_kernel
+#b e820_init_bootmem_data
c
// monitor print line
enum {
MPL_TITLE,
- MPL_ROOTDEV,
MPL_CLOCK,
MPL_KEYBOARD,
MPL_IDE,
extern void reboot();
extern void cnsl_init();
-extern void init_ttys();
#define VERSION "0.3.1"
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"
cnsl_init();
printl(MPL_TITLE, " KERNEL MONITOR");
- printl(MPL_ROOTDEV, "root device %08x", system.root_dev);
setup_tasks();
ata_init();
return;
setup_fs();
-}
\ No newline at end of file
+}
// 而一屏所需要的显存为 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
}
}
+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);
}
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) {
tty_set_cursor(current_tty);
}
-tty_t *current_tty;
\ No newline at end of file
+tty_t *current_tty;
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);
e820_print_map();
e820_init_bootmem_data();
init_bootmem_allocator();
- // asm("cli;hlt;");
}
// 由于只有在构建buddy system的时候才会用到
// }
}
+extern void init_ttys();
+
void init_mm() {
printk("init bootmem alloc...\n");
extern void init_bootmem();
printk("init global paging...\n");
init_paging();
+ // 只能将这个调用放在此处
+ // 在这之前是没开启页映射用的是物理地址
+ // 在这之后需要用到线性地址来定位显存
+ init_ttys();
+
printk("init buddy system...\n");
extern void init_buddy_system();
init_buddy_system();