[refactor] 整理注释

This commit is contained in:
2026-06-06 10:31:20 +08:00
Unverified
parent a9ba4457c6
commit 30d48d2881
19 changed files with 177 additions and 192 deletions
+11 -11
View File
@@ -19,7 +19,7 @@ static inline BOOLEAN bitmap_test(UINTN idx) {
return (g_pmm.bitmap[idx / 8] >> (idx % 8)) & 1;
}
// Clean stale entries from free list head
// 清理空闲链表头部的过期条目
static void clean_free_list() {
while (g_pmm.free_list_head != NULL &&
bitmap_test((UINTN)g_pmm.free_list_head / PAGE_SIZE)) {
@@ -58,7 +58,7 @@ EFI_STATUS pmm_init() {
UINTN entry_count = map_size / desc_size;
// First pass: count total pages and find max physical address
// 第一遍:统计总页数并找到最大物理地址
UINT64 max_addr = 0;
UINT64 total_free = 0;
for (UINTN i = 0; i < entry_count; i++) {
@@ -73,16 +73,16 @@ EFI_STATUS pmm_init() {
g_pmm.base_addr = 0;
g_pmm.max_addr = max_addr;
// How many pages does the bitmap cover?
// 位图覆盖的页数
UINTN total_pages = (UINTN)(max_addr / PAGE_SIZE);
g_pmm.total_pages = total_pages;
// Bitmap size in bytes, rounded up to page boundary
// 位图大小(字节),向上取整到页边界
g_pmm.bitmap_size = ((total_pages + 7) / 8);
UINTN bitmap_pages = (g_pmm.bitmap_size + PAGE_SIZE - 1) / PAGE_SIZE;
g_pmm.bitmap_size = bitmap_pages * PAGE_SIZE; // round to full pages
// Place bitmap at the end of the highest free conventional memory region
// 将位图放在最高空闲常规内存区域的末尾
UINT64 bitmap_addr = 0;
for (UINTN i = 0; i < entry_count; i++) {
EFI_MEMORY_DESCRIPTOR* desc = (EFI_MEMORY_DESCRIPTOR*)((UINT8*)mem_map + i * desc_size);
@@ -105,12 +105,12 @@ EFI_STATUS pmm_init() {
g_pmm.bitmap = (UINT8*)(UINTN)bitmap_addr;
// Init bitmap: mark ALL pages as used (0xFF)
// 初始化位图:将所有页标记为已使用
for (UINTN i = 0; i < g_pmm.bitmap_size; i++) {
g_pmm.bitmap[i] = 0xFF;
}
// Mark free pages (EfiConventionalMemory) as free in bitmap
// 将空闲页(EfiConventionalMemory)在位图中标记为空闲
g_pmm.free_pages = 0;
UINT64 bm_start_page = bitmap_addr / PAGE_SIZE;
UINT64 bm_end_page = (bitmap_addr + g_pmm.bitmap_size + PAGE_SIZE - 1) / PAGE_SIZE;
@@ -123,19 +123,19 @@ EFI_STATUS pmm_init() {
UINT64 end_page = start_page + desc->NumberOfPages;
for (UINT64 p = start_page; p < end_page; p++) {
// Skip bitmap pages
// 跳过位图占用的页
if (p >= bm_start_page && p < bm_end_page) continue;
bitmap_clear((UINTN)p);
g_pmm.free_pages++;
}
}
// Mark bitmap pages as used
// 将位图占用的页标记为已使用
for (UINT64 p = bm_start_page; p < bm_end_page; p++) {
bitmap_set((UINTN)p);
}
// Reserve low memory (first 4 MB) — UEFI firmware may use it during BS calls
// 保留低内存(前 4MB)— 固件可能在 Boot Services 调用期间使用
UINT64 low_reserve_pages = 0x400;
for (UINT64 p = 0; p < low_reserve_pages && p < g_pmm.total_pages; p++) {
if (!bitmap_test((UINTN)p)) {
@@ -144,7 +144,7 @@ EFI_STATUS pmm_init() {
}
}
// Build free list by linking free pages
// 通过链接空闲页构建空闲链表
g_pmm.free_list_head = NULL;
void* prev = NULL;
for (UINTN i = 0; i < entry_count; i++) {