Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 3.15 KB | None | 0 0
  1. diff --git a/kernel/arch/x86_64/core/paging.d b/kernel/arch/x86_64/core/paging.d
  2. index a44df60..9e427da 100644
  3. --- a/kernel/arch/x86_64/core/paging.d
  4. +++ b/kernel/arch/x86_64/core/paging.d
  5. @@ -413,56 +413,23 @@ static:
  6.         return ErrorVal.Success;
  7.     }
  8.  
  9. -   bool createGib(ubyte* location, ulong size, AccessMode flags) {
  10. +   bool createSegment2(ubyte* location, ulong size, AccessMode flags) {
  11.         uint pagelevel = sizeToPageLevel(size);
  12.  
  13. -       bool global = (flags & AccessMode.Global) != 0;
  14. -
  15. -       ulong vAddr = cast(ulong)location;
  16.         bool success;
  17. -       PhysicalAddress phys = PageAllocator.allocPage();
  18.  
  19.         switch(pagelevel){
  20.         case 1:
  21. -           // create the segment in the AddressSpace
  22. -           PageLevel!(1)* segmentParent;
  23. -           walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
  24. +           success = createGib!(1)(location, flags);
  25.             break;
  26.         case 2:
  27. -           PageLevel!(2)* segmentParent;
  28. -           walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
  29. -
  30. -           // 'map' the segment into the Global Space
  31. -           if(success && global){
  32. -               PageLevel!(1)* globalSegmentParent;
  33. -               success = false;
  34. -
  35. -               walk!(mapSegmentHelper)(root, getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
  36. -           }
  37. +           success = createGib!(2)(location, flags);
  38.             break;
  39.         case 3:
  40. -           PageLevel!(3)* segmentParent;
  41. -           walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
  42. -
  43. -           // 'map' the segment into the Global Space
  44. -           if(success && global){
  45. -               PageLevel!(2)* globalSegmentParent;
  46. -               success = false;
  47. -
  48. -               walk!(mapSegmentHelper)(root, getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
  49. -           }
  50. +           success = createGib!(3)(location, flags);
  51.             break;
  52.         case 4:
  53. -           PageLevel!(4)* segmentParent;
  54. -           walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
  55. -
  56. -           // 'map' the segment into the Global Space
  57. -           if(success && global){
  58. -               PageLevel!(3)* globalSegmentParent;
  59. -               success = false;
  60. -
  61. -               walk!(mapSegmentHelper)(root, getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
  62. -           }
  63. +           success = createGib!(4)(location, flags);
  64.             break;
  65.         }
  66.  
  67. @@ -471,6 +438,34 @@ static:
  68.         return success;
  69.     }
  70.  
  71. +   template createGib(ushort PL){
  72. +       bool createGib(ubyte *location, AccessMode flags){
  73. +           bool global = (flags & AccessMode.Global) != 0;
  74. +
  75. +           ulong vAddr = cast(ulong)location;
  76. +           bool success;
  77. +           PhysicalAddress phys = PageAllocator.allocPage();
  78. +
  79. +           if(phys is null)
  80. +               return false;
  81. +
  82. +           PageLevel!(PL)* segmentParent;
  83. +           walk!(mapSegmentHelper)(root, vAddr, flags, success, segmentParent, phys);
  84. +
  85. +           static if(PL != 1){
  86. +               // 'map' the segment into the Global Space
  87. +               if(success && global){
  88. +                   PageLevel!(PL-1)* globalSegmentParent;
  89. +                   success = false;
  90. +
  91. +                   walk!(mapSegmentHelper)(root, getGlobalAddress(vAddr), flags, success, globalSegmentParent, phys);
  92. +               }
  93. +           }
  94. +
  95. +           return success;
  96. +       }
  97. +   }
  98. +
  99.     template mapSegmentHelper(U, T){
  100.         bool mapSegmentHelper(T table, uint idx, ref AccessMode flags, ref bool success, ref U segmentParent, ref PhysicalAddress phys){
  101.             static if(is(T == U)){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement