aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/lib/memory.c12
-rw-r--r--src/kernel/memory/paging.c3
2 files changed, 9 insertions, 6 deletions
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index 75f7870..04697a3 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -53,7 +53,11 @@ u32 memory_get_all()
u32 memory_get_free()
{
- return memory_get_all() - paging_get_used_pages() * 4;
+ int free_memory = memory_get_all() - paging_get_used_pages() * 4;
+ if (free_memory < 0)
+ return 0;
+ else
+ return free_memory;
}
void memory_print()
@@ -63,9 +67,9 @@ void memory_print()
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 used memory: %dMiB", ((memory_get_all() - memory_get_free()) >> 10) + 1);
- info("Total free memory: %dMiB", (memory_get_free() >> 10) + 1);
+ info("Total memory found: %dMiB", (memory_get_all() >> 10));
+ info("Total used memory: %dMiB", ((memory_get_all() - memory_get_free()) >> 10));
+ info("Total free memory: %dMiB", (memory_get_free() >> 10));
}
void memory_info_init(struct multiboot_tag_basic_meminfo *tag)
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index 432b51c..5ed3fdd 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -190,8 +190,7 @@ u32 paging_get_used_pages()
u32 n = 0;
for (u32 i = 0; i < PAGE_COUNT; i++) {
for (u32 j = 0; j < PAGE_COUNT; j++) {
- u8 flags = page_tables[i][j] & PT_USED;
- if (flags == 1)
+ if (page_tables[i][j] & PT_USED)
n++;
}
}