🔧 调整mm模块,使其能获取到multiboot2传来的信息

This commit is contained in:
fslongjin 2022-02-22 17:05:53 +08:00
parent 3ac56adff4
commit 12cc6a8375

View File

@ -1,6 +1,7 @@
#include "mm.h"
#include "../common/printk.h"
#include "../common/kprint.h"
#include "../driver/multiboot2/multiboot2.h"
ul Total_Memory = 0;
ul total_2M_pages = 0;
@ -14,25 +15,26 @@ void mm_init()
memory_management_struct.kernel_data_end = (ul)&_edata;
memory_management_struct.kernel_end = (ul)&_end;
// 实模式下获取到的信息的起始地址转换为ARDS指针
struct ARDS *ards_ptr = (struct ARDS *)0xffff800000007e00;
struct multiboot_mmap_entry_t *mb2_mem_info;
int count;
multiboot2_iter(multiboot2_get_memory, mb2_mem_info, &count);
for (int i = 0; i < 32; ++i)
for (int i = 0; i < count; ++i)
{
//可用的内存
if (ards_ptr->type == 1)
Total_Memory += ards_ptr->Length;
if (mb2_mem_info->type == 1)
Total_Memory += mb2_mem_info->len;
// 保存信息到mms
memory_management_struct.e820[i].BaseAddr = ards_ptr->BaseAddr;
memory_management_struct.e820[i].Length = ards_ptr->Length;
memory_management_struct.e820[i].type = ards_ptr->type;
memory_management_struct.e820[i].BaseAddr = mb2_mem_info->addr;
memory_management_struct.e820[i].Length = mb2_mem_info->len;
memory_management_struct.e820[i].type = mb2_mem_info->type;
memory_management_struct.len_e820 = i;
++ards_ptr;
++mb2_mem_info;
// 脏数据
if (ards_ptr->type > 4 || ards_ptr->Length == 0 || ards_ptr->type < 1)
if (mb2_mem_info->type > 4 || mb2_mem_info->len == 0 || mb2_mem_info->type < 1)
break;
}
printk("[ INFO ] Total amounts of RAM : %ld bytes\n", Total_Memory);
@ -57,8 +59,6 @@ void mm_init()
}
kinfo("Total amounts of 2M pages : %ld.", total_2M_pages);
// 物理地址空间的最大地址包含了物理内存、内存空洞、ROM等
ul max_addr = memory_management_struct.e820[memory_management_struct.len_e820].BaseAddr + memory_management_struct.e820[memory_management_struct.len_e820].Length;
// 初始化mms的bitmap
@ -190,7 +190,6 @@ void mm_init()
printk_color(INDIGO, BLACK, "**cr3:\t%#018lx\n", *phys_2_virt(*(phys_2_virt(cr3)) & (~0xff)) & (~0xff));
*/
/*
// 消除一致性页表映射将页目录PML4E的前10项清空
for (int i = 0; i < 10; ++i)