From 46bbd72f3eeaff9386b2a90af88f3d46b458a0e8 Mon Sep 17 00:00:00 2001 From: rtm Date: Sat, 15 Jul 2006 12:03:57 +0000 Subject: no more recursive locks wakeup1() assumes you hold proc_table_lock sleep(chan, lock) provides atomic sleep-and-release to wait for condition ugly code in swtch/scheduler to implement new sleep fix lots of bugs in pipes, wait, and exit fix bugs if timer interrupt goes off in schedule() console locks per line, not per byte --- console.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'console.c') diff --git a/console.c b/console.c index b85a295..d228edb 100644 --- a/console.c +++ b/console.c @@ -4,7 +4,8 @@ #include "spinlock.h" struct spinlock console_lock; -int use_printf_lock = 0; +int paniced = 0; +int use_console_lock = 0; /* * copy console output to parallel port, which you can tell @@ -23,15 +24,18 @@ lpt_putc(int c) outb(0x378+2, 0x08); } -void -cons_putc(int c) +static void +real_cons_putc(int c) { int crtport = 0x3d4; // io port of CGA unsigned short *crt = (unsigned short *) 0xB8000; // base of CGA memory int ind; - if(use_printf_lock) - acquire(&console_lock); + if(paniced){ + cli(); + while(1) + ; + } lpt_putc(c); @@ -63,8 +67,15 @@ cons_putc(int c) outb(crtport + 1, ind >> 8); outb(crtport, 15); outb(crtport + 1, ind); +} - if(use_printf_lock) +void +cons_putc(int c) +{ + if(use_console_lock) + acquire(&console_lock); + real_cons_putc(c); + if(use_console_lock) release(&console_lock); } @@ -91,7 +102,7 @@ printint(int xx, int base, int sgn) while(i > 0){ i -= 1; - cons_putc(buf[i]); + real_cons_putc(buf[i]); } } @@ -104,13 +115,16 @@ cprintf(char *fmt, ...) int i, state = 0, c; unsigned int *ap = (unsigned int *) &fmt + 1; + if(use_console_lock) + acquire(&console_lock); + for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; } else { - cons_putc(c); + real_cons_putc(c); } } else if(state == '%'){ if(c == 'd'){ @@ -120,20 +134,25 @@ cprintf(char *fmt, ...) printint(*ap, 16, 0); ap++; } else if(c == '%'){ - cons_putc(c); + real_cons_putc(c); } state = 0; } } + + if(use_console_lock) + release(&console_lock); } void panic(char *s) { - use_printf_lock = 0; + __asm __volatile("cli"); + use_console_lock = 0; cprintf("panic: "); cprintf(s, 0); cprintf("\n", 0); + paniced = 1; // freeze other CPU while(1) ; } -- cgit v1.2.3