aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/memory
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/memory')
-rw-r--r--src/kernel/memory/alloc.c8
-rw-r--r--src/kernel/memory/alloc.h1
-rw-r--r--src/kernel/memory/paging.c17
-rw-r--r--src/kernel/memory/paging.h2
4 files changed, 21 insertions, 7 deletions
diff --git a/src/kernel/memory/alloc.c b/src/kernel/memory/alloc.c
index a4fb60a..904be3a 100644
--- a/src/kernel/memory/alloc.c
+++ b/src/kernel/memory/alloc.c
@@ -361,6 +361,14 @@ void *malloc(u32 req_size)
return NULL;
}
+// Definitely improveable
+void *valloc(u32 req_size)
+{
+ u32 mask = l_page_size - 1;
+ u32 mem = malloc(req_size + l_page_size);
+ return (void *)((mem + mask) & ~mask);
+}
+
void free(void *ptr)
{
struct liballoc_minor *min;
diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h
index 6c4290e..2e8697f 100644
--- a/src/kernel/memory/alloc.h
+++ b/src/kernel/memory/alloc.h
@@ -4,6 +4,7 @@
#include <stdint.h>
void *malloc(u32);
+void *valloc(u32 req_size); // Page-aligned
void *realloc(void *, u32);
void *calloc(u32, u32);
void free(void *);
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index de93ffb..380b7e0 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -13,12 +13,13 @@ void paging_init(u32 *dir, int user)
{
for (u32 i = 0; i < 1024; i++) {
for (u32 j = 0; j < 1024; j++) {
- current_page_tables[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW;
+ current_page_tables[i][j] =
+ ((j * 0x1000) + (i * 0x400000)) | PT_RW | (user ? PT_USER : 0);
}
}
for (u32 i = 0; i < 1024; i++) {
- current_page_directory[i] = ((u32)current_page_tables[i]) | PD_RW | PD_PRESENT;
+ dir[i] = ((u32)current_page_tables[i]) | PD_RW | PD_PRESENT | (user ? PD_USER : 0);
}
}
@@ -26,6 +27,7 @@ extern void KERNEL_END();
void paging_install(u32 multiboot_address)
{
paging_switch_directory(kernel_page_directory);
+ current_page_tables = kernel_page_tables;
paging_init(current_page_directory, 0);
// if mmap approach didn't work
@@ -40,7 +42,8 @@ void paging_install(u32 multiboot_address)
u32 *paging_make_directory(int user)
{
- u32 *dir = malloc(1024 * 1024 * 32);
+ u32 *dir = valloc(1024 * 1024 * 32);
+ current_page_tables = valloc(1024 * 1024 * 32);
paging_init(dir, user);
@@ -68,9 +71,11 @@ void paging_enable()
void paging_switch_directory(u32 *dir)
{
- current_page_tables = kernel_page_tables;
+ current_page_tables = (u32(*)[1024])dir;
current_page_directory = dir;
- asm("mov %0, %%cr3" ::"r"(current_page_directory));
+ log("huh");
+ asm("mov %0, %%cr3" ::"r"(dir));
+ log("huh");
}
void invlpg(u32 addr)
@@ -189,4 +194,4 @@ u32 paging_get_used_pages()
}
}
return n;
-}
+} \ No newline at end of file
diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h
index 8857381..9f37ed6 100644
--- a/src/kernel/memory/paging.h
+++ b/src/kernel/memory/paging.h
@@ -51,4 +51,4 @@ void paging_set_user(u32 virt, u32 count);
u32 paging_find_pages(u32 count);
u32 paging_alloc_pages(u32 count);
-#endif
+#endif \ No newline at end of file