From: Ben Gras Date: Wed, 6 Mar 2013 12:17:07 +0000 (+0000) Subject: VM: ARM/I386 PDE/PTE macro unification X-Git-Tag: v3.3.0~1086 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=0022ee2cb50fae02d2f685e319d656856fcd83de;p=minix.git VM: ARM/I386 PDE/PTE macro unification . further reduces special cases in pagetable.c Change-Id: Ifd7dd9ee10ca618a47bb4a372467205fbe6da90e --- diff --git a/servers/vm/arch/earm/pagetable.h b/servers/vm/arch/earm/pagetable.h index b7f0fb911..8c74cf8ca 100644 --- a/servers/vm/arch/earm/pagetable.h +++ b/servers/vm/arch/earm/pagetable.h @@ -44,5 +44,9 @@ #define VM_PAGE_SIZE ARM_PAGE_SIZE +/* virtual address -> pde, pte macros */ +#define ARCH_VM_PTE(v) ARM_VM_PTE(v) +#define ARCH_VM_PDE(v) ARM_VM_PDE(v) + #endif diff --git a/servers/vm/arch/i386/pagetable.c b/servers/vm/arch/i386/pagetable.c index 0605ccbc6..7194e9fcf 100644 --- a/servers/vm/arch/i386/pagetable.c +++ b/servers/vm/arch/i386/pagetable.c @@ -177,13 +177,8 @@ static u32_t findhole(int pages) assert(curv >= vmin); assert(curv < vmax); -#if defined(__i386__) - pde = I386_VM_PDE(curv); - pte = I386_VM_PTE(curv); -#elif defined(__arm__) - pde = ARM_VM_PDE(curv); - pte = ARM_VM_PTE(curv); -#endif + pde = ARCH_VM_PDE(curv); + pte = ARCH_VM_PTE(curv); if((pt->pt_dir[pde] & ARCH_VM_PDE_PRESENT) && (pt->pt_pt[pde][pte] & ARCH_VM_PTE_PRESENT)) { @@ -439,13 +434,8 @@ int vm_addrok(void *vir, int writeflag) int pde, pte; vir_bytes v = (vir_bytes) vir; -#if defined(__i386__) - pde = I386_VM_PDE(v); - pte = I386_VM_PTE(v); -#elif defined(__arm__) - pde = ARM_VM_PDE(v); - pte = ARM_VM_PTE(v); -#endif + pde = ARCH_VM_PDE(v); + pte = ARCH_VM_PTE(v); if(!(pt->pt_dir[pde] & ARCH_VM_PDE_PRESENT)) { printf("addr not ok: missing pde %d\n", pde); @@ -539,13 +529,9 @@ int pt_ptalloc_in_range(pt_t *pt, vir_bytes start, vir_bytes end, /* Allocate all the page tables in the range specified. */ int pde, first_pde, last_pde; -#if defined(__i386__) - first_pde = I386_VM_PDE(start); - last_pde = I386_VM_PDE(end-1); -#elif defined(__arm__) - first_pde = ARM_VM_PDE(start); - last_pde = ARM_VM_PDE(end-1); -#endif + first_pde = ARCH_VM_PDE(start); + last_pde = ARCH_VM_PDE(end-1); + assert(first_pde >= 0); assert(last_pde < ARCH_VM_DIR_ENTRIES); @@ -639,43 +625,26 @@ int pt_map_in_range(struct vmproc *src_vmp, struct vmproc *dst_vmp, end = end ? end : VM_DATATOP; assert(start % VM_PAGE_SIZE == 0); assert(end % VM_PAGE_SIZE == 0); -#if defined(__i386__) - assert(start <= end); - assert(I386_VM_PDE(end) < ARCH_VM_DIR_ENTRIES); -#elif defined(__arm__) - assert(ARM_VM_PDE(start) >= 0 && start <= end); - assert(ARM_VM_PDE(end) < ARCH_VM_DIR_ENTRIES); -#endif + + assert(ARCH_VM_PDE(start) >= 0 && start <= end); + assert(ARCH_VM_PDE(end) < ARCH_VM_DIR_ENTRIES); #if LU_DEBUG printf("VM: pt_map_in_range: src = %d, dst = %d\n", src_vmp->vm_endpoint, dst_vmp->vm_endpoint); printf("VM: pt_map_in_range: transferring from 0x%08x (pde %d pte %d) to 0x%08x (pde %d pte %d)\n", -#if defined(__i386__) - start, I386_VM_PDE(start), I386_VM_PTE(start), - end, I386_VM_PDE(end), I386_VM_PTE(end)); -#elif defined(__arm__) - start, ARM_VM_PDE(start), ARM_VM_PTE(start), - end, ARM_VM_PDE(end), ARM_VM_PTE(end)); -#endif + start, ARCH_VM_PDE(start), ARCH_VM_PTE(start), + end, ARCH_VM_PDE(end), ARCH_VM_PTE(end)); #endif /* Scan all page-table entries in the range. */ for(viraddr = start; viraddr <= end; viraddr += VM_PAGE_SIZE) { -#if defined(__i386__) - pde = I386_VM_PDE(viraddr); -#elif defined(__arm__) - pde = ARM_VM_PDE(viraddr); -#endif + pde = ARCH_VM_PDE(viraddr); if(!(pt->pt_dir[pde] & ARCH_VM_PDE_PRESENT)) { if(viraddr == VM_DATATOP) break; continue; } -#if defined(__i386__) - pte = I386_VM_PTE(viraddr); -#elif defined(__arm__) - pte = ARM_VM_PTE(viraddr); -#endif + pte = ARCH_VM_PTE(viraddr); if(!(pt->pt_pt[pde][pte] & ARCH_VM_PTE_PRESENT)) { if(viraddr == VM_DATATOP) break; continue; @@ -772,13 +741,8 @@ int pt_writable(struct vmproc *vmp, vir_bytes v) u32_t entry; pt_t *pt = &vmp->vm_pt; assert(!(v % VM_PAGE_SIZE)); -#if defined(__i386__) - int pde = I386_VM_PDE(v); - int pte = I386_VM_PTE(v); -#elif defined(__arm__) - int pde = ARM_VM_PDE(v); - int pte = ARM_VM_PTE(v); -#endif + int pde = ARCH_VM_PDE(v); + int pte = ARCH_VM_PTE(v); assert(pt->pt_dir[pde] & ARCH_VM_PDE_PRESENT); assert(pt->pt_pt[pde]); @@ -851,13 +815,8 @@ int pt_writemap(struct vmproc * vmp, /* Now write in them. */ for(p = 0; p < pages; p++) { u32_t entry; -#if defined(__i386__) - int pde = I386_VM_PDE(v); - int pte = I386_VM_PTE(v); -#elif defined(__arm__) - int pde = ARM_VM_PDE(v); - int pte = ARM_VM_PTE(v); -#endif + int pde = ARCH_VM_PDE(v); + int pte = ARCH_VM_PTE(v); assert(!(v % VM_PAGE_SIZE)); assert(pte >= 0 && pte < ARCH_VM_PT_ENTRIES); @@ -973,13 +932,8 @@ int pt_checkrange(pt_t *pt, vir_bytes v, size_t bytes, pages = bytes / VM_PAGE_SIZE; for(p = 0; p < pages; p++) { -#if defined(__i386__) - int pde = I386_VM_PDE(v); - int pte = I386_VM_PTE(v); -#elif defined(__arm__) - int pde = ARM_VM_PDE(v); - int pte = ARM_VM_PTE(v); -#endif + int pde = ARCH_VM_PDE(v); + int pte = ARCH_VM_PTE(v); assert(!(v % VM_PAGE_SIZE)); assert(pte >= 0 && pte < ARCH_VM_PT_ENTRIES); @@ -1202,11 +1156,7 @@ void pt_init(void) index++; kernmappings++; -#if defined(__i386__) - usedpde = I386_VM_PDE(offset); -#elif defined(__arm__) - usedpde = ARM_VM_PDE(offset); -#endif + usedpde = ARCH_VM_PDE(offset); while(usedpde > kernmap_pde) { int newpde = freepde(); assert(newpde == kernmap_pde+1); diff --git a/servers/vm/arch/i386/pagetable.h b/servers/vm/arch/i386/pagetable.h index d40039d4b..a7b3c4030 100644 --- a/servers/vm/arch/i386/pagetable.h +++ b/servers/vm/arch/i386/pagetable.h @@ -40,4 +40,8 @@ #define VM_PAGE_SIZE I386_PAGE_SIZE +/* virtual address -> pde, pte macros */ +#define ARCH_VM_PTE(v) I386_VM_PTE(v) +#define ARCH_VM_PDE(v) I386_VM_PDE(v) + #endif