From af81645a2a085ab6b6f44098d54231e48d575852 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Jul 2019 21:43:37 +0200 Subject: [PATCH] Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug output. This is very handy for the DebugLogStream implementation, among others. :^) --- AK/LogStream.h | 3 +-- AK/kstdio.h | 1 + Kernel/Process.cpp | 9 +++++++++ Kernel/Process.h | 1 + Kernel/Syscall.cpp | 2 ++ Kernel/Syscall.h | 3 ++- Kernel/kprintf.cpp | 8 +++++++- Kernel/kstdio.h | 3 +++ Libraries/LibC/stdio.cpp | 6 ++++++ Libraries/LibC/stdio.h | 1 + 10 files changed, 33 insertions(+), 4 deletions(-) diff --git a/AK/LogStream.h b/AK/LogStream.h index e5906a776f1..ec88773d38f 100644 --- a/AK/LogStream.h +++ b/AK/LogStream.h @@ -79,8 +79,7 @@ public: virtual void write(const char* characters, int length) const override { - for (int i = 0; i < length; ++i) - dbgprintf("%c", characters[i]); + dbgputstr(characters, length); } }; diff --git a/AK/kstdio.h b/AK/kstdio.h index 57a64acb7fb..3ba8c33f6f0 100644 --- a/AK/kstdio.h +++ b/AK/kstdio.h @@ -6,4 +6,5 @@ #include #define kprintf printf #define dbgprintf printf +#define dbgputstr(characters, length) fwrite(characters, 1, length, stdout) #endif diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 1a0e5ecbb24..e32d6b50cdc 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2722,3 +2722,12 @@ int Process::sys$dbgputch(u8 ch) IO::out8(0xe9, ch); return 0; } + +int Process::sys$dbgputstr(const u8* characters, int length) +{ + if (!validate_read(characters, length)) + return -EFAULT; + for (int i = 0; i < length; ++i) + IO::out8(0xe9, characters[i]); + return 0; +} diff --git a/Kernel/Process.h b/Kernel/Process.h index eb603f9f775..f9dd19c3c98 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -105,6 +105,7 @@ public: void finalize(); int sys$dbgputch(u8); + int sys$dbgputstr(const u8*, int length); int sys$dump_backtrace(); int sys$gettid(); int sys$donate(int tid); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index d547f62b8bd..9334c326812 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -72,6 +72,8 @@ static u32 handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3 break; case Syscall::SC_dbgputch: return current->process().sys$dbgputch((u8)arg1); + case Syscall::SC_dbgputstr: + return current->process().sys$dbgputstr((const u8*)arg1, (int)arg2); case Syscall::SC_sleep: return current->process().sys$sleep((unsigned)arg1); case Syscall::SC_usleep: diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 40a585a959c..4a365530d4d 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -117,7 +117,8 @@ struct timeval; __ENUMERATE_SYSCALL(halt) \ __ENUMERATE_SYSCALL(reboot) \ __ENUMERATE_SYSCALL(dump_backtrace) \ - __ENUMERATE_SYSCALL(dbgputch) + __ENUMERATE_SYSCALL(dbgputch) \ + __ENUMERATE_SYSCALL(dbgputstr) namespace Syscall { diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp index 48a49d6b3ef..468ce55ab74 100644 --- a/Kernel/kprintf.cpp +++ b/Kernel/kprintf.cpp @@ -57,12 +57,18 @@ int ksprintf(char* buffer, const char* fmt, ...) return ret; } +extern "C" int dbgputstr(const char* characters, int length) +{ + for (int i = 0; i < length; ++i) + IO::out8(0xe9, characters[i]); + return 0; +} + static void debugger_putch(char*&, char ch) { IO::out8(0xe9, ch); } - extern "C" int dbgprintf(const char* fmt, ...) { color_on(); diff --git a/Kernel/kstdio.h b/Kernel/kstdio.h index bca2bfc6242..ce7d6fdae4a 100644 --- a/Kernel/kstdio.h +++ b/Kernel/kstdio.h @@ -1,7 +1,10 @@ #pragma once +#include + extern "C" { int dbgprintf(const char* fmt, ...); +int dbgputstr(const char*, int); int kprintf(const char* fmt, ...); int ksprintf(char* buf, const char* fmt, ...); } diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index 2ce4a8ab5b1..b1288a57805 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -488,6 +488,12 @@ void dbgputch(char ch) syscall(SC_dbgputch, ch); } +int dbgputstr(const char* characters, int length) +{ + int rc = syscall(SC_dbgputstr, characters, length); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + char* tmpnam(char*) { ASSERT_NOT_REACHED(); diff --git a/Libraries/LibC/stdio.h b/Libraries/LibC/stdio.h index dd166acf20e..18214fb0e8e 100644 --- a/Libraries/LibC/stdio.h +++ b/Libraries/LibC/stdio.h @@ -79,6 +79,7 @@ int fprintf(FILE*, const char* fmt, ...); int printf(const char* fmt, ...); int dbgprintf(const char* fmt, ...); void dbgputch(char); +int dbgputstr(const char*, ssize_t); int sprintf(char* buffer, const char* fmt, ...); int snprintf(char* buffer, size_t, const char* fmt, ...); int putchar(int ch);