diff options
Diffstat (limited to 'src/kernel/lib/memory.c')
-rw-r--r-- | src/kernel/lib/memory.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index a030c9a..3132e05 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -1,4 +1,7 @@ #include <stddef.h> +#include <stdint.h> +#include <kernel/paging/paging.h> +#include <kernel/io/io.h> void *memcpy(void *dest, const void *src, size_t count) { const char *sp = (const char *) src; @@ -23,4 +26,36 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size) { return 1; } return 0; -}
\ No newline at end of file +} + +uint32_t total_memory; + +struct memory_entry { + uint64_t base; + uint64_t length; + uint32_t type; +} __attribute__((packed)); + +struct memory_entry *memory_get_entries() { + return (struct memory_entry *) 0xA000; +} + +void memory_init() { + uint64_t maxbase = 0; + uint64_t maxlength = 0; + for (struct memory_entry *i = memory_get_entries(); i->type; i++) { + if (i->type == 1 && i->base > maxbase) { + maxbase = i->base; + maxlength = i->length; + } + } + total_memory = maxbase + maxlength; + total_memory /= 1024; + serial_write_dec(total_memory); +} + +uint32_t memory_get_free() { + return (total_memory) - paging_get_used_pages() * 4; +} + +uint32_t memory_get_all() { return total_memory; }
\ No newline at end of file |