提交 006f8758 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Console locking and better panic behavoir.

上级 05d36ff7
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#define BACKSPACE 0x100 #define BACKSPACE 0x100
static int panicked = 0;
static struct { static struct {
struct spinlock lock; struct spinlock lock;
int locking; int locking;
...@@ -52,14 +54,11 @@ printint(void (*putch) (void*, char), void *putarg, ...@@ -52,14 +54,11 @@ printint(void (*putch) (void*, char), void *putarg,
static void static void
consputc(int c) consputc(int c)
{ {
// XXX(sbw)
#if 0
if(panicked){ if(panicked){
cli(); cli();
for(;;) for(;;)
; ;
} }
#endif
if(c == BACKSPACE){ if(c == BACKSPACE){
uartputc('\b'); uartputc(' '); uartputc('\b'); uartputc('\b'); uartputc(' '); uartputc('\b');
...@@ -201,15 +200,20 @@ puts(const char *s) ...@@ -201,15 +200,20 @@ puts(const char *s)
void __attribute__((noreturn)) void __attribute__((noreturn))
panic(const char *s) panic(const char *s)
{ {
extern void sys_halt();
cli(); cli();
if (cons.locking)
acquire(&cons.lock);
cons.locking = 0; cons.locking = 0;
cprintf("cpu%d: panic: ", mycpu()->id); cprintf("cpu%d: panic: ", mycpu()->id);
cprintf(s); cprintf(s);
cprintf("\n"); cprintf("\n");
panicked = 1;
extern void sys_halt(); // Never release cons.lock
sys_halt(); sys_halt();
for(;;) for(;;)
; ;
} }
...@@ -323,11 +327,11 @@ void ...@@ -323,11 +327,11 @@ void
initconsole(void) initconsole(void)
{ {
initlock(&cons.lock, "console"); initlock(&cons.lock, "console");
cons.locking = 1;
devsw[CONSOLE].write = consolewrite; devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread; devsw[CONSOLE].read = consoleread;
picenable(IRQ_KBD); picenable(IRQ_KBD);
ioapicenable(IRQ_KBD, 0); ioapicenable(IRQ_KBD, 0);
// XXX(sbw) enable once we setup %gs
cons.locking = 0;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论