Problem when 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
kshitijburman
Posts: 2
Joined: Mon Jul 21, 2014 12:35 pm

Problem when enabling paging

Post by kshitijburman »

Ok i give up i thought that paging would be easy.
I have tried sevral method but none of them worked. :cry:
here is my code i will be really thankfull to you if you can figure out what i am missing
paging.c

Code: Select all

u32int *kernel_dir;
u32int *first_table;
extern void enablePaging();

void init_paging()
{
	int i,address;
	
	kernel_dir = (u32int*)alloc_block();
	first_table= (u32int*)alloc_block();
	
	putint(kernel_dir);putchar('\n');
	putint(first_table);putchar('\n');
	
	memset((u8int*)kernel_dir,0,4096);
	memset((u8int*)first_table,0,4096);
	
	for(i=0;i<1024;i++)
	{
		kernel_dir[i] = 0 | 2;
	}
	address = 0;
	for(i=0;i<1024;i++)
	{
		first_table[i] = address | 3;
		address = address + 4096;
	}	
	
	kernel_dir[0] = first_table;
	kernel_dir[0] |= 3;
	
   //switch_page_directory(kernel_dir);
   enablePaging();
}
paging.asm

Code: Select all

global enablePaging
extern kernel_dir
enablePaging:
	mov eax,[kernel_dir]
	mov cr3,eax
	
	mov eax,cr0
	or eax,0x80000000
	mov cr0,eax
	mov eax,[kernel_dir]
	nop
	ret
Bochsout.txt

Code: Select all

Booting from 07c0:0000
00050847509i[CPU0 ] CPU is in protected mode (active)
00050847509i[CPU0 ] CS.d_b = 32 bit
00050847509i[CPU0 ] SS.d_b = 32 bit
00050847509i[CPU0 ] EFER   = 0x00000000
00050847509i[CPU0 ] | RAX=0000000000108000  RBX=0000000000002000
00050847509i[CPU0 ] | RCX=00000000003ff003  RDX=0000000000109000
00050847509i[CPU0 ] | RSP=00000000013eff94  RBP=0000000000000000
00050847509i[CPU0 ] | RSI=0000000000000000  RDI=0000000000000000
00050847509i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00050847509i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00050847509i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00050847509i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00050847509i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af pf cf
00050847509i[CPU0 ] | SEG selector     base    limit G D
00050847509i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00050847509i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00050847509i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00050847509i[CPU0 ] | RIP=0000000000101d09 (0000000000101d09)
00050847509i[CPU0 ] | CR0=0xe0000013 CR2=0x00000000013eff90
00050847509i[CPU0 ] | CR3=0x00108000 CR4=0x00000000
00050847509i[CPU0 ] 0x0000000000101d09>> ret  : C3
00050847509p[CPU0 ] >>PANIC<< exception(): 3rd (14) exception with no resolution
and one thing i have tried inline asm also but comes with same error.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Problem when enabling paging

Post by Candy »

Looks like you're enabling 32-bit non-PAE paging with an identity-mapped bottom 4M and nothing else mapped. I don't immediately see anything wrong with it honestly...

[edit] No wait, I do see it. Your stack is at about 20MB, which is way above the 4M you have mapped. Map more space or move your stack.
kshitijburman
Posts: 2
Joined: Mon Jul 21, 2014 12:35 pm

Re: Problem when enabling paging

Post by kshitijburman »

Candy wrote: Your stack is at about 20MB, which is way above the 4M you have mapped. Map more space or move your stack.
Thanks a lot=D>
After a little investigation i have figured out the problem.
before

Code: Select all

 
boot:
   ;mov esp, _sys_stack 
   call  main
after your suggestion i have corrected it

Code: Select all

 
boot:
   mov esp, _sys_stack 
   call  main
i still can't belive how can i miss it.#-o
Post Reply