diff --git a/common/setup.c b/common/setup.c index fb269bb4..0a525a12 100644 --- a/common/setup.c +++ b/common/setup.c @@ -72,6 +72,8 @@ bool_cmd("hpet", opt_hpet); io_port_t __data_rmode com_ports[2] = {COM1_PORT, COM2_PORT}; +boot_flags_t boot_flags; + static unsigned bsp_cpu_id = 0; const char *kernel_cmdline; @@ -240,6 +242,8 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic, map_vga_area(); write_cr3(cr3.paddr); + boot_flags.virt = true; + WRITE_SP(get_free_pages_top(PAGE_ORDER_2M, GFP_KERNEL)); if (opt_debug) dump_pagetables(); diff --git a/include/setup.h b/include/setup.h index c8dfd68c..49a7f976 100644 --- a/include/setup.h +++ b/include/setup.h @@ -35,10 +35,16 @@ #include +struct boot_flags { + uint64_t virt : 1, rsvd : 63; +}; +typedef struct boot_flags boot_flags_t; + extern io_port_t com_ports[2]; extern const char *kernel_cmdline; extern char cpu_identifier[49]; +extern boot_flags_t boot_flags; /* Static declarations */ diff --git a/mm/vmm.c b/mm/vmm.c index a495f719..8a86acf8 100644 --- a/mm/vmm.c +++ b/mm/vmm.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,9 @@ void *get_free_pages(unsigned int order, uint32_t flags) { void *va = NULL; mfn_t mfn; + if (!boot_flags.virt) + panic("Unable to use %s() before final page tables are set\n", __func__); + if (!frame) return NULL;