From db22b587966b4a4eaa47536f32ca812532446bcb Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Mon, 18 May 2015 00:48:07 +0200 Subject: heavy refactoring underway --- lib/logger/log.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/logger/log.h | 13 ++++++++++ 2 files changed, 92 insertions(+) create mode 100644 lib/logger/log.c create mode 100644 lib/logger/log.h (limited to 'lib/logger') diff --git a/lib/logger/log.c b/lib/logger/log.c new file mode 100644 index 0000000..9348f01 --- /dev/null +++ b/lib/logger/log.c @@ -0,0 +1,79 @@ +#define FOOLOS_MODULE_NAME "log" + +#include +#include + +#include "log.h" + +#include "kernel/kernel.h" +#include "kernel/config.h" +#include "terminal/vt52.h" +#include "kernel/timer.h" + + +static char buffer[LOG_BUF_SIZE]; +static int first=0; +static int last=0; +static bool init=true;// + + +static void log_string(char *str) +{ + while(*str!=0) + { + fifo_put(&get_fool()->fifo_stdout,*(str++)); + } +} + +void log(char *module_name, int log_level, char *format_string, ...) +{ + + #ifdef FOOLOS_LOG_OFF + return; + #endif + + if(log_level=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + } + + +} + +void panic(char *module_name, char *message) +{ + char buf_log[256]; + tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); + log_string(buf_log); + + while(1) + { + asm volatile("cli"); + asm volatile("hlt"); + } + +} diff --git a/lib/logger/log.h b/lib/logger/log.h new file mode 100644 index 0000000..38f1219 --- /dev/null +++ b/lib/logger/log.h @@ -0,0 +1,13 @@ +#ifndef FOOLOS_LOG_H +#define FOOLOS_LOG_H + +#define FOOLOS_LOG_ERROR 5 +#define FOOLOS_LOG_WARNING 4 +#define FOOLOS_LOG_INFO 3 +#define FOOLOS_LOG_DEBUG 2 +#define FOOLOS_LOG_FINE 1 + +void log(char *module_name, int prio, char *format_string, ...); +void panic(char *module_name, char *format_string); + +#endif -- cgit v1.2.3