mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:17:34 +00:00
Kernel+LibC: Add a DebugLogDevice that forwards everything to I/O port 0xe9.
This is then used to implement the userspace dbgprintf() in a far more efficient way than what we had before. :^)
This commit is contained in:
parent
3b986da643
commit
3817f5f619
7 changed files with 61 additions and 7 deletions
28
Kernel/Devices/DebugLogDevice.cpp
Normal file
28
Kernel/Devices/DebugLogDevice.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include <Kernel/Devices/DebugLogDevice.h>
|
||||||
|
#include <Kernel/IO.h>
|
||||||
|
|
||||||
|
static DebugLogDevice* s_the;
|
||||||
|
|
||||||
|
DebugLogDevice& DebugLogDevice::the()
|
||||||
|
{
|
||||||
|
ASSERT(s_the);
|
||||||
|
return *s_the;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLogDevice::DebugLogDevice()
|
||||||
|
: CharacterDevice(1, 18)
|
||||||
|
{
|
||||||
|
s_the = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLogDevice::~DebugLogDevice()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t DebugLogDevice::write(Process&, const byte* data, ssize_t data_size)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < data_size; ++i)
|
||||||
|
IO::out8(0xe9, data[i]);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
17
Kernel/Devices/DebugLogDevice.h
Normal file
17
Kernel/Devices/DebugLogDevice.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include <Kernel/Devices/CharacterDevice.h>
|
||||||
|
|
||||||
|
class DebugLogDevice final : public CharacterDevice {
|
||||||
|
public:
|
||||||
|
DebugLogDevice();
|
||||||
|
virtual ~DebugLogDevice() override;
|
||||||
|
|
||||||
|
static DebugLogDevice& the();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// ^CharacterDevice
|
||||||
|
virtual ssize_t read(Process&, byte*, ssize_t) override { return 0; }
|
||||||
|
virtual ssize_t write(Process&, const byte*, ssize_t) override;
|
||||||
|
virtual bool can_write(Process&) const override { return true; }
|
||||||
|
virtual bool can_read(Process&) const override { return true; }
|
||||||
|
virtual const char* class_name() const override { return "DebugLogDevice"; }
|
||||||
|
};
|
|
@ -57,6 +57,7 @@ VFS_OBJS = \
|
||||||
Devices/FullDevice.o \
|
Devices/FullDevice.o \
|
||||||
Devices/ZeroDevice.o \
|
Devices/ZeroDevice.o \
|
||||||
Devices/RandomDevice.o \
|
Devices/RandomDevice.o \
|
||||||
|
Devices/DebugLogDevice.o \
|
||||||
FileSystem/FileSystem.o \
|
FileSystem/FileSystem.o \
|
||||||
FileSystem/DiskBackedFileSystem.o \
|
FileSystem/DiskBackedFileSystem.o \
|
||||||
FileSystem/Ext2FileSystem.o \
|
FileSystem/Ext2FileSystem.o \
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <Kernel/Devices/BXVGADevice.h>
|
#include <Kernel/Devices/BXVGADevice.h>
|
||||||
#include <Kernel/Net/E1000NetworkAdapter.h>
|
#include <Kernel/Net/E1000NetworkAdapter.h>
|
||||||
#include <Kernel/Net/NetworkTask.h>
|
#include <Kernel/Net/NetworkTask.h>
|
||||||
|
#include <Kernel/Devices/DebugLogDevice.h>
|
||||||
|
|
||||||
#define SPAWN_TERMINAL
|
#define SPAWN_TERMINAL
|
||||||
//#define SPAWN_LAUNCHER
|
//#define SPAWN_LAUNCHER
|
||||||
|
@ -42,6 +43,7 @@ VirtualConsole* tty2;
|
||||||
VirtualConsole* tty3;
|
VirtualConsole* tty3;
|
||||||
KeyboardDevice* keyboard;
|
KeyboardDevice* keyboard;
|
||||||
PS2MouseDevice* ps2mouse;
|
PS2MouseDevice* ps2mouse;
|
||||||
|
DebugLogDevice* dev_debuglog;
|
||||||
NullDevice* dev_null;
|
NullDevice* dev_null;
|
||||||
VFS* vfs;
|
VFS* vfs;
|
||||||
|
|
||||||
|
@ -151,6 +153,7 @@ extern "C" [[noreturn]] void init()
|
||||||
init_ksyms();
|
init_ksyms();
|
||||||
|
|
||||||
vfs = new VFS;
|
vfs = new VFS;
|
||||||
|
dev_debuglog = new DebugLogDevice;
|
||||||
|
|
||||||
auto console = make<Console>();
|
auto console = make<Console>();
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ mknod mnt/dev/random c 1 8
|
||||||
mknod mnt/dev/null c 1 3
|
mknod mnt/dev/null c 1 3
|
||||||
mknod mnt/dev/zero c 1 5
|
mknod mnt/dev/zero c 1 5
|
||||||
mknod mnt/dev/full c 1 7
|
mknod mnt/dev/full c 1 7
|
||||||
|
mknod -m 666 mnt/dev/debuglog c 1 18
|
||||||
mknod mnt/dev/keyboard c 85 1
|
mknod mnt/dev/keyboard c 85 1
|
||||||
mknod mnt/dev/psaux c 10 1
|
mknod mnt/dev/psaux c 10 1
|
||||||
mknod -m 666 mnt/dev/ptmx c 5 2
|
mknod -m 666 mnt/dev/ptmx c 5 2
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
static FILE __default_streams[3];
|
static FILE __default_streams[4];
|
||||||
FILE* stdin;
|
FILE* stdin;
|
||||||
FILE* stdout;
|
FILE* stdout;
|
||||||
FILE* stderr;
|
FILE* stderr;
|
||||||
|
FILE* stddbg;
|
||||||
|
|
||||||
void init_FILE(FILE& fp, int fd, int mode)
|
void init_FILE(FILE& fp, int fd, int mode)
|
||||||
{
|
{
|
||||||
|
@ -39,9 +40,16 @@ void __stdio_init()
|
||||||
stdin = &__default_streams[0];
|
stdin = &__default_streams[0];
|
||||||
stdout = &__default_streams[1];
|
stdout = &__default_streams[1];
|
||||||
stderr = &__default_streams[2];
|
stderr = &__default_streams[2];
|
||||||
|
stddbg = &__default_streams[3];
|
||||||
init_FILE(*stdin, 0, isatty(0) ? _IOLBF : _IOFBF);
|
init_FILE(*stdin, 0, isatty(0) ? _IOLBF : _IOFBF);
|
||||||
init_FILE(*stdout, 1, isatty(1) ? _IOLBF : _IOFBF);
|
init_FILE(*stdout, 1, isatty(1) ? _IOLBF : _IOFBF);
|
||||||
init_FILE(*stderr, 2, _IONBF);
|
init_FILE(*stderr, 2, _IONBF);
|
||||||
|
int fd = open("/dev/debuglog", O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("open /dev/debuglog");
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
init_FILE(*stddbg, fd, _IOLBF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int setvbuf(FILE* stream, char* buf, int mode, size_t size)
|
int setvbuf(FILE* stream, char* buf, int mode, size_t size)
|
||||||
|
@ -263,16 +271,11 @@ void rewind(FILE* stream)
|
||||||
fseek(stream, 0, SEEK_SET);
|
fseek(stream, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sys_putch(char*&, char ch)
|
|
||||||
{
|
|
||||||
syscall(SC_putch, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
int dbgprintf(const char* fmt, ...)
|
int dbgprintf(const char* fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
int ret = printf_internal(sys_putch, nullptr, fmt, ap);
|
int ret = vfprintf(stddbg, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef struct __STDIO_FILE FILE;
|
||||||
extern FILE* stdin;
|
extern FILE* stdin;
|
||||||
extern FILE* stdout;
|
extern FILE* stdout;
|
||||||
extern FILE* stderr;
|
extern FILE* stderr;
|
||||||
|
extern FILE* stddbg;
|
||||||
|
|
||||||
typedef size_t fpos_t;
|
typedef size_t fpos_t;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue