summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2021-07-21 21:31:52 +0200
committerdzwdz2021-07-21 21:31:52 +0200
commit36089d20ca1f7c57f36c4172759a5084bdf87a3a (patch)
treeac31e75f3379e0dcad6cb98f23cba6cbce236380 /src/kernel
parent46fb83d6eb44b5d52520783570dc40b7ef25260b (diff)
barebones syscall
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/arch/generic.h1
-rw-r--r--src/kernel/arch/i386/sysenter.s28
-rw-r--r--src/kernel/syscalls.c6
3 files changed, 35 insertions, 0 deletions
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h
index a535514..08f26a7 100644
--- a/src/kernel/arch/generic.h
+++ b/src/kernel/arch/generic.h
@@ -17,6 +17,7 @@ void halt_cpu();
// src/arch/i386/sysenter.s
void sysexit(void (*fun)(), void *stack_top);
void sysenter_setup();
+void syscall_handler();
// all of those can allocate memory
struct pagedir *pagedir_new();
diff --git a/src/kernel/arch/i386/sysenter.s b/src/kernel/arch/i386/sysenter.s
index 0cfeb10..3fcd4c3 100644
--- a/src/kernel/arch/i386/sysenter.s
+++ b/src/kernel/arch/i386/sysenter.s
@@ -4,6 +4,8 @@
.set SEG_r3data, 4
.set IA32_SYSENTER_CS, 0x174
+.set IA32_SYSENTER_ESP, 0x175
+.set IA32_SYSENTER_EIP, 0x176
.section .text
.global sysexit
@@ -30,7 +32,33 @@ sysexit:
.type sysenter_setup, @function
sysenter_setup:
xor %edx, %edx
+
mov $(SEG_r0code << 3), %eax
mov $IA32_SYSENTER_CS, %ecx
wrmsr
+
+ mov $IA32_SYSENTER_ESP, %ecx
+ mov $_bss_end, %eax
+ wrmsr
+
+ mov $IA32_SYSENTER_EIP, %ecx
+ mov $sysenter_handler, %eax
+ wrmsr
+
ret
+
+sysenter_handler:
+ pushal
+
+ mov %cr0, %eax
+ and $0x7FFFFFFF, %eax // disable paging
+ mov %eax, %cr0
+
+ call syscall_handler
+
+ mov %cr0, %eax
+ or $0x80000000, %eax // enable paging
+ mov %eax, %cr0
+
+ popal
+ sysexit
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
new file mode 100644
index 0000000..25b8eb5
--- /dev/null
+++ b/src/kernel/syscalls.c
@@ -0,0 +1,6 @@
+#include <kernel/arch/generic.h>
+#include <kernel/panic.h>
+
+void syscall_handler() {
+ log_const("in a syscall!");
+}