diff options
Diffstat (limited to 'src/kernel/lib/memory.c')
-rw-r--r-- | src/kernel/lib/memory.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index 61b1414..0f3cb34 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -58,10 +58,10 @@ u32 memory_get_free() void memory_print() { // TODO: Fix multiboot mem lower/upper - /*if (meminfo != NULL) { + 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); } @@ -76,18 +76,17 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag) u32 sum = 0; struct multiboot_mmap_entry *mmap; - for (mmap = ((struct multiboot_tag_mmap *)tag)->entries; - (multiboot_u8 *)mmap < (multiboot_u8 *)tag + tag->size; + for (mmap = ((struct multiboot_tag_mmap *)tag)->entries; (u8 *)mmap < (u8 *)tag + tag->size; mmap = (multiboot_memory_map_t *)((u32)mmap + ((struct multiboot_tag_mmap *)tag)->entry_size)) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { debug("Found free memory"); - /* paging_set_present(mmap->addr, mmap->len >> 12); */ + paging_set_present(mmap->addr, mmap->len >> 12); sum += mmap->len; } else if (mmap->type == MULTIBOOT_MEMORY_RESERVED) { debug("Found reserved memory"); - /* paging_set_present(mmap->addr, mmap->len >> 12); */ - /* paging_set_used(mmap->addr, mmap->len >> 12); */ + paging_set_present(mmap->addr, mmap->len >> 12); + paging_set_used(mmap->addr, mmap->len >> 12); } else if (mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE) { debug("Found ACPI reclaimable memory"); } else if (mmap->type == MULTIBOOT_MEMORY_NVS) { @@ -97,4 +96,24 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag) } } total = sum >> 10; // I want kb +} + +int memory_init(u32 multiboot_address) +{ + int ret = 0; + struct multiboot_tag *tag; + + for (tag = (struct multiboot_tag *)(multiboot_address + 8); + tag->type != MULTIBOOT_TAG_TYPE_END; + tag = (struct multiboot_tag *)((u8 *)tag + ((tag->size + 7) & ~7))) { + if (tag->type == MULTIBOOT_TAG_TYPE_BASIC_MEMINFO) { + info("Got memory info"); + memory_info_init((struct multiboot_tag_basic_meminfo *)tag); + } else if (tag->type == MULTIBOOT_TAG_TYPE_MMAP) { + info("Got memory map"); + memory_mmap_init((struct multiboot_tag_mmap *)tag); + ret = 1; + } + } + return ret; }
\ No newline at end of file |