diff options
Diffstat (limited to 'src/kernel/lib/memory.c')
-rw-r--r-- | src/kernel/lib/memory.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index f9e0054..4763ca0 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -1,5 +1,9 @@ #include <stddef.h> #include <stdint.h> +#include <kernel/system.h> +#include <kernel/lib/stdio.h> +#include <kernel/memory/paging.h> +#include <kernel/multiboot.h> void *memcpy(void *dest, const void *src, size_t count) { @@ -31,39 +35,29 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size) return 0; } -uint32_t total_memory; +multiboot_info_t *multiboot_header; -struct memory_entry { - uint64_t base; - uint64_t length; - uint32_t type; -} __attribute__((packed)); - -struct memory_entry *memory_get_entries() +void memory_print() { - return (struct memory_entry *)0xA000; + if (multiboot_header->flags & MULTIBOOT_INFO_MEMORY) { + serial_printf("Mem lower: 0x%x", multiboot_header->mem_lower); + serial_printf("Mem upper: 0x%x", multiboot_header->mem_upper); + } else { + serial_printf("No memory information available!"); + } } -void memory_init() +void memory_init(multiboot_info_t *grub_header) { - uint64_t max_base = 0; - uint64_t max_length = 0; - for (struct memory_entry *i = memory_get_entries(); i->type; i++) { - if (i->type == 1 && i->base > max_base) { - max_base = i->base; - max_length = i->length; - } - } - total_memory = (uint32_t)(max_base + max_length); - total_memory /= 1024; + multiboot_header = grub_header; } uint32_t memory_get_free() { - return total_memory; // - paging_get_used_pages() * 4; + return multiboot_header->mem_upper - paging_get_used_pages() * 4; } uint32_t memory_get_all() { - return total_memory; + return multiboot_header->mem_upper; }
\ No newline at end of file |