Page 2 of 2

Re:Initializing paging not working, what have I forgotten?

Posted: Tue Jan 27, 2004 9:24 am
by Pype.Clicker
there's something that sounds concerning with the content you put in the page table.

you'll have PTE[0]=0x102003, PTE[1]=0x103003, PTE[2]=0x104003, etc, right ?

now the question is what do you have on those physical pages ? will you be happy if virtual address 0x00000xxx are mapped to 0x00102xxx ?

Another concern is where does your VM_pages() function reside ? and your stack ? will those still be mapped correctly once the paging will be activated ??

i would have rather expected something like PTE[0x100]=0x100003, PTE[0x101]=0x101003, etc.

imho, the best help you can give yourself is pick a blank sheet and draw your mapping, checking your code could stand it ...

Re:Initializing paging not working, what have I forgotten?

Posted: Tue Jan 27, 2004 11:29 am
by frank
now the question is what do you have on those physical pages
Afaik nothing, unless an old task used the memory and is still in there?
( I don't know if the memory gets cleared after a reboot? )
Should I zero it?
will you be happy if virtual address 0x00000xxx are mapped to 0x00102xxx ?
hmm I think I should keep it simple and stupid 'till it works.

Btw, I looked up a memory map and noticed the EBDA (Extended Bios Data Area), can I overwrite this or will I need this later in os development?
Will the BIOS/Cpu write data in here later?
Another concern is where does your VM_pages() function reside and your stack ? will those still be mapped correctly once the paging will be activated ??
main -> VM_Init -> VM_Probe_Size (this function works) -> VM_pages.
The function is located somewhere after 0x102000.. (kernel start)

My stack is located at 0x1000 - 0x2000

Code: Select all

MEMORY 
{
   stack : org = 0x00001000, len = 0x00002000
}

Re:Initializing paging not working, what have I forgotten?

Posted: Tue Jan 27, 2004 4:31 pm
by Pype.Clicker
so the bootloader put your kernel from at the physical 0x00100000 .. 0x00123000 (for instance), right ? but when you activate paging, you start with virtual 0x00000000 => physical 0x00102000, so the virtual 0x00100000 will be pointing to 0x00202000, which will make your kernel suddenly move away and when you'll try to find the next instruction or the return address on the stack, they're no longer there.

So the processor will do something wrong and complain with a #PF, a #GP or something else, but your GDT and IDT have displaced aswell (remember: the content of xDTR is not translated by the segmentation unit, but it *is* translated by paging ...), so you got Double Fault and Tripple Fault ...

I would start with a 1:1 mapping as a start, if i were you ...

Re:Initializing paging not working, what have I forgotten?

Posted: Wed Jan 28, 2004 5:25 am
by frank
Hmm it does not crash :o ;D
Haven't re-set the gdt yet though
(Grub had set the gdt for me, I'm using grub 'cause I was working too much around without it. I had written a gdt though and some other things though (that is somewhere in 2002, still have the code))

Btw, can I use the EBDA (Extended Bios Data Area) as free memory?
( 9FC00- 9FFFF )
Or will I need this later?

Code: Select all


void VM_Pages()
{
   unsigned int * mem;
   unsigned int i = 0;

   // Page Directory Start
   mem = (unsigned int *) 0x9A000;                                          
   
   // Make the Page Directory Entries, set their address
   // Also set them as non-present   
   for (i=0; i<1024; i++)                                          
   {
      mem[i] = (0x9B000 + (i*4));
      mem[i] = mem[i]   | 2; 
   }
   
   // use this entry
   mem[0] = mem[0] | 3;         
   
   // Page Table start is at 0x9B000
   mem = (unsigned int *) 0x9B000;                                          
   for (i=0; i<1024; i++)                                                            
   {
      mem[i] = (i*4096);
      mem[i] = mem[i] | 3;      
   }
            
   asm volatile("movl $0x9A000,%eax;" \
                       "movl %eax,%cr3;" \
                     "movl %cr0,%eax;" \
                     "addl $0x80000000,%eax;" \
                     "movl %eax,%cr0");                                             
}



Thanks all!

Re:Initializing paging not working, what have I forgotten?

Posted: Wed Jan 28, 2004 8:00 am
by Pype.Clicker
about EBDA ... Do you need those 1KB *that hard*? ... if you know it's here (by the mean of BIOS memory map, for instance), can't you just leave it there ... personnally, i dunno what's in the EBDA, but if there's for instance things related to VBE, you'll find yourself in trouble later ... If it's just about disk/netbios/whatever, you probably won't need it.