kern

changeset 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 7795225808b3
files src/main.c src/vm-asm.S src/vm.c src/vm.h
diffstat 4 files changed, 23 insertions(+), 23 deletions(-) [+]
line diff
     1.1 --- a/src/main.c	Wed Apr 06 07:42:44 2011 +0300
     1.2 +++ b/src/main.c	Sat Apr 09 07:14:06 2011 +0300
     1.3 @@ -57,7 +57,10 @@
     1.4  	/* silence the blasted timer interrupt */
     1.5  	interrupt(32, do_nothing);
     1.6  
     1.7 -	init_vm(mbinf);
     1.8 +	/* initialize the physical memory manager */
     1.9 +	init_mem(mbinf);
    1.10 +	/* initialize paging and the virtual memory manager */
    1.11 +	init_vm();
    1.12  
    1.13  	dbg_print_vm(MEM_USER);
    1.14  	dbg_print_vm(MEM_KERNEL);
     2.1 --- a/src/vm-asm.S	Wed Apr 06 07:42:44 2011 +0300
     2.2 +++ b/src/vm-asm.S	Sat Apr 09 07:14:06 2011 +0300
     2.3 @@ -1,6 +1,6 @@
     2.4  	.text
     2.5  /* enable_paging(void)
     2.6 - * sets the cr0 bit 31 which enables page translation */
     2.7 + * sets bit 31 of cr0 which enables page translation */
     2.8  	.globl enable_paging
     2.9  enable_paging:
    2.10  	movl %cr0, %eax
    2.11 @@ -9,7 +9,7 @@
    2.12  	ret
    2.13  
    2.14  /* disable_paging(void)
    2.15 - * clears the cr0 bit 31 */
    2.16 + * clears bit 31 of cr0 which disables page translation */
    2.17  	.globl disable_paging
    2.18  disable_paging:
    2.19  	movl %cr0, %eax
    2.20 @@ -17,6 +17,8 @@
    2.21  	movl %eax, %cr0
    2.22  	ret
    2.23  
    2.24 +/* get_paging_status(void)
    2.25 + * returns 0 if paging is disabled or 1 if it's enabled */
    2.26  	.globl get_paging_status
    2.27  get_paging_status:
    2.28  	movl %cr0, %eax
     3.1 --- a/src/vm.c	Wed Apr 06 07:42:44 2011 +0300
     3.2 +++ b/src/vm.c	Sat Apr 09 07:14:06 2011 +0300
     3.3 @@ -53,13 +53,10 @@
     3.4  static struct page_range first_node;
     3.5  
     3.6  
     3.7 -void init_vm(struct mboot_info *mb)
     3.8 +void init_vm(void)
     3.9  {
    3.10  	uint32_t idmap_end;
    3.11  
    3.12 -	/* initialize the physical memory map and allocator */
    3.13 -	init_mem(mb);
    3.14 -
    3.15  	/* setup the page tables */
    3.16  	pgdir = (uint32_t*)alloc_phys_page();
    3.17  	memset(pgdir, 0, PGSIZE);
    3.18 @@ -83,12 +80,12 @@
    3.19  	node_pool = 0;
    3.20  
    3.21  	first_node.start = ADDR_TO_PAGE(KMEM_START);
    3.22 -	first_node.end = PAGE_COUNT;
    3.23 +	first_node.end = ADDR_TO_PAGE(PGTBL_BASE);
    3.24  	first_node.next = 0;
    3.25  	pglist[MEM_KERNEL] = &first_node;
    3.26  
    3.27  	pglist[MEM_USER] = alloc_node();
    3.28 -	pglist[MEM_USER]->start = 0;
    3.29 +	pglist[MEM_USER]->start = ADDR_TO_PAGE(idmap_end);
    3.30  	pglist[MEM_USER]->end = ADDR_TO_PAGE(KMEM_START);
    3.31  	pglist[MEM_USER]->next = 0;
    3.32  }
    3.33 @@ -149,7 +146,7 @@
    3.34  	if(!(pgdir[diridx] & PG_PRESENT)) {
    3.35  		goto err;
    3.36  	}
    3.37 -	pgtbl = (uint32_t*)(pgdir[diridx] & ADDR_PGENT_MASK);
    3.38 +	pgtbl = PGTBL(diridx);
    3.39  
    3.40  	if(!(pgtbl[pgidx] & PG_PRESENT)) {
    3.41  		goto err;
    3.42 @@ -168,18 +165,9 @@
    3.43  int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr)
    3.44  {
    3.45  	int i, phys_pg;
    3.46 -	uint32_t paddr;
    3.47  
    3.48  	for(i=0; i<pgcount; i++) {
    3.49 -		if(ppg_start < 0) {
    3.50 -			if(!(paddr = alloc_phys_page())) {
    3.51 -				return -1;
    3.52 -			}
    3.53 -			phys_pg = ADDR_TO_PAGE(paddr);
    3.54 -		} else {
    3.55 -			phys_pg = ppg_start + i;
    3.56 -		}
    3.57 -
    3.58 +		phys_pg = ppg_start < 0 ? -1 : ppg_start + i;
    3.59  		map_page(vpg_start + i, phys_pg, attr);
    3.60  	}
    3.61  	return 0;
    3.62 @@ -212,7 +200,7 @@
    3.63  	if(!(pgdir[diridx] & PG_PRESENT)) {
    3.64  		panic("virt_to_phys(%x): page table %d not present\n", vaddr, diridx);
    3.65  	}
    3.66 -	pgtbl = (uint32_t*)(pgdir[diridx] & PGENT_ADDR_MASK);
    3.67 +	pgtbl = PGTBL(diridx);
    3.68  
    3.69  	if(!(pgtbl[pgidx] & PG_PRESENT)) {
    3.70  		panic("virt_to_phys(%x): page %d not present\n", vaddr, ADDR_TO_PAGE(vaddr));
    3.71 @@ -271,12 +259,19 @@
    3.72  
    3.73  void pgfree(int start, int num)
    3.74  {
    3.75 -	int area, end, intr_state;
    3.76 +	int i, area, end, intr_state;
    3.77  	struct page_range *node, *new, *prev, *next;
    3.78  
    3.79  	intr_state = get_intr_state();
    3.80  	disable_intr();
    3.81  
    3.82 +	for(i=0; i<num; i++) {
    3.83 +		uint32_t phys = virt_to_phys(PAGE_TO_ADDR(start + i));
    3.84 +		if(phys) {
    3.85 +			free_phys_page(ADDR_TO_PAGE(phys));
    3.86 +		}
    3.87 +	}
    3.88 +
    3.89  	if(!(new = alloc_node())) {
    3.90  		panic("pgfree: can't allocate new page_range node to add the freed pages\n");
    3.91  	}
     4.1 --- a/src/vm.h	Wed Apr 06 07:42:44 2011 +0300
     4.2 +++ b/src/vm.h	Sat Apr 09 07:14:06 2011 +0300
     4.3 @@ -35,7 +35,7 @@
     4.4  #define PAGE_TO_PGTBL_PG(x)		((uint32_t)(x) & 0x3ff)
     4.5  
     4.6  
     4.7 -void init_vm(struct mboot_info *mb);
     4.8 +void init_vm(void);
     4.9  
    4.10  int map_page(int vpage, int ppage, unsigned int attr);
    4.11  int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);