My Haiku ARM (UEFI) port progress

I think that riscv64 version will be fine until some issues will be found (random crashes in unrelated places etc.).

It will be nice to write page table setup code like this. It will allow to use existing ARM kernel VMTranslationMap code. Otherwise kernel-user address range swapping (declared here) and kernel page table code adjustments will be needed.

That will require ARM versions of LookupPte() and Map() functions. riscv64 version:

static Pte*
LookupPte(addr_t virtAdr, bool alloc)
{
	Pte *pte = (Pte*)VirtFromPhys(sPageTable);
	for (int level = 2; level > 0; level --) {
		pte += PhysAdrPte(virtAdr, level);
		if (!((1 << pteValid) & pte->flags)) {
			if (!alloc)
				return NULL;
			pte->ppn = AllocPhysPage() / B_PAGE_SIZE;
			if (pte->ppn == 0)
				return NULL;
			memset((Pte*)VirtFromPhys(B_PAGE_SIZE * pte->ppn), 0, B_PAGE_SIZE);
			pte->flags |= (1 << pteValid);
		}
		pte = (Pte*)VirtFromPhys(B_PAGE_SIZE * pte->ppn);
	}
	pte += PhysAdrPte(virtAdr, 0);
	return pte;
}


static void
Map(addr_t virtAdr, phys_addr_t physAdr, uint64 flags)
{
	// dprintf("Map(0x%" B_PRIxADDR ", 0x%" B_PRIxADDR ")\n", virtAdr, physAdr);
	Pte* pte = LookupPte(virtAdr, true);
	if (pte == NULL)
		panic("can't allocate page table");

	pte->ppn = physAdr / B_PAGE_SIZE;
	pte->flags = (1 << pteValid) | flags;
}

Produced page table should be passed to arch_start_kernel() and applied there.

Some information about ARM32 page tables: ARM Paging - OSDev Wiki.

6 Likes