From 311b32aef8cd42ea5877e4c61b270d0c4a170e1d Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 9 Aug 2010 15:43:45 +0000 Subject: [PATCH] - add macro for a static initialization of a semaphore - create a special process which reads the kernel messages from a buffer and dump them on the screen git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@51 315a16e6-25f9-4109-90ae-ca3045a26c18 --- include/metalsvm/semaphore.h | 2 ++ kernel/main.c | 2 +- libkern/stdio.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/metalsvm/semaphore.h b/include/metalsvm/semaphore.h index 1787d62a..7b708a06 100644 --- a/include/metalsvm/semaphore.h +++ b/include/metalsvm/semaphore.h @@ -35,6 +35,8 @@ typedef struct { spinlock_t lock; } sem_t; +#define SEM_INIT(v) {v, {[0 ... MAX_TASKS-1] = MAX_TASKS}, 0, SPINLOCK_INIT}; + inline static int sem_init(sem_t* s, unsigned int v) { unsigned int i; diff --git a/kernel/main.c b/kernel/main.c index cd206b3c..cb3d1c59 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -192,13 +192,13 @@ int main(void) system_init(); irq_init(); - koutput_init(); timer_init(); #ifdef CONFIG_KEYBOARD keyboard_init(); #endif mmu_init(); multitasking_init(); + koutput_init(); irq_enable(); diff --git a/libkern/stdio.c b/libkern/stdio.c index 3ac198bb..f5a15f72 100644 --- a/libkern/stdio.c +++ b/libkern/stdio.c @@ -20,20 +20,41 @@ #include #include #include +#include +#include #include #ifdef CONFIG_VGA #include #endif static atomic_int32_t kmsg_counter = ATOMIC_INIT(0); -static unsigned char kmessages[KMSG_SIZE]; +static unsigned char kmessages[KMSG_SIZE] = {[0 ... KMSG_SIZE-1] = 0}; + +#ifdef CONFIG_VGA +static sem_t sem_output = SEM_INIT(0); + +static int STDCALL output_task(void* arg) +{ + uint32_t rpos = 0; + + do { + sem_wait(&sem_output); + vga_putchar((int) kmessages[rpos]); + rpos = (rpos + 1) % KMSG_SIZE; + } while(1); + + return 0; +} +#endif int koutput_init(void) { #ifdef CONFIG_VGA + tid_t id; + vga_init(); + create_kernel_task(&id, output_task, NULL); #endif - memset(kmessages, 0, sizeof(unsigned char)*KMSG_SIZE); return 0; } @@ -45,10 +66,9 @@ int kputchar(int c) pos = atomic_int32_inc(&kmsg_counter); kmessages[pos % KMSG_SIZE] = c; - #ifdef CONFIG_VGA - ret = vga_putchar(c); -#endif + sem_post(&sem_output); +#endif return ret; } @@ -61,11 +81,10 @@ int kputs(const char *str) for(i=0; str[i] != '\0'; i++) { pos = atomic_int32_inc(&kmsg_counter); kmessages[pos % KMSG_SIZE] = str[i]; - } - #ifdef CONFIG_VGA - i = vga_puts(str); + sem_post(&sem_output); #endif + } return i; }