1, to set page dir[0], it is because when in protected mode,
a)whether paging enabled or not ,the cpu always use CS:EIP to look for the physical address,
which is cs->baseaddress + eip(the offset from baseaddr) ,
this is linear address, when paging is diabled, it's also the physical address.
b)when paging enabled, there is one more translation step,which use the page table to translate the linear address to physical address.
consider the code below:
Code: Select all
__asm__ volatile ( "mov %0, %%eax\n"
"mov %%eax, %%cr3\n"
"mov %%cr0, %%eax\n"
"orl $0x80000000, %%eax\n"
"mov %%eax, %%cr0\n" :: "m" (kernelpagedirPtr));
assume the CS:EIP is 08:0xc01000xx,
if page dir[0] is not set,
08->baseaddress = 0x40000000;
the linear address of EIP:08->baseaddress+0xc01000xx = 0x001000xx.
now the next translation step is to look for the page table dir, it would fail.
the same reason can explain why page dir[768] must be set.
look at the gdt_flush call.
in this call, there is a jmp,
Code: Select all
c01002f4 <gdt_flush>:
c01002f4: 0f 01 15 00 40 10 c0 lgdtl 0xc0104000
c01002fb: 66 b8 10 00 mov $0x10,%ax
c01002ff: 8e d8 movl %eax,%ds
c0100301: 8e c0 movl %eax,%es
c0100303: 8e e0 movl %eax,%fs
c0100305: 8e e8 movl %eax,%gs
c0100307: 8e d0 movl %eax,%ss
c0100309: ea 10 03 10 c0 08 00 ljmp $0x8,$0xc0100310
so ljmp 8:0xc0100310, would be translated as
8->baseaddress = 0;
0+0xc0100310 = 0xc0100310,
if there was no matched page dir ,this address 0xc0100310 would not be translated into physical address.
that's all.
hope my english can be understood by you all.
thanks you all anyway.