asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \
_temp__; \
})
-
-
#define set_cr3(value) \
{ \
register unsigned int _temp__ = (value); \
asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \
}
+
+#define get_cr4() \
+ ({ \
+ register unsigned int _temp__; \
+ asm volatile("mov %%cr4, %0" : "=r" (_temp__)); \
+ _temp__; \
+ })
+#define set_cr4(value) \
+ { \
+ register unsigned int _temp__ = (value); \
+ asm volatile("mov %0, %%cr4" : : "r" (_temp__)); \
+ }
+
#define CR0_PG 0x80000000
+#define CR4_PSE 0x00000010
#define MAP_FLAGS (PTE_PRESENT | PTE_READ_WRITE)
if (!paging_enb)
return _virt;
- if (_virt >= 0xA0000 && _virt < 0xC0000)
- return _virt;
- if (_virt >= 0x200000 && _virt < 0x300000)
- return _virt - 0x200000 + /* XXX */ 0x1FF82000;
- if (_virt >= 0x1F0000 && _virt < 0x1F2000)
- return _virt - 0x1F0000 + 0x1FF80000;
- if ((_virt & ~0xFFF) == 0x4000)
- return _virt - 0x4000 + curmapped;
+ 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);
- outputf("WARNING: v2p(%08x)", _virt);
- return 0xFFFFFFFF;
+ pte = ((unsigned long *)p2v(ADDR_12_MASK(pde)))[PTE_FOR(_virt)];
+ if (!(pte & PTE_PRESENT))
+ return 0xFFFFFFFF;
+ return (pte & ~0xFFF) + (_virt & 0xFFF);
}
void *p2v(unsigned long phys)
return 0;
}
+int addmap_4m(unsigned long vaddr, unsigned long paddr)
+{
+ /* PDE_PAGE_SIZE = (1 << 7) */
+ ((unsigned long *)p2v((unsigned long)pd))[PDE_FOR(vaddr)] =
+ paddr | PDE_PRESENT | PDE_READ_WRITE | PDE_PAGE_SIZE;
+
+ return 0;
+}
+
void *demap(unsigned long client_pd, unsigned long vaddr)
{
unsigned long pde = ((unsigned long *)p2v(client_pd))[PDE_FOR(vaddr)];
/* Enable paging. */
set_cr3((unsigned long)pd);
+ set_cr4(get_cr4() | CR4_PSE); /* ITT, we 4MByte page. */
set_cr0(get_cr0() | CR0_PG);
outb(0x80, 0x03);
paging_enb = 1;