kern

diff src/vm.c @ 26:387078ef5c0d

fixes here and there
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 09 Apr 2011 07:14:06 +0300
parents 9939a6d7a45a
children 373a9f50b4e6
line diff
     1.1 --- a/src/vm.c	Wed Apr 06 07:42:44 2011 +0300
     1.2 +++ b/src/vm.c	Sat Apr 09 07:14:06 2011 +0300
     1.3 @@ -53,13 +53,10 @@
     1.4  static struct page_range first_node;
     1.5  
     1.6  
     1.7 -void init_vm(struct mboot_info *mb)
     1.8 +void init_vm(void)
     1.9  {
    1.10  	uint32_t idmap_end;
    1.11  
    1.12 -	/* initialize the physical memory map and allocator */
    1.13 -	init_mem(mb);
    1.14 -
    1.15  	/* setup the page tables */
    1.16  	pgdir = (uint32_t*)alloc_phys_page();
    1.17  	memset(pgdir, 0, PGSIZE);
    1.18 @@ -83,12 +80,12 @@
    1.19  	node_pool = 0;
    1.20  
    1.21  	first_node.start = ADDR_TO_PAGE(KMEM_START);
    1.22 -	first_node.end = PAGE_COUNT;
    1.23 +	first_node.end = ADDR_TO_PAGE(PGTBL_BASE);
    1.24  	first_node.next = 0;
    1.25  	pglist[MEM_KERNEL] = &first_node;
    1.26  
    1.27  	pglist[MEM_USER] = alloc_node();
    1.28 -	pglist[MEM_USER]->start = 0;
    1.29 +	pglist[MEM_USER]->start = ADDR_TO_PAGE(idmap_end);
    1.30  	pglist[MEM_USER]->end = ADDR_TO_PAGE(KMEM_START);
    1.31  	pglist[MEM_USER]->next = 0;
    1.32  }
    1.33 @@ -149,7 +146,7 @@
    1.34  	if(!(pgdir[diridx] & PG_PRESENT)) {
    1.35  		goto err;
    1.36  	}
    1.37 -	pgtbl = (uint32_t*)(pgdir[diridx] & ADDR_PGENT_MASK);
    1.38 +	pgtbl = PGTBL(diridx);
    1.39  
    1.40  	if(!(pgtbl[pgidx] & PG_PRESENT)) {
    1.41  		goto err;
    1.42 @@ -168,18 +165,9 @@
    1.43  int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr)
    1.44  {
    1.45  	int i, phys_pg;
    1.46 -	uint32_t paddr;
    1.47  
    1.48  	for(i=0; i<pgcount; i++) {
    1.49 -		if(ppg_start < 0) {
    1.50 -			if(!(paddr = alloc_phys_page())) {
    1.51 -				return -1;
    1.52 -			}
    1.53 -			phys_pg = ADDR_TO_PAGE(paddr);
    1.54 -		} else {
    1.55 -			phys_pg = ppg_start + i;
    1.56 -		}
    1.57 -
    1.58 +		phys_pg = ppg_start < 0 ? -1 : ppg_start + i;
    1.59  		map_page(vpg_start + i, phys_pg, attr);
    1.60  	}
    1.61  	return 0;
    1.62 @@ -212,7 +200,7 @@
    1.63  	if(!(pgdir[diridx] & PG_PRESENT)) {
    1.64  		panic("virt_to_phys(%x): page table %d not present\n", vaddr, diridx);
    1.65  	}
    1.66 -	pgtbl = (uint32_t*)(pgdir[diridx] & PGENT_ADDR_MASK);
    1.67 +	pgtbl = PGTBL(diridx);
    1.68  
    1.69  	if(!(pgtbl[pgidx] & PG_PRESENT)) {
    1.70  		panic("virt_to_phys(%x): page %d not present\n", vaddr, ADDR_TO_PAGE(vaddr));
    1.71 @@ -271,12 +259,19 @@
    1.72  
    1.73  void pgfree(int start, int num)
    1.74  {
    1.75 -	int area, end, intr_state;
    1.76 +	int i, area, end, intr_state;
    1.77  	struct page_range *node, *new, *prev, *next;
    1.78  
    1.79  	intr_state = get_intr_state();
    1.80  	disable_intr();
    1.81  
    1.82 +	for(i=0; i<num; i++) {
    1.83 +		uint32_t phys = virt_to_phys(PAGE_TO_ADDR(start + i));
    1.84 +		if(phys) {
    1.85 +			free_phys_page(ADDR_TO_PAGE(phys));
    1.86 +		}
    1.87 +	}
    1.88 +
    1.89  	if(!(new = alloc_node())) {
    1.90  		panic("pgfree: can't allocate new page_range node to add the freed pages\n");
    1.91  	}