:: commit 6d47bf9d81efee4dbe60a23ff1e6df6adf16a3c5

Kacper Słomiński <kacper.slominski72@gmail.com> — 2021-06-30 18:59

parents: 78ec547086

multiboot1: account for memory that crosses 1MB when summing up sizes

diff --git a/stage23/protos/multiboot1.c b/stage23/protos/multiboot1.c
index 4b32e565..d3b78721 100644
--- a/stage23/protos/multiboot1.c
+++ b/stage23/protos/multiboot1.c
@@ -225,10 +225,17 @@ void multiboot1_load(char *config, char *cmdline) {
             memmap[i].type = MEMMAP_USABLE;
 
         if (memmap[i].type == MEMMAP_USABLE) {
-            if (memmap[i].base < 0x100000)
-                memory_lower += memmap[i].length;
-            else
+            if (memmap[i].base < 0x100000) {
+                if (memmap[i].base + memmap[i].length > 0x100000) {
+                    size_t low_len = 0x100000 - memmap[i].base;
+                    memory_lower += low_len;
+                    memory_upper += memmap[i].length - low_len;
+                } else {
+                    memory_lower += memmap[i].length;
+                }
+            } else {
                 memory_upper += memmap[i].length;
+            }
         }
     }
 
tab: 248 wrap: offon