diff options
author | rtm <rtm> | 2006-07-15 12:03:57 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-15 12:03:57 +0000 |
commit | 46bbd72f3eeaff9386b2a90af88f3d46b458a0e8 (patch) | |
tree | 31ca93c160a10c50948329b30d27475aa6b38313 /console.c | |
parent | d9872ffa951291fcc3f7a92c0d235b86435c5714 (diff) | |
download | xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.tar.gz xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.tar.bz2 xv6-labs-46bbd72f3eeaff9386b2a90af88f3d46b458a0e8.zip |
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
Diffstat (limited to 'console.c')
-rw-r--r-- | console.c | 39 |
1 files changed, 29 insertions, 10 deletions
@@ -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) ; } |