* page table.
*/
#define SPAREPAGES 5
+int missing_spares = SPAREPAGES;
static struct {
void *page;
u32_t phys;
vm_assert(!(vir % I386_PAGE_SIZE));
vm_assert(!(phys % I386_PAGE_SIZE));
FREE_MEM(ABS2CLICK(phys), pages);
- if(pt_writemap(&vmp->vm_pt,
- vir + CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys),
+ if(pt_writemap(&vmp->vm_pt, arch_vir2map(vmp, vir),
MAP_NONE, pages*I386_PAGE_SIZE, 0, WMF_OVERWRITE) != OK)
vm_panic("vm_freepages: pt_writemap failed",
NO_NUM);
PRIVATE void *vm_getsparepage(u32_t *phys)
{
int s;
+ vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES);
for(s = 0; s < SPAREPAGES; s++) {
if(sparepages[s].page) {
void *sp;
sp = sparepages[s].page;
*phys = sparepages[s].phys;
sparepages[s].page = NULL;
+ missing_spares++;
+ vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES);
return sp;
}
}
{
int s, n = 0;
static int total = 0, worst = 0;
- for(s = 0; s < SPAREPAGES; s++)
+ vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES);
+ for(s = 0; s < SPAREPAGES && missing_spares > 0; s++)
if(!sparepages[s].page) {
n++;
sparepages[s].page = vm_allocpages(&sparepages[s].phys, 1,
VMP_SPARE);
+ missing_spares--;
+ vm_assert(missing_spares >= 0 && missing_spares <= SPAREPAGES);
}
if(worst < n) worst = n;
total += n;
* Where in our virtual address space can we put it?
*/
loc = findhole(pt, I386_PAGE_SIZE * pages,
- CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys) + vmp->vm_stacktop,
+ arch_vir2map(vmp, vmp->vm_stacktop),
vmp->vm_arch.vm_data_top);
if(loc == NO_MEM) {
level--;
level--;
/* Return user-space-ready pointer to it. */
- return (void *) (loc - CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys));
+ return (void *) arch_map2vir(vmp, loc);
}
/*===========================================================================*
}
/* Where to start looking for free virtual address space? */
- pt->pt_virtop = VM_STACKTOP +
- CLICK2ABS(vmproc[VMP_SYSTEM].vm_arch.vm_seg[D].mem_phys);
+ pt->pt_virtop = 0;
return OK;
}
I386_PAGE_SIZE, &sparepages[s].phys)) != OK)
vm_panic("pt_init: sys_umap failed", r);
}
+
+ missing_spares = 0;
/* Make new page table for ourselves, partly copied
* from the current one.
/* Where our free virtual address space starts.
* This is only a hint to the VM system.
*/
- newpt->pt_virtop = (vmp->vm_arch.vm_seg[S].mem_vir +
- vmp->vm_arch.vm_seg[S].mem_len) << CLICK_SHIFT;
+ newpt->pt_virtop = 0;
/* Let other functions know VM now has a private page table. */
vmp->vm_flags |= VMF_HASPT;
* can use to map in arbitrary physical pages.
*/
varmap_loc = findhole(newpt, I386_PAGE_SIZE,
- CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys) + vmp->vm_stacktop,
+ arch_vir2map(vmp, vmp->vm_stacktop),
vmp->vm_arch.vm_data_top);
if(varmap_loc == NO_MEM) {
vm_panic("no virt addr for vm mappings", NO_NUM);
}
- varmap = (unsigned char *) (varmap_loc -
- CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys));
+ varmap = (unsigned char *) arch_map2vir(vmp, varmap_loc);
/* All OK. */
return;