From: John Hodge Date: Mon, 17 May 2010 15:03:17 +0000 (+0800) Subject: Working on mem management X-Git-Tag: rel0.06~185 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d80e25f1971c283a2fdcfa96a1f51a5039f2a30a;p=tpg%2Facess2.git Working on mem management --- diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index 985fa844..19bf72f4 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -12,18 +12,20 @@ #define PDIR_SHIFT 21 #define PTAB_SHIFT 12 +#define PADDR_MASK 0x7FFFFFFF##FFFFF000 + #define PF_PRESENT 0x1 #define PF_WRITE 0x2 #define PF_USER 0x4 -#define PF_NX 0x80000000##00000000 #define PF_COW 0x200 #define PF_PAGED 0x400 +#define PF_NX 0x80000000##00000000 // === MACROS === #define PAGETABLE(idx) (*((tPAddr*)MM_FRACTAL_BASE+(idx))) #define PAGEDIR(idx) PAGETABLE((MM_FRACTAL_BASE>>12)+((idx)&0x7FFFFFF)) -#define PAGEDIRPTR(idx) PAGETABLE((MM_FRACTAL_BASE>>21)+((idx)&0x3FFFF)) -#define PAGEMAPLVL4(idx) PAGETABLE((MM_FRACTAL_BASE>>30)+((idx)&0x1FF)) +#define PAGEDIRPTR(idx) PAGEDIR((MM_FRACTAL_BASE>>21)+((idx)&0x3FFFF)) +#define PAGEMAPLVL4(idx) PAGEDIRPTR((MM_FRACTAL_BASE>>30)+((idx)&0x1FF)) // === GLOBALS === @@ -76,6 +78,9 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr) return 1; } +/** + * \brief Removed a mapped page + */ void MM_Unmap(tVAddr VAddr) { // Check PML4 @@ -282,3 +287,56 @@ tPAddr MM_Clone(void) // #4 Return return 0; } + +void MM_ClearUser(void) +{ + tVAddr addr = 0; + // #1 Traverse the structure < 2^47, Deref'ing all pages + // #2 Free tables/dirs/pdps once they have been cleared + + for( addr = 0; addr < 0x800000000000; ) + { + if( PAGEMAPLVL4(addr >> PML4_SHIFT) & 1 ) + { + if( PAGEDIRPTR(addr >> PDP_SHIFT) & 1 ) + { + if( PAGEDIR(addr >> PDIR_SHIFT) & 1 ) + { + // Page + if( PAGETABLE(addr >> PTAB_SHIFT) & 1 ) { + MM_DerefPhys( PAGETABLE(addr >> PTAB_SHIFT) & PADDR_MASK ); + PAGETABLE(addr >> PTAB_SHIFT) = 0; + } + addr += 1 << PTAB_SHIFT; + // Dereference the PDIR Entry + if( (addr + (1 << PTAB_SHIFT)) >> PDIR_SHIFT != (addr >> PDIR_SHIFT) ) { + MM_DerefPhys( PAGEMAPLVL4(addr >> PDIR_SHIFT) & PADDR_MASK ); + PAGEDIR(addr >> PDIR_SHIFT) = 0; + } + } + else { + addr += 1 << PDIR_SHIFT; + continue; + } + // Dereference the PDP Entry + if( (addr + (1 << PDIR_SHIFT)) >> PDP_SHIFT != (addr >> PDP_SHIFT) ) { + MM_DerefPhys( PAGEMAPLVL4(addr >> PDP_SHIFT) & PADDR_MASK ); + PAGEDIRPTR(addr >> PDP_SHIFT) = 0; + } + } + else { + addr += 1 << PDP_SHIFT; + continue; + } + // Dereference the PML4 Entry + if( (addr + (1 << PDP_SHIFT)) >> PML4_SHIFT != (addr >> PML4_SHIFT) ) { + MM_DerefPhys( PAGEMAPLVL4(addr >> PML4_SHIFT) & PADDR_MASK ); + PAGEMAPLVL4(addr >> PML4_SHIFT) = 0; + } + } + else { + addr += (tVAddr)1 << PML4_SHIFT; + continue; + } + } +} diff --git a/Makefile.cfg b/Makefile.cfg index 405a4fcb..3c8e9f6d 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -33,7 +33,7 @@ FILESYSTEMS := DRIVERS := MODULES := Storage/ATA Storage/FDD MODULES += Network/NE2000 -MODULES += Display/VESA +#MODULES += Display/VESA MODULES += Display/BochsGA MODULES += Filesystems/Ext2 MODULES += Filesystems/FAT