diff options
Diffstat (limited to 'lib/logger/log.c')
| -rw-r--r-- | lib/logger/log.c | 79 |
1 files changed, 79 insertions, 0 deletions
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 <stdarg.h> +#include <stdbool.h> + +#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<FOOLOS_LOG_INFO)return; + + char buf_info[256]; + char buf_log[256]; + char buf_time[20]; + + uint32_t t=timer_get_ticks(); + uint32_t s=t/25; + uint32_t ms=t*1000/25-1000*s; + + tfp_sprintf(buf_time,"[%3d.%05d]",s,ms); + + va_list va; + va_start(va,format_string); + tfp_vsprintf(buf_info,format_string,va); + va_end(va); + + tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info); + + if(init)log_string(buf_log); + + for(int i=0;buf_log[i]!=0;i++) + { + buffer[last]=buf_log[i]; + last=(last+1)%LOG_BUF_SIZE; + if(first<last)if(last-first>=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"); + } + +} |
