diff options
author | Marvin Borner | 2020-05-26 00:37:10 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-26 00:37:10 +0200 |
commit | b70116dc7c57132c109955c4b174ff2417afda68 (patch) | |
tree | 03d63c7ce7e5d4774e9e393991c376cd8c52ebea /src | |
parent | 7e53464d7bb2187fe0754fbdc04becbdccae11fe (diff) |
Some workarounds which apparently work.
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/fs/elf.c | 2 | ||||
-rw-r--r-- | src/kernel/memory/paging.c | 40 | ||||
-rw-r--r-- | src/kernel/memory/paging.h | 4 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 6 |
4 files changed, 36 insertions, 16 deletions
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index e11b91f..27857a9 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -48,6 +48,8 @@ struct process *elf_load(char *path) debug("File is valid: %s", path); } + // TODO: Fix here + halt_loop(); struct process *proc = process_make_new(); strcpy(proc->name, path); proc->registers.eip = header->entry; 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; diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h index 29409ab..f42bb2e 100644 --- a/src/kernel/memory/paging.h +++ b/src/kernel/memory/paging.h @@ -24,14 +24,14 @@ #define PT_USED 1 << 9 u32 **current_page_directory; -u32 *kernel_page_directory[1024] __attribute__((aligned(4096))); +u32 kernel_page_directory[1024] __attribute__((aligned(4096))); int paging_enabled; void paging_install(); void paging_enable(); void paging_disable(); -u32 **paging_make_directory(int user); +u32 **paging_make_directory(); void paging_switch_directory(u32 **dir); void paging_map(u32 phy, u32 virt, u16 flags); diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index 900d775..fa41313 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -183,12 +183,12 @@ struct process *process_make_new() proc->registers.cs = 0x1B; proc->registers.ds = 0x23; proc->registers.ss = 0x23; - proc->cr3 = paging_make_directory(1); + proc->cr3 = paging_make_directory(); proc->brk = 0x50000000; - for (int i = 0; i < 1024; i++) - proc->cr3[i] = kernel_page_directory[i]; + /* for (int i = 0; i < 1024; i++) */ + /* proc->cr3[i] = kernel_page_directory[i]; */ proc->pid = pid++; return proc; |