From 203c6950ab45e89ababa594d5b359118e17bfd02 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 17 Apr 2020 00:39:10 +0200 Subject: Started implementing multiboot2 standard --- src/kernel/lib/lib.h | 4 ++-- src/kernel/lib/memory.c | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src/kernel/lib') diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index ae8ee9c..8f4e13f 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -32,10 +32,10 @@ void *memset(void *dest, char val, size_t count); */ int memcmp(const void *a_ptr, const void *b_ptr, size_t size); -void memory_init(multiboot_info_t *grub_header); +void memory_init(struct multiboot_tag_basic_meminfo *tag); void memory_print(); uint32_t memory_get_all(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index 3202691..2544ee0 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -35,29 +35,32 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size) return 0; } -multiboot_info_t *multiboot_header; +struct multiboot_tag_basic_meminfo *meminfo = NULL; -void memory_print() +uint32_t memory_get_all() { - if (multiboot_header->flags & MULTIBOOT_INFO_MEMORY) { - log("Mem lower: 0x%x", multiboot_header->mem_lower); - log("Mem upper: 0x%x", multiboot_header->mem_upper); + if (meminfo != NULL) { + return meminfo->mem_lower + meminfo->mem_upper; } else { - log("No memory information available!"); + warn("Got no memory info, guessing size!"); + return 42000; // This should not happen on a modern pc but well idk, 42MB? } } -void memory_init(multiboot_info_t *grub_header) +uint32_t memory_get_free() { - multiboot_header = grub_header; + return memory_get_all() - paging_get_used_pages() * 4; } -uint32_t memory_get_free() +void memory_print() { - return multiboot_header->mem_upper - paging_get_used_pages() * 4; + info("Mem lower: 0x%x", meminfo->mem_lower); + info("Mem upper: 0x%x", meminfo->mem_upper); + info("Total memory found: %dMiB", (memory_get_all() >> 10) + 1); + info("Total free memory: %dMiB", (memory_get_free() >> 10) + 1); } -uint32_t memory_get_all() +void memory_init(struct multiboot_tag_basic_meminfo *tag) { - return multiboot_header->mem_upper; -} \ No newline at end of file + meminfo = tag; +} -- cgit v1.2.3