serial console support

This commit is contained in:
cinap_lenrek 2011-05-13 08:53:43 +00:00
parent 36ab78221c
commit 76f99f7cb3
3 changed files with 37 additions and 52 deletions

View file

@ -141,6 +141,10 @@ except that the
.B bootfile .B bootfile
variable is set to variable is set to
.IR kernelpath . .IR kernelpath .
Writing the string
.B rdb
activates the remote kernel debugger (see
.IR rdbfs (4)).
Only the host Only the host
owner has the ability to open this file. owner has the ability to open this file.
.PP .PP

View file

@ -120,7 +120,10 @@ fn main{
if(test -e '#b' && test -x /bin/aux/kbdfs){ if(test -e '#b' && test -x /bin/aux/kbdfs){
bind -a '#b' /dev 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){ if(test -e '#u' && test -x /bin/usb/usbd){

View file

@ -86,9 +86,7 @@ char Efront[] = "the front fell off";
int scanfd; int scanfd;
int ledsfd; int ledsfd;
int consfd; int consfd;
int echofd;
int kbdopen; int kbdopen;
int consopen; int consopen;
@ -401,25 +399,31 @@ void
consproc(void *) consproc(void *)
{ {
char *p, *e, *x, buf[64]; char *p, *e, *x, buf[64];
int n; int n, cr;
Rune r; Rune r;
threadsetname("consproc"); threadsetname("consproc");
cr = 0;
p = buf; p = buf;
e = buf + sizeof(buf); e = buf + sizeof(buf);
while((n = read(consfd, p, e - p)) > 0){ while((n = read(consfd, p, e - p)) > 0){
x = buf + n; x = buf + n;
while(p < x && fullrune(p, x - p)){ while(p < x && fullrune(p, x - p)){
p += chartorune(&r, 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); send(rawchan, &r);
}
} }
n = x - p; n = x - p;
if(n > 0){ memmove(buf, p, n);
memmove(buf, p, n); p = buf + n;
p = buf + n;
}
} }
} }
@ -429,66 +433,44 @@ consproc(void *)
void void
lineproc(void *aux) lineproc(void *aux)
{ {
char *l, *p, *e, *s; Rune rb[256], r;
Channel *cook; Channel *cook;
int done; int nr, done;
Rune r;
cook = aux; cook = aux;
threadsetname("lineproc"); threadsetname("lineproc");
for(;;){ for(;;){
l = emalloc9p(1024); nr = 0;
p = l;
e = l + 1024-(UTFmax+1);
done = 0; done = 0;
do { do {
recv(cook, &r); recv(cook, &r);
switch(r){ switch(r){
case '\0': /* flush */ case '\0': /* flush */
p = l; nr = 0;
continue; continue;
case '\b': /* backspace */ case '\b': /* backspace */
case Knack: /* ^U */ case Knack: /* ^U */
s = l; while(nr > 0){
while(s < p){ nr--;
Rune x; fprint(1, "\b");
int i; if(r == '\b')
break;
i = chartorune(&x, s);
s += i;
if(r == '\b'){
if(s >= p){
write(echofd, "\b", 1);
s -= i;
break;
}
} else
write(echofd, "\b", 1);
} }
if(r == '\b')
p = s;
else
p = l;
continue; continue;
case Keof: /* ^D */ case Keof: /* ^D */
done = 1; done = 1;
break; break;
case '\r':
continue;
case '\n': case '\n':
done = 1; done = 1;
/* no break */ /* no break */
default: default:
s = p; rb[nr++] = r;
p += runetochar(p, &r); fprint(1, "%C", r);
if(p > s)
write(echofd, s, p - s);
} }
} while(!done && p < e); } while(!done && nr < nelem(rb));
*p = 0; sendp(linechan, utfconv(rb, nr));
sendp(linechan, l);
} }
} }
@ -978,7 +960,7 @@ fswrite(Req *r)
case Qcons: case Qcons:
n = r->ifcall.count; n = r->ifcall.count;
if(write(echofd, r->ifcall.data, n) != n){ if(write(1, r->ifcall.data, n) != n){
responderror(r); responderror(r);
return; return;
} }
@ -1138,7 +1120,6 @@ threadmain(int argc, char** argv)
char *srv = nil; char *srv = nil;
consfd = -1; consfd = -1;
echofd = 1;
ARGBEGIN{ ARGBEGIN{
case 'd': case 'd':
@ -1162,12 +1143,9 @@ threadmain(int argc, char** argv)
if((ledsfd = open("/dev/leds", OWRITE)) < 0) if((ledsfd = open("/dev/leds", OWRITE)) < 0)
fprint(2, "%s: warning: can't open /dev/leds: %r\n", argv0); fprint(2, "%s: warning: can't open /dev/leds: %r\n", argv0);
if(*argv){ if(*argv)
if((consfd = open(*argv, ORDWR)) < 0) if((consfd = open(*argv, OREAD)) < 0)
fprint(2, "%s: warning: can't open %s: %r\n", argv0, *argv); fprint(2, "%s: warning: can't open %s: %r\n", argv0, *argv);
else
echofd = consfd;
}
keychan = chancreate(sizeof(Key), 8); keychan = chancreate(sizeof(Key), 8);
reqchan = chancreate(sizeof(Req*), 0); reqchan = chancreate(sizeof(Req*), 0);