diff options
| author | Miguel <m.i@gmx.at> | 2018-08-22 14:46:13 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-08-22 14:46:13 +0200 |
| commit | eddfc270d887283674563530b9fd982a2692f8c3 (patch) | |
| tree | cd6f0269bdb971e5921226d2594d303f2855ea98 /kernel/log.c | |
| parent | d99ddc6f38879fb30eaeb7dcafe25d1476613cb1 (diff) | |
cleaning up
Diffstat (limited to 'kernel/log.c')
| -rw-r--r-- | kernel/log.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/kernel/log.c b/kernel/log.c new file mode 100644 index 0000000..ff1b8bf --- /dev/null +++ b/kernel/log.c @@ -0,0 +1,63 @@ +#define FOOLOS_MODULE_NAME "log" +#include "log.h" + +#include <stdarg.h> +#include <stdbool.h> + +#include "kernel/kernel.h" +#include "kernel/fifo.h" + +#include "lib/string/string.h" + +static void log_string(char *str) +{ +// if(get_max_fd()>=2) syscall_write(2,str,strlen(str)); + while(*str!=0) + { + serial_write(*str++); + } +} + +void log(char *module_name, int log_level, char *format_string, ...) +{ + #ifdef FOOLOS_LOG_OFF + return; + #endif + + if(log_level<FOOLOS_LOG_LEVEL)return; + + char buf_info[256]; + char buf_log[256]; + char buf_time[20]; + + uint64_t t=timer_get_uptime_ms(); + uint32_t ms=t%1000; + uint32_t s=t/1000; + + tfp_sprintf(buf_time,"[%04d %03d]",s,ms); + + va_list va; + va_start(va,format_string); + tfp_vsprintf(buf_info,format_string,va); + va_end(va); + + tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %10s:\033[37;40m %s\n",buf_time,module_name,buf_info); + + log_string(buf_log); +} + +void panic(char *module_name, char *message) +{ + char buf_log[256]; + tfp_sprintf(buf_log,"\033[41;37m\n !! KERNEL PANIC !! %s: %s\n\n\033[37;40m",module_name,message); + + //PANIC DIRECTLY TO STDOUT// + syscall_write(1,buf_log,strlen(buf_log)); + log_string(buf_log); + + while(1) + { + asm volatile("cli"); + asm volatile("hlt"); + } +} |
