Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
after setting up gdt, idt, irs's, irq's and the pit I wanted to turn to memory managment and have chosen to use paging (as is supposed to be the easiest one).
I create the pagingTable and directory. But as soon as i enable it, bochs just restarts.
#include <Paging.h>
#include <Printing.h>
unsigned int *page_directory;
unsigned int *page_table;
extern int __KERNEL_END;
extern void enablePaging();
void paging_install()
{
//the paging directory is just behind the kernel
page_directory = (unsigned int *) __KERNEL_END;
//the first paging directory (this means for the first 4mb for memory) is right behind the paging directory
page_table = (unsigned int *) __KERNEL_END + 0x01000;
//now we fill the table
int i;
int adress = 0;
for(i = 0; i < 1024; i++)
{
page_table[i] = adress | 3; //Attributes: supervisor, read/write, present
adress += 0x01000; //0x01000 = 4096 = 4kb
}
//at the table to the directory
page_directory[0] = (int)page_table;
page_directory[0] |= 3; //Attributes: supervisor, read/write, present
//fill the rest of the tables in the directory with non-present flags
for(i = 0; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
//
//finally enable and start paging
//
//load the page directory pointer
__asm__ __volatile__("mov %0, %%cr3":: "b"(page_directory));
//now start it!
//enablePaging();
}
In paging_install you first set page_directory[0] to point to your page table after which you clear it in the following loop. This will invalidate your first page table and will crash.
If the error occurs again, post your bochs crash log (last few lines only please).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
page_directory = (unsigned int *) __KERNEL_END;
//the first paging directory (this means for the first 4mb for memory) is right behind the paging directory
page_table = (unsigned int *) __KERNEL_END + 0x01000;
is the __KERNEL_END aligned to 4k? if not ,try (__KERNEL_END+0xfff)&0xfffff000
//fill the rest of the tables in the directory with non-present flags
for(i = 0; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
why is "i" start at 0 and never used? you have cleaned the first entry.
unsigned int *page_directory;
unsigned int *page_table;
extern int __KERNEL_END;
extern void enablePaging();
void paging_install()
{
[b]int temp = (__KERNEL_END + 0X0fff) & 0x0fffff000;
//the paging directory is just behind the kernel
page_directory = (unsigned int *) temp;
//the first paging directory (this means for the first 4mb for memory) is right behind the paging directory
page_table = (unsigned int *) temp + 0x01000;[/b]
//now we fill the table
int i;
int adress = 0;
for(i = 0; i < 1024; i++)
{
page_table[i] = adress | 3; //Attributes: supervisor, read/write, present
adress += 0x01000; //0x01000 = 4096 = 4kb
}
//at the table to the directory
page_directory[0] = (int)page_table;
page_directory[0] |= 3; //Attributes: supervisor, read/write, present
//fill the rest of the tables in the directory with non-present flags
for([b]i = 1[/b]; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
//
//finally enable and start paging
//
//load the page directory pointer
__asm__ __volatile__("mov %0, %%cr3":: "b"(page_directory));
//now start it!
enablePaging();
}
Every human has to do something idiot to prevent becoming a complete one
//fill the rest of the tables in the directory with non-present flags
for([b]i = 1[/b]; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
you changed the loop,but not "page_directory[0] " ,OK?
it should be "page_directory " ,right?
Even the compiler could have told you about this bug. If you want to save yourself some work, have the compiler enforce proper coding practices. (pass -Wall -Wextra -Werror -pedantic on the command line)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
//fill the rest of the tables in the directory with non-present flags
for([b]i = 1[/b]; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
you changed the loop,but not "page_directory[0] " ,OK?
it should be "page_directory " ,right?