]> git.corax.cc Git - corax/commitdiff
Add debug syscall for low-level/last-resort debugging
authorMatthias Kruk <m@m10k.eu>
Sun, 5 Jan 2020 06:27:34 +0000 (15:27 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 5 Jan 2020 06:27:34 +0000 (15:27 +0900)
config.h
include/corax/syscall.h
kernel/core/posixcall.c
kernel/klibc/posixcall.S

index 923be4fcd8ed8b0d9280517beeeb85ea68b20dc8..758607f3e1d4c75e412233f6e212d52198306a7e 100644 (file)
--- 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
index 07b64cd8da67b650f3a13dd4db1577d5c247750a..9c7fed04b3e4d82c9f47ea6e39dcdbf5665cd852 100644 (file)
@@ -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
 
index f0fa769c9a55cb2a9056d59c2518535abae79253..289a9eec16bf93537c07acaf70aec72d9ec521ca 100644 (file)
@@ -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;
index ecc60041bb472ea6060dba88352ab931b258e05c..9d7479fea77c63b1714a915b8e92e45edb2a94ea 100644 (file)
        .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) */