aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2019-10-31 15:19:12 +0100
committerMarvin Borner2019-10-31 15:19:12 +0100
commit2c7b6e0431d6dfbaf385d30e87e7eb9fd4a0e61d (patch)
tree04e3aaf05509fb9bdc16ccb30a773dac931c290e
parent7d5a9792e57b4088cce5cc97837eb04016b57a4d (diff)
Some user mode improvements
-rw-r--r--src/kernel/boot.asm29
-rw-r--r--src/kernel/gdt/gdt.c2
-rw-r--r--src/kernel/graphics/vesa.c2
-rw-r--r--src/kernel/kernel.c3
-rw-r--r--src/kernel/syscall/syscall.c3
-rw-r--r--src/userspace/main.c6
6 files changed, 26 insertions, 19 deletions
diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm
index 8f24066..2501ed9 100644
--- a/src/kernel/boot.asm
+++ b/src/kernel/boot.asm
@@ -51,23 +51,22 @@ stublet:
%include "src/kernel/interact.asm"
global switch_to_user
+extern test_user
switch_to_user:
- cli
- mov ax,0x23
- mov ds,ax
- mov es,ax
- mov fs,ax
- mov gs,ax
+ sti
+ mov ax, 0x23
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
- mov eax,esp
- push 0x23
- push eax
- pushf
- pop eax
- or eax, 0x200
- push eax
- push 0x1B
- iret
+ mov eax, esp
+ push 0x23
+ push eax
+ pushf
+ push 0x1B
+ push test_user
+ iret
; Store the stack
SECTION .bss
diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c
index b933950..1c69602 100644
--- a/src/kernel/gdt/gdt.c
+++ b/src/kernel/gdt/gdt.c
@@ -97,7 +97,7 @@ void gdt_install() {
// Remove old GDT and install the new changes!
gdt_flush();
- tss_flush(); // FAILS
+ tss_flush();
vga_log("Installed Global Descriptor Table", 2);
}
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 32ca717..858ed95 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -167,7 +167,7 @@ void set_optimal_resolution() {
switch_to_vga();
} else vga_log("Mode detection succeeded", 11);
- timer_wait(500);
+ // timer_wait(500);
vbe_set_mode(highest);
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index dd15409..b133a0c 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -39,10 +39,11 @@ void kernel_main(struct multiboot *mboot_ptr) {
initrd_test();
// User mode!
+ info("Switching to user mode...");
syscalls_install();
switch_to_user();
- syscall_serial_write("Hello, user world!\n");
+ panic("This should NOT happen!");
// asm volatile ("div %0" :: "r"(0)); // Exception testing x/0
loop:
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index d1dbd6b..dec3e8e 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -18,6 +18,7 @@ static void *syscalls[3] = {
uint32_t num_syscalls = 3;
void syscall_handler(struct regs *r) {
+ serial_write("SYSCALL");
if (r->eax >= num_syscalls)
return;
@@ -41,5 +42,5 @@ void syscall_handler(struct regs *r) {
}
void syscalls_install() {
- irq_install_handler(0x80, &syscall_handler);
+ irq_install_handler(0x80, syscall_handler);
}
diff --git a/src/userspace/main.c b/src/userspace/main.c
new file mode 100644
index 0000000..d332d8e
--- /dev/null
+++ b/src/userspace/main.c
@@ -0,0 +1,6 @@
+#include <kernel/syscall/syscall.h>
+
+void test_user() {
+ asm volatile ("hlt");
+ syscall_serial_write("Hello, user world!\n");
+} \ No newline at end of file