31 lines
816 B
C
31 lines
816 B
C
![]() |
#include "paging.h"
|
||
|
|
||
|
void paging_enable(){
|
||
|
int *page_dir=(int*)PAGING_DIR_LOCATION;
|
||
|
int *page_table=(int*)PAGING_TABLE_LOCATION;
|
||
|
|
||
|
// Init page directory
|
||
|
for(int i=0;i<1024;i++)
|
||
|
page_dir[i]=0;
|
||
|
page_dir[0]=(int)page_table;
|
||
|
page_dir[0] |=7; // Permissions
|
||
|
|
||
|
// Init page table 0
|
||
|
int addr_offset=0;
|
||
|
for(int i=0;i<1024;i++){
|
||
|
page_table[i]=addr_offset;
|
||
|
page_table[i]|=7; // Permission
|
||
|
addr_offset+=4096; // 4Ko pages
|
||
|
}
|
||
|
|
||
|
// Turns on paging
|
||
|
asm(
|
||
|
"movl %0, %%eax \n\t"
|
||
|
"movl %%eax, %%cr3 \n\t" // Configure page table location
|
||
|
"movl %%cr0, %%eax \n\t"
|
||
|
"orl %1, %%eax \n\t"
|
||
|
"movl %%eax, %%cr0 \n\t" // Turn on paging
|
||
|
:: "i" (PAGING_DIR_LOCATION), "i" (PAGING_CR0_BIT)
|
||
|
);
|
||
|
|
||
|
}
|