Permalink
Browse files

add walk template to PageLevel struct and use implicit this pointer i…

…nstead of table parameter
  • Loading branch information...
1 parent 4faa268 commit 75a2e032b2a25bb96149f4f00bf444804a2af556 @wolfwood wolfwood committed Aug 13, 2011
Showing with 37 additions and 31 deletions.
  1. +7 −7 kernel/arch/x86_64/core/paging.d
  2. +30 −24 user/environment.d
@@ -161,7 +161,7 @@ static:
// page not present or privilege violation?
if((stack.errorCode & 1) == 0){
bool allocate;
- walk!(pageFaultHelper)(root, cr2, allocate);
+ root.walk!(pageFaultHelper)(cr2, allocate);
if(allocate){
return;
@@ -265,7 +265,7 @@ static:
return null;
addrFrag = cast(ulong)vAddr;
- walk!(mapSegmentHelper)(root, addrFrag, flags, success, segmentParent, newRootPhysAddr);
+ root.walk!(mapSegmentHelper)(addrFrag, flags, success, segmentParent, newRootPhysAddr);
getNextIndex(addrFrag, idx);
getNextIndex(addrFrag, idx);
@@ -341,9 +341,9 @@ public:
if(destination is null){ // our open, segment mapped from global space to destination address
T* segmentParent;
- walk!(mapSegmentHelper)(root, cast(ulong)location, flags, success, segmentParent, locationAddr);
+ root.walk!(mapSegmentHelper)(cast(ulong)location, flags, success, segmentParent, locationAddr);
}else{
- walk!(mapSegmentHelper)(root, getGlobalAddress(cast(ulong)destination), flags, success, globalSegmentParent, locationAddr);
+ root.walk!(mapSegmentHelper)(getGlobalAddress(cast(ulong)destination), flags, success, globalSegmentParent, locationAddr);
}
}else{
// verify destinationRoot is a valid root page table (or null for a local operation)
@@ -359,7 +359,7 @@ public:
switchAddressSpace(destinationRoot, oldRoot);
}
- walk!(mapSegmentHelper)(root, cast(ulong)destination, flags, success, segmentParent, locationAddr);
+ root.walk!(mapSegmentHelper)(cast(ulong)destination, flags, success, segmentParent, locationAddr);
if(destinationRoot !is null){
// Return to our old address space
@@ -383,15 +383,15 @@ public:
PhysicalAddress phys = PageAllocator.allocPage();
T* segmentParent;
- walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
+ root.walk!(mapSegmentHelper)(vAddr, flags, success, segmentParent, phys);
static if(T.level != 1){
// 'map' the segment into the Global Space
if(success && global){
PageLevel!(T.level -1)* globalSegmentParent;
success = false;
- walk!(mapSegmentHelper)(root, getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
+ root.walk!(mapSegmentHelper)(getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
}
}
View
@@ -117,8 +117,6 @@ template PageLevel(ushort L){
alias L level;
static if(L == 1){
- PageTableEntry!("primary")[512] entries;
-
void* physicalAddress(uint idx) {
if(!entries[idx].present){
return null;
@@ -144,9 +142,11 @@ template PageLevel(ushort L){
}
return cast(ubyte*)vAddr;
}
- }else{
- PageTableEntry!("secondary")[512] entries;
+ //private:
+ PageTableEntry!("primary")[512] entries;
+
+ }else{
PageLevel!(L-1)* getTable(uint idx) {
if (entries[idx].present == 0) {
return null;
@@ -204,6 +204,9 @@ template PageLevel(ushort L){
return cast(ubyte*)vAddr;
}
+
+ PageTableEntry!("secondary")[512] entries;
+
private:
PageLevel!(L-1)* calculateVirtualAddress(uint idx){
static if(L == 4){
@@ -221,6 +224,25 @@ template PageLevel(ushort L){
}
}
} // end static if
+
+
+ public:
+ template walk(alias U, S...){
+ void walk(ulong addr, ref S s){
+ ulong idx;
+
+ getNextIndex(addr, idx);
+
+ if(U(this, idx, s)){
+
+ static if(L != 1){
+ this.getTable(idx).walk!(U)(addr, s);
+ }
+ }
+ }
+ }
+
+
}
}
@@ -293,7 +315,7 @@ uint sizeToPageLevel(ulong size){
bool isValidAddress(ubyte* vAddr){
bool valid = true;
- walk!(isValidAddressHelper)(root, cast(ulong)vAddr, valid);
+ root.walk!(isValidAddressHelper)(cast(ulong)vAddr, valid);
return valid;
}
@@ -311,7 +333,7 @@ template isValidAddressHelper(T){
AccessMode modesForAddress(ubyte* vAddr){
AccessMode flags;
- walk!(modesForAddressHelper)(root, cast(ulong)vAddr, flags);
+ root.walk!(modesForAddressHelper)(cast(ulong)vAddr, flags);
return flags;
}
@@ -336,7 +358,7 @@ template getPhysicalAddressOfSegment(T){
PhysicalAddress physAddr;
T levelOfSegment;
- walk!(getPhysicalAddressOfSegmentHelper)(root, cast(AddressFragment)vAddr, physAddr, levelOfSegment);
+ root.walk!(getPhysicalAddressOfSegmentHelper)(cast(AddressFragment)vAddr, physAddr, levelOfSegment);
return physAddr;
}
@@ -361,7 +383,7 @@ template getPhysicalAddressOfSegmentHelper(T, U){
PhysicalAddress findPhysicalAddressOfSegment(ubyte* vAddr){
PhysicalAddress physAddr;
- walk!(findPhysicalAddressOfSegmentHelper)(root, cast(AddressFragment)vAddr, physAddr);
+ root.walk!(findPhysicalAddressOfSegmentHelper)(cast(AddressFragment)vAddr, physAddr);
return physAddr;
}
@@ -459,22 +481,6 @@ template preorderFindFreeSegmentHelper(T, PL){
}
// --- table manipulation templates ---
-template walk(alias U, T, S...){
- void walk(T table, ulong addr, ref S s){
- ulong idx;
-
- getNextIndex(addr, idx);
-
- if(U(table, idx, s)){
-
- static if(!(is (T == PageLevel!(1)*))){
- auto table2 = table.getTable(idx);
-
- walk!(U)(table2, addr, s);
- }
- }
- }
-}
template traverse(alias PRE, alias POST, T, S...){
bool traverse(T table, ulong startAddr, ulong endAddr, ref S s){

0 comments on commit 75a2e03

Please sign in to comment.