- add an IO lock to synchronite the access to the IO buffer

git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@6 315a16e6-25f9-4109-90ae-ca3045a26c18
This commit is contained in:
stefan 2010-08-02 07:40:40 +00:00
parent 763b19a3c5
commit d2293f130d

View file

@ -20,12 +20,14 @@
#include <metalsvm/stdio.h>
#include <metalsvm/string.h>
#include <metalsvm/stdarg.h>
#include <metalsvm/spinlocks.h>
#ifdef USE_VGA
#include <asm/vga.h>
#endif
static unsigned int kmsg_counter = 0;
static unsigned char kmessages[KMSG_SIZE];
static spinlock_t kio_lock = SPINLOCK_INIT;
int koutput_init(void)
{
@ -39,25 +41,31 @@ int koutput_init(void)
int kputchar(int c)
{
int ret = 1;
spinlock_lock(&kio_lock);
kmessages[kmsg_counter++ % KMSG_SIZE] = c;
#ifdef USE_VGA
return vga_putchar(c);
#else
return 1;
ret = vga_putchar(c);
#endif
spinlock_unlock(&kio_lock);
return ret;
}
int kputs(const char *str)
{
int i;
spinlock_lock(&kio_lock);
for(i=0; str[i] != '\0'; i++)
kmessages[kmsg_counter++ % KMSG_SIZE] = str[i];
#ifdef USE_VGA
return vga_puts(str);
#else
return i;
i = vga_puts(str);
#endif
spinlock_unlock(&kio_lock);
return i;
}
static void kprintu(unsigned int val, int* count)