Files
jsix/src/kernel/log.cpp
Justin C. Miller 88b090fe94 [kernel] Run global constructors
Look up the global constructor list that the linker outputs, and run
them all. Required creation of the `kutil::no_construct` template for
objects that are constructed before the global constructors are run.

Also split the `memory_initialize` function into two - one for just
those objects that need to happen before the global ctors, and one
after.

Tags: memory c++
2020-05-31 23:58:01 -07:00

60 lines
1.5 KiB
C++

#include "kutil/memory.h"
#include "kutil/no_construct.h"
#include "console.h"
#include "log.h"
#include "scheduler.h"
static uint8_t log_buffer[0x10000];
// The logger is initialized _before_ global constructors are called,
// so that we can start log output immediately. Keep its constructor
// from being called here so as to not overwrite the previous initialization.
static kutil::no_construct<log::logger> __g_logger_storage;
static log::logger &g_logger = __g_logger_storage.value;
static const uint8_t level_colors[] = {0x07, 0x07, 0x0f, 0x0b, 0x09};
static void
output_log(log::area_t area, log::level severity, const char *message)
{
auto *cons = console::get();
cons->set_color(level_colors[static_cast<int>(severity)]);
cons->printf("%7s %5s: %s\n",
g_logger.area_name(area),
g_logger.level_name(severity),
message);
cons->set_color();
}
void
logger_task()
{
uint8_t buffer[257];
auto *ent = reinterpret_cast<log::logger::entry *>(buffer);
auto *cons = console::get();
//g_logger.set_immediate(nullptr);
log::info(logs::task, "Starting kernel logger task");
scheduler &s = scheduler::get();
while (true) {
if(g_logger.get_entry(buffer, sizeof(buffer))) {
buffer[ent->bytes] = 0;
cons->set_color(level_colors[static_cast<int>(ent->severity)]);
cons->printf("%7s %5s: %s\n",
g_logger.area_name(ent->area),
g_logger.level_name(ent->severity),
ent->message);
cons->set_color();
} else {
s.schedule();
}
}
}
void logger_init()
{
new (&g_logger) log::logger(log_buffer, sizeof(log_buffer), output_log);
}