move panicked check to uart.c
This commit is contained in:
		
							parent
							
								
									748809e1b3
								
							
						
					
					
						commit
						490f91ab53
					
				
					 4 changed files with 32 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -33,13 +33,6 @@
 | 
			
		|||
void
 | 
			
		||||
consputc(int c)
 | 
			
		||||
{
 | 
			
		||||
  extern volatile int panicked; // from printf.c
 | 
			
		||||
 | 
			
		||||
  if(panicked){
 | 
			
		||||
    for(;;)
 | 
			
		||||
      ;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(c == BACKSPACE){
 | 
			
		||||
    // if the user typed backspace, overwrite with a space.
 | 
			
		||||
    uartputc_sync('\b'); uartputc_sync(' '); uartputc_sync('\b');
 | 
			
		||||
| 
						 | 
				
			
			@ -66,12 +59,6 @@ int
 | 
			
		|||
consolewrite(int user_src, uint64 src, int n)
 | 
			
		||||
{
 | 
			
		||||
  int i;
 | 
			
		||||
  extern volatile int panicked; // from printf.c
 | 
			
		||||
 | 
			
		||||
  if(panicked){
 | 
			
		||||
    for(;;)
 | 
			
		||||
      ;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  acquire(&cons.lock);
 | 
			
		||||
  for(i = 0; i < n; i++){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -121,7 +121,7 @@ panic(char *s)
 | 
			
		|||
  printf("panic: ");
 | 
			
		||||
  printf(s);
 | 
			
		||||
  printf("\n");
 | 
			
		||||
  panicked = 1; // freeze output from other CPUs
 | 
			
		||||
  panicked = 1; // freeze uart output from other CPUs
 | 
			
		||||
  for(;;)
 | 
			
		||||
    ;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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_r; // read next from uart_tx_buf[uar_tx_r++]
 | 
			
		||||
 | 
			
		||||
extern volatile int panicked; // from printf.c
 | 
			
		||||
 | 
			
		||||
void uartstart();
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +87,12 @@ void
 | 
			
		|||
uartputc(int c)
 | 
			
		||||
{
 | 
			
		||||
  acquire(&uart_tx_lock);
 | 
			
		||||
 | 
			
		||||
  if(panicked){
 | 
			
		||||
    for(;;)
 | 
			
		||||
      ;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  while(1){
 | 
			
		||||
    if(((uart_tx_w + 1) % UART_TX_BUF_SIZE) == uart_tx_r){
 | 
			
		||||
      // buffer is full.
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +117,11 @@ uartputc_sync(int c)
 | 
			
		|||
{
 | 
			
		||||
  push_off();
 | 
			
		||||
 | 
			
		||||
  if(panicked){
 | 
			
		||||
    for(;;)
 | 
			
		||||
      ;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // wait for Transmit Holding Empty to be set in LSR.
 | 
			
		||||
  while((ReadReg(LSR) & LSR_TX_IDLE) == 0)
 | 
			
		||||
    ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										20
									
								
								user/grind.c
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								user/grind.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -292,8 +292,8 @@ go(int which_child)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main()
 | 
			
		||||
void
 | 
			
		||||
iter()
 | 
			
		||||
{
 | 
			
		||||
  unlink("a");
 | 
			
		||||
  unlink("b");
 | 
			
		||||
| 
						 | 
				
			
			@ -331,3 +331,19 @@ main()
 | 
			
		|||
 | 
			
		||||
  exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main()
 | 
			
		||||
{
 | 
			
		||||
  while(1){
 | 
			
		||||
    int pid = fork();
 | 
			
		||||
    if(pid == 0){
 | 
			
		||||
      iter();
 | 
			
		||||
      exit(0);
 | 
			
		||||
    }
 | 
			
		||||
    if(pid > 0){
 | 
			
		||||
      wait(0);
 | 
			
		||||
    }
 | 
			
		||||
    sleep(20);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue