vm: reduce noise in merged pagetable.c

This commit is contained in:
Ben Gras 2012-11-09 19:00:46 +01:00
parent 3771a0833d
commit 6cf98dbe00
2 changed files with 16 additions and 62 deletions

View file

@ -38,23 +38,14 @@ static int vm_self_pages;
/* PDE used to map in kernel, kernel physical address. */ /* PDE used to map in kernel, kernel physical address. */
static int pagedir_pde = -1; static int pagedir_pde = -1;
#if defined(__i386__)
static u32_t global_bit = 0, pagedir_pde_val; static u32_t global_bit = 0, pagedir_pde_val;
#elif defined(__arm__)
static u32_t pagedir_pde_val;
#endif
static multiboot_module_t *kern_mb_mod = NULL; static multiboot_module_t *kern_mb_mod = NULL;
static size_t kern_size = 0; static size_t kern_size = 0;
static int kern_start_pde = -1; static int kern_start_pde = -1;
#if defined(__i386__) /* big page size available in hardware? */
/* 4MB page size available in hardware? */
static int bigpage_ok = 0;
#elif defined(__arm__)
/* 1MB page size available in hardware? */
static int bigpage_ok = 1; static int bigpage_ok = 1;
#endif
/* Our process table entry. */ /* Our process table entry. */
struct vmproc *vmprocess = &vmproc[VM_PROC_NR]; struct vmproc *vmprocess = &vmproc[VM_PROC_NR];
@ -81,8 +72,8 @@ static struct {
void *pagedir; void *pagedir;
phys_bytes phys; phys_bytes phys;
} sparepagedirs[SPAREPAGEDIRS]; } sparepagedirs[SPAREPAGEDIRS];
#endif #endif
int missing_spares = SPAREPAGES; int missing_spares = SPAREPAGES;
static struct { static struct {
void *page; void *page;
@ -116,17 +107,13 @@ int kernmappings = 0;
phys_bytes page_directories_phys; phys_bytes page_directories_phys;
u32_t *page_directories = NULL; u32_t *page_directories = NULL;
#if defined(__i386__)
static char static_sparepages[VM_PAGE_SIZE*STATIC_SPAREPAGES] static char static_sparepages[VM_PAGE_SIZE*STATIC_SPAREPAGES]
__aligned(VM_PAGE_SIZE); __aligned(VM_PAGE_SIZE);
#elif defined(__arm__)
#if defined(__arm__)
static char static_sparepagedirs[ARCH_PAGEDIR_SIZE*STATIC_SPAREPAGEDIRS + ARCH_PAGEDIR_SIZE] __aligned(ARCH_PAGEDIR_SIZE); static char static_sparepagedirs[ARCH_PAGEDIR_SIZE*STATIC_SPAREPAGEDIRS + ARCH_PAGEDIR_SIZE] __aligned(ARCH_PAGEDIR_SIZE);
#endif #endif
#if defined(__arm__)
static char static_sparepages[VM_PAGE_SIZE*STATIC_SPAREPAGES] __aligned(VM_PAGE_SIZE);
#endif
#if SANITYCHECKS #if SANITYCHECKS
/*===========================================================================* /*===========================================================================*
* pt_sanitycheck * * pt_sanitycheck *
@ -417,11 +404,7 @@ void *vm_allocpage(phys_bytes *phys, int reason)
assert(level >= 1); assert(level >= 1);
assert(level <= 2); assert(level <= 2);
#if defined(__i386__)
if((level > 1) || !pt_init_done) { if((level > 1) || !pt_init_done) {
#elif defined(__arm__)
if(level > 1 || !pt_init_done) {
#endif
void *s; void *s;
#if defined(__i386__) #if defined(__i386__)
s=vm_getsparepage(phys); s=vm_getsparepage(phys);
@ -852,12 +835,12 @@ int pt_ptmap(struct vmproc *src_vmp, struct vmproc *dst_vmp)
physaddr = pt->pt_dir[pde] & ARCH_VM_PDE_MASK; physaddr = pt->pt_dir[pde] & ARCH_VM_PDE_MASK;
#endif #endif
if((r=pt_writemap(dst_vmp, &dst_vmp->vm_pt, viraddr, physaddr, VM_PAGE_SIZE, if((r=pt_writemap(dst_vmp, &dst_vmp->vm_pt, viraddr, physaddr, VM_PAGE_SIZE,
#if defined(__i386__) ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_USER | ARCH_VM_PTE_RW
ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_USER | ARCH_VM_PTE_RW, #ifdef __arm__
#elif defined(__arm__) | ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_USER | ARCH_VM_PTE_RW |
ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_USER | ARCH_VM_PTE_RW | ARM_VM_PTE_WB | ARM_VM_PTE_SHAREABLE
ARM_VM_PTE_WB | ARM_VM_PTE_SHAREABLE,
#endif #endif
,
WMF_OVERWRITE)) != OK) { WMF_OVERWRITE)) != OK) {
return r; return r;
} }
@ -1142,9 +1125,7 @@ void pt_init(void)
{ {
pt_t *newpt; pt_t *newpt;
int s, r, p; int s, r, p;
#if defined(__i386__)
int global_bit_ok = 0; int global_bit_ok = 0;
#endif
vir_bytes sparepages_mem; vir_bytes sparepages_mem;
#if defined(__arm__) #if defined(__arm__)
vir_bytes sparepagedirs_mem; vir_bytes sparepagedirs_mem;
@ -1175,8 +1156,8 @@ void pt_init(void)
/* Get ourselves spare pagedirs. */ /* Get ourselves spare pagedirs. */
sparepagedirs_mem = (vir_bytes) static_sparepagedirs; sparepagedirs_mem = (vir_bytes) static_sparepagedirs;
assert(!(sparepagedirs_mem % ARCH_PAGEDIR_SIZE)); assert(!(sparepagedirs_mem % ARCH_PAGEDIR_SIZE));
#endif #endif
/* Spare pages are used to allocate memory before VM has its own page /* Spare pages are used to allocate memory before VM has its own page
* table that things (i.e. arbitrary physical memory) can be mapped into. * table that things (i.e. arbitrary physical memory) can be mapped into.
* We get it by pre-allocating it in our bss (allocated and mapped in by * We get it by pre-allocating it in our bss (allocated and mapped in by
@ -1207,18 +1188,10 @@ void pt_init(void)
for(s = 0; s < SPAREPAGES; s++) { for(s = 0; s < SPAREPAGES; s++) {
vir_bytes v = (sparepages_mem + s*VM_PAGE_SIZE);; vir_bytes v = (sparepages_mem + s*VM_PAGE_SIZE);;
phys_bytes ph; phys_bytes ph;
#if defined(__i386__)
if((r=sys_umap(SELF, VM_D, (vir_bytes) v,
#elif defined(__arm__)
if((r=sys_umap(SELF, VM_D, (vir_bytes) v, if((r=sys_umap(SELF, VM_D, (vir_bytes) v,
#endif
VM_PAGE_SIZE*SPAREPAGES, &ph)) != OK) VM_PAGE_SIZE*SPAREPAGES, &ph)) != OK)
panic("pt_init: sys_umap failed: %d", r); panic("pt_init: sys_umap failed: %d", r);
#if defined(__i386__)
if(s >= STATIC_SPAREPAGES) { if(s >= STATIC_SPAREPAGES) {
#elif defined(__arm__)
if(s >= STATIC_SPAREPAGES) {
#endif
sparepages[s].page = NULL; sparepages[s].page = NULL;
missing_spares++; missing_spares++;
continue; continue;
@ -1231,17 +1204,12 @@ void pt_init(void)
/* global bit and 4MB pages available? */ /* global bit and 4MB pages available? */
global_bit_ok = _cpufeature(_CPUF_I386_PGE); global_bit_ok = _cpufeature(_CPUF_I386_PGE);
bigpage_ok = _cpufeature(_CPUF_I386_PSE); bigpage_ok = _cpufeature(_CPUF_I386_PSE);
#elif defined(__arm__)
/* 1MB pages available? */
bigpage_ok = 1;
#endif
#if defined(__i386__)
/* Set bit for PTE's and PDE's if available. */ /* Set bit for PTE's and PDE's if available. */
if(global_bit_ok) if(global_bit_ok)
global_bit = I386_VM_GLOBAL; global_bit = I386_VM_GLOBAL;
#endif #endif
/* Allocate us a page table in which to remember page directory /* Allocate us a page table in which to remember page directory
* pointers. * pointers.
*/ */
@ -1382,11 +1350,7 @@ void pt_init(void)
/* Copy kernel-initialized pagetable contents into our /* Copy kernel-initialized pagetable contents into our
* normally accessible pagetable. * normally accessible pagetable.
*/ */
#if defined(__i386__)
if(sys_abscopy(ptaddr_kern, ptaddr_us, VM_PAGE_SIZE) != OK) if(sys_abscopy(ptaddr_kern, ptaddr_us, VM_PAGE_SIZE) != OK)
#elif defined(__arm__)
if(sys_abscopy(ptaddr_kern, ptaddr_us, ARM_PAGETABLE_SIZE) != OK)
#endif
panic("pt_init: abscopy failed"); panic("pt_init: abscopy failed");
} }
@ -1408,10 +1372,7 @@ int pt_bind(pt_t *pt, struct vmproc *who)
int slot; int slot;
u32_t phys; u32_t phys;
void *pdes; void *pdes;
#if defined(__arm__)
int i;
int pages_per_pagedir = ARCH_PAGEDIR_SIZE/VM_PAGE_SIZE; int pages_per_pagedir = ARCH_PAGEDIR_SIZE/VM_PAGE_SIZE;
#endif
/* Basic sanity checks. */ /* Basic sanity checks. */
assert(who); assert(who);
@ -1423,11 +1384,7 @@ int pt_bind(pt_t *pt, struct vmproc *who)
slot = who->vm_slot; slot = who->vm_slot;
assert(slot >= 0); assert(slot >= 0);
assert(slot < ELEMENTS(vmproc)); assert(slot < ELEMENTS(vmproc));
#if defined(__i386__)
assert(slot < ARCH_VM_PT_ENTRIES);
#elif defined(__arm__)
assert(slot < ARCH_VM_PT_ENTRIES / pages_per_pagedir); assert(slot < ARCH_VM_PT_ENTRIES / pages_per_pagedir);
#endif
#if defined(__i386__) #if defined(__i386__)
phys = pt->pt_dir_phys & ARCH_VM_ADDR_MASK; phys = pt->pt_dir_phys & ARCH_VM_ADDR_MASK;
@ -1435,19 +1392,20 @@ int pt_bind(pt_t *pt, struct vmproc *who)
phys = pt->pt_dir_phys & ARM_VM_PTE_MASK; phys = pt->pt_dir_phys & ARM_VM_PTE_MASK;
#endif #endif
assert(pt->pt_dir_phys == phys); assert(pt->pt_dir_phys == phys);
#if defined(__arm__)
assert(!(pt->pt_dir_phys % ARCH_PAGEDIR_SIZE)); assert(!(pt->pt_dir_phys % ARCH_PAGEDIR_SIZE));
#endif
/* Update "page directory pagetable." */ /* Update "page directory pagetable." */
#if defined(__i386__) #if defined(__i386__)
page_directories[slot] = phys | ARCH_VM_PDE_PRESENT|ARCH_VM_PTE_RW; page_directories[slot] = phys | ARCH_VM_PDE_PRESENT|ARCH_VM_PTE_RW;
#elif defined(__arm__) #elif defined(__arm__)
{
int i;
for (i = 0; i < pages_per_pagedir; i++) for (i = 0; i < pages_per_pagedir; i++)
page_directories[slot*pages_per_pagedir+i] = page_directories[slot*pages_per_pagedir+i] =
(phys+i*VM_PAGE_SIZE) | (phys+i*VM_PAGE_SIZE) |
ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_RW | ARCH_VM_PTE_PRESENT | ARCH_VM_PTE_RW |
ARCH_VM_PTE_USER; ARCH_VM_PTE_USER;
}
#endif #endif
/* This is where the PDE's will be visible to the kernel /* This is where the PDE's will be visible to the kernel
@ -1492,11 +1450,7 @@ int pt_mapkernel(pt_t *pt)
int kern_pde = kern_start_pde; int kern_pde = kern_start_pde;
phys_bytes addr, mapped = 0; phys_bytes addr, mapped = 0;
#if defined(__i386__) /* Any page table needs to map in the kernel address space. */
/* Any i386 page table needs to map in the kernel address space. */
#elif defined(__arm__)
/* Any ARM page table needs to map in the kernel address space. */
#endif
assert(bigpage_ok); assert(bigpage_ok);
assert(pagedir_pde >= 0); assert(pagedir_pde >= 0);
assert(kern_pde >= 0); assert(kern_pde >= 0);

View file

@ -25,7 +25,7 @@
#define ARCH_VM_PTE_PRESENT I386_VM_PRESENT #define ARCH_VM_PTE_PRESENT I386_VM_PRESENT
#define ARCH_VM_PTE_USER I386_VM_USER #define ARCH_VM_PTE_USER I386_VM_USER
#define ARCH_VM_PTE_RW I386_VM_WRITE #define ARCH_VM_PTE_RW I386_VM_WRITE
#define ARCH_PAGEDIR_SIZE I386_PAGEDIR_SIZE #define ARCH_PAGEDIR_SIZE I386_PAGE_SIZE
#define ARCH_VM_BIGPAGE I386_VM_BIGPAGE #define ARCH_VM_BIGPAGE I386_VM_BIGPAGE
#define ARCH_VM_PT_ENTRIES I386_VM_PT_ENTRIES #define ARCH_VM_PT_ENTRIES I386_VM_PT_ENTRIES