aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs/elf.c
diff options
context:
space:
mode:
authorMarvin Borner2020-04-26 16:45:43 +0200
committerMarvin Borner2020-04-26 16:45:43 +0200
commitd3047efc1085d3e2f5524f629e55dc456a2f5065 (patch)
tree4e3a0bc956710c05ca64fdeccb310b7a0560cf37 /src/kernel/fs/elf.c
parent69d08dcb4580f8e544464bf54432ab07a7f58fc6 (diff)
Some elf userspace testing
Diffstat (limited to 'src/kernel/fs/elf.c')
-rw-r--r--src/kernel/fs/elf.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c
index dd1e764..b9ea22a 100644
--- a/src/kernel/fs/elf.c
+++ b/src/kernel/fs/elf.c
@@ -5,6 +5,7 @@
#include <kernel/lib/lib.h>
#include <kernel/memory/paging.h>
#include <kernel/fs/ext2.h>
+#include <kernel/gdt/gdt.h>
int is_elf(elf_header_t *header)
{
@@ -35,6 +36,7 @@ void elf_load(char *path)
debug("File is valid: %s", path);
}
+ uint32_t eip = 0;
uint32_t seg_begin, seg_end;
for (int i = 0; i < header->phnum; i++) {
if (program_header->type == 1) {
@@ -54,9 +56,37 @@ void elf_load(char *path)
if (program_header->flags == PF_X + PF_R + PF_W ||
program_header->flags == PF_X + PF_R) {
debug("Found code segment");
- // current_process->regs.eip = header->entry + seg_begin;
+ eip = header->entry + seg_begin;
}
}
program_header++;
- }
-} \ No newline at end of file
+ };
+
+ // Just some testing, will be moved later
+ uint32_t sp;
+ asm("mov %%esp, %0" : "=rm"(sp));
+ set_kernel_stack(sp);
+
+ // paging_switch_directory(1);
+ uint32_t esp = paging_alloc_pages(0x1000);
+ asm("mov %0, %%esp" ::"r"(esp + 0x1000));
+
+ log("Jumping to usermode!");
+ asm volatile("\
+ cli; \
+ mov $0x23, %%ax; \
+ mov %%ax, %%ds; \
+ mov %%ax, %%es; \
+ mov %%ax, %%fs; \
+ mov %%ax, %%gs; \
+ mov %%esp, %%eax; \
+ pushl $0x23; \
+ pushl %%esp; \
+ pushf; \
+ push $0x1B; \
+ push %0; \
+ iret; \
+ "
+ :
+ : "r"(eip));
+}