[kernel] Conditionally add an isa-debugcon output to logger

There have been a number of incidents lately where I've needed to see
logs but have been working on init, and broken the log output of
srv.logger. This commit adds a debug console output to io port 0x6600
if enabled at the top of logger.cpp.
This commit is contained in:
Justin C. Miller
2023-02-06 20:53:47 -08:00
parent 9297017688
commit 6a6b75b418
3 changed files with 36 additions and 4 deletions

View File

@@ -75,7 +75,7 @@ if [[ -n $TMUX ]]; then
if [[ -n $debug ]]; then
tmux split-window -h "gdb ${debugtarget}" &
else
tmux split-window -h -l 80 "sleep 1; telnet localhost 45455" &
tmux split-window -h -l 100 "sleep 1; telnet localhost 45455" &
tmux last-pane
tmux split-window -l 10 "sleep 1; telnet localhost 45454" &
fi
@@ -91,9 +91,9 @@ qemu-system-x86_64 \
-drive "if=pflash,format=raw,readonly,file=${assets}/ovmf/x64/ovmf_code.fd" \
-drive "if=pflash,format=raw,file=${build}/ovmf_vars.fd" \
-drive "format=raw,file=${build}/jsix.img" \
-chardev socket,host=localhost,port=45455,server,nowait,telnet=on,id=jsix_debug -device isa-debugcon,iobase=0x6600,chardev=jsix_debug \
-monitor telnet:localhost:45454,server,nowait \
-serial stdio \
-serial telnet:localhost:45455,server,nowait \
-smp "${smp}" \
-m 4096 \
-cpu "${cpu}" \

View File

@@ -10,7 +10,10 @@
#include "objects/system.h"
#include "objects/thread.h"
static uint8_t log_buffer[128 * 1024];
static constexpr bool j6_debugcon_enable = false;
static constexpr uint16_t j6_debugcon_port = 0x6600;
static uint8_t log_buffer[log::logger::log_pages * arch::frame_size];
// The logger is initialized _before_ global constructors are called,
// so that we can start log output immediately. Keep its constructor
@@ -30,6 +33,19 @@ const char *logger::s_area_names[] = {
nullptr
};
inline void
debug_out(const char *msg, size_t size)
{
asm ( "rep outsb;" :: "c"(size), "d"(j6_debugcon_port), "S"(msg) );
}
inline void
debug_newline()
{
static const char *newline = "\r\n";
asm ( "rep outsb;" :: "c"(2), "d"(j6_debugcon_port), "S"(newline) );
}
logger::logger() :
m_buffer(nullptr, 0)
{
@@ -52,7 +68,15 @@ logger::logger(uint8_t *buffer, size_t size) :
void
logger::output(level severity, logs area, const char *fmt, va_list args)
{
uint8_t buffer[256];
char buffer[256];
if constexpr (j6_debugcon_enable) {
size_t dlen = util::format({buffer, sizeof(buffer)}, "%7s %7s| ",
s_area_names[static_cast<uint8_t>(area)],
s_level_names[static_cast<uint8_t>(severity)]);
debug_out(buffer, dlen);
}
entry *header = reinterpret_cast<entry *>(buffer);
header->bytes = sizeof(entry);
header->area = area;
@@ -62,6 +86,11 @@ logger::output(level severity, logs area, const char *fmt, va_list args)
header->message[mlen] = 0;
header->bytes += mlen + 1;
if constexpr (j6_debugcon_enable) {
debug_out(header->message, mlen);
debug_newline();
}
util::scoped_lock lock {m_lock};
uint8_t *out;

View File

@@ -29,6 +29,9 @@ constexpr unsigned areas_count =
class logger
{
public:
/// Size of the log ring buffer
static constexpr unsigned log_pages = 16;
/// Default constructor. Creates a logger without a backing store.
logger();