[kernel] Revive the debugcon logger as a kernel thread
The debugcon logger is now separate from logger::output, and is instead a kernel-internal thread that watches for logs and prints them to the deubcon device.
This commit is contained in:
@@ -13,6 +13,8 @@ variables:
|
|||||||
"-fcolor-diagnostics",
|
"-fcolor-diagnostics",
|
||||||
"-U__STDCPP_THREADS__",
|
"-U__STDCPP_THREADS__",
|
||||||
"-D_LIBCPP_HAS_NO_THREADS",
|
"-D_LIBCPP_HAS_NO_THREADS",
|
||||||
|
"-D__jsix_config=${build_config}",
|
||||||
|
"-D__jsix_config_${build_config}",
|
||||||
"-DVERSION_MAJOR=${version_major}",
|
"-DVERSION_MAJOR=${version_major}",
|
||||||
"-DVERSION_MINOR=${version_minor}",
|
"-DVERSION_MINOR=${version_minor}",
|
||||||
"-DVERSION_PATCH=${version_patch}",
|
"-DVERSION_PATCH=${version_patch}",
|
||||||
|
|||||||
1
configure
vendored
1
configure
vendored
@@ -35,6 +35,7 @@ def generate(output, config, manifest):
|
|||||||
"source_root": root,
|
"source_root": root,
|
||||||
"build_root": output,
|
"build_root": output,
|
||||||
"module_root": path,
|
"module_root": path,
|
||||||
|
"config": config,
|
||||||
}
|
}
|
||||||
code = compile(open(modfile, 'r').read(), modfile, "exec")
|
code = compile(open(modfile, 'r').read(), modfile, "exec")
|
||||||
|
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ class Module:
|
|||||||
build.default(dump)
|
build.default(dump)
|
||||||
|
|
||||||
def add_input(self, path, **kwargs):
|
def add_input(self, path, **kwargs):
|
||||||
from .source import Source
|
from .source import make_source
|
||||||
s = Source(self.root, path, **kwargs)
|
s = make_source(self.root, path, **kwargs)
|
||||||
self.sources.append(s)
|
self.sources.append(s)
|
||||||
return s.outputs
|
return s.outputs
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class Project:
|
|||||||
build.variable("ninja_required_version", "1.3")
|
build.variable("ninja_required_version", "1.3")
|
||||||
build.variable("build_root", output)
|
build.variable("build_root", output)
|
||||||
build.variable("source_root", root)
|
build.variable("source_root", root)
|
||||||
|
build.variable("build_config", config)
|
||||||
build.newline()
|
build.newline()
|
||||||
|
|
||||||
build.include(root / "assets/build/rules.ninja")
|
build.include(root / "assets/build/rules.ninja")
|
||||||
|
|||||||
66
src/kernel/debugcon.cpp
Normal file
66
src/kernel/debugcon.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include <util/format.h>
|
||||||
|
|
||||||
|
#include "debugcon.h"
|
||||||
|
#include "interrupts.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
namespace debugcon {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const char *level_names[] = {"", "fatal", "error", "warn", "info", "verbose", "spam"};
|
||||||
|
const char *area_names[] = {
|
||||||
|
#define LOG(name, lvl) #name ,
|
||||||
|
#include <j6/tables/log_areas.inc>
|
||||||
|
#undef LOG
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
inline void debug_out(const char *msg, size_t size) {
|
||||||
|
asm ( "rep outsb;" :: "c"(size), "d"(port), "S"(msg) );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void debug_newline() {
|
||||||
|
static const char *newline = "\r\n";
|
||||||
|
asm ( "rep outsb;" :: "c"(2), "d"(port), "S"(newline) );
|
||||||
|
}
|
||||||
|
} // anon namespace
|
||||||
|
|
||||||
|
void
|
||||||
|
output(logs area, log::level level, const char *message, size_t mlen)
|
||||||
|
{
|
||||||
|
char buffer [256];
|
||||||
|
size_t dlen = util::format({buffer, sizeof(buffer)}, "%7s %7s| ",
|
||||||
|
area_names[static_cast<uint8_t>(area)],
|
||||||
|
level_names[static_cast<uint8_t>(level)]);
|
||||||
|
debug_out(buffer, dlen);
|
||||||
|
|
||||||
|
debug_out(message, mlen);
|
||||||
|
debug_newline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
logger_task()
|
||||||
|
{
|
||||||
|
using entry = log::logger::entry;
|
||||||
|
|
||||||
|
uint64_t seen = 0;
|
||||||
|
size_t buf_size = 128;
|
||||||
|
uint8_t *buf = new uint8_t [buf_size];
|
||||||
|
entry *header = reinterpret_cast<entry*>(buf);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
size_t size = g_logger.get_entry(seen, buf, buf_size);
|
||||||
|
if (size > buf_size) {
|
||||||
|
delete [] buf;
|
||||||
|
buf_size *= 2;
|
||||||
|
buf = new uint8_t [buf_size];
|
||||||
|
header = reinterpret_cast<entry*>(buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
output(header->area, header->severity, header->message, size - sizeof(entry));
|
||||||
|
seen = header->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace debugcon
|
||||||
30
src/kernel/debugcon.h
Normal file
30
src/kernel/debugcon.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
/// \file debugcon.h
|
||||||
|
/// Kernel debugcon log output process
|
||||||
|
|
||||||
|
#include "scheduler.h"
|
||||||
|
|
||||||
|
namespace debugcon {
|
||||||
|
|
||||||
|
static constexpr bool enable =
|
||||||
|
#ifdef __jsix_config_debug
|
||||||
|
true;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static constexpr uint16_t port = 0x6600;
|
||||||
|
|
||||||
|
void logger_task();
|
||||||
|
|
||||||
|
inline void
|
||||||
|
init_logger()
|
||||||
|
{
|
||||||
|
if constexpr (enable) {
|
||||||
|
static constexpr uint8_t pri = scheduler::max_priority - 1;
|
||||||
|
scheduler &s = scheduler::get();
|
||||||
|
s.create_kernel_task(logger_task, pri, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace debugcon
|
||||||
@@ -69,6 +69,9 @@ kernel = module("kernel",
|
|||||||
"wait_queue.cpp",
|
"wait_queue.cpp",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
if config == "debug":
|
||||||
|
kernel.add_input("debugcon.cpp")
|
||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
#include "debugcon.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -50,7 +51,6 @@ kernel_main(bootproto::args *args)
|
|||||||
|
|
||||||
disable_legacy_pic();
|
disable_legacy_pic();
|
||||||
|
|
||||||
|
|
||||||
bsp_late_init();
|
bsp_late_init();
|
||||||
|
|
||||||
using bootproto::boot_flags;
|
using bootproto::boot_flags;
|
||||||
@@ -71,6 +71,10 @@ kernel_main(bootproto::args *args)
|
|||||||
scheduler *sched = new scheduler {g_num_cpus};
|
scheduler *sched = new scheduler {g_num_cpus};
|
||||||
smp::ready();
|
smp::ready();
|
||||||
|
|
||||||
|
// Initialize the debug console logger (does nothing if not built
|
||||||
|
// in debug mode)
|
||||||
|
debugcon::init_logger();
|
||||||
|
|
||||||
// Load the init server
|
// Load the init server
|
||||||
load_init_server(args->init, args->init_modules);
|
load_init_server(args->init, args->init_modules);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ logger::output(level severity, logs area, const char *fmt, va_list args)
|
|||||||
char buffer[buffer_len];
|
char buffer[buffer_len];
|
||||||
entry *header = reinterpret_cast<entry *>(buffer);
|
entry *header = reinterpret_cast<entry *>(buffer);
|
||||||
|
|
||||||
size_t size = sizeof(buffer);
|
size_t size = sizeof(entry);
|
||||||
size += util::vformat({header->message, message_len}, fmt, args);
|
size += util::vformat({header->message, message_len}, fmt, args);
|
||||||
|
|
||||||
util::scoped_lock lock {m_lock};
|
util::scoped_lock lock {m_lock};
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ inline T * push(uintptr_t &rsp, size_t size = sizeof(T)) {
|
|||||||
void
|
void
|
||||||
scheduler::create_kernel_task(void (*task)(), uint8_t priority, bool constant)
|
scheduler::create_kernel_task(void (*task)(), uint8_t priority, bool constant)
|
||||||
{
|
{
|
||||||
thread *th = process::kernel_process().create_thread(0, priority);
|
process &kp = process::kernel_process();
|
||||||
|
thread *th = kp.create_thread(0, priority);
|
||||||
auto *tcb = th->tcb();
|
auto *tcb = th->tcb();
|
||||||
|
|
||||||
th->add_thunk_kernel(reinterpret_cast<uintptr_t>(task));
|
th->add_thunk_kernel(reinterpret_cast<uintptr_t>(task));
|
||||||
@@ -78,10 +79,7 @@ scheduler::create_kernel_task(void (*task)(), uint8_t priority, bool constant)
|
|||||||
|
|
||||||
th->set_state(thread::state::ready);
|
th->set_state(thread::state::ready);
|
||||||
|
|
||||||
log::verbose(logs::task, "Creating kernel task: thread %llx pri %d", th->koid(), tcb->priority);
|
log::verbose(logs::task, "Spawned new kernel task <%02lx:%02lx>", kp.obj_id(), th->obj_id());
|
||||||
log::verbose(logs::task, " RSP0 %016lx", tcb->rsp0);
|
|
||||||
log::verbose(logs::task, " RSP %016lx", tcb->rsp);
|
|
||||||
log::verbose(logs::task, " PML4 %016lx", tcb->pml4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|||||||
@@ -157,4 +157,14 @@ const T * read(const_buffer &b) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T * at(buffer &b, size_t i) {
|
||||||
|
return reinterpret_cast<T*>(util::offset_pointer(b.pointer, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const T * at(const_buffer &b, size_t i) {
|
||||||
|
return reinterpret_cast<const T*>(util::offset_pointer(b.pointer, i));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|||||||
Reference in New Issue
Block a user