X-Git-Url: http://git.joshuawise.com/netwatch.git/blobdiff_plain/9343e9338ddf1015a63a95e4e78bfe659a557b76..73d65ee64db897452946c14e2b911b4c1f106b26:/aseg-paging/pagingstub.c?ds=inline diff --git a/aseg-paging/pagingstub.c b/aseg-paging/pagingstub.c index 7d430b9..782bf0f 100644 --- a/aseg-paging/pagingstub.c +++ b/aseg-paging/pagingstub.c @@ -23,14 +23,26 @@ void ps_switch_stack (void (*call)(), int stack); 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) @@ -49,17 +61,19 @@ unsigned long v2p(void *virt) 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) @@ -97,6 +111,15 @@ int addmap(unsigned long vaddr, unsigned long paddr) 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)]; @@ -158,6 +181,7 @@ void c_entry(void) /* 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;