kern
diff src/vm.c @ 18:096807345aa2
fixed the stupid mistake. forgot to page-align the page directory
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 27 Mar 2011 06:28:26 +0300 |
parents | 098b1cb5eeaa |
children | 8be069e6bb05 |
line diff
1.1 --- a/src/vm.c Sat Mar 26 21:39:14 2011 +0200 1.2 +++ b/src/vm.c Sun Mar 27 06:28:26 2011 +0300 1.3 @@ -16,7 +16,7 @@ 1.4 static void pgfault(int inum, uint32_t err); 1.5 1.6 /* page directory */ 1.7 -static uint32_t pgdir[1024]; 1.8 +static uint32_t *pgdir; 1.9 1.10 #define KMEM_START 0xc0000000 1.11 #define IDMAP_START 0xa0000 1.12 @@ -31,6 +31,7 @@ 1.13 { 1.14 init_mem(mb); 1.15 1.16 + pgdir = (uint32_t*)alloc_phys_page(); 1.17 memset(pgdir, 0, sizeof pgdir); 1.18 1.19 /* map the video memory and kernel code 1-1 */ 1.20 @@ -51,6 +52,8 @@ 1.21 if(!(pgdir[diridx] & PG_PRESENT)) { 1.22 uint32_t addr = alloc_phys_page(); 1.23 pgtbl = (uint32_t*)addr; 1.24 + memset(pgtbl, 0, PGSIZE); 1.25 + 1.26 pgdir[diridx] = addr | (attr & ATTR_PGDIR_MASK) | PG_PRESENT; 1.27 } else { 1.28 pgtbl = (uint32_t*)(pgdir[diridx] & ADDR_PGENT_MASK); 1.29 @@ -128,6 +131,25 @@ 1.30 } 1.31 */ 1.32 1.33 +uint32_t virt_to_phys(uint32_t vaddr) 1.34 +{ 1.35 + uint32_t pgaddr, *pgtbl; 1.36 + int diridx = ADDR_TO_PGTBL(vaddr); 1.37 + int pgidx = ADDR_TO_PGTBL_PG(vaddr); 1.38 + 1.39 + if(!(pgdir[diridx] & PG_PRESENT)) { 1.40 + panic("virt_to_phys(%x): page table %d not present\n", vaddr, diridx); 1.41 + } 1.42 + pgtbl = (uint32_t*)(pgdir[diridx] & PGENT_ADDR_MASK); 1.43 + 1.44 + if(!(pgtbl[pgidx] & PG_PRESENT)) { 1.45 + panic("virt_to_phys(%x): page %d not present\n", vaddr, ADDR_TO_PAGE(vaddr)); 1.46 + } 1.47 + pgaddr = pgtbl[pgidx] & PGENT_ADDR_MASK; 1.48 + 1.49 + return pgaddr | ADDR_TO_PGOFFS(vaddr); 1.50 +} 1.51 + 1.52 static void pgfault(int inum, uint32_t err) 1.53 { 1.54 printf("~~~~ PAGE FAULT ~~~~\n");