summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
authordzwdz2021-07-22 19:11:42 +0200
committerdzwdz2021-07-22 19:11:42 +0200
commit4823f92f9d3feabdc758d8cd6eef855de90fee2a (patch)
tree374c065807f422818d79b35c33082df3d00b461d /src/kernel/syscalls.c
parent8a168f2be5d90f972975abf0b40145a75c0231b7 (diff)
implement the debuglog() syscall
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index a42dc44..2af8cf9 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -1,15 +1,29 @@
#include <kernel/arch/generic.h>
#include <kernel/panic.h>
+#include <kernel/proc.h>
+#include <kernel/syscalls.h>
+#include <stdint.h>
-int syscall_handler(int a, int b, int c, int d) {
- // verify that the parameters get passed correctly
- if (a != 1) panic();
- if (b != 2) panic();
- if (c != 3) panic();
- if (d != 4) panic();
+int sc_debuglog(const char *msg, size_t len) {
+ struct pagedir *pages = process_current->pages;
+ void *phys = pagedir_virt2phys(pages, msg, true, false);
- log_const("in a syscall!");
+ // page overrun check
+ if (((uintptr_t)msg & PAGE_MASK) + len > PAGE_SIZE)
+ len = PAGE_SIZE - ((uintptr_t)msg & PAGE_MASK);
+ if (((uintptr_t)msg & PAGE_MASK) + len > PAGE_SIZE)
+ panic(); // just in case I made an off by 1 error
- // used to check if the return value gets passed correctly
- return 0x4e;
+ log_write(phys, len);
+ return len;
+}
+
+int syscall_handler(int num, int a, int b, int c) {
+ switch (num) {
+ case SC_DEBUGLOG:
+ return sc_debuglog((void*)a, b);
+ default:
+ log_const("unknown syscall ");
+ panic();
+ }
}