From 3817f5f6191902d2592dab810d074a266d27596e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 18 Apr 2019 16:08:52 +0200 Subject: 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. :^) --- Kernel/Devices/DebugLogDevice.cpp | 28 ++++++++++++++++++++++++++++ Kernel/Devices/DebugLogDevice.h | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Kernel/Devices/DebugLogDevice.cpp create mode 100644 Kernel/Devices/DebugLogDevice.h (limited to 'Kernel/Devices') diff --git a/Kernel/Devices/DebugLogDevice.cpp b/Kernel/Devices/DebugLogDevice.cpp new file mode 100644 index 0000000000..321cd97d35 --- /dev/null +++ b/Kernel/Devices/DebugLogDevice.cpp @@ -0,0 +1,28 @@ +#include +#include + +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; +} + diff --git a/Kernel/Devices/DebugLogDevice.h b/Kernel/Devices/DebugLogDevice.h new file mode 100644 index 0000000000..dd6db9f4d2 --- /dev/null +++ b/Kernel/Devices/DebugLogDevice.h @@ -0,0 +1,17 @@ +#include + +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"; } +}; -- cgit v1.2.3