diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-01-15 15:46:54 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-01-15 15:46:54 +0100 |
| commit | 1799e1ba1b825eda639141b0597a1783576b69da (patch) | |
| tree | b63fef64c38eea6667ceae97bce809a6639e2fcb /arch | |
| parent | 213274bdd6ea6267143594b71fbfd6a38eba350b (diff) | |
| download | teachos-1799e1ba1b825eda639141b0597a1783576b69da.tar.xz teachos-1799e1ba1b825eda639141b0597a1783576b69da.zip | |
x86_64/debug: implement debug port detection
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/include/x86_64/debug/qemu_output.hpp | 10 | ||||
| -rw-r--r-- | arch/x86_64/src/debug/qemu_output.cpp | 7 |
2 files changed, 10 insertions, 7 deletions
diff --git a/arch/x86_64/include/x86_64/debug/qemu_output.hpp b/arch/x86_64/include/x86_64/debug/qemu_output.hpp index 6ff4da6..61b47d6 100644 --- a/arch/x86_64/include/x86_64/debug/qemu_output.hpp +++ b/arch/x86_64/include/x86_64/debug/qemu_output.hpp @@ -15,13 +15,13 @@ namespace teachos::debug::x86_64 //! This device implements output to the port 0xE9 debug console present in QEMU in Bochs. It is designed to wrap a //! different output device (e.g. a VGA text output device) and forwards the written data accordingly. //! - //! @note Support for the device has to be enabled when the emulator is started. Since there is no reliable way to - //! detect the presence of the port, writes will still happen even if the device is not enabled in the emulator. It is - //! thus possible that the output is simply lost. + //! @note Support for the device has to be enabled when the emulator is started. The device will try to detect if the + //! port is available. If the port is detected, any output to the device will be written to port before being + //! forwarded to the lower device. struct qemu_output : cio::output_device { //! The port to write to. - using dbg = io::x86_64::port<0xE9, char, io::x86_64::port_write>; + using port = io::x86_64::port<0xE9, unsigned char, io::x86_64::port_write, io::x86_64::port_read>; //! Construct a new debug device wrapper for the given output device. //! @@ -34,6 +34,8 @@ namespace teachos::debug::x86_64 private: //! The device to forward the output to. output_device & m_lower; + //! Whether the device has been detected. + bool m_present; }; } // namespace teachos::debug::x86_64 diff --git a/arch/x86_64/src/debug/qemu_output.cpp b/arch/x86_64/src/debug/qemu_output.cpp index 773306f..0af5bdc 100644 --- a/arch/x86_64/src/debug/qemu_output.cpp +++ b/arch/x86_64/src/debug/qemu_output.cpp @@ -2,6 +2,7 @@ #include "kapi/cio.hpp" +#include <algorithm> #include <string_view> namespace teachos::debug::x86_64 @@ -9,15 +10,15 @@ namespace teachos::debug::x86_64 qemu_output::qemu_output(output_device & lower) : m_lower{lower} + , m_present{port::read() == port::address} {} auto qemu_output::write(cio::output_stream stream, std::string_view text) -> void { - for (auto c : text) + if (m_present) { - dbg::write(c); + std::ranges::for_each(text, port::write<port::value_type>); } - m_lower.write(stream, text); } |
