[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++
This commit is contained in:
Justin C. Miller
2020-05-31 23:58:01 -07:00
parent c6c3a556b3
commit 88b090fe94
17 changed files with 126 additions and 67 deletions

View File

@@ -1,11 +1,16 @@
#include "kutil/memory.h"
#include "kutil/no_construct.h"
#include "console.h"
#include "log.h"
#include "scheduler.h"
static uint8_t log_buffer[0x10000];
static log::logger g_logger(log_buffer, sizeof(log_buffer));
// 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};
@@ -50,6 +55,5 @@ logger_task()
void logger_init()
{
new (&g_logger) log::logger(log_buffer, sizeof(log_buffer));
g_logger.set_immediate(output_log);
new (&g_logger) log::logger(log_buffer, sizeof(log_buffer), output_log);
}