page directory and page table.

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
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

page directory and page table.

Post by huxuelei »

Hi, I want to put my page directory and page table near the end of my kernel.I get the start address of the page directory like this:

Code: Select all

extern int end;
int base  = (int)&end;

void enablepage()
{

	if (base & 0xFFFFF000)
	{
		base &= 0xFFFFF000;
		base += 0x1000;
	}

	pageDirectory = (unsigned int*)base;
	pageTable = (unsigned int*)(base + 0x1000);

        initializepage();
}
At this time, when i enable the paging, i got the follow information in boch:

Code: Select all

00033080153i[CPU0 ] EFER   = 0x00000000
00033080153i[CPU0 ] | RAX=0000000080000011  RBX=000000000002d000
00033080153i[CPU0 ] | RCX=00000000000b8000  RDX=000000000011efc4
00033080153i[CPU0 ] | RSP=0000000000067e38  RBP=0000000000067e38
00033080153i[CPU0 ] | RSI=0000000000053c8e  RDI=0000000000053c8f
00033080153i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00033080153i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00033080153i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00033080153i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00033080153i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00033080153i[CPU0 ] | SEG selector     base    limit G D
00033080153i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00033080153i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00033080153i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00033080153i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00033080153i[CPU0 ] | RIP=00000000001042ee (00000000001042ee)
00033080153i[CPU0 ] | CR0=0x80000011 CR1=0x0 CR2=0x00000000001064c0
00033080153i[CPU0 ] | CR3=0x00200000 CR4=0x00000000
00033080153i[CPU0 ] (instruction unavailable) page not present
00033080153e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
but if i change my code to this:

Code: Select all

void enablepage()
{

	pageDirectory = (unsigned int*)0x200000;
	pageTable = (unsigned int*)(0x200000 + 0x1000);

        initializepage();
}
everything is fine.no any error happend when i enable the paging.


I remembered someone told me i can put the page directory and page table at any place in the available memory.
could someone tell me what's wrong with my code?
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: page directory and page table.

Post by itisiuk »

It wasnt page alianged by the looks of it.

i.e.
page 1 is at 0x0000
page 2 is at 0x1000
e.t.c

the end of your kernel is probably for example 0x12345
so your page directory should be stored at 0x13000 not 0x12345
Post Reply