From: acevest Date: Wed, 17 May 2023 14:55:44 +0000 (+0800) Subject: get_npd -> get_npde; get_npt -> get_npte X-Git-Url: http://zhaoyanbai.com/repos/man.named-rrchecker.html?a=commitdiff_plain;h=f04eda4c1e59288baf27dd1ac6ad5cea260edae6;p=kernel.git get_npd -> get_npde; get_npt -> get_npte --- diff --git a/include/page.h b/include/page.h index daa3dfe..50b7c2a 100644 --- a/include/page.h +++ b/include/page.h @@ -17,6 +17,19 @@ #ifndef _PAGE_H #define _PAGE_H +/* + +| CR0的PG | CR4的PAE | CR4的PSE | PDE的PS | 页面规模 | 物理地址规模 | +| ------- | -------- | -------- | ------- | -------- | ------------ | +| 0 | × | × | × | ― | 禁止分页 | +| 1 | 0 | 0 | × | 4KB | 32位 | +| 1 | 0 | 1 | 0 | 4KB | 32位 | +| 1 | 0 | 1 | 1 | 4MB | 32位 | +| 1 | 1 | × | 0 | 4KB | 36位 | +| 1 | 1 | × | 1 | 2MB | 36位 | + +*/ + #define PAGE_P 0x1 // 在内存中 #define PAGE_WR 0x2 // 表示可读写 #define PAGE_US 0x4 // 用户级 @@ -31,8 +44,8 @@ #ifndef ASM #include #include -#define get_npd(addr) (((u32)(addr)) >> 22) -#define get_npt(addr) ((((u32)(addr)) >> 12) & 0x3FF) +#define get_npde(addr) (((u32)(addr)) >> 22) +#define get_npte(addr) ((((u32)(addr)) >> 12) & 0x3FF) #include diff --git a/mm/mm.c b/mm/mm.c index 0e7c1f2..1626bb6 100644 --- a/mm/mm.c +++ b/mm/mm.c @@ -31,11 +31,11 @@ pte_t __initdata init_pgt[PTECNT_PER_PAGE * BOOT_INIT_PAGETBL_CNT] __attribute__ void set_page_shared(void *x) { unsigned long addr = (unsigned long)x; addr = PAGE_ALIGN(addr); - unsigned int npd = get_npd(addr); + unsigned int npd = get_npde(addr); init_pgd[npd] |= PAGE_US; pte_t *pte = pa2va(init_pgd[npd] & PAGE_MASK); - pte[get_npt(addr)] |= PAGE_US; + pte[get_npte(addr)] |= PAGE_US; } void init_paging() { @@ -59,7 +59,7 @@ void init_paging() { memset((void *)pgtb_addr, 0, PAGE_SIZE); - init_pgd[get_npd(page_addr)] = (pde_t)((unsigned long)va2pa(pgtb_addr) | PAGE_P | PAGE_WR); + init_pgd[get_npde(page_addr)] = (pde_t)((unsigned long)va2pa(pgtb_addr) | PAGE_P | PAGE_WR); } pte = ((pte_t *)pgtb_addr) + ti; @@ -67,7 +67,7 @@ void init_paging() { } // paging for kernel space - unsigned long delta = get_npd(PAGE_OFFSET); + unsigned long delta = get_npde(PAGE_OFFSET); for (i = delta; i < PDECNT_PER_PAGE; ++i) { init_pgd[i] = init_pgd[i - delta]; init_pgd[i - delta] = 0; @@ -75,14 +75,14 @@ void init_paging() { // 接下来为显存建立页映射 unsigned long vram_phys_addr = system.vbe_phys_addr; - for (int pde_inx = 0; pde_inx < get_npd(VRAM_VADDR_SIZE); pde_inx++) { + for (int pde_inx = 0; pde_inx < get_npde(VRAM_VADDR_SIZE); pde_inx++) { pgtb_addr = (unsigned long *)(alloc_from_bootmem(PAGE_SIZE, "vrampaging")); if (0 == pgtb_addr) { panic("no pages for paging..."); } // 后续要初始化,所以此处不用memset // memset((void *)pgtb_addr, 0, PAGE_SIZE); - init_pgd[get_npd(VRAM_VADDR_BASE) + pde_inx] = (pde_t)((unsigned long)va2pa(pgtb_addr) | PAGE_P | PAGE_WR); + init_pgd[get_npde(VRAM_VADDR_BASE) + pde_inx] = (pde_t)((unsigned long)va2pa(pgtb_addr) | PAGE_P | PAGE_WR); for (int pte_inx = 0; pte_inx < PTECNT_PER_PAGE; pte_inx++) { pgtb_addr[pte_inx] = vram_phys_addr | PAGE_P | PAGE_WR; diff --git a/mm/page.c b/mm/page.c index 4a9f54e..6ac0e51 100644 --- a/mm/page.c +++ b/mm/page.c @@ -24,8 +24,8 @@ void do_no_page(void *addr) { unsigned long page = alloc_one_page(0); assert(page != 0); - int npde = get_npd(addr); - int npte = get_npt(addr); + int npde = get_npde(addr); + int npte = get_npte(addr); if (page_dir[npde] == 0) { page_tbl = (pte_t *)alloc_one_page(0); @@ -48,8 +48,8 @@ void do_wp_page(void *addr) { panic("%s invalid addr", __func__); } - int npde = get_npd(addr); - int npte = get_npt(addr); + int npde = get_npde(addr); + int npte = get_npte(addr); pde_t *page_dir = (pde_t *)pa2va(current->cr3); pte_t *page_tbl = pa2va(PAGE_ALIGN(page_dir[npde]));