From: Matthias Kruk Date: Sun, 5 Jan 2020 06:27:34 +0000 (+0900) Subject: Add debug syscall for low-level/last-resort debugging X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=1cc3fb1fcb51af6ef8bda7cbe2d3be76b1fc574b;p=corax Add debug syscall for low-level/last-resort debugging --- diff --git a/config.h b/config.h index 923be4f..758607f 100644 --- a/config.h +++ b/config.h @@ -46,6 +46,7 @@ #define CONFIG_DEBUG_NET 1 #define CONFIG_DEBUG_IPC 1 #define CONFIG_DEBUG_HEAP 0 +#define CONFIG_DEBUG_SYSDEBUG 1 #define CONFIG_SOCKET_MAX 1024 #define CONFIG_NET_MBUF_SIZE 2048 diff --git a/include/corax/syscall.h b/include/corax/syscall.h index 07b64cd..9c7fed0 100644 --- a/include/corax/syscall.h +++ b/include/corax/syscall.h @@ -30,6 +30,8 @@ #define SYS_INB 11 #define SYS_OUTB 12 +#define SYS_DEBUG 13 + /* Corax-specific variations of POSIX syscalls */ #define SYS_EXECFVE 128 diff --git a/kernel/core/posixcall.c b/kernel/core/posixcall.c index f0fa769..289a9ee 100644 --- a/kernel/core/posixcall.c +++ b/kernel/core/posixcall.c @@ -405,6 +405,25 @@ int sys_outb(stack_frame_t *stk) return(0); } +#if FEATURE(DEBUG_SYSDEBUG) +int sys_debug(const char *str, const u32_t len) +{ + char buffer[128]; + int ret_val; + process_t *cproc; + + cproc = process_get_current(); + ret_val = len < sizeof(buffer) ? len : sizeof(buffer); + + process_memcpy_ptok(cproc, buffer, str, ret_val); + buffer[sizeof(buffer) - 1] = 0; + + dbg_printf("%s\n", buffer); + + return(ret_val); +} +#endif /* FEATURE(DEBUG_SYSDEBUG) */ + int sys_posixcall(stack_frame_t *stk) { int ret_val; @@ -473,6 +492,12 @@ int sys_posixcall(stack_frame_t *stk) ret_val = sys_outb(stk); break; +#if FEATURE(DEBUG_SYSDEBUG) + case SYS_DEBUG: + ret_val = sys_debug((const char*)stk->ebx, (u32_t)stk->ecx); + break; +#endif /* FEATURE(DEBUG_SYSDEBUG) */ + default: ret_val = -EOPNOTSUPP; break; diff --git a/kernel/klibc/posixcall.S b/kernel/klibc/posixcall.S index ecc6004..9d7479f 100644 --- a/kernel/klibc/posixcall.S +++ b/kernel/klibc/posixcall.S @@ -15,6 +15,10 @@ .global mmap .global munmap +#if FEATURE(DEBUG_SYSDEBUG) + .global debug +#endif /* FEATURE(DEBUG_SYSDEBUG) */ + _exit: pushl %ebx @@ -102,4 +106,18 @@ munmap: popl %ebx ret +#if FEATURE(DEBUG_SYSDEBUG) +debug: + pushl %ebx + + movl $SYS_DEBUG, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + int $SYSCALL_POSIX + + popl %ebx + ret + +#endif /* FEATURE(DEBUG_SYSDEBUG) */ + #endif /* FEATURE(POSIX) */