I'm currently working on paging code in my OS. I've read "setting up paging" & James'm "Paging" tutorials.
When I'm using code form these tutorials I have following problems:
1. When I write data to CR3 I get "assignment makes integer from pointer without a cast" error. (I use -Wextra - Werror flags) How can I fix that? [solved]
2. When I set CR0 my emulator crashes (It happened on qemu, vmware and virtualbox. I've tried to run my OS (*.iso file) on bochs but I got "invalid image file" error). [solved] Why is this happenning?
And I've got few questions:
1.I saw that many people use end symbol definied in the linker. My kernel ends at 0x1078c4 and I've got one module loaded at 0x109000 ending at 0x109257. According to mbi at 0x108000 there is kernel elf section table. When I use code form james'm tutorial my "heap" starts after kernel end. Is page_directory colliding with my module and elf section. Is this causing these errors? Where should I put my page_directory?
2. For what reason people use mmap in their mm? Is this used for skipping some importand data in page table?
Here is code based on "setting paging tutorial" which I use:
Code: Select all
void init_paging()
{
unsigned int *page_directory = (unsigned int*) 0x9C000;
unsigned int *first_page_table = page_directory + 1024;
int i = 0;
for(i = 0; i < 1024; i++)
{
page_directory[i] = 0 | 2;
}
unsigned int address = 0;
unsigned int j;
for(j = 0; j < 1024; j++)
{
first_page_table[j] = address | 3;
address = address + 4096;
}
page_directory[0] = first_page_table;
page_directory[0] |= 3;
asm ("mov %0, %%cr3":: "b"(page_directory));
unsigned int cr0;
asm ("mov %%cr0, %0": "=b"(cr0));
cr0 |= 0x80000000;
asm ("mov %0, %%cr0":: "b"(cr0));
}
Wojciech Różowski