From 6d47bf9d81efee4dbe60a23ff1e6df6adf16a3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?= Date: Wed, 30 Jun 2021 20:59:59 +0200 Subject: [PATCH] multiboot1: account for memory that crosses 1MB when summing up sizes --- stage23/protos/multiboot1.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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; + } } }