problem enabling paging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

problem enabling paging

Post by dansmahajan »

I am not able to setup paging virtual machine terminates after executing this statement

Code: Select all

    __asm__ __volatile__("mov %0, %%cr0":: "r"(cr0));
below is a snippet from my virtual mem mngr

Code: Select all

bool switch_page_directory(page_directory_t *dir)
{
	if(!dir){puts("r u kidding me");
		return false;}
	current_directory = dir;
    __asm__ __volatile__("mov %0, %%cr3":: "r"(&dir->pde));puts("1");
    u32int cr0;
    __asm__ __volatile__("mov %%cr0, %0": "=r"(cr0));puts("2");
    cr0 |= 0x80000000; // Enable paging!
    __asm__ __volatile__("mov %0, %%cr0":: "r"(cr0));//puts("3");
	return true;
}
void initialize_virtual_mm()
{
	
	//default ptable
	page_table_t *ptable = (page_table_t *)alloc_frame();
	memset(ptable,0,sizeof(page_table_t));
	
	//ptable for mapping kernel to 3gb virtual addr
	page_table_t *ptable1 = (page_table_t *)alloc_frame();
	memset(ptable1,0,sizeof(page_table_t));
	
	pd_entry pde0=0x0;
	pd_entry_set_ptable(&pde0,(phys_addr)ptable);
	pd_entry_add_attrib(&pde0,PDE_PRESENT);
	pd_entry_add_attrib(&pde0,PDE_WRITABLE);
	
	u32int i,frame,virtual; //identity mapping the ist 4mb i.e allocating 1st ptable to kernel and BIOS stuff
	frame=i=0;
	
	for (i=0, frame=0x0, virtual=0x00000000; i<1024; i++, frame+=4096, virtual+=4096) {

 		//! create a new page
		pt_entry page=0;
		pt_entry_add_attrib (&page, PTE_PRESENT);
 		pt_entry_set_frame (&page, frame);

		//! ...and add it to the page table
		ptable->pte [PAGE_TABLE_INDEX (virtual) ] = page;
	}
	
	//mapping the kernel which is above 1mb to 3gb virtual
	for(i=0,frame=0x100000,virtual=0xc0000000;i<1024;i++,frame+=4096,virtual+=4096)
	{
		pt_entry pte=0;
		pt_entry_set_frame(&pte,frame);
		pt_entry_add_attrib(&pte,PTE_PRESENT);
		ptable1->pte[PAGE_TABLE_INDEX(virtual)] = pte;
	}
	
	kernel_directory = (page_directory_t *)alloc_frame();
	memset(kernel_directory,0,sizeof(page_directory_t));
	
	//mapping the ptable for 3gb virtual addr to its appropriate pde
	pd_entry* entry = &kernel_directory->pde [PAGE_DIR_INDEX (0xc0000000) ];
	pd_entry_add_attrib (entry, PDE_PRESENT);
	pd_entry_add_attrib (entry, PDE_WRITABLE);
	pd_entry_set_ptable (entry, (phys_addr)ptable1);
	//mapping the ptable for 0-4mb virtual addr to its appropriate pde
	pd_entry* entry2 = &kernel_directory->pde [PAGE_DIR_INDEX (0x00000000) ];
	puts("\nentry2 val: ");puthex((u32int)*entry2);
	pd_entry_add_attrib (entry2, PDE_PRESENT);
	pd_entry_add_attrib (entry2, PDE_WRITABLE);
	pd_entry_set_ptable (entry2, (phys_addr)ptable);
	
	isr_install_handler(14,page_fault);	
	switch_page_directory(kernel_directory);
}
i am not to able debug the problem.so what is the problem???
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: problem enabling paging

Post by bluemoon »

dansmahajan wrote:I am not able to setup paging virtual machine terminates after executing this statement
I suppose the VM terminated with some information.

By the way, your inline assembly code missed some clobber list which can cause all sort of funny things when you turn on optimizations.
Post Reply