From e8c6577617bffa4402c07c7aa20e3c24f03c1c20 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 00:48:07 -0400 Subject: program loading, others big kernel additions: paging, elf loading, separate kernel and user page allocation it now properly loads and runs sd0:bin/init.elf still need to determine which disk was booted from, and start the init on that disk --- src/kernel/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'src/kernel/main.c') diff --git a/src/kernel/main.c b/src/kernel/main.c index 0c57ef3..eb57a01 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -1,21 +1,30 @@ #include #include "serial.h" #include "panic.h" +#include "paging.h" #include "boot.h" #include "util.h" #include "fat.h" #include "ide.h" -#include "mem.h" +#include "idt.h" +#include "pmap.h" +#include "task.h" #include "pci.h" #include "log.h" +#include "elf.h" +void reset_tree(); void tree(struct drive *d); +void _start_user_mode() __attribute__ ((noreturn)); + __attribute__ ((noreturn)) void main() { char nbuf[11]; - init_mmap(); + init_pagemap(); + init_paging(); + init_tasks(); init_serial(); init_log(); @@ -57,6 +66,8 @@ void main() { init_fat(); //other fs drivers + init_drives(); + init_ide(); //other drive drivers @@ -97,13 +108,44 @@ void main() { logch('\n'); - u32_dec(pages_left * 4, nbuf); + for (uint8_t n = 0; n < n_drives; ++n) { + if (drives[n].get_free_sectors(drives + n) == -1) + continue; + + u32_dec(n, nbuf); + logsz("sd"); + logsz(nbuf); + logsz(" tree:\n"); + + reset_tree(); + tree(drives + n); + logch('\n'); + } + + if (!try_elf_run(drives, "BIN/INIT.ELF")) + panic("Failed to load init program."); + + if (BOOT_INFO->support_flags & BIS_PAE) + logsz("Processor supports PAE (but Portland OS does not yet).\n\n"); + else + logsz("Processor does not support PAE.\n\n"); + + u32_dec(kernel_pages_left * 4, nbuf); + logsz(nbuf); + logsz("k / "); + u32_dec(max_kernel_pages * 4, nbuf); + logsz(nbuf); + logsz("k kernel heap free.\n"); + u32_dec(user_pages_left * 4, nbuf); + logsz(nbuf); + logsz("k / "); + u32_dec(max_user_pages * 4, nbuf); logsz(nbuf); - logsz("k dynamic memory free.\n\n"); + logsz("k user memory free.\n"); - logsz("sd0 root:\n"); - tree(&drives[0]); +//while (1) +// asm ("hlt"); - while (1) - asm ("hlt"); + init_idt(); + _start_user_mode(); } \ No newline at end of file -- cgit v1.2.3