#include <lunaix/device.h>
#include <lunaix/foptions.h>
#include <lunaix/input.h>
+#include <lunaix/isrm.h>
#include <lunaix/lxconsole.h>
#include <lunaix/mm/mmio.h>
#include <lunaix/mm/page.h>
x86_page_table* __kernel_ptd;
-struct proc_info tmp;
-
extern void
__proc0(); /* proc0.c */
void
_kernel_pre_init()
{
+ // interrupts
_init_idt();
+ isrm_init();
intr_routine_init();
+ // memory
pmm_init(MEM_1MB + (_k_init_mb_info->mem_upper << 10));
vmm_init();
_k_init_mb_info->mmap_length / sizeof(multiboot_memory_map_t);
setup_memory((multiboot_memory_map_t*)_k_init_mb_info->mmap_addr, map_size);
-
- __kernel_ptd = cpu_rcr3();
-
- tmp = (struct proc_info){ .page_table = __kernel_ptd };
-
- __current = &tmp;
}
void
_kernel_init()
{
int errno = 0;
+
+ // allocators
cake_init();
valloc_init();
+ sched_init();
+
+ // crt
tty_init(ioremap(VGA_FRAMEBUFFER, PG_SIZE));
tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
+ // file system & device subsys
vfs_init();
fsm_init();
input_init();
vfs_export_attributes();
+ lxconsole_init();
+
if ((errno = vfs_mount_root("ramfs", NULL))) {
panickf("Fail to mount root. (errno=%d)", errno);
}
vfs_mount("/sys", "twifs", NULL, MNT_RO);
vfs_mount("/task", "taskfs", NULL, MNT_RO);
- lxconsole_init();
+ lxconsole_spawn_ttydev();
+ device_init_builtin();
- sched_init();
+ syscall_install();
spawn_proc0();
}
: "i"(KSTACK_TOP), "i"(KCODE_SEG), "r"(proc0->intr_ctx.eip)
: "%ebx", "memory");
+ // 加载x87默认配置
+ asm volatile("fninit\n"
+ "fxsave (%%eax)" ::"a"(proc0->fxstate)
+ : "memory");
+
// 向调度器注册进程。
commit_process(proc0);
for (uintptr_t i = &__usrtext_start; i < &__usrtext_end; i += PG_SIZE) {
vmm_set_mapping(PD_REFERENCED, i, V2P(i), PG_PREM_UR, VMAP_NULL);
}
+
+ // reserve higher half
+ for (size_t i = L1_INDEX(KERNEL_MM_BASE); i < 1023; i++) {
+ assert(vmm_set_mapping(PD_REFERENCED, i << 22, 0, 0, VMAP_NOMAP));
+ }
}