History

devcons: add #c/kmesg, redraw kmesg buffer after resize

when resizing the screen, the text contents where lost. with the kmesg buffer, we can just re-render the text.

cinap_lenrek committed 8 years ago

Commit bc760551 parent fee6fdd3 files · +84 −33Browse files

Unified · Split

3 files
  1. kern/dat.h +19 −9
  2. kern/devcons.c +53 −1
  3. kern/term.c +12 −23
kern/dat.h+19−9
@@ -350,15 +350,15 @@ enum · 349 unmodified lines
350350
351351 struct Proc
352352 {
353− uint state;
354− uint mach;
353+ uint state;
354+ uint mach;
355355
356356 ulong pid;
357357 ulong parentpid;
358358
359359 Pgrp *pgrp; /* Process group for namespace */
360360 Fgrp *fgrp; /* File descriptor group */
361− Rgrp *rgrp;
361+ Rgrp *rgrp;
362362
363363 Lock rlock; /* sync sleep/wakeup with postnote */
364364 Rendez *r; /* rendezvous point slept on */
@@ -372,21 +372,21 @@ struct Proc · 7 unmodified lines
372372
373373 int nerrlab;
374374 Label errlab[NERR];
375− char user[KNAMELEN];
375+ char user[KNAMELEN];
376376 char *syserrstr; /* last error from a system call, errbuf0 or 1 */
377377 char *errstr; /* reason we're unwinding the error stack, errbuf1 or 0 */
378378 char errbuf0[ERRMAX];
379379 char errbuf1[ERRMAX];
380380 char genbuf[128]; /* buffer used e.g. for last name element from namec */
381− char text[KNAMELEN];
381+ char text[KNAMELEN];
382382
383383 Chan *slash;
384384 Chan *dot;
385385
386− Proc *qnext;
386+ Proc *qnext;
387387
388388 void (*fn)(void*);
389− void *arg;
389+ void *arg;
390390
391391 char oproc[1024]; /* reserved for os */
392392
@@ -469,6 +469,16 @@ enum · 76 unmodified lines
469469
470470 #define DEVDOTDOT -1
471471
472−extern Proc *_getproc(void);
473−extern void _setproc(Proc*);
472+extern Proc *_getproc(void);
473+extern void _setproc(Proc*);
474474 #define up (_getproc())
475+
476+/*
477+ * Log console output so it can be retrieved via /dev/kmesg.
478+ * This is good for catching boot-time messages after the fact.
479+ */
480+struct {
481+ Lock lk;
482+ uint n;
483+ char buf[16384];
484+} kmesg;
kern/devcons.c+53−1
@@ -97,6 +97,35 @@ printinit(void) · 96 unmodified lines
9797 qnoblock(kbdq, 1);
9898 }
9999
100+static void
101+kmesgputs(char *str, int n)
102+{
103+ uint nn, d;
104+
105+ ilock(&kmesg.lk);
106+ /* take the tail of huge writes */
107+ if(n > sizeof kmesg.buf){
108+ d = n - sizeof kmesg.buf;
109+ str += d;
110+ n -= d;
111+ }
112+
113+ /* slide the buffer down to make room */
114+ nn = kmesg.n;
115+ if(nn + n >= sizeof kmesg.buf){
116+ d = nn + n - sizeof kmesg.buf;
117+ if(d)
118+ memmove(kmesg.buf, kmesg.buf+d, sizeof kmesg.buf-d);
119+ nn -= d;
120+ }
121+
122+ /* copy the data in */
123+ memmove(kmesg.buf+nn, str, n);
124+ nn += n;
125+ kmesg.n = nn;
126+ iunlock(&kmesg.lk);
127+}
128+
100129 /*
101130 * Print a string on the console. Convert \n to \r\n for serial
102131 * line consoles. Locking of the queues is left up to the screen
@@ -106,6 +135,11 @@ printinit(void) · 3 unmodified lines
106135 static void
107136 putstrn0(char *str, int n, int usewrite)
108137 {
138+ /*
139+ * how many different output devices do we need?
140+ */
141+ kmesgputs(str, n);
142+
109143 /*
110144 * if someone is reading /dev/kprint,
111145 * put the message there.
@@ -298,6 +332,7 @@ enum{ · 186 unmodified lines
298332 Qconsctl,
299333 Qcputime,
300334 Qdrivers,
335+ Qkmesg,
301336 Qkprint,
302337 Qhostdomain,
303338 Qhostowner,
@@ -331,7 +366,8 @@ static Dirtab consdir[]={ · 27 unmodified lines
331366 "drivers", {Qdrivers}, 0, 0444,
332367 "hostdomain", {Qhostdomain}, DOMLEN, 0664,
333368 "hostowner", {Qhostowner}, 0, 0664,
334− "kprint", {Qkprint, 0, QTEXCL}, 0, DMEXCL|0440,
369+ "kmesg", {Qkmesg}, 0, 0440,
370+ "kprint", {Qkprint, 0, QTEXCL}, 0, DMEXCL|0440,
335371 "null", {Qnull}, 0, 0666,
336372 "osversion", {Qosversion}, 0, 0444,
337373 "pgrpid", {Qpgrpid}, NUMSIZE, 0444,
@@ -554,6 +590,22 @@ consread(Chan *c, void *buf, long n, vlong off) · 216 unmodified lines
554590 case Qcputime:
555591 return 0;
556592
593+ case Qkmesg:
594+ /*
595+ * This is unlocked to avoid tying up a process
596+ * that's writing to the buffer. kmesg.n never
597+ * gets smaller, so worst case the reader will
598+ * see a slurred buffer.
599+ */
600+ if(off >= kmesg.n)
601+ n = 0;
602+ else{
603+ if(off+n > kmesg.n)
604+ n = kmesg.n - off;
605+ memmove(buf, kmesg.buf+off, n);
606+ }
607+ return n;
608+
557609 case Qkprint:
558610 return qread(kprintoq, buf, n);
559611
kern/term.c+12−23
@@ -8,28 +8,18 @@ · 7 unmodified lines
88 #include <memdraw.h>
99 #include "screen.h"
1010
11−#define MINX 8
12−#define Backgnd 0xFF /* white */
11+extern Memimage *gscreen;
1312
14− Memsubfont *memdefont;
15−
16−struct{
17− Point pos;
18− int bwid;
19−}out;
20−
21−Lock screenlock;
22−
23−Memimage *conscol;
24−Memimage *back;
25−extern Memimage *gscreen;
26−
27−static Rectangle flushr;
28−static Rectangle window;
29−static Point curpos;
30−static int h;
31−static void termscreenputs(char*, int);
13+static Memsubfont *memdefont;
14+static Lock screenlock;
15+static Memimage *conscol;
16+static Memimage *back;
17+static Rectangle flushr;
18+static Rectangle window;
19+static Point curpos;
20+static int h;
3221
22+static void termscreenputs(char*, int);
3323
3424 static void
3525 screenflush(void)
@@ -84,6 +74,8 @@ screenwin(void) · 48 unmodified lines
8474 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
8575 flushmemscreen(gscreen->r);
8676 qunlock(&drawlock);
77+
78+ termscreenputs(kmesg.buf, kmesg.n);
8779 }
8880
8981 static struct {
@@ -137,9 +129,6 @@ void · 47 unmodified lines
137129 terminit(void)
138130 {
139131 memdefont = getmemdefont();
140− out.pos.x = MINX;
141− out.pos.y = 0;
142− out.bwid = memdefont->info[' '].width;
143132 screenwin();
144133 screenputs = termscreenputs;
145134 kproc("resize", resizeproc, nil);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t