Page 1 of 1
Help with paging
Posted: Thu Dec 30, 2004 4:38 am
by Zity
Hello..
I tries to enable paging in my os, but i doesn't work. When i try to enable it, restart my computer.
I used this tutorial
http://osdever.net/tutorials/paging.php?the_id=43
I get no error the pc just restart and I have no idea about whats wrong.
Hope Somebody can help ???
Re:Help with paging
Posted: Thu Dec 30, 2004 5:30 am
by bluecode
Can you give us some Code?
Re:Help with paging
Posted: Thu Dec 30, 2004 5:58 am
by Zity
Here is my C function
-------------------------------
Code: Select all
void enable_paging()
{
unsigned long *page_directory = (unsigned long *) 0x9C000;
unsigned long *page_table = (unsigned long *) 0x9D000;
unsigned long address=0; // holds the physical address of where a page is
unsigned int i;
// map the first 4MB of memory
for(i=0; i<1024; i++)
{
page_table[i] = address | 3; // attribute set to: supervisor level, read/write, present(011 in binary)
address = address + 4096;
};
page_directory[0] = page_table; // HERE I GET THIS WARNING "warning: assignment makes integer from pointer without a cast"
page_directory[0] = page_directory[0] | 3;
for(i=1; i<1024; i++)
{
page_directory[i] = 0 | 2; // attribute set to: supervisor level, read/write, not present(010 in binary)
};
write_cr3(page_directory); // put that page directory address into CR3
write_cr0(read_cr0() | 0x80000000); // set the paging bit in CR0 to 1
}
Here is my assembler code
---------------------------------
Code: Select all
[global _read_cr0]
_read_cr0:
mov eax, cr0
retn
[global _write_cr0]
_write_cr0:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov cr0, eax
pop ebp
retn
[global _read_cr3]
_read_cr3:
mov eax, cr3
retn
[global _write_cr3]
_write_cr3:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov cr3, eax
pop ebp
retn
Re:Help with paging
Posted: Thu Dec 30, 2004 6:18 am
by Pype.Clicker
That tutorial assumes your startup code, stack, IDT, GDT and stuff are all located below 4MB (physically speaking) and that code, data and stack segment are zero-based.
Is this the case for you ?
Re:Help with paging
Posted: Thu Dec 30, 2004 6:30 am
by Zity
Yes i think so...
Re:Help with paging
Posted: Thu Dec 30, 2004 7:03 am
by Zity
Now i get a "Page Fault" from my interrupts..
Re:Help with paging
Posted: Thu Dec 30, 2004 7:12 am
by Pype.Clicker
That's yet much better... if you can, try to make your handler print the value for CR2 and the return address (cs:eip) where the fault occured.
Re:Help with paging
Posted: Thu Dec 30, 2004 8:05 am
by Zity
Can't figure out how to do that :-[
Re:Help with paging
Posted: Thu Dec 30, 2004 8:17 am
by Zity
Allright, fount out how to write the cr2 value but now is the interrupt handler i silent >:(
Re:Help with paging
Posted: Thu Dec 30, 2004 8:33 am
by Pype.Clicker
in case of such error that disappear when the content of the code change, i suggest you make sure you put your *whole* kernel in memory ... What bootloader do you use ?
Re:Help with paging
Posted: Thu Dec 30, 2004 8:38 am
by Zity
Re:Help with paging
Posted: Thu Dec 30, 2004 10:34 am
by Pype.Clicker
according to the "read.me"
7) Reads the file (KERNEL.BIN) to RAM starting at physical 1Mb.
Builds two page tables and one page directory mapping:
a) The first 4Mb linear to the first 4Mb physical
b) Linear FF800000 (where all my protected mode images start) to physical
RAM starting at 1Mb
c) Self map the page directory to the end of linear memory
9) Switch to protected mode with paging turned on
10) JMP to KERNEL.BIN at linear FF800000
So the page table and directory *is already set up*. By reloading it (without mapping FF8xxxxx, you're making your kernel disappear from the virtual address space ...
Re:Help with paging
Posted: Fri Dec 31, 2004 1:31 am
by Zity
Hmm.. I'm just stupid sometimes.. ::)