Help with paging
Help with paging
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 ???
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
Here is my C function
-------------------------------
Here is my assembler code
---------------------------------
-------------------------------
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
}
---------------------------------
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
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Help with paging
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 ?
Is this the case for you ?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Help with paging
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
Allright, fount out how to write the cr2 value but now is the interrupt handler i silent >:(
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Help with paging
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
I use this bootloader http://www.osdever.net/downloads/bootse ... ootf02.zip by John Fine
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Help with paging
according to the "read.me"
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 ...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