aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2021-02-28 19:45:41 +0100
committerMarvin Borner2021-02-28 19:45:41 +0100
commit21522ad5f2fe55e633cd025e292537ca37e042fb (patch)
treeef195992681c69818e21ba2dd66d90af0d049b6f /kernel/features
parentd50d3aeaaeaca4a75a807759a54d1d6ae8b5bce4 (diff)
Kinda working paging
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/memory.c26
-rw-r--r--kernel/features/proc.asm6
2 files changed, 22 insertions, 10 deletions
diff --git a/kernel/features/memory.c b/kernel/features/memory.c
index f8e183a..4dfebff 100644
--- a/kernel/features/memory.c
+++ b/kernel/features/memory.c
@@ -28,10 +28,7 @@ void paging_switch_dir(u32 dir)
cr3_set(dir);
}
-void paging_invalidate_tlb(void)
-{
- /* __asm__ volatile("invlpg"); */
-}
+extern void paging_invalidate_tlb(void);
/**
* Physical
@@ -390,8 +387,9 @@ void memory_initialize(struct mem_info *mem_info)
u32 size = p->lsize;
if (p->hsize)
- size = U32_MAX;
+ size = U32_MAX - p->lbase;
+ /* printf("Memory region: %x-%x\n", p->lbase, p->lbase + size); */
if (p->type == MEMORY_AVAILABLE) {
physical_set_free(p->lbase, size / PAGE_SIZE);
memory_total += size;
@@ -403,22 +401,30 @@ void memory_initialize(struct mem_info *mem_info)
memory_used = 0;
printf("Detected memory: %dKiB (%dMiB)\n", memory_total >> 10, memory_total >> 20);
+ // Map kernel
memory_map_identity(&kernel_dir, kernel_memory_range(), MEMORY_NONE);
+ // Map kernel stack
+ memory_map_identity(&kernel_dir, memory_range_around_address(STACK_START, 0x1000),
+ MEMORY_NONE);
+
+ // Map kernel heap
+ memory_map_identity(&kernel_dir, memory_range_around_address(HEAP_START, HEAP_INIT_SIZE),
+ MEMORY_NONE);
+
+ // Map stack guard?
+ /* memory_map_identity(&kernel_dir, memory_range_around_address(0xdeadbeef, 0x1), MEMORY_NONE); */
+
// Unmap NULL byte/page
virtual_free(&kernel_dir, memory_range(0, PAGE_SIZE));
physical_set_used(0, 1);
memory_dir_switch(&kernel_dir);
- printf("Enabling...\n");
paging_enable();
- printf("Enabled!\n");
}
-#define HEAP_START 0x00f00000
void paging_install(struct mem_info *mem_info)
{
- heap_init(HEAP_START);
memory_initialize(mem_info);
- printf("OK!\n");
+ heap_init(HEAP_START);
}
diff --git a/kernel/features/proc.asm b/kernel/features/proc.asm
index 1a2ba65..dfc3448 100644
--- a/kernel/features/proc.asm
+++ b/kernel/features/proc.asm
@@ -28,3 +28,9 @@ proc_jump_userspace:
push dword [_eip]
iret
+
+global paging_invalidate_tlb
+paging_invalidate_tlb:
+ mov eax, cr3
+ mov cr3, eax
+ ret