diff --git a/src/kernel/arch/x86_64/memm_x86_64.c b/src/kernel/arch/x86_64/memm_x86_64.c index cd86dba..080de11 100644 --- a/src/kernel/arch/x86_64/memm_x86_64.c +++ b/src/kernel/arch/x86_64/memm_x86_64.c @@ -110,7 +110,6 @@ bool memm_map_pageframes_to( return false; while (size != 0) { - // 这是当前需要映射的页的内存对齐(或者说是当前映射的页的大小) memm_page_size align = memm_get_page_align(physical); if (align == MEMM_PAGE_SIZE_1G) { @@ -123,6 +122,20 @@ bool memm_map_pageframes_to( align = MEMM_4K_ALIGN_MASK + 1; } align /= MEMM_PAGE_SIZE; + memory_manager_t *mm = memm_get_manager(); + switch (align) + { + case MEMM_PAGE_SIZE_4K: + mm->mapped_4k_page++; + case MEMM_PAGE_SIZE_2M: + mm->mapped_2m_page++; + case MEMM_PAGE_SIZE_1G: + mm->mapped_1g_page++; + } + for (usize i = physical / MEMM_PAGE_SIZE; i < physical / MEMM_PAGE_SIZE + align; i++) + { + bitmap_set(mm->page_map, i); + } map_pageframe_to(target, physical, user, write, align); diff --git a/src/kernel/main.c b/src/kernel/main.c index 06be3cb..d352580 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -35,7 +35,7 @@ void kmain(void *mb2_bootinfo) } // 初始化内存管理模块 - mem_manager_t *memm = memm_new(mem_size); + memory_manager_t *memm = memm_new(mem_size); // 初始化tty模块 tty_controller_t *tty_controler = tty_controller_new(); diff --git a/src/kernel/memm/memm.c b/src/kernel/memm/memm.c index 9afab18..f2cbf71 100644 --- a/src/kernel/memm/memm.c +++ b/src/kernel/memm/memm.c @@ -5,9 +5,9 @@ #include #include -mem_manager_t memory_manager; +memory_manager_t memory_manager; -mem_manager_t *memm_new(usize mem_size) +memory_manager_t *memm_new(usize mem_size) { memset(&memory_manager, 0, sizeof(memory_manager)); memory_manager.memory_size = mem_size; @@ -47,20 +47,20 @@ mem_manager_t *memm_new(usize mem_size) } // 配置分配器页地图 - memory_manager.map_with_allocator = + memory_manager.allocator_map = allocator0->allocate(&allocator0->allocator_instance, pmc_size); - memset(memory_manager.map_with_allocator, 0, pmc_size); + memset(memory_manager.allocator_map, 0, pmc_size); for (usize i = kernel_initial_size / MEMM_PAGE_SIZE; i < MEMM_ALLOC_ONLY_MEMORY / MEMM_PAGE_SIZE; i += MEMM_PAGE_SIZE) { - bitmap_set(memory_manager.map_with_allocator, i); + bitmap_set(memory_manager.allocator_map, i); } // 分配器释放页地图 - memory_manager.map_with_destructed_allocator = + memory_manager.destructed_allocator_map = allocator0->allocate(&allocator0->allocator_instance, pmc_size); - memset(memory_manager.map_with_destructed_allocator, 0, pmc_size); + memset(memory_manager.destructed_allocator_map, 0, pmc_size); // 配置空闲页线段搜索表 memory_manager.available_pages_table = lst_new(0, memory_manager.page_amount); @@ -69,6 +69,11 @@ mem_manager_t *memm_new(usize mem_size) return &memory_manager; } +memory_manager_t *memm_get_manager() +{ + return &memory_manager; +} + allocator_t *memm_allocator_new(void *start, usize length, usize type, usize pid) { allocator_t *allocator = start; @@ -177,7 +182,7 @@ void *memm_allocate(usize size, usize pid) return nullptr; // 内存中已经没有可分配的页了 for (usize i = allocator_start; i < allocator_start + size; i++) { - bitmap_set(memory_manager.map_with_allocator, i); + bitmap_set(memory_manager.allocator_map, i); } memm_map_pageframes_to( allocator_start * MEMM_PAGE_SIZE, allocator_start * MEMM_PAGE_SIZE,