Update paging system
This commit is contained in:
parent
f37f5d86b7
commit
717556178c
3 changed files with 34 additions and 23 deletions
|
@ -58,6 +58,5 @@ extern "C" void boucane(u64 mb_info){
|
|||
// Booting!
|
||||
printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH);
|
||||
|
||||
|
||||
while(1);
|
||||
}
|
|
@ -136,7 +136,7 @@ void paging_deallocate_table(u64* table){
|
|||
}
|
||||
}
|
||||
|
||||
void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
|
||||
void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options, char useKernelTables){
|
||||
u16 pml4=virt>>39&0x1FF;
|
||||
u16 pdp=virt>>30&0x1FF;
|
||||
u16 pd=virt>>21&0x1FF;
|
||||
|
@ -145,29 +145,30 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
|
|||
|
||||
// Solve pdp
|
||||
if(pml4_table[pml4] == 0){
|
||||
pml4_table[pml4]=(u64)paging_allocate_table();
|
||||
pml4_table[pml4]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pml4_table[pml4]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve pd
|
||||
u64* pdp_table=(u64*)(VIRT(PAGE(pml4_table[pml4])));
|
||||
if(pdp_table[pdp] == 0){
|
||||
pdp_table[pdp]=(u64)paging_allocate_table();
|
||||
pdp_table[pdp]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options);
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve pd
|
||||
u64* pdp_table=(u64*)(VIRT(PAGE(pml4_table[pml4])));
|
||||
if(pdp_table[pdp] == 0){
|
||||
pdp_table[pdp]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pdp_table[pdp]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve pt
|
||||
u64* pd_table=(u64*)(VIRT(PAGE(pdp_table[pdp])));
|
||||
if(pd_table[pd] == 0){
|
||||
pd_table[pd]=(u64)paging_allocate_table();
|
||||
pd_table[pd]=(u64)(useKernelTables ? paging_allocate_table() : VIRT(PAGE_ALLOCATE()));
|
||||
pd_table[pd]|=options;
|
||||
paging_allocate_addr(pml4_table,virt,phy,options);
|
||||
paging_allocate_addr(pml4_table,virt,phy,options,useKernelTables);
|
||||
return;
|
||||
}
|
||||
|
||||
// Solve address
|
||||
u64* pt_table=(u64*)(VIRT(PAGE(pd_table[pd])));
|
||||
if(pt_table[pt] == 0){
|
||||
|
@ -175,4 +176,12 @@ void paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 options){
|
|||
pt_table[pt]|=options;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u64* paging_create_task(int npages){
|
||||
u64 *pml4=VIRT(PAGE_ALLOCATE());
|
||||
u64 sum=(u64)pml4+kvar_kernel_vma;
|
||||
paging_allocate_addr(pml4, 0, (u64)PAGE_ALLOCATE(), PAGING_OPT_P|PAGING_OPT_RW, 0);
|
||||
return pml4;
|
||||
}
|
|
@ -19,23 +19,23 @@
|
|||
|
||||
/// @brief Get page address that contain addr
|
||||
#define PAGE(addr) (addr&(~(0xFFF)))
|
||||
#define VIRT(addr) (addr+kvar_kernel_vma)
|
||||
#define VIRT(addr) ((u64*)(((u64)addr)+kvar_kernel_vma))
|
||||
|
||||
/// @brief Mapping facilities
|
||||
#define PAGE_ID_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW)
|
||||
#define PAGE_ID_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,1)
|
||||
#define PAGE_ID_RMAP(addr, n) { \
|
||||
for(u64 i=0;i<(n);i+=4096){ \
|
||||
paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW); \
|
||||
paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,1); \
|
||||
}}
|
||||
#define PAGE_MAP(addr) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW)
|
||||
#define PAGE_MAP(addr) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,1)
|
||||
#define PAGE_RMAP(addr, n) { \
|
||||
for(u64 i=0;i<(n);i+=4096){ \
|
||||
paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW); \
|
||||
paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,1); \
|
||||
}}
|
||||
#define PAGE_MAP_PHY(addr,phy) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(phy),PAGING_OPT_P|PAGING_OPT_RW)
|
||||
#define PAGE_MAP_PHY(addr,phy) paging_allocate_addr(kpages[0],(u64)((addr)+kvar_kernel_vma),(u64)(phy),PAGING_OPT_P|PAGING_OPT_RW,1)
|
||||
#define PAGE_RMAP_PHY(addr,phy, n) { \
|
||||
for(u64 i=0;i<(n);i+=4096){ \
|
||||
paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(phy))+i,PAGING_OPT_P|PAGING_OPT_RW); \
|
||||
paging_allocate_addr(kpages[0],(((u64)(addr))+kvar_kernel_vma)+i,((u64)(phy))+i,PAGING_OPT_P|PAGING_OPT_RW,1); \
|
||||
}}
|
||||
|
||||
/// @brief All PAE table structures are allocated here
|
||||
|
@ -80,4 +80,7 @@ void paging_deallocate_table(u64* table);
|
|||
* Map virtual page associated to virt
|
||||
* to the physical page associated with phy
|
||||
*/
|
||||
void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options);
|
||||
void paging_allocate_addr(u64* pml4_table,u64 virt, u64 phy, u16 options, char useKernelTables);
|
||||
|
||||
|
||||
u64* paging_create_task(int npages);
|
Loading…
Add table
Reference in a new issue