Skip to content

Commit

Permalink
Fix mmap_parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed May 23, 2024
1 parent bcef875 commit 6f755e9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/kernel/mem/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand All @@ -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
}

Expand All @@ -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);
Expand Down

0 comments on commit 6f755e9

Please sign in to comment.