commit 52eb0a14862adbdea550d35b84852cddba01d07c
parent 0905c02b4a2494937fda3213e1a8bd347c6a5b73
Author: evenfri <evenfri256@gmail.com>
Date: Sat, 8 Aug 2026 02:54:02 +0800
fix multiboot get memory, fix build mklib
Diffstat:
3 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/build/mkhdr b/build/mkhdr
@@ -21,5 +21,3 @@ cleanfiles=
nukefiles=
lib=
shortlib=
-
-<|cat $LPLAN9/config 2>/dev/null || true
diff --git a/build/mklib b/build/mklib
@@ -13,4 +13,4 @@ all install:V: $lib
cleanfiles=$cleanfiles $lib
-<$LPLAN9/src/mkcommon
+<$kernel/build/mkcommon
diff --git a/init.c b/init.c
@@ -10,24 +10,21 @@ void multiboot(uint32_t magic, multiboot_info_t *mbi) {
kpanic("invalid magic number!");
}
- if (!(mbi->flags >> 6 & 0x1)) {
+ if (!(mbi->flags & (1 << 6))) {
kpanic("invalid memory map given by GRUB");
}
-
- for (int i = 0; i < (int)mbi->mmap_length; i += sizeof(multiboot_memory_map_t)) {
- multiboot_memory_map_t* mmmt =
- (multiboot_memory_map_t*) (mbi->mmap_addr + i);
-
- if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
+ uint32_t offset = 0;
+ uint64_t total_ram = 0;
+ while (offset < mbi->mmap_length) {
+ multiboot_memory_map_t *entry = (multiboot_memory_map_t*)(mbi->mmap_addr + offset);
+ if (entry->type == MULTIBOOT_MEMORY_AVAILABLE) {
+ total_ram += entry->len;
}
+ offset += entry->size + sizeof(entry->size);
}
- if (mbi->flags & 0x1) {
- /* mem_lower — ram before 640 KB */
- /* mem_upper — ram > 1024 KB */
- uint32_t total_kb = mbi->mem_lower + mbi->mem_upper;
- uint32_t total_mb = total_kb / 1024;
- printk("memory: %d kb, %d mb\n", total_kb, total_mb);
- }
+ printk("memory size: %d KiB (%d MiB)\n",
+ (int)(total_ram / 1024),
+ (int)(total_ram / (1024 * 1024)));
}
void init(uint32_t magic, multiboot_info_t *mbi) {