diff --git a/kernel/include/logging.hpp b/kernel/include/logging.hpp new file mode 100644 index 00000000..563594c5 --- /dev/null +++ b/kernel/include/logging.hpp @@ -0,0 +1,26 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include +#include + +#ifndef LOGGING_HPP +#define LOGGING_HPP + +namespace logging { + +bool is_early(); +bool is_file(); +void finalize(); +void to_file(); + +void log(const char* s); +void log(const std::string& s); + +} //end of namespace logging + +#endif \ No newline at end of file diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 15a964cd..fcfe0baa 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -22,6 +22,7 @@ #include "gdt.hpp" #include "terminal.hpp" #include "scheduler.hpp" +#include "logging.hpp" #include "vfs/vfs.hpp" #include "fs/sysfs.hpp" @@ -62,7 +63,21 @@ void kernel_main(){ //Call global constructors _init(); - //Finalize memory operations + //Try to init VESA + if(vesa::vesa_enabled && !vesa::init()){ + vesa::vesa_enabled = false; + + //Unfortunately, we are in long mode, we cannot go back + //to text mode for now + suspend_boot(); + } + + init_console(); + + //Starting from here, the logging system can use the console + logging::finalize(); + + //Finalize memory operations (register sysfs values) paging::finalize(); physical_allocator::finalize(); virtual_allocator::finalize(); @@ -77,22 +92,14 @@ void kernel_main(){ //Init the virtual file system vfs::init(); - //Try to init VESA - if(vesa::vesa_enabled && !vesa::init()){ - vesa::vesa_enabled = false; - - //Unfortunately, we are in long mode, we cannot go back - //to text mode for now - suspend_boot(); - } + //Starting from here, the logging system can output logs to file + logging::to_file(); stdio::init_terminals(); //Only install system calls when everything else is ready install_system_calls(); - init_console(); - sysfs::set_constant_value("/sys/", "version", "0.1"); sysfs::set_constant_value("/sys/", "author", "Baptiste Wicht"); diff --git a/kernel/src/logging.cpp b/kernel/src/logging.cpp new file mode 100644 index 00000000..cdbe2000 --- /dev/null +++ b/kernel/src/logging.cpp @@ -0,0 +1,65 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include "logging.hpp" +#include "assert.hpp" + +namespace { + +bool early = true; +bool file = false; + +constexpr const size_t MAX_EARLY = 128; + +size_t current_early = 0; +const char* early_logs[MAX_EARLY]; + +} //end of anonymous namespace + +bool logging::is_early(){ + return early; +} + +bool logging::is_file(){ + return file; +} + +void logging::finalize(){ + //Starting from there, the messages will be displayed on + //the screen + early = false; +} + +void logging::to_file(){ + file = true; + + //TODO +} + +void logging::log(const char* s){ + if(is_early()){ + thor_assert(current_early < MAX_EARLY, "early log buffer is full"); + + early_logs[current_early++] = s; + } else { + if(is_file()){ + //TODO + } else { + //TODO + } + } +} + +void logging::log(const std::string& s){ + thor_assert(!is_early(), "log(string) in only valid in normal mode"); + + if(is_file()){ + //TODO + } else { + //TODO + } +}