diff options
Diffstat (limited to 'src/kernel/lib')
-rw-r--r-- | src/kernel/lib/alloc.c | 4 | ||||
-rw-r--r-- | src/kernel/lib/alloc.h | 2 | ||||
-rw-r--r-- | src/kernel/lib/lib.h | 5 | ||||
-rw-r--r-- | src/kernel/lib/memory.c | 37 |
4 files changed, 45 insertions, 3 deletions
diff --git a/src/kernel/lib/alloc.c b/src/kernel/lib/alloc.c index 85ae7db..4266676 100644 --- a/src/kernel/lib/alloc.c +++ b/src/kernel/lib/alloc.c @@ -4,12 +4,12 @@ #include <kernel/paging/paging.h> int liballoc_lock() { - asm volatile ("cli"); + // asm volatile ("cli"); return 0; } int liballoc_unlock() { - asm volatile ("sti"); + // asm volatile ("sti"); return 0; } diff --git a/src/kernel/lib/alloc.h b/src/kernel/lib/alloc.h index 5658da7..6ed9efb 100644 --- a/src/kernel/lib/alloc.h +++ b/src/kernel/lib/alloc.h @@ -1,6 +1,8 @@ #ifndef MELVIX_ALLOC_H #define MELVIX_ALLOC_H +#include <stddef.h> + #define PREFIX(func) k ## func int liballoc_lock(); diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index 5cc3d1f..c431e1d 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -2,6 +2,7 @@ #define MELVIX_LIB_H #include <stddef.h> +#include <stdint.h> /** * Find the length of a string @@ -67,4 +68,8 @@ 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(); + +uint32_t memory_get_all(); + #endif 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 |