* This needs to be called before any allocations occur
* FIXME: put the map at the *top* of space and we can then align the
* data blocks if the platform needs big alignments.
+ * FIXME: some platforms need table and user RAM split (eg the mini68K can
+ * put the tables below 64K in protected space but not user pages)
*/
void vmmu_init(void)
{
reserved gaps */
i = num;
after = first;
+
+ /* Assign the blocks correctly */
while (after && i--) {
after->home = dlist;
after->gap = 0;
first->prev = dlist;
break;
}
- if (dlist->next < first)
+ if (dlist->next < first) {
dlist = dlist->next;
- else if (dlist->next > first) {
+ } else if (dlist->next > first) {
nlink = dlist->next;
dlist->next = first;
first->prev = dlist;
continue;
}
/* If we get here then we couldn't resolve the conflict */
- kputs("alloc: vaddr conflict");
return NULL; /* Whole call fails */
}
#else
static struct mmu_context *last_mmu;
static struct mmu_context mmu_context[PTABSIZE];
-/* For the moment. If we add separate va info then we can use that if not
- we use the map table */
+/*
+ * Our process can have multiple memory segments via memalloc/free so
+ * we have to actually use the mapping table to work out what we are
+ * using. Fortunately most of our queries will be within the page
+ * so the usual path is a single lookup with no overlap.
+ */
usize_t valaddr(const char *ppv, usize_t l)
{
uint8_t *pp = (uint8_t *)ppv;
/* FIXME: we need to handle the initial init map somehow */
- if (pp < membase || pp + l >= memtop || pp + l < pp)
+ if (pp < membase || pp + l >= memtop || pp + l < pp) {
+ kprintf("BAD ADDR %p\n", pp);
return 0;
+ }
+#ifdef FIXME
l = (l + MMU_BLKSIZE - 1) / MMU_BLKSIZE;
n++;
m++;
}
+#endif
return l;
}
platform_mmu_setup(m);
return 0;
}
- if (vmmu_dup(mmu_context[udata.u_page].mmu.next, &m->mmu))
+ if (vmmu_dup(&mmu_context[udata.u_page].mmu, &m->mmu))
return ENOMEM;
return 0;
}
int pagemap_realloc(usize_t size)
{
struct mmu_context *mmu = mmu_context + udata.u_page;
+ kprintf("Reallocating mmu %d to %d\n", udata.u_page, size);
pagemap_free(udata.u_ptab);
mmu->base = vmmu_alloc(&mmu->mmu, size, NULL, 0, 1);
if (mmu->base == NULL)
return ENOMEM;
+ kprintf("Allocated at %p\n", mmu->base);
+ vmmu_setcontext(&mmu->mmu);
return 0;
}