From c614cef2af17fe4c523a48a9f77274187ebc9bc4 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 23 Feb 2003 21:20:00 +0000 Subject: [PATCH] - Added macros NPGPTD, NBPTD, and NPDEPTD, for dealing with the size of the page directory. - Use these instead of the magic constants 1 or PAGE_SIZE where appropriate. There are still numerous assumptions that the page directory is exactly 1 page. Sponsored by: DARPA, Network Associates Laboratories --- sys/amd64/amd64/genassym.c | 1 + sys/amd64/amd64/locore.S | 4 ++-- sys/amd64/amd64/locore.s | 4 ++-- sys/amd64/amd64/pmap.c | 13 +++++++------ sys/amd64/amd64/vm_machdep.c | 2 +- sys/amd64/include/pmap.h | 8 ++++---- sys/i386/i386/genassym.c | 1 + sys/i386/i386/locore.s | 4 ++-- sys/i386/i386/pmap.c | 13 +++++++------ sys/i386/i386/vm_machdep.c | 2 +- sys/i386/include/param.h | 6 +++++- sys/i386/include/pmap.h | 8 ++++---- 12 files changed, 37 insertions(+), 29 deletions(-) diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c index 7d80831a0a2a..e681e2081999 100644 --- a/sys/amd64/amd64/genassym.c +++ b/sys/amd64/amd64/genassym.c @@ -108,6 +108,7 @@ ASSYM(KSTACK_PAGES, KSTACK_PAGES); ASSYM(PAGE_SIZE, PAGE_SIZE); ASSYM(NPTEPG, NPTEPG); ASSYM(NPDEPG, NPDEPG); +ASSYM(NPGPTD, NPGPTD); ASSYM(PDESIZE, sizeof(pd_entry_t)); ASSYM(PTESIZE, sizeof(pt_entry_t)); ASSYM(PTESHIFT, PTESHIFT); diff --git a/sys/amd64/amd64/locore.S b/sys/amd64/amd64/locore.S index afd9a662788a..38ac21129757 100644 --- a/sys/amd64/amd64/locore.S +++ b/sys/amd64/amd64/locore.S @@ -749,7 +749,7 @@ no_kernend: movl %esi,R(KPTphys) /* Allocate Page Table Directory */ - ALLOCPAGES(1) + ALLOCPAGES(NPGPTD) movl %esi,R(IdlePTD) /* Allocate UPAGES */ @@ -805,7 +805,7 @@ no_kernend: /* Map page directory. */ movl R(IdlePTD), %eax - movl $1, %ecx + movl $NPGPTD, %ecx fillkptphys($PG_RW) /* Map proc0's UPAGES in the physical way ... */ diff --git a/sys/amd64/amd64/locore.s b/sys/amd64/amd64/locore.s index afd9a662788a..38ac21129757 100644 --- a/sys/amd64/amd64/locore.s +++ b/sys/amd64/amd64/locore.s @@ -749,7 +749,7 @@ no_kernend: movl %esi,R(KPTphys) /* Allocate Page Table Directory */ - ALLOCPAGES(1) + ALLOCPAGES(NPGPTD) movl %esi,R(IdlePTD) /* Allocate UPAGES */ @@ -805,7 +805,7 @@ no_kernend: /* Map page directory. */ movl R(IdlePTD), %eax - movl $1, %ecx + movl $NPGPTD, %ecx fillkptphys($PG_RW) /* Map proc0's UPAGES in the physical way ... */ diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index d141abb94c9c..e5b8a7ca7537 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -1286,14 +1286,15 @@ pmap_pinit(pmap) * page directory table. */ if (pmap->pm_pdir == NULL) - pmap->pm_pdir = - (pd_entry_t *)kmem_alloc_pageable(kernel_map, PAGE_SIZE); + pmap->pm_pdir = (pd_entry_t *)kmem_alloc_pageable(kernel_map, + NBPTD); /* * allocate object for the ptes */ if (pmap->pm_pteobj == NULL) - pmap->pm_pteobj = vm_object_allocate(OBJT_DEFAULT, PTDPTDI + 1); + pmap->pm_pteobj = vm_object_allocate(OBJT_DEFAULT, PTDPTDI + + NPGPTD); /* * allocate the page directory page @@ -1305,7 +1306,7 @@ pmap_pinit(pmap) ptdpg->valid = VM_PAGE_BITS_ALL; vm_page_unlock_queues(); - pmap_qenter((vm_offset_t) pmap->pm_pdir, &ptdpg, 1); + pmap_qenter((vm_offset_t)pmap->pm_pdir, &ptdpg, NPGPTD); if ((ptdpg->flags & PG_ZERO) == 0) bzero(pmap->pm_pdir, PAGE_SIZE); @@ -3423,7 +3424,7 @@ pmap_pid_dump(int pid) int i,j; index = 0; pmap = vmspace_pmap(p->p_vmspace); - for (i = 0; i < NPDEPG; i++) { + for (i = 0; i < NPDEPTD; i++) { pd_entry_t *pde; pt_entry_t *pte; vm_offset_t base = i << PDRSHIFT; @@ -3483,7 +3484,7 @@ pads(pm) if (pm == kernel_pmap) return; - for (i = 0; i < NPDEPG; i++) + for (i = 0; i < NPDEPTD; i++) if (pm->pm_pdir[i]) for (j = 0; j < NPTEPG; j++) { va = (i << PDRSHIFT) + (j << PAGE_SHIFT); diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c index 903a2b090743..45148e9e2c11 100644 --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -514,7 +514,7 @@ cpu_reset_real() #endif #endif /* PC98 */ /* force a shutdown by unmapping entire address space ! */ - bzero((caddr_t) PTD, PAGE_SIZE); + bzero((caddr_t)PTD, NBPTD); /* "good night, sweet prince .... " */ invltlb(); diff --git a/sys/amd64/include/pmap.h b/sys/amd64/include/pmap.h index 44f0b25f579b..0cd3944736d4 100644 --- a/sys/amd64/include/pmap.h +++ b/sys/amd64/include/pmap.h @@ -101,9 +101,9 @@ #endif #ifndef NKPDE #ifdef SMP -#define NKPDE (KVA_PAGES - 2) /* addressable number of page tables/pde's */ +#define NKPDE (KVA_PAGES - (NPGPTD + 1)) /* number of page tables/pde's */ #else -#define NKPDE (KVA_PAGES - 1) /* addressable number of page tables/pde's */ +#define NKPDE (KVA_PAGES - NPGPTD) /* number of page tables/pde's */ #endif #endif @@ -115,14 +115,14 @@ * * SMP_PRIVPAGES: The per-cpu address space is 0xff80000 -> 0xffbfffff */ -#define APTDPTDI (NPDEPG-1) /* alt ptd entry that points to APTD */ +#define APTDPTDI (NPDEPG-NPGPTD) /* alt ptd entry that points to APTD */ #ifdef SMP #define MPPTDI (APTDPTDI-1) /* per cpu ptd entry */ #define KPTDI (MPPTDI-NKPDE) /* start of kernel virtual pde's */ #else #define KPTDI (APTDPTDI-NKPDE)/* start of kernel virtual pde's */ #endif /* SMP */ -#define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */ +#define PTDPTDI (KPTDI-NPGPTD) /* ptd entry that points to ptd! */ #define UMAXPTDI (PTDPTDI-1) /* ptd entry for user space end */ #define UMAXPTEOFF (NPTEPG) /* pte entry for user space end */ diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index 7d80831a0a2a..e681e2081999 100644 --- a/sys/i386/i386/genassym.c +++ b/sys/i386/i386/genassym.c @@ -108,6 +108,7 @@ ASSYM(KSTACK_PAGES, KSTACK_PAGES); ASSYM(PAGE_SIZE, PAGE_SIZE); ASSYM(NPTEPG, NPTEPG); ASSYM(NPDEPG, NPDEPG); +ASSYM(NPGPTD, NPGPTD); ASSYM(PDESIZE, sizeof(pd_entry_t)); ASSYM(PTESIZE, sizeof(pt_entry_t)); ASSYM(PTESHIFT, PTESHIFT); diff --git a/sys/i386/i386/locore.s b/sys/i386/i386/locore.s index afd9a662788a..38ac21129757 100644 --- a/sys/i386/i386/locore.s +++ b/sys/i386/i386/locore.s @@ -749,7 +749,7 @@ no_kernend: movl %esi,R(KPTphys) /* Allocate Page Table Directory */ - ALLOCPAGES(1) + ALLOCPAGES(NPGPTD) movl %esi,R(IdlePTD) /* Allocate UPAGES */ @@ -805,7 +805,7 @@ no_kernend: /* Map page directory. */ movl R(IdlePTD), %eax - movl $1, %ecx + movl $NPGPTD, %ecx fillkptphys($PG_RW) /* Map proc0's UPAGES in the physical way ... */ diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index d141abb94c9c..e5b8a7ca7537 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -1286,14 +1286,15 @@ pmap_pinit(pmap) * page directory table. */ if (pmap->pm_pdir == NULL) - pmap->pm_pdir = - (pd_entry_t *)kmem_alloc_pageable(kernel_map, PAGE_SIZE); + pmap->pm_pdir = (pd_entry_t *)kmem_alloc_pageable(kernel_map, + NBPTD); /* * allocate object for the ptes */ if (pmap->pm_pteobj == NULL) - pmap->pm_pteobj = vm_object_allocate(OBJT_DEFAULT, PTDPTDI + 1); + pmap->pm_pteobj = vm_object_allocate(OBJT_DEFAULT, PTDPTDI + + NPGPTD); /* * allocate the page directory page @@ -1305,7 +1306,7 @@ pmap_pinit(pmap) ptdpg->valid = VM_PAGE_BITS_ALL; vm_page_unlock_queues(); - pmap_qenter((vm_offset_t) pmap->pm_pdir, &ptdpg, 1); + pmap_qenter((vm_offset_t)pmap->pm_pdir, &ptdpg, NPGPTD); if ((ptdpg->flags & PG_ZERO) == 0) bzero(pmap->pm_pdir, PAGE_SIZE); @@ -3423,7 +3424,7 @@ pmap_pid_dump(int pid) int i,j; index = 0; pmap = vmspace_pmap(p->p_vmspace); - for (i = 0; i < NPDEPG; i++) { + for (i = 0; i < NPDEPTD; i++) { pd_entry_t *pde; pt_entry_t *pte; vm_offset_t base = i << PDRSHIFT; @@ -3483,7 +3484,7 @@ pads(pm) if (pm == kernel_pmap) return; - for (i = 0; i < NPDEPG; i++) + for (i = 0; i < NPDEPTD; i++) if (pm->pm_pdir[i]) for (j = 0; j < NPTEPG; j++) { va = (i << PDRSHIFT) + (j << PAGE_SHIFT); diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index 903a2b090743..45148e9e2c11 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -514,7 +514,7 @@ cpu_reset_real() #endif #endif /* PC98 */ /* force a shutdown by unmapping entire address space ! */ - bzero((caddr_t) PTD, PAGE_SIZE); + bzero((caddr_t)PTD, NBPTD); /* "good night, sweet prince .... " */ invltlb(); diff --git a/sys/i386/include/param.h b/sys/i386/include/param.h index cf9cfe40d87c..54fe27aaaf42 100644 --- a/sys/i386/include/param.h +++ b/sys/i386/include/param.h @@ -87,8 +87,12 @@ #define PAGE_MASK (PAGE_SIZE-1) #define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) -#define NPDEPG (PAGE_SIZE/(sizeof (pd_entry_t))) +#define NPGPTD 1 #define PDRSHIFT 22 /* LOG2(NBPDR) */ + +#define NBPTD (NPGPTD< 0xffbfffff */ -#define APTDPTDI (NPDEPG-1) /* alt ptd entry that points to APTD */ +#define APTDPTDI (NPDEPG-NPGPTD) /* alt ptd entry that points to APTD */ #ifdef SMP #define MPPTDI (APTDPTDI-1) /* per cpu ptd entry */ #define KPTDI (MPPTDI-NKPDE) /* start of kernel virtual pde's */ #else #define KPTDI (APTDPTDI-NKPDE)/* start of kernel virtual pde's */ #endif /* SMP */ -#define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */ +#define PTDPTDI (KPTDI-NPGPTD) /* ptd entry that points to ptd! */ #define UMAXPTDI (PTDPTDI-1) /* ptd entry for user space end */ #define UMAXPTEOFF (NPTEPG) /* pte entry for user space end */