Skip to content

Commit

Permalink
Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug o…
Browse files Browse the repository at this point in the history
…utput.

This is very handy for the DebugLogStream implementation, among others. :^)
  • Loading branch information
awesomekling committed Jul 21, 2019
1 parent 0ef13e6 commit af81645
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 4 deletions.
3 changes: 1 addition & 2 deletions AK/LogStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class DebugLogStream final : public LogStream {

virtual void write(const char* characters, int length) const override
{
for (int i = 0; i < length; ++i)
dbgprintf("%c", characters[i]);
dbgputstr(characters, length);
}
};

Expand Down
1 change: 1 addition & 0 deletions AK/kstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#include <stdio.h>
#define kprintf printf
#define dbgprintf printf
#define dbgputstr(characters, length) fwrite(characters, 1, length, stdout)
#endif
9 changes: 9 additions & 0 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Process : public InlineLinkedListNode<Process>
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);
Expand Down
2 changes: 2 additions & 0 deletions Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Kernel/Syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
8 changes: 7 additions & 1 deletion Kernel/kprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions Kernel/kstdio.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#include <AK/Types.h>

extern "C" {
int dbgprintf(const char* fmt, ...);
int dbgputstr(const char*, int);
int kprintf(const char* fmt, ...);
int ksprintf(char* buf, const char* fmt, ...);
}
Expand Down
6 changes: 6 additions & 0 deletions Libraries/LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit af81645

Please sign in to comment.