aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-04-17 17:47:36 +0200
committerMarvin Borner2020-04-17 17:47:36 +0200
commit0aea2cf7d4c53f49e48c272ac7427ab337b476db (patch)
tree5f473266b41fc64580c8f62be4330732eb22c58e
parent1d763a07224504b645aea2f42699722ad0030cfb (diff)
Added more precise memory measurement
-rw-r--r--src/kernel/kernel.c1
-rw-r--r--src/kernel/lib/lib.h4
-rw-r--r--src/kernel/lib/memory.c29
-rw-r--r--src/kernel/multiboot.c6
4 files changed, 32 insertions, 8 deletions
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index bf58e23..42395d4 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -40,7 +40,6 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address)
idt_install();
isrs_install();
irq_install();
-
multiboot_parse(multiboot_address);
paging_install();
diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h
index 8f4e13f..e107da6 100644
--- a/src/kernel/lib/lib.h
+++ b/src/kernel/lib/lib.h
@@ -32,7 +32,9 @@ void *memset(void *dest, char val, size_t count);
*/
int memcmp(const void *a_ptr, const void *b_ptr, size_t size);
-void memory_init(struct multiboot_tag_basic_meminfo *tag);
+void memory_info_init(struct multiboot_tag_basic_meminfo *tag);
+
+void memory_mmap_init(struct multiboot_tag_mmap *tag);
void memory_print();
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index 2544ee0..db26c47 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -35,11 +35,14 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
return 0;
}
+uint32_t total = 0;
struct multiboot_tag_basic_meminfo *meminfo = NULL;
uint32_t memory_get_all()
{
- if (meminfo != NULL) {
+ if (total != 0) {
+ return total;
+ } else if (meminfo != NULL) {
return meminfo->mem_lower + meminfo->mem_upper;
} else {
warn("Got no memory info, guessing size!");
@@ -54,13 +57,31 @@ uint32_t memory_get_free()
void memory_print()
{
- info("Mem lower: 0x%x", meminfo->mem_lower);
- info("Mem upper: 0x%x", meminfo->mem_upper);
+ if (meminfo != NULL) {
+ info("Mem lower: 0x%x", meminfo->mem_lower);
+ info("Mem upper: 0x%x", meminfo->mem_upper);
+ }
info("Total memory found: %dMiB", (memory_get_all() >> 10) + 1);
info("Total free memory: %dMiB", (memory_get_free() >> 10) + 1);
}
-void memory_init(struct multiboot_tag_basic_meminfo *tag)
+void memory_info_init(struct multiboot_tag_basic_meminfo *tag)
{
meminfo = tag;
}
+
+void memory_mmap_init(struct multiboot_tag_mmap *tag)
+{
+ uint32_t sum = 0;
+ struct multiboot_mmap_entry *mmap;
+
+ for (mmap = ((struct multiboot_tag_mmap *)tag)->entries;
+ (multiboot_uint8_t *)mmap < (multiboot_uint8_t *)tag + tag->size;
+ mmap = (multiboot_memory_map_t *)((uint32_t)mmap +
+ ((struct multiboot_tag_mmap *)tag)->entry_size)) {
+ if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) {
+ sum += mmap->len;
+ }
+ }
+ total = sum >> 10; // I want kb
+}
diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c
index 6b402fa..2c5fa60 100644
--- a/src/kernel/multiboot.c
+++ b/src/kernel/multiboot.c
@@ -16,20 +16,22 @@ void multiboot_parse(uint32_t multiboot_address)
info("Got cmdline");
break;
case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
- info("Got bootloader name: %s", ((struct multiboot_tag_string *) tag)->string);
+ info("Got bootloader name: %s",
+ ((struct multiboot_tag_string *)tag)->string);
break;
case MULTIBOOT_TAG_TYPE_MODULE:
info("Got modules");
break;
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
info("Got memory info");
- memory_init((struct multiboot_tag_basic_meminfo *)tag);
+ memory_info_init((struct multiboot_tag_basic_meminfo *)tag);
break;
case MULTIBOOT_TAG_TYPE_BOOTDEV:
info("Got boot device");
break;
case MULTIBOOT_TAG_TYPE_MMAP:
info("Got memory map");
+ memory_mmap_init((struct multiboot_tag_mmap *)tag);
break;
case MULTIBOOT_TAG_TYPE_VBE:
info("Got VBE info");