shithub: riscv

Download patch

ref: 76f99f7cb3731b3718209aee445ad409f184a3a9
parent: 36ab78221c2424a836cbc6a6ec7e92df8a16d6fe
author: cinap_lenrek <cinap_lenrek@localhost>
date: Fri May 13 04:53:43 EDT 2011

serial console support

--- a/sys/man/3/cons
+++ b/sys/man/3/cons
@@ -141,6 +141,10 @@
 .B bootfile
 variable is set to
 .IR kernelpath .
+Writing the string
+.B rdb
+activates the remote kernel debugger (see
+.IR rdbfs (4)).
 Only the host
 owner has the ability to open this file.
 .PP
--- a/sys/src/9/boot/bootrc
+++ b/sys/src/9/boot/bootrc
@@ -120,7 +120,10 @@
 
 if(test -e '#b' && test -x /bin/aux/kbdfs){
 	bind -a '#b' /dev
-	aux/kbdfs -s cons
+	a=$console(1)
+	if(! ~ $#a 0)
+		a=/dev/eia^$a
+	aux/kbdfs -s cons $a
 }
 
 if(test -e '#u' && test -x /bin/usb/usbd){
--- a/sys/src/cmd/aux/kbdfs.c
+++ b/sys/src/cmd/aux/kbdfs.c
@@ -86,9 +86,7 @@
 
 int scanfd;
 int ledsfd;
-
 int consfd;
-int echofd;
 
 int kbdopen;
 int consopen;
@@ -401,11 +399,12 @@
 consproc(void *)
 {
 	char *p, *e, *x, buf[64];
-	int n;
+	int n, cr;
 	Rune r;
 
 	threadsetname("consproc");
 
+	cr = 0;
 	p = buf;
 	e = buf + sizeof(buf);
 	while((n = read(consfd, p, e - p)) > 0){
@@ -412,14 +411,19 @@
 		x = buf + n;
 		while(p < x && fullrune(p, x - p)){
 			p += chartorune(&r, p);
-			if(r)
+			if(r){
+				if(r == '\n' && cr){
+					cr = 0;
+					continue;
+				}
+				if(cr = (r == '\r'))
+					r = '\n';
 				send(rawchan, &r);
+			}
 		}
 		n = x - p;
-		if(n > 0){
-			memmove(buf, p, n);
-			p = buf + n;
-		}
+		memmove(buf, p, n);
+		p = buf + n;
 	}
 }
 
@@ -429,66 +433,44 @@
 void
 lineproc(void *aux)
 {
-	char *l, *p, *e, *s;
+	Rune rb[256], r;
 	Channel *cook;
-	int done;
-	Rune r;
-
+	int nr, done;
+	
 	cook = aux;
 
 	threadsetname("lineproc");
 
 	for(;;){
-		l = emalloc9p(1024);
-		p = l;
-		e = l + 1024-(UTFmax+1);
+		nr = 0;
 		done = 0;
 		do {
 			recv(cook, &r);
 			switch(r){
 			case '\0':	/* flush */
-				p = l;
+				nr = 0;
 				continue;
 			case '\b':	/* backspace */
 			case Knack:	/* ^U */
-				s = l;
-				while(s < p){
-					Rune x;
-					int i;
-
-					i = chartorune(&x, s);
-					s += i;
-					if(r == '\b'){
-						if(s >= p){
-							write(echofd, "\b", 1);
-							s -= i;
-							break;
-						}
-					} else
-						write(echofd, "\b", 1);
+				while(nr > 0){
+					nr--;
+					fprint(1, "\b");
+					if(r == '\b')
+						break;
 				}
-				if(r == '\b')
-					p = s;
-				else
-					p = l;
 				continue;
 			case Keof:	/* ^D */
 				done = 1;
 				break;
-			case '\r':
-				continue;
 			case '\n':
 				done = 1;
 				/* no break */
 			default:
-				s = p;
-				p += runetochar(p, &r);
-				if(p > s)
-					write(echofd, s, p - s);
+				rb[nr++] = r;
+				fprint(1, "%C", r);
 			}
-		} while(!done && p < e);
-		*p = 0;
-		sendp(linechan, l);
+		} while(!done && nr < nelem(rb));
+		sendp(linechan, utfconv(rb, nr));
 	}
 }
 
@@ -978,7 +960,7 @@
 
 	case Qcons:
 		n = r->ifcall.count;
-		if(write(echofd, r->ifcall.data, n) != n){
+		if(write(1, r->ifcall.data, n) != n){
 			responderror(r);
 			return;
 		}
@@ -1138,7 +1120,6 @@
 	char *srv = nil;
 
 	consfd = -1;
-	echofd = 1;
 
 	ARGBEGIN{
 	case 'd':
@@ -1162,12 +1143,9 @@
 	if((ledsfd = open("/dev/leds", OWRITE)) < 0)
 		fprint(2, "%s: warning: can't open /dev/leds: %r\n", argv0);
 
-	if(*argv){
-		if((consfd = open(*argv, ORDWR)) < 0)
+	if(*argv)
+		if((consfd = open(*argv, OREAD)) < 0)
 			fprint(2, "%s: warning: can't open %s: %r\n", argv0, *argv);
-		else
-			echofd = consfd;
-	}
 
 	keychan = chancreate(sizeof(Key), 8);
 	reqchan = chancreate(sizeof(Req*), 0);