summaryrefslogtreecommitdiff
path: root/Source/Kernel/MemoryManager/PhysMem.ns.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/MemoryManager/PhysMem.ns.cpp')
-rw-r--r--Source/Kernel/MemoryManager/PhysMem.ns.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/Source/Kernel/MemoryManager/PhysMem.ns.cpp b/Source/Kernel/MemoryManager/PhysMem.ns.cpp
index d3ce0b9..54eb4de 100644
--- a/Source/Kernel/MemoryManager/PhysMem.ns.cpp
+++ b/Source/Kernel/MemoryManager/PhysMem.ns.cpp
@@ -9,21 +9,17 @@ namespace PhysMem {
u32int nframes;
Bitset *frames;
-KernelSegment keSeg;
-
void initPaging(u32int mem_size) {
nframes = mem_size / 0x1000;
frames = new Bitset(nframes);
- for (u32int i = 0; i < Mem::placementAddress / 0x1000; i++) frames->setBit(i);
-
kernelPageDirectory = new (Mem::alloc(sizeof(PageDirectory), true)) PageDirectory();
- kernelPageDirectory->map(&keSeg);
u32int i = 0xC0000000;
while (i < Mem::placementAddress) {
- keSeg.identityMap(i);
+ page_t *p2 = kernelPageDirectory->getPage(i, true);
+ allocFrame(p2, false, false);
i += 0x1000;
}
//Also map thoses pages at begning of virtual memory
@@ -46,15 +42,30 @@ void removeTemporaryPages() {
}
}
-u32int getFrame() {
- u32int idx = frames->firstFreeBit();
- if (idx == (u32int) - 1) PANIC("No more free frames !");
- frames->setBit(idx);
- return idx;
+void allocFrame(page_t *page, bool is_user, bool is_writable) {
+ if (page->frame != 0) {
+ return;
+ } else {
+ u32int idx = frames->firstFreeBit();
+ if (idx == (u32int) - 1) PANIC("No more free frames !");
+ frames->setBit(idx);
+ page->present = 1;
+ page->user = (is_user ? 1 : 0);
+ page->rw = (is_writable ? 1 : 0);
+ page->frame = idx;
+ }
}
-void freeFrame(u32int frame) {
- frames->clearBit(frame);
+void freeFrame(page_t *page) {
+ if (page->frame == 0) {
+ return;
+ } else {
+ if (page->frame >= 0x100) { //First 1M are reserved (system)
+ frames->clearBit(page->frame);
+ }
+ page->present = 0;
+ page->frame = 0;
+ }
}
u32int free() {