console/uart tweaks

This commit is contained in:
Robert Morris 2019-07-27 05:47:19 -04:00
parent cf48b24c03
commit a33f60fea3
3 changed files with 20 additions and 7 deletions

View file

@ -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);
}

View file

@ -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){

View file

@ -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)
{