diff --git a/src/kernel/mem/mmap.c b/src/kernel/mem/mmap.c index ce99fb3..2f17d75 100644 --- a/src/kernel/mem/mmap.c +++ b/src/kernel/mem/mmap.c @@ -13,6 +13,7 @@ uint32_t mmap_number_of_entries; multiboot_memory_map_t *mmap_entries; uint8_t count_physical_reserved; uint32_t _mmap_last_available_item; +size_t _mmap_phys_memory_avail; // This variable contains the memory size const char *mmap_types[] = { "Invalid", @@ -26,8 +27,7 @@ const char *mmap_types[] = { // This function is apparently only printing the list of mmap items and their value. void _mmap_parse(struct multiboot_tag_mmap *mmap_root){ int total_entries = 0; - size_t phys_memory_avail= 0; - size_t total_phys_memory = 0; + _mmap_phys_memory_avail= 0; pretty_logf(Verbose, "size: 0x%x", sizeof(struct multiboot_tag_mmap)); mmap_number_of_entries = (mmap_root->size - sizeof(*mmap_root))/mmap_root->entry_size; size_t mmap_number_of_entries_2 = (mmap_root->size - sizeof(struct multiboot_tag_mmap))/mmap_root->entry_size; @@ -42,16 +42,14 @@ void _mmap_parse(struct multiboot_tag_mmap *mmap_root){ pretty_logf(Verbose, "\t[%d] Address: 0x%x - Len: 0x%x Type: (%d) %s", i, mmap_entries[i].addr, mmap_entries[i].len, mmap_entries[i].type, (char *) mmap_types[mmap_entries[i].type]); if ( mmap_entries[i].type == 1 ) { - phys_memory_avail += mmap_entries[i].len; + _mmap_phys_memory_avail += mmap_entries[i].len; _mmap_last_available_item = i; } - total_phys_memory += mmap_entries[i].len; - total_entries++; i++; } - pretty_logf(Verbose, "Total entries: %d - Total phys_mem: 0x%u - Phys mem_avail: 0x%u", total_entries, total_phys_memory, phys_memory_avail ); + pretty_logf(Verbose, "Total entries: %d - Phys mem_avail: 0x%u", total_entries, _mmap_phys_memory_avail ); #endif } @@ -61,9 +59,9 @@ void _mmap_setup(){ count_physical_reserved=0; if(used_frames > 0){ uint32_t counter = 0; - uint64_t mem_limit = (tagmem->mem_upper + 1024) * 1024; while(counter < mmap_number_of_entries){ - if (mmap_entries[counter].addr < mem_limit && + uint64_t upper_address_to_map = (mmap_entries[_mmap_last_available_item].addr + mmap_entries[_mmap_last_available_item].len); + if (mmap_entries[counter].addr < upper_address_to_map && mmap_entries[counter].type > 1){ pretty_logf(Verbose, "\tFound unusable entry at addr: %x", mmap_entries[counter].addr); pmm_reserve_area(mmap_entries[counter].addr, mmap_entries[counter].len);