diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-13 08:53:43 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-13 08:53:43 +0000 |
commit | 76f99f7cb3731b3718209aee445ad409f184a3a9 (patch) | |
tree | 532972f2e189578646c3a8421f19d572f84d89dd /sys/src | |
parent | 36ab78221c2424a836cbc6a6ec7e92df8a16d6fe (diff) |
serial console support
Diffstat (limited to 'sys/src')
-rw-r--r-- | sys/src/9/boot/bootrc | 5 | ||||
-rw-r--r-- | sys/src/cmd/aux/kbdfs.c | 80 |
2 files changed, 33 insertions, 52 deletions
diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index 3d95f4d74..baa76f238 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -120,7 +120,10 @@ fn main{ 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){ diff --git a/sys/src/cmd/aux/kbdfs.c b/sys/src/cmd/aux/kbdfs.c index a6852bfd3..ab64dc277 100644 --- a/sys/src/cmd/aux/kbdfs.c +++ b/sys/src/cmd/aux/kbdfs.c @@ -86,9 +86,7 @@ char Efront[] = "the front fell off"; int scanfd; int ledsfd; - int consfd; -int echofd; int kbdopen; int consopen; @@ -401,25 +399,31 @@ void 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){ 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 @@ consproc(void *) 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 @@ fswrite(Req *r) 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 @@ threadmain(int argc, char** argv) char *srv = nil; consfd = -1; - echofd = 1; ARGBEGIN{ case 'd': @@ -1162,12 +1143,9 @@ threadmain(int argc, char** argv) 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); |