unify logging

This commit is contained in:
Kevin Lange 2012-12-07 18:33:07 -08:00
parent 761d8ae8d3
commit a9d895a923
19 changed files with 18 additions and 143 deletions

View File

@ -79,7 +79,6 @@ gdt_set_gate(
*/
void
gdt_install() {
blog("Setting up Global Descriptor Tables...");
/* GDT pointer and limits */
gp.limit = (sizeof(struct gdt_entry) * 6) - 1;
gp.base = (unsigned int)&gdt;
@ -97,7 +96,6 @@ gdt_install() {
/* Go go go */
gdt_flush();
tss_flush();
bfinish(0);
}
/**

View File

@ -54,11 +54,9 @@ idt_set_gate(
*/
void
idt_install() {
blog("Setting up Interrupt Descriptor Tables...");
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
idtp.base = (uintptr_t)&idt;
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
bfinish(0);
}

View File

@ -88,11 +88,9 @@ irq_gates() {
*/
void
irq_install() {
blog("Setting up and enabling hardware interrupts...");
irq_remap();
irq_gates();
IRQ_RES;
bfinish(0);
}
void irq_ack(int irq_no) {

View File

@ -62,7 +62,6 @@ isrs_uninstall_handler(
void
isrs_install() {
blog("Setting up Interrupt Service Routines...");
/* Exception Handlers */
idt_set_gate(0, (unsigned)_isr0, 0x08, 0x8E);
idt_set_gate(1, (unsigned)_isr1, 0x08, 0x8E);
@ -97,7 +96,6 @@ isrs_install() {
idt_set_gate(30, (unsigned)_isr30, 0x08, 0x8E);
idt_set_gate(31, (unsigned)_isr31, 0x08, 0x8E);
idt_set_gate(SYSCALL_VECTOR, (unsigned)_isr127, 0x08, 0x8E);
bfinish(0);
}
char *exception_messages[] = {

View File

@ -29,13 +29,11 @@ set_fpu_cw(const uint16_t cw) {
*/
void
enable_fpu() {
blog("Enabling floating-point arithmetic unit...");
LOG(INFO, "Enabling floating-point arithmetic unit");
debug_print(NOTICE, "Enabling floating-point arithmetic unit");
size_t cr4;
asm volatile ("mov %%cr4, %0" : "=r"(cr4));
cr4 |= 0x200;
asm volatile ("mov %0, %%cr4" :: "r"(cr4));
set_fpu_cw(0x37F);
bfinish(0);
}

View File

@ -39,8 +39,7 @@ void keyboard_handler(struct regs *r) {
* pipe device for userspace.
*/
void keyboard_install() {
blog("Initializing PS/2 keyboard driver...");
LOG(INFO, "Initializing PS/2 keyboard driver");
debug_print(NOTICE, "Initializing PS/2 keyboard driver");
/* Create a device pipe */
keyboard_pipe = make_pipe(128);
@ -48,8 +47,6 @@ void keyboard_install() {
/* Install the interrupt handler */
irq_install_handler(KEYBOARD_IRQ, keyboard_handler);
bfinish(0);
}
void keyboard_reset_ps2() {

View File

@ -32,7 +32,7 @@ void mouse_wait(uint8_t a_type) {
return;
}
}
kprintf("[mouse] timeout\n");
debug_print(INFO, "mouse timeout");
return;
} else {
while (--timeout) {
@ -40,7 +40,7 @@ void mouse_wait(uint8_t a_type) {
return;
}
}
kprintf("[mouse] timeout\n");
debug_print(INFO, "mouse timeout");
return;
}
}
@ -111,7 +111,7 @@ void mouse_handler(struct regs *r) {
}
void mouse_install() {
LOG(INFO, "Initializing mouse cursor driver");
debug_print(NOTICE, "Initializing PS/2 mouse interface");
uint8_t status;
IRQ_OFF;
mouse_pipe = make_pipe(sizeof(mouse_device_packet_t) * PACKETS_IN_PIPE);

View File

@ -32,8 +32,7 @@ void serial_enable(int device) {
void
serial_install() {
blog("Installing serial communication driver...");
LOG(INFO, "Installing serial communication driver");
debug_print(NOTICE, "Installing serial communication driver");
serial_enable(SERIAL_PORT_A);
serial_enable(SERIAL_PORT_B);
@ -44,7 +43,6 @@ serial_install() {
outportb(SERIAL_PORT_A + 1, 0x01); /* Enable interrupts on receive */
outportb(SERIAL_PORT_B + 1, 0x01); /* Enable interrupts on receive */
#endif
bfinish(0);
}
int serial_rcvd(int device) {

View File

@ -52,11 +52,9 @@ timer_handler(
* Device installer for the PIT
*/
void timer_install() {
blog("Installing Programmable Interval Timer...");
LOG(INFO,"Initializing interval timer");
debug_print(NOTICE,"Initializing interval timer");
irq_install_handler(TIMER_IRQ, timer_handler);
timer_phase(100); /* 100Hz */
bfinish(0);
}
/*

View File

@ -1098,7 +1098,7 @@ void ext2_disk_mount(uint32_t offset_sector, uint32_t max_sector) {
}
debug_print(NOTICE, "Root file system is ready.");
fs_root = RN;
LOG(INFO,"Mounted EXT2 disk, root VFS node is at 0x%x", RN);
debug_print(NOTICE, "Mounted EXT2 disk, root VFS node is at 0x%x", RN);
}
void ext2_disk_forget_superblock() {

View File

@ -1053,7 +1053,7 @@ void ext2_ramdisk_mount(uint32_t offset) {
RN = (fs_node_t *)malloc(sizeof(fs_node_t));
assert(ext2_ramdisk_node_root(root_inode, RN));
fs_root = RN;
LOG(INFO,"Mounted EXT2 ramdisk, root VFS node is at 0x%x", RN);
debug_print(NOTICE, "Mounted EXT2 ramdisk, root VFS node is at 0x%x", RN);
}
void ext2_ramdisk_forget_superblock() {

View File

@ -9,23 +9,6 @@ typedef enum {
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();
void blog(char * string);
void bfinish(int status);
log_type_t debug_level;
void _debug_print(char * title, int line_no, log_type_t level, char *fmt, ...);

View File

@ -73,7 +73,7 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
if (mboot_mag == MULTIBOOT_EAX_MAGIC) {
/* Multiboot (GRUB, native QEMU, PXE) */
blog("Relocating Multiboot structures...");
debug_print(NOTICE, "Relocating Multiboot structures...");
mboot_ptr = mboot;
char cmdline_[1024];
@ -102,8 +102,6 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
/* Relocate the command line */
cmdline = (char *)kmalloc(len + 1);
memcpy(cmdline, cmdline_, len + 1);
bfinish(0);
}
/* Initialize core modules */
@ -116,9 +114,6 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower); /* Paging */
heap_install(); /* Kernel heap */
/* Install the logging module */
logging_install();
/* Hardware drivers */
timer_install(); /* PIC driver */
serial_install(); /* Serial console */

View File

@ -236,7 +236,6 @@ memory_total(){
void
paging_install(uint32_t memsize) {
blog("Setting up memory paging...");
nframes = memsize / 4;
frames = (uint32_t *)kmalloc(INDEX_FROM_BIT(nframes * 8));
memset(frames, 0, INDEX_FROM_BIT(nframes));
@ -264,7 +263,6 @@ paging_install(uint32_t memsize) {
current_directory = clone_directory(kernel_directory);
switch_page_directory(kernel_directory);
bfinish(0);
}
void
@ -367,9 +365,7 @@ page_fault(
void
heap_install() {
blog("Initializing block allocator...");
heap_end = (placement_pointer + 0x1000) & ~0xFFF;
bfinish(0);
}
void *

View File

@ -16,7 +16,7 @@ tree_t * shm_tree = NULL;
void shm_install() {
LOG(INFO, "Installing SHM");
debug_print(NOTICE, "Installing shared memory layer...");
shm_tree = tree_create();
tree_set_root(shm_tree, NULL);
}
@ -80,7 +80,7 @@ static shm_chunk_t * create_chunk (shm_node_t * parent, size_t size) {
shm_chunk_t *chunk = malloc(sizeof(shm_chunk_t));
if (chunk == NULL) {
LOG(ERROR, "[shm] Could not allocate a shm_chunk_t!\n");
debug_print(ERROR, "Failed to allocate a shm_chunk_t!");
return NULL;
}
@ -91,7 +91,7 @@ static shm_chunk_t * create_chunk (shm_node_t * parent, size_t size) {
chunk->num_frames = (size / 0x1000) + ((size % 0x1000) ? 1 : 0);
chunk->frames = malloc(sizeof(uintptr_t) * chunk->num_frames);
if (chunk->frames == NULL) {
LOG(ERROR, "[shm] Could not allocate a uintptr_t[%d]!\n", chunk->num_frames);
debug_print(ERROR, "Failed to allocate uintptr_t[%d]", chunk->num_frames);
free(chunk);
return NULL;
}
@ -219,7 +219,7 @@ void * shm_obtain (char * path, size_t * size) {
chunk = create_chunk(node, *size);
if (chunk == NULL) {
LOG(ERROR, "[shm] Could not allocate a shm_chunk_t!\n");
debug_print(ERROR, "Could not allocate a shm_chunk_t");
spin_unlock(&bsl);
return NULL;
}

View File

@ -11,81 +11,6 @@
#include <logging.h>
#include <va_list.h>
static list_t * log_buffer;
static char * messages[] = {
"info",
"note",
"warn",
"err ",
"crit"
};
void logging_install() {
blog("Installing stored logging...");
log_buffer = list_create();
LOG(INFO, "Kernel log initialized");
bfinish(0);
}
void debug_print_log_entry(log_entry_t * l) {
int i;
i = kprintf("[%s] %s ",
messages[l->type],
l->module);
while (i < 40) {
kprintf(" ");
++i;
}
i = kprintf("line %d", l->line);
while (i < 10) {
kprintf(" ");
++i;
}
kprintf("%s\n", 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);
va_list args;
va_start(args, fmt);
vasprintf(l->text, fmt, args);
va_end(args);
list_insert(log_buffer, l);
}
/*
* Messsage... <--- ---> [ OK ]
*/
static char * boot_messages[] = {
"\033[1;32m OK ",
"\033[1;33m WARN ",
"\033[1;31mERROR!"
};
char * last_message = NULL;
void blog(char * string) {
last_message = string;
kprintf("\033[0m%s\033[1000C\033[8D[ \033[1;34m....\033[0m ]", string);
}
void bfinish(int status) {
if (!last_message) { return; }
kprintf("\033[1000D\033[0m%s\033[1000C\033[8D[%s\033[0m]\n", last_message, boot_messages[status]);
}
log_type_t debug_level = NOTICE;
static char * c_messages[] = {

View File

@ -594,11 +594,9 @@ uint32_t num_syscalls;
void
syscalls_install() {
blog("Initializing syscall table...");
for (num_syscalls = 0; syscalls[num_syscalls] != 0; ++num_syscalls);
LOG(INFO, "Initializing syscall table with %d functions", num_syscalls);
debug_print(NOTICE, "Initializing syscall table with %d functions", num_syscalls);
isrs_install_handler(0x7F, &syscall_handler);
bfinish(0);
}
void

View File

@ -166,10 +166,9 @@ clone_table(
*/
void
tasking_install() {
blog("Initializing multitasking...");
IRQ_OFF; /* Disable interrupts */
LOG(NOTICE, "Initializing multitasking");
debug_print(NOTICE, "Initializing multitasking");
/* Initialize the process tree */
initialize_process_tree();
@ -182,7 +181,6 @@ tasking_install() {
/* Reenable interrupts */
IRQ_RES;
bfinish(0);
}
/*

View File

@ -47,7 +47,7 @@ uint16_t bochs_current_scroll() {
void
graphics_install_bochs(uint16_t resolution_x, uint16_t resolution_y) {
blog("Setting up BOCHS/QEMU graphics controller...");
debug_print(NOTICE, "Setting up BOCHS/QEMU graphics controller...");
outports(0x1CE, 0x00);
uint16_t i = inports(0x1CF);
if (i < 0xB0C0 || i > 0xB0C6) {
@ -96,13 +96,12 @@ graphics_install_bochs(uint16_t resolution_x, uint16_t resolution_y) {
mem_found:
finalize_graphics(resolution_x, resolution_y, PREFERRED_B);
bfinish(0);
}
/* }}} end bochs support */
void graphics_install_preset(uint16_t w, uint16_t h) {
blog("Graphics were pre-configured (thanks, bootloader!), locating video memory...");
debug_print(NOTICE, "Graphics were pre-configured (thanks, bootloader!), locating video memory...");
uint16_t b = 32; /* If you are 24 bit, go away, we really do not support you. */
/* XXX: Massive hack */
@ -157,8 +156,6 @@ mem_found:
((uint32_t *)lfb_vid_memory)[x + y * w] = 0xFF000000 | (f * 0x10000) | (f * 0x100) | f;
}
}
bfinish(0);
}