diff --git a/src/kernel/include/memory/firstfit_allocator.hpp b/src/kernel/include/memory/firstfit_allocator.hpp index 9b5dbc4f..724b4fce 100644 --- a/src/kernel/include/memory/firstfit_allocator.hpp +++ b/src/kernel/include/memory/firstfit_allocator.hpp @@ -44,7 +44,7 @@ class FirstFitAllocator : public AllocatorBase { klog::Err("addr not aligned. 0x%lX\n", addr); throw; } - printf("%s: 0x%p(0x%X pages) init.\n", name_, addr_, length_); + printf("%s: 0x%p(0x%lX pages) init.\n", name_, (void *)addr_, length_); } /// @name 构造/析构函数 diff --git a/src/kernel/virtual_memory_manager.cpp b/src/kernel/virtual_memory_manager.cpp index cc082ba2..d9f9d1e6 100644 --- a/src/kernel/virtual_memory_manager.cpp +++ b/src/kernel/virtual_memory_manager.cpp @@ -26,7 +26,25 @@ VirtualMemoryManager::VirtualMemoryManager(uint32_t, uint8_t*) { // 分配一页用于保存页目录 pt_t pgd_kernel = (pt_t)AllocKernelPage(); + auto old_pgd_kernel = GetPageDirectory(); + // 0x7C02023 + // 0x530001 + // memcpy(pgd_kernel, old_pgd_kernel, 1024); memset(pgd_kernel, 0, PhysicalMemoryManager::kPageSize); + for (auto i = 0; i < 1024; i++) { + if (!pgd_kernel[i]) { + continue; + } + klog::Debug("first pgd_kernel[%d]: 0x%X\n", i, pgd_kernel[i]); + uint64_t* pte = ((uint64_t*)pgd_kernel[i]); + + for (auto j = 0; j < 1024; j++) { + if (!pte[j]) { + continue; + } + klog::Debug("first pte[%d]: 0x%X\n", j, pte[j]); + } + } // 映射内核空间 for (uint64_t addr = kBasicInfo.GetInstance().kernel_addr; addr < kBasicInfo.GetInstance().kernel_addr + kKernelSpaceSize; @@ -36,6 +54,22 @@ VirtualMemoryManager::VirtualMemoryManager(uint32_t, uint8_t*) { cpu::vmm::VMM_PAGE_READABLE | cpu::vmm::VMM_PAGE_WRITABLE | cpu::vmm::VMM_PAGE_EXECUTABLE); } + + for (auto i = 0; i < 1024; i++) { + if (!pgd_kernel[i]) { + continue; + } + klog::Debug("last pgd_kernel[%d]: 0x%X\n", i, pgd_kernel[i]); + uint64_t* pte = ((uint64_t*)pgd_kernel[i]); + + for (auto j = 0; j < 1024; j++) { + if (!pte[j]) { + continue; + } + klog::Debug("last pte[%d]: 0x%X\n", j, pte[j]); + } + } + // 设置页目录 klog::Debug("SetPageDirectory: 0x%X\n", pgd_kernel); SetPageDirectory(pgd_kernel);