summaryrefslogtreecommitdiff
path: root/kernel/console.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-07-27 05:47:19 -0400
committerRobert Morris <[email protected]>2019-07-27 05:47:19 -0400
commita33f60fea30c931207aa05c933dab4bd992a40c2 (patch)
tree95b86005813fb780887e9c81ebe60753c2de6a06 /kernel/console.c
parentcf48b24c03325a4489e5dea9e2419893b7bf8783 (diff)
downloadxv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.tar.gz
xv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.tar.bz2
xv6-labs-a33f60fea30c931207aa05c933dab4bd992a40c2.zip
console/uart tweaks
Diffstat (limited to 'kernel/console.c')
-rw-r--r--kernel/console.c19
1 files changed, 13 insertions, 6 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);
}