:: commit c05c65205754b53b34d43ac2442f276ef82938d1

mintsuki <mintsuki@protonmail.com> — 2020-06-05 18:57

parents: ab1e871023

Add more verbose memory map logging

diff --git a/qloader2.bin b/qloader2.bin
index 5ee26d82..db78c793 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/lib/e820.c b/src/lib/e820.c
index 6648e5e2..13ae08c1 100644
--- a/src/lib/e820.c
+++ b/src/lib/e820.c
@@ -4,27 +4,11 @@
 #include <lib/real.h>
 #include <lib/blib.h>
 #include <lib/print.h>
+#include <lib/memmap.h>
 
 struct e820_entry_t *e820_map;
 size_t e820_entries;
 
-static const char *e820_type(uint32_t type) {
-    switch (type) {
-        case 1:
-            return "Usable RAM";
-        case 2:
-            return "Reserved";
-        case 3:
-            return "ACPI reclaimable";
-        case 4:
-            return "ACPI NVS";
-        case 5:
-            return "Bad memory";
-        default:
-            return "???";
-    }
-}
-
 void init_e820(void) {
     struct rm_regs r = {0};
 
@@ -53,11 +37,6 @@ void init_e820(void) {
         balloc(sizeof(struct e820_entry_t));
     }
 
-    for (size_t i = 0; i < e820_entries; i++) {
-        print("e820: [%X -> %X] : %X  <%s>\n",
-              e820_map[i].base,
-              e820_map[i].base + e820_map[i].length,
-              e820_map[i].length,
-              e820_type(e820_map[i].type));
-    }
+    print("E820 memory map:\n");
+    print_memmap(e820_map, e820_entries);
 }
diff --git a/src/lib/memmap.c b/src/lib/memmap.c
index 594b394b..ef572556 100644
--- a/src/lib/memmap.c
+++ b/src/lib/memmap.c
@@ -4,6 +4,7 @@
 #include <lib/memmap.h>
 #include <lib/e820.h>
 #include <lib/blib.h>
+#include <lib/print.h>
 
 #define PAGE_SIZE   4096
 #define MEMMAP_BASE ((size_t)0x100000)
@@ -12,6 +13,35 @@
 static struct e820_entry_t memmap[MEMMAP_MAX_ENTRIES];
 static size_t memmap_entries = 0;
 
+static const char *memmap_type(uint32_t type) {
+    switch (type) {
+        case 1:
+            return "Usable RAM";
+        case 2:
+            return "Reserved";
+        case 3:
+            return "ACPI reclaimable";
+        case 4:
+            return "ACPI NVS";
+        case 5:
+            return "Bad memory";
+        case 10:
+            return "Kernel/Modules";
+        default:
+            return "???";
+    }
+}
+
+void print_memmap(struct e820_entry_t *mm, size_t size) {
+    for (size_t i = 0; i < size; i++) {
+        print("e820: [%X -> %X] : %X  <%s>\n",
+              mm[i].base,
+              mm[i].base + mm[i].length,
+              mm[i].length,
+              memmap_type(mm[i].type));
+    }
+}
+
 static void align_entry_down(uint64_t *base, uint64_t *length) {
     uint64_t orig_base = *base;
 
@@ -76,6 +106,10 @@ struct e820_entry_t *get_memmap(size_t *entries) {
     }
 
     *entries = memmap_entries;
+
+    print("Memory map requested. Current layout:\n");
+    print_memmap(memmap, memmap_entries);
+
     return memmap;
 }
 
@@ -127,6 +161,9 @@ void init_memmap(void) {
 
         memmap_entries++;
     }
+
+    print("Memory map initialised. Current layout:\n");
+    print_memmap(memmap, memmap_entries);
 }
 
 void memmap_alloc_range(uint64_t base, uint64_t length) {
@@ -174,9 +211,11 @@ void memmap_alloc_range(uint64_t base, uint64_t length) {
             target->base   = base;
             target->length = length;
 
+            print("Memory map changed. Current layout:\n");
+            print_memmap(memmap, memmap_entries);
             return;
         }
     }
 
     panic("Out of memory");
-}
\ No newline at end of file
+}
diff --git a/src/lib/memmap.h b/src/lib/memmap.h
index a4c03fb0..b33282dc 100644
--- a/src/lib/memmap.h
+++ b/src/lib/memmap.h
@@ -7,5 +7,6 @@
 void init_memmap(void);
 void memmap_alloc_range(uint64_t base, uint64_t length);
 struct e820_entry_t *get_memmap(size_t *entries);
+void print_memmap(struct e820_entry_t *mm, size_t size);
 
 #endif
tab: 248 wrap: offon