From c05c65205754b53b34d43ac2442f276ef82938d1 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Fri, 5 Jun 2020 20:57:09 +0200 Subject: [PATCH] Add more verbose memory map logging --- qloader2.bin | Bin 32768 -> 32768 bytes src/lib/e820.c | 27 +++------------------------ src/lib/memmap.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/lib/memmap.h | 1 + 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/qloader2.bin b/qloader2.bin index 5ee26d826ee933860b1707a73d93708aa189f2f3..db78c7936c7ed352ba46d76e1346148af23f51d4 100644 GIT binary patch delta 7444 zcma)B3tUuX+CS$o1EYd7sK|H$#~X@*f{Jog5+^kw2POt@Xts$*NHd*T+bske>Em=7 z>+9`et)(ov>u$AcOBN=ZB*fTdTP&+lNl}pw4wa=JYp#0s|C||&-L2p6n;&!LeV^z5 zT;J!t9V#n@%1U8>m@eAV$#I?tQwYy_qNp8z?D8L#q}eQ1ch9Qp7dXxpo)L2uzsBuv za2)5(A`Ismnx9{45;+UUDf(EBt0k(t*;GTn(vf$s=}M%iZy@DvHW-+E;7j_RpH_l=qp(zzd(nx!_ z@y)948>(u<@7MGzK1i66vp8<~D&t#Kmq3G;#%@E z9lOJ$W4wAo(C2;sTV6eh@#y$pp*DN4pLI|cBFEUv<=5XQ4baH`-Y+?w#Fi~D?ivhj zAUo{RyY8$6(q-I!T|m)gw`TU+Vv!@lK`V>wZ+xebZig01U6qJo&? z@b&6BJazbX%@2XSECZUHv%gnA5e@Q4jv$MN_Mj;pP5$H`moqe0xxSVVcKc+l>%aZ~ zBPvH}T93G+ubH<-ylsZg_#=`=EGP(pA~t-0rQ*L`h#?o=(OmGsg`Q&a z#aqMc7n7z|%_Ezw56~78K`{RvKjqy|X-$ioSOI~pp#iTPj=st!Ys&Jw@{oE}Yu8W? z7u3@8KP zbI-Z2hHWwJF@f%Gza%{JCse9`q-U;==&K%kFbo2nX}5m?~F<7~EZO#e<~!(;W?lqyzg zOgB9_@jozc7!y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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 #include #include +#include #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