- /* Clear out the page directory except for one entry pointing to the
- * page table, and clear the page table entirely. */
- outb(0x80, 0x52);
- pagedirectory[0] = (smbase + 0x1000) | PTE_PRESENT | PTE_READ_WRITE;
- outb(0x80, 0x53);
- for (i = 1; i < 1024; i++)
- {
- pagedirectory[i] = 0;
- }
+unsigned long v2p(void *virt)
+{
+ unsigned long _virt = (unsigned long)virt;
+
+ if (!paging_enb)
+ return _virt;
+
+ unsigned long pde = ((unsigned long *)p2v((unsigned long)pd))[PDE_FOR(_virt)];
+ unsigned long pte;
+
+ if (!(pde & PTE_PRESENT))
+ return 0xFFFFFFFF;
+
+ if (pde & PDE_PAGE_SIZE)
+ return ADDR_12_MASK(pde) + (_virt & 0x3FFFFF);
+
+ pte = ((unsigned long *)p2v(ADDR_12_MASK(pde)))[PTE_FOR(_virt)];
+ if (!(pte & PTE_PRESENT))
+ return 0xFFFFFFFF;
+ return (pte & ~0xFFF) + (_virt & 0xFFF);
+}