:: commit 2ec27cbeee9f3f0e6d8177ac1d8823bf767b4bd6

mintsuki <mintsuki@protonmail.com> — 2020-04-30 21:59

parents: 96f8c65f01

Dynamically allocate e820

diff --git a/qloader2.bin b/qloader2.bin
index 185ecb8f..acd1bd6d 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/lib/e820.c b/src/lib/e820.c
index 1b092f72..f0e2e1a3 100644
--- a/src/lib/e820.c
+++ b/src/lib/e820.c
@@ -2,7 +2,7 @@
 #include <lib/real.h>
 #include <lib/blib.h>
 
-struct e820_entry_t e820_map[E820_MAX_ENTRIES];
+struct e820_entry_t *e820_map;
 
 static const char *e820_type(uint32_t type) {
     switch (type) {
@@ -25,28 +25,32 @@ int init_e820(void) {
     struct rm_regs r = {0};
 
     int entry_count;
-    for (int i = 0; i < E820_MAX_ENTRIES; i++) {
+
+    e820_map = balloc(sizeof(struct e820_entry_t));
+    for (int i = 0; ; i++) {
+        struct e820_entry_t entry;
+
         r.eax = 0xe820;
         r.ecx = 24;
         r.edx = 0x534d4150;
-        r.edi = (uint32_t)&e820_map[i];
+        r.edi = (uint32_t)&entry;
         rm_int(0x15, &r, &r);
 
+        e820_map[i] = entry;
+
         if (r.eflags & EFLAGS_CF) {
             entry_count = i;
-            goto done;
+            break;
         }
 
         if (!r.ebx) {
             entry_count = ++i;
-            goto done;
+            break;
         }
-    }
 
-    print("e820: Too many entries!\n");
-    for (;;);
+        balloc(sizeof(struct e820_entry_t));
+    }
 
-done:
     for (int i = 0; i < entry_count; i++) {
         print("e820: [%X -> %X] : %X  <%s>\n",
               e820_map[i].base,
diff --git a/src/lib/e820.h b/src/lib/e820.h
index c0f7253d..95e7ab2b 100644
--- a/src/lib/e820.h
+++ b/src/lib/e820.h
@@ -12,7 +12,7 @@ struct e820_entry_t {
     uint32_t unused;
 } __attribute__((packed));
 
-extern struct e820_entry_t e820_map[E820_MAX_ENTRIES];
+extern struct e820_entry_t *e820_map;
 
 int init_e820(void);
 
tab: 248 wrap: offon