From 68e5bb377165bdfef843fb97996334e5b20e812a Mon Sep 17 00:00:00 2001 From: Tyler Philbrick Date: Thu, 9 May 2024 14:14:22 -0700 Subject: [PATCH] arch: clean up duplicate limine requests --- arch/x86_64/phy_mem.c | 2 ++ dump.sh | 2 +- kernel/lib/limine.c | 78 ------------------------------------------- kernel/main.c | 7 ++-- run.rb | 2 +- 5 files changed, 9 insertions(+), 82 deletions(-) diff --git a/arch/x86_64/phy_mem.c b/arch/x86_64/phy_mem.c index 8ff6f19b..b54e701c 100644 --- a/arch/x86_64/phy_mem.c +++ b/arch/x86_64/phy_mem.c @@ -38,6 +38,8 @@ uintptr_t direct_map_of(uintptr_t addr) { return addr | hhdm_cache; } +uintptr_t limine_hhdm() { return direct_map_of(0); } + uintptr_t physical_of(uintptr_t addr) { return (uintptr_t)addr - direct_map_of(0); } diff --git a/dump.sh b/dump.sh index e24d342e..1c1b1a97 100755 --- a/dump.sh +++ b/dump.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -file="${1-build/kernel/nightingale_kernel}" +file="${1-build/system_root/boot/nightingale_kernel}" objdump_binary="llvm-objdump" format="intel" diff --git a/kernel/lib/limine.c b/kernel/lib/limine.c index 2b094fdf..1ce1c425 100644 --- a/kernel/lib/limine.c +++ b/kernel/lib/limine.c @@ -6,76 +6,10 @@ #include void limine_init() { - limine_memmap(); - printf("initfs address: %p\n", limine_module()); printf("rsdp address: %p\n", limine_rsdp()); printf("boot time: %li\n", limine_boot_time()); printf("kernel command line: %s\n", limine_kernel_command_line()); - - printf("hhdm map: %#lx\n", limine_hhdm()); -} - -__MUST_EMIT -static struct limine_memmap_request memmap_request = { - .id = LIMINE_MEMMAP_REQUEST, - .revision = 0, -}; - -void limine_memmap() { - static const char *type_names[] = { - [LIMINE_MEMMAP_ACPI_NVS] = "acpi", - [LIMINE_MEMMAP_ACPI_RECLAIMABLE] = "reclaim (ac)", - [LIMINE_MEMMAP_BAD_MEMORY] = "bad", - [LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE] = "reclaim (bl)", - [LIMINE_MEMMAP_FRAMEBUFFER] = "framebuffer", - [LIMINE_MEMMAP_KERNEL_AND_MODULES] = "kernel", - [LIMINE_MEMMAP_RESERVED] = "reserved", - [LIMINE_MEMMAP_USABLE] = "usable", - }; - - uint64_t available_memory = 0; - - assert(memmap_request.response); - for (int i = 0; i < memmap_request.response->entry_count; i++) { - struct limine_memmap_entry *entry = memmap_request.response->entries[i]; - - printf("%-15s %016lx %08lx\n", type_names[entry->type], entry->base, - entry->length); - - int pm_type = PM_NOMEM; - switch (entry->type) { - case LIMINE_MEMMAP_USABLE: - pm_type = PM_REF_ZERO; - available_memory += entry->length; - break; - case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE: - case LIMINE_MEMMAP_RESERVED: - case LIMINE_MEMMAP_KERNEL_AND_MODULES: - case LIMINE_MEMMAP_FRAMEBUFFER: - case LIMINE_MEMMAP_ACPI_NVS: - case LIMINE_MEMMAP_ACPI_RECLAIMABLE: - pm_type = PM_LEAK; - break; - } - - pm_set(entry->base, entry->base + entry->length, pm_type); - } - - printf("available memory: %lu (%lu KB)\n", available_memory, - available_memory / 1024); -} - -__MUST_EMIT -static struct limine_module_request module_request = { - .id = LIMINE_MODULE_REQUEST, - .revision = 1, -}; - -void *limine_module() { - assert(module_request.response); - - return module_request.response->modules[0]->address; } __MUST_EMIT @@ -126,18 +60,6 @@ int64_t limine_boot_time() { return boot_time_request.response->boot_time; } -__MUST_EMIT -static struct limine_hhdm_request hhdm_request = { - .id = LIMINE_HHDM_REQUEST, - .revision = 0, -}; - -virt_addr_t limine_hhdm() { - assert(hhdm_request.response); - - return hhdm_request.response->offset; -} - __MUST_EMIT static struct limine_framebuffer_request framebuffer_request = { .id = LIMINE_FRAMEBUFFER_REQUEST, diff --git a/kernel/main.c b/kernel/main.c index 00b6b3f4..1d575295 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -68,8 +69,10 @@ __USED size_t kernel_file_len = limine_kernel_file_len(); limine_load_kernel_elf(kernel_file_ptr, kernel_file_len); - initfs = (struct tar_header *)limine_module(); - fs_init(initfs); + void *initrd_base; + size_t initrd_len; + get_initrd_info(&initrd_base, &initrd_len); + fs_init(initrd_base); threads_init(); if (print_boot_info) diff --git a/run.rb b/run.rb index 3fcc44d1..a647c717 100755 --- a/run.rb +++ b/run.rb @@ -66,7 +66,7 @@ qemu_command = "qemu-system-x86_64 -s -vga std -no-reboot -m #{options[:ram]} -cdrom #{options[:iso_file]} " qemu_command += " -S" if options[:debug_wait] qemu_command += " -display none" unless options[:video] -qemu_command += " -d int,cpu_reset" if options[:show_interrupts] +qemu_command += " -d int,cpu_reset -M smm=off" if options[:show_interrupts] case options[:network] when "rtl"