From 4823f92f9d3feabdc758d8cd6eef855de90fee2a Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 22 Jul 2021 19:11:42 +0200 Subject: implement the debuglog() syscall --- src/kernel/syscalls.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/kernel/syscalls.c') 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 #include +#include +#include +#include -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(); + } } -- cgit v1.2.3