aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib
diff options
context:
space:
mode:
authorMarvin Borner2020-04-14 23:42:03 +0200
committerMarvin Borner2020-04-14 23:42:03 +0200
commitb11a2a876e7bd14078d26e12eab62db997a4dc76 (patch)
treef2ba2781d3d059810e3a0ccb04f637444c448e5e /src/kernel/lib
parent4391a5a374b7b75ca8fa69d35dcb5c5f9ad7f765 (diff)
Switched to grub
This really isn't what I wanted because grub is very big and bloaty but my own bootloader was very poorly written and I really want to implement a filesystem like ext2 which wouldn't work with my own bootloader. Furthermore this commit fixes many small issues including the one occurring due to the statically linked user binary (I just removed the linking for now).
Diffstat (limited to 'src/kernel/lib')
-rw-r--r--src/kernel/lib/lib.h5
-rw-r--r--src/kernel/lib/memory.c38
2 files changed, 20 insertions, 23 deletions
diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h
index b2b7056..ae8ee9c 100644
--- a/src/kernel/lib/lib.h
+++ b/src/kernel/lib/lib.h
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <kernel/multiboot.h>
/**
* Copy n data from src to dest
@@ -31,7 +32,9 @@ 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();
+void memory_init(multiboot_info_t *grub_header);
+
+void memory_print();
uint32_t memory_get_all();
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