Code: Select all
#define MEMORY_SIZE 128
unsigned ptablepool1[1024+1024];
unsigned ptablepool2[MEMORY_SIZE/4 * 1024];
unsigned* optable;
unsigned* iptable[MEMORY_SIZE/4];
void paging_init(void)
{ //outter page table set up
int j;
unsigned i; //page aligned pointer
i = (unsigned) ptablepool1;
i += 4096;
i &= ~4095;
optable = (unsigned*) i; //optable now points to i
//inner page table set up
i = (unsigned) ptablepool2;
i += 4096;
i &= ~4095;
for(j=0;j<(MEMORY_SIZE/4);++j,i+=4096)
iptable[j]=(unsigned*)i;
for(i=0;i<1023;i++){
if(i>= MEMORY_SIZE/4){
//address past end of RAM
optable[i]=0; //present bit to 0
}
else{ //make outer point to inner
unsigned p = (unsigned) iptable[i];
p |= 3; //set W and P to 1
optable[i] = p; //optable[i] points to inner table i
//***********Fill inner page table
for(j=0;j<1024;++j){
p = i*1024+j; //frame number
p <<=12; //move to upper 20 bits
p |= 3; //set w and p bits
iptable[i][j] = p;
}
}
}
i = (unsigned) optable; //activate paging
asm volatile ("mov %%eax,%%cr3\n"
"mov %%cr0,%%eax\n"
"or $0x80000000,%%eax\n"
"mov %%eax,%%cr0\n"
"jmp flushqueue\n"
"flushqueue:\n"
"nop" : "+a" (i) );
}
Code: Select all
kprintf("%d at iteration %d\n", iptable[i], i);
kprintf("%d at iteration %d\n", optable[i], i);
if(i == 1022)
halt();
Help/Tips/Etc. are greatly appreciated.
--Troubled Dev