mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-08 20:10:04 -04:00
Prepare some logging system
This commit is contained in:
parent
56a908b912
commit
8ee25e1dab
26
kernel/include/logging.hpp
Normal file
26
kernel/include/logging.hpp
Normal file
@ -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 <types.hpp>
|
||||
#include <string.hpp>
|
||||
|
||||
#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
|
@ -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");
|
||||
|
||||
|
65
kernel/src/logging.cpp
Normal file
65
kernel/src/logging.cpp
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user