Skip to content

Commit

Permalink
arch: clean up duplicate limine requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler569 committed May 9, 2024
1 parent c9fcf64 commit 68e5bb3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 82 deletions.
2 changes: 2 additions & 0 deletions arch/x86_64/phy_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion dump.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
78 changes: 0 additions & 78 deletions kernel/lib/limine.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,10 @@
#include <stdio.h>

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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions kernel/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <elf.h>
#include <ng/arch-2.h>
#include <ng/arch.h>
#include <ng/commandline.h>
#include <ng/debug.h>
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 68e5bb3

Please sign in to comment.