aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/memory/paging.c
diff options
context:
space:
mode:
authorMarvin Borner2020-05-26 00:37:10 +0200
committerMarvin Borner2020-05-26 00:37:10 +0200
commitb70116dc7c57132c109955c4b174ff2417afda68 (patch)
tree03d63c7ce7e5d4774e9e393991c376cd8c52ebea /src/kernel/memory/paging.c
parent7e53464d7bb2187fe0754fbdc04becbdccae11fe (diff)
Some workarounds which apparently work.
Diffstat (limited to 'src/kernel/memory/paging.c')
-rw-r--r--src/kernel/memory/paging.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index db9fc2d..59965b7 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -5,31 +5,49 @@
#include <system.h>
u32 **current_page_directory;
-u32 *kernel_page_directory[1024] __attribute__((aligned(4096)));
+u32 kernel_page_directory[1024] __attribute__((aligned(4096)));
u32 kernel_page_tables[1024][1024] __attribute__((aligned(4096)));
+u32 *temp_dir[1024] __attribute__((aligned(4096)));
-void paging_init(u32 **dir, int user)
+void paging_init(u32 **dir)
{
for (u32 i = 0; i < 1024; i++) {
for (u32 j = 0; j < 1024; j++) {
- dir[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW | (user ? PT_USER : 0);
+ dir[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW | PT_USER;
}
}
for (u32 i = 0; i < 1024; i++) {
- dir[i] = ((u32)dir[i]) | PD_RW | PD_PRESENT | (user ? PD_USER : 0);
+ dir[i] = ((u32)dir[i]) | PD_RW | PD_PRESENT | PD_USER;
}
}
-extern void KERNEL_END();
-void paging_install()
+void paging_kernel_init(u32 *dir)
{
for (u32 i = 0; i < 1024; i++) {
- kernel_page_directory[i] = kernel_page_tables[i];
+ for (u32 j = 0; j < 1024; j++) {
+ kernel_page_tables[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW;
+ }
+ }
+
+ for (u32 i = 0; i < 1024; i++) {
+ kernel_page_directory[i] = ((u32)kernel_page_tables[i]) | PD_RW | PD_PRESENT;
}
- paging_init((u32 **)kernel_page_directory, 0);
+ current_page_directory = temp_dir;
+ for (int i = 0; i < 1024; i++) {
+ current_page_directory[i] = kernel_page_tables[i];
+ for (int j = 0; j < 1024; j++) {
+ current_page_directory[i][j] = kernel_page_tables[i][j];
+ }
+ }
+}
+
+extern void KERNEL_END();
+void paging_install()
+{
paging_switch_directory((u32 **)kernel_page_directory);
+ paging_kernel_init(kernel_page_directory);
if (!memory_init())
paging_set_present(0, memory_get_all() >> 3);
@@ -51,14 +69,15 @@ void paging_install()
info("Malloc test succeeded!");
}
-u32 **paging_make_directory(int user)
+u32 **paging_make_directory()
{
u32 **dir = valloc(1024 * 32);
dir[0] = valloc(1024 * 1024 * 32);
for (int i = 1; i < 1024; i++)
dir[i] = dir[0] + i * 1024;
- paging_init(dir, user);
+ paging_init(dir);
+ paging_set_present(0, memory_get_all() >> 3);
return dir;
}
@@ -74,7 +93,6 @@ void paging_disable()
void paging_enable()
{
- asm("mov %0, %%cr3" ::"r"(current_page_directory));
u32 cr0;
asm("mov %%cr0, %0" : "=r"(cr0));
cr0 |= 0x80000000;