summaryrefslogtreecommitdiff
path: root/src/kernel/mem/paging.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/mem/paging.c')
-rw-r--r--src/kernel/mem/paging.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/kernel/mem/paging.c b/src/kernel/mem/paging.c
index 3e2bffa..5953fc6 100644
--- a/src/kernel/mem/paging.c
+++ b/src/kernel/mem/paging.c
@@ -7,8 +7,6 @@
#include <core/sys.h>
#include <task/task.h>
-#define FIRST_KERNEL_PAGETABLE (K_HIGHHALF_ADDR >> 22)
-
static struct bitset frames;
struct page_directory *kernel_pagedir, *current_pagedir;
@@ -18,6 +16,9 @@ struct page_directory *kernel_pagedir, *current_pagedir;
/* Allocates a page of physical memory. */
uint32_t frame_alloc() {
uint32_t free = bitset_firstFree(&frames);
+ if (free == (uint32_t) -1) {
+ PANIC("Out of memory!");
+ }
bitset_set(&frames, free);
return free;
}
@@ -37,9 +38,9 @@ void paging_init(size_t totalRam) {
uint32_t i;
frames.size = totalRam / 0x1000;
- frames.bits = kmalloc(INDEX_FROM_BIT(frames.size));
+ frames.bits = ksbrk(INDEX_FROM_BIT(frames.size));
- kernel_pagedir = kmalloc(sizeof(struct page_directory));
+ kernel_pagedir = ksbrk(sizeof(struct page_directory));
kernel_pagedir->mappedSegs = 0;
kernel_pagedir->tablesPhysical = kmalloc_page(&kernel_pagedir->physicalAddr);
for (i = 0; i < 1024; i++) {
@@ -160,10 +161,15 @@ struct page *pagedir_getPage(struct page_directory *pd, uint32_t address, int ma
return &pd->tables[table_idx]->pages[address % 1024];
} else if (make) {
pd->tables[table_idx] = kmalloc_page(pd->tablesPhysical + table_idx);
- if (table_idx >= FIRST_KERNEL_PAGETABLE)
- tasking_updateKernelPagetable(table_idx, pd->tables[table_idx], pd->tablesPhysical[table_idx]);
+
memset((uint8_t*)pd->tables[table_idx], 0, 0x1000);
pd->tablesPhysical[table_idx] |= 0x07;
+
+ if (table_idx >= FIRST_KERNEL_PAGETABLE) {
+ monitor_write("UKPI ");
+ tasking_updateKernelPagetable(table_idx, pd->tables[table_idx], pd->tablesPhysical[table_idx]);
+ }
+
return &pd->tables[table_idx]->pages[address % 1024];
} else {
return 0;