init paging problem
Posted: Thu Oct 20, 2005 4:45 am
I read ImplementBasicPaging tutorial and write this code. But weird things happen, Im going to be mad. I map 1-1 virtual-physical memory.
When I check last value of t it is 3 not 1024... And last value of i is also 1010.
I think Im misused some pointers but I couldnt find.
What is wrong with this code, please help..
Code: Select all
void InitPaging(void)
{
unsigned long *PageDirectory = (unsigned long *) 0x9C000;
unsigned long *PageTable = (unsigned long *) 0x9D000;
unsigned long Address=0;
unsigned int i,t;
for(t=0; t<1024; t++) {
for(i=0; i<1024; i++) {
PageTable[i] = Address | PTE_SUPERVISOR | PTE_READWRITE | PTE_PRESENT;
Address += 4096; // 4096 = 4kb
}
(unsigned long*)PageDirectory[t] = (unsigned long*)PageTable;
PageDirectory[t] = PageDirectory[t] | PDE_SUPERVISOR | PDE_READWRITE | PDE_PRESENT;
PageTable += 4096;
}
WriteCR3((unsigned int)PageDirectory);
WriteCR0(ReadCR0() | 0x80000000);
}
I think Im misused some pointers but I couldnt find.
What is wrong with this code, please help..