[log] Simple logging facility

This commit is contained in:
Kevin Lange 2011-12-14 17:47:30 -06:00
parent b108375731
commit 748a8e8d28
6 changed files with 98 additions and 8 deletions

View File

@ -7,12 +7,7 @@
*/
#include <system.h>
#include <process.h>
typedef __builtin_va_list va_list;
#define va_start(ap,last) __builtin_va_start(ap, last)
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap,type) __builtin_va_arg(ap,type)
#define va_copy(dest, src) __builtin_va_copy(dest,src)
#include <va_list.h>
static char buf[1024] = {-1};
static int ptr = -1;

50
kernel/core/logging.c Normal file
View File

@ -0,0 +1,50 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* Kernel Logging Facility
*
* Maintains a log in-memory as well as to serial (unless
* told not to).
*/
#include <system.h>
#include <list.h>
#include <logging.h>
static list_t * log_buffer;
static char * messages[] = {
"info",
"note",
"warn",
"err ",
"crit"
};
void logging_install() {
log_buffer = list_create();
}
void debug_print_log_entry(log_entry_t * l) {
kprintf("[%s] %s line %d: %s\n",
messages[l->type],
l->module,
l->line,
l->text);
}
void debug_print_log() {
foreach(entry, log_buffer) {
debug_print_log_entry((log_entry_t *)entry->value);
}
}
void klog(log_type_t type, char *module, unsigned int line, const char *fmt, ...) {
if (!log_buffer) return;
log_entry_t * l = malloc(sizeof(log_entry_t));
l->type = type;
l->module = module;
l->line = line;
l->text = malloc(sizeof(char) * 1024);
sprintf(l->text, fmt);
list_insert(log_buffer, l);
}

View File

@ -24,7 +24,7 @@
#include <list.h>
#include <tree.h>
#include <process.h>
#include <logging.h>
struct {
char path[1024];
@ -426,6 +426,11 @@ uint32_t shell_cmd_ps(int argc, char * argv[]) {
return 0;
}
uint32_t shell_cmd_dmesg(int argc, char * argv[]) {
debug_print_log();
return 0;
}
void install_commands() {
shell_install_command("cd", shell_cmd_cd);
shell_install_command("ls", shell_cmd_ls);
@ -442,6 +447,7 @@ void install_commands() {
shell_install_command("test-list", shell_cmd_testlist);
shell_install_command("test-tree", shell_cmd_testtree);
shell_install_command("ps", shell_cmd_ps);
shell_install_command("dmesg", shell_cmd_dmesg);
}
void add_path_contents() {

26
kernel/include/logging.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef LOGGING_H
#define LOGGING_H
typedef enum {
INFO = 0, /* Unimportant */
NOTICE, /* Important, but not bad */
WARNING, /* Not what was expected, but still okay */
ERROR, /* This is bad... */
CRITICAL /* Shit */
} log_type_t;
typedef struct {
log_type_t type;
char * module;
unsigned int line;
char * text;
} log_entry_t;
void klog(log_type_t type, char *module, unsigned int line, const char *fmt, ...);
#define LOG(type, ...) klog((type), __FILE__, __LINE__, __VA_ARGS__)
void debug_print_log();
void logging_install();
#endif

10
kernel/include/va_list.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef VA_LIST_H
#define VA_LIST_H
typedef __builtin_va_list va_list;
#define va_start(ap,last) __builtin_va_start(ap, last)
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap,type) __builtin_va_arg(ap,type)
#define va_copy(dest, src) __builtin_va_copy(dest,src)
#endif

View File

@ -38,6 +38,7 @@
#include <boot.h>
#include <ext2.h>
#include <fs.h>
#include <logging.h>
extern uintptr_t heap_end;
@ -111,11 +112,13 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
isrs_install(); /* Interrupt service requests */
irq_install(); /* Hardware interrupt requests */
/* Memory management */
paging_install(mboot_ptr->mem_upper); /* Paging */
heap_install(); /* Kernel heap */
/* Install the logging module */
logging_install();
/* Hardware drivers */
timer_install(); /* PIC driver */
keyboard_install(); /* Keyboard interrupt handler */