From: AceVest Date: Fri, 25 Apr 2014 15:52:31 +0000 (+0800) Subject: rewrite init_paging X-Git-Tag: 0.3.0~81 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/openssl_button.gif?a=commitdiff_plain;h=9983abdb68fa83260f961b332dbbb6fdf05d4354;p=kernel.git rewrite init_paging --- diff --git a/include/page.h b/include/page.h index b4791d0..57798cf 100644 --- a/include/page.h +++ b/include/page.h @@ -19,9 +19,9 @@ -#define PAGE_P 0x0 -#define PAGE_WR 0x1 -#define PAGE_US 0x2 +#define PAGE_P 0x1 +#define PAGE_WR 0x2 +#define PAGE_US 0x4 #define PAGE_SHIFT (12) #define PAGE_SIZE (1UL << PAGE_SHIFT) @@ -33,8 +33,8 @@ #ifndef ASM #include #include -#define get_npd(vaddr) (((u32)(vaddr))>>22) -#define get_npt(vaddr) ((((u32)(vaddr))>>12) & 0x3FF) +#define get_npd(addr) (((u32)(addr))>>22) +#define get_npt(addr) ((((u32)(addr))>>12) & 0x3FF) #include diff --git a/mm/mm.c b/mm/mm.c index 2c712ec..a853839 100644 --- a/mm/mm.c +++ b/mm/mm.c @@ -296,39 +296,35 @@ pte_t __initdata init_pgt[PTECNT_PER_PAGE*BOOT_INIT_PAGETBL_CNT] __attribute__(( void init_paging() { - unsigned long di, ti; - unsigned long *pde, *pte; - - unsigned long max_pfn = bootmem_data.max_pfn; - unsigned long min_pfn = BOOT_INIT_PAGETBL_CNT*1024; - - unsigned long pde_end = (pfn2pa(bootmem_data.max_pfn) >> 22); - if(1) // need to fix. - pde_end++; - for(di=BOOT_INIT_PAGETBL_CNT; di= pde_end) + unsigned long ti = pfn % PAGE_PTE_CNT; + unsigned long page_addr = pfn2pa(pfn); + if(ti == 0) { - *pde = 0; - continue; - } + pgtb_addr = (unsigned long) va2pa(bootmem_alloc_pages(1)); + if(0 == pgtb_addr) + panic("No Pages for Paging..."); - unsigned long pt_addr = (unsigned long) va2pa(bootmem_alloc_pages(1)); + memset((void *)pgtb_addr, 0, PAGE_SIZE); - *pde = pt_addr | 7; - *(pde + (PAGE_OFFSET>>22)) = *pde; // for kernel paging + init_pgd[get_npd(page_addr)] = (pde_t)(pgtb_addr | PAGE_P | PAGE_WR | PAGE_US); + } - for(ti=0; ti