move panicked check to uart.c

This commit is contained in:
Robert Morris 2020-08-28 05:51:48 -04:00 committed by Frans Kaashoek
parent 748809e1b3
commit 490f91ab53
4 changed files with 32 additions and 16 deletions

View file

@ -33,13 +33,6 @@
void void
consputc(int c) consputc(int c)
{ {
extern volatile int panicked; // from printf.c
if(panicked){
for(;;)
;
}
if(c == BACKSPACE){ if(c == BACKSPACE){
// if the user typed backspace, overwrite with a space. // if the user typed backspace, overwrite with a space.
uartputc_sync('\b'); uartputc_sync(' '); uartputc_sync('\b'); uartputc_sync('\b'); uartputc_sync(' '); uartputc_sync('\b');
@ -66,12 +59,6 @@ int
consolewrite(int user_src, uint64 src, int n) consolewrite(int user_src, uint64 src, int n)
{ {
int i; int i;
extern volatile int panicked; // from printf.c
if(panicked){
for(;;)
;
}
acquire(&cons.lock); acquire(&cons.lock);
for(i = 0; i < n; i++){ for(i = 0; i < n; i++){

View file

@ -121,7 +121,7 @@ panic(char *s)
printf("panic: "); printf("panic: ");
printf(s); printf(s);
printf("\n"); printf("\n");
panicked = 1; // freeze output from other CPUs panicked = 1; // freeze uart output from other CPUs
for(;;) for(;;)
; ;
} }

View file

@ -45,6 +45,8 @@ char uart_tx_buf[UART_TX_BUF_SIZE];
int uart_tx_w; // write next to uart_tx_buf[uart_tx_w++] int uart_tx_w; // write next to uart_tx_buf[uart_tx_w++]
int uart_tx_r; // read next from uart_tx_buf[uar_tx_r++] int uart_tx_r; // read next from uart_tx_buf[uar_tx_r++]
extern volatile int panicked; // from printf.c
void uartstart(); void uartstart();
void void
@ -85,6 +87,12 @@ void
uartputc(int c) uartputc(int c)
{ {
acquire(&uart_tx_lock); acquire(&uart_tx_lock);
if(panicked){
for(;;)
;
}
while(1){ while(1){
if(((uart_tx_w + 1) % UART_TX_BUF_SIZE) == uart_tx_r){ if(((uart_tx_w + 1) % UART_TX_BUF_SIZE) == uart_tx_r){
// buffer is full. // buffer is full.
@ -109,6 +117,11 @@ uartputc_sync(int c)
{ {
push_off(); push_off();
if(panicked){
for(;;)
;
}
// wait for Transmit Holding Empty to be set in LSR. // wait for Transmit Holding Empty to be set in LSR.
while((ReadReg(LSR) & LSR_TX_IDLE) == 0) while((ReadReg(LSR) & LSR_TX_IDLE) == 0)
; ;

View file

@ -292,8 +292,8 @@ go(int which_child)
} }
} }
int void
main() iter()
{ {
unlink("a"); unlink("a");
unlink("b"); unlink("b");
@ -331,3 +331,19 @@ main()
exit(0); exit(0);
} }
int
main()
{
while(1){
int pid = fork();
if(pid == 0){
iter();
exit(0);
}
if(pid > 0){
wait(0);
}
sleep(20);
}
}