diff options
| author | Robert Morris <rtm@csail.mit.edu> | 2019-07-27 05:47:19 -0400 | 
|---|---|---|
| committer | Robert Morris <rtm@csail.mit.edu> | 2019-07-27 05:47:19 -0400 | 
| commit | a33f60fea30c931207aa05c933dab4bd992a40c2 (patch) | |
| tree | 95b86005813fb780887e9c81ebe60753c2de6a06 | |
| parent | cf48b24c03325a4489e5dea9e2419893b7bf8783 (diff) | |
| download | xv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.tar.gz xv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.tar.bz2 xv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.zip | |
console/uart tweaks
| -rw-r--r-- | kernel/console.c | 19 | ||||
| -rw-r--r-- | kernel/trap.c | 4 | ||||
| -rw-r--r-- | kernel/uart.c | 4 | 
3 files changed, 20 insertions, 7 deletions
| diff --git a/kernel/console.c b/kernel/console.c index 650e2af..6fb79cd 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -39,7 +39,7 @@ consputc(int c)    }    if(c == BACKSPACE){ -    // if the user typed backspace, erase the character. +    // if the user typed backspace, overwrite with a space.      uartputc('\b'); uartputc(' '); uartputc('\b');    } else {      uartputc(c); @@ -134,10 +134,10 @@ consoleread(int user_dst, uint64 dst, int n)  }  // -// the uart interrupt handler, uartintr(), calls this -// for each input character. do erase/kill processing, -// append to cons.buf, wake up reader if a whole -// line has arrived. +// the console input interrupt handler. +// uartintr() calls this for input character. +// do erase/kill processing, append to cons.buf, +// wake up consoleread() if a whole line has arrived.  //  void  consoleintr(int c) @@ -165,9 +165,16 @@ consoleintr(int c)    default:      if(c != 0 && cons.e-cons.r < INPUT_BUF){        c = (c == '\r') ? '\n' : c; -      cons.buf[cons.e++ % INPUT_BUF] = c; + +      // echo back to the user.        consputc(c); + +      // store for consumption by consoleread(). +      cons.buf[cons.e++ % INPUT_BUF] = c; +        if(c == '\n' || c == C('D') || cons.e == cons.r+INPUT_BUF){ +        // wake up consoleread() if a whole line (or end-of-file) +        // has arrived.          cons.w = cons.e;          wakeup(&cons.r);        } diff --git a/kernel/trap.c b/kernel/trap.c index 53d86ca..ec57bed 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -180,7 +180,9 @@ devintr()    if((scause & 0x8000000000000000L) &&       (scause & 0xff) == 9){ -    // supervisor external interrupt, via PLIC. +    // this is a supervisor external interrupt, via PLIC. + +    // irq indicates which device interrupted.      int irq = plic_claim();      if(irq == UART0_IRQ){ diff --git a/kernel/uart.c b/kernel/uart.c index b8dd664..ba66237 100644 --- a/kernel/uart.c +++ b/kernel/uart.c @@ -43,6 +43,7 @@ uartinit(void)    *R(1) = 0x01;  } +// write one output character to the UART.  void  uartputc(int c)  { @@ -52,6 +53,8 @@ uartputc(int c)    *R(0) = c;  } +// read one input character from the UART. +// return -1 if none is waiting.  int  uartgetc(void)  { @@ -63,6 +66,7 @@ uartgetc(void)    }  } +// trap.c calls here when the uart interrupts.  void  uartintr(void)  { | 
