Browse Source

Plan 9 from Bell Labs 2003-06-19

David du Colombier 21 years ago
parent
commit
2903f7d48e
6 changed files with 162 additions and 4 deletions
  1. 4 2
      dist/replica/plan9.db
  2. 4 0
      dist/replica/plan9.log
  3. 10 1
      sys/man/3/cons
  4. 60 1
      sys/src/9/port/devcons.c
  5. 30 0
      sys/src/9/port/mkrootall
  6. 54 0
      sys/src/9/port/mkrootc

+ 4 - 2
dist/replica/plan9.db

@@ -4718,7 +4718,7 @@ sys/man/3/apm - 664 sys sys 984709634 1625
 sys/man/3/arch - 664 sys sys 958419692 1425
 sys/man/3/audio - 664 sys sys 1015024777 2932
 sys/man/3/cap - 664 sys sys 1032632323 2137
-sys/man/3/cons - 664 sys sys 1017251174 8348
+sys/man/3/cons - 664 sys sys 1055954719 8588
 sys/man/3/draw - 664 sys sys 1040457030 13813
 sys/man/3/dup - 664 sys sys 1015024778 1099
 sys/man/3/env - 664 sys sys 1015024778 1409
@@ -5229,7 +5229,7 @@ sys/src/9/port/dev.c - 664 sys sys 1048912316 8379
 sys/src/9/port/devaudio.c - 664 sys sys 1055688292 21132
 sys/src/9/port/devbridge.c - 664 sys sys 1055688301 24308
 sys/src/9/port/devcap.c - 664 sys sys 1048644215 4113
-sys/src/9/port/devcons.c - 664 sys sys 1055700516 20933
+sys/src/9/port/devcons.c - 664 sys sys 1055954715 21969
 sys/src/9/port/devdraw.c - 664 sys sys 1039753332 41987
 sys/src/9/port/devdup.c - 664 sys sys 1014931172 2332
 sys/src/9/port/devenv.c - 664 sys sys 1048644225 6992
@@ -5270,6 +5270,8 @@ sys/src/9/port/mkerrstr - 775 sys sys 1015278340 75
 sys/src/9/port/mkextract - 775 sys sys 1039753334 435
 sys/src/9/port/mkfile - 664 sys sys 1045531976 266
 sys/src/9/port/mkroot - 775 sys sys 1039753334 235
+sys/src/9/port/mkrootall - 775 sys sys 1055954696 386
+sys/src/9/port/mkrootc - 775 sys sys 1055954695 717
 sys/src/9/port/mksystab - 664 sys sys 1014931176 783
 sys/src/9/port/netif.c - 664 sys sys 1045063591 13188
 sys/src/9/port/netif.h - 664 sys sys 1045063591 2944

+ 4 - 0
dist/replica/plan9.log

@@ -12319,3 +12319,7 @@
 1055826132 1 c sys/src/9/bitsy/mkfile - 664 sys sys 1055825921 2471
 1055826132 2 c sys/src/9/mtx/mkfile - 664 sys sys 1055825923 1508
 1055826132 3 c sys/src/9/pc/mkfile - 664 sys sys 1055825916 3100
+1055954727 0 c sys/man/3/cons - 664 sys sys 1055954719 8588
+1055954727 1 c sys/src/9/port/devcons.c - 664 sys sys 1055954715 21969
+1055954727 2 a sys/src/9/port/mkrootall - 775 sys sys 1055954696 386
+1055954727 3 a sys/src/9/port/mkrootc - 775 sys sys 1055954695 717

+ 10 - 1
sys/man/3/cons

@@ -12,6 +12,7 @@ cons \- console, clocks, process/process group ids, user, null, reboot, etc.
 .B /dev/drivers
 .B /dev/hostdomain
 .B /dev/hostowner
+.B /dev/kmesg
 .B /dev/kprint
 .B /dev/null
 .B /dev/osversion
@@ -110,6 +111,14 @@ At the moment, it contains one field: the 9P protocol version, currently
 .BR 2000 .
 .PP
 The
+.B kmesg
+file holds the last 16 kilobytes of output written to the console
+by the kernel's print statements or by processes writing to
+.BR /dev/cons .
+It is useful for retrieving boot messages once the boot
+process is over.
+.PP
+The
 .B kprint
 file may be read to receive a copy of the data written
 to the console by the kernel's print statements or by processes
@@ -131,7 +140,7 @@ on terminals until you have started
 The
 .B null
 file throws away anything written to it
-and always returns zero bytes when read.
+and always returns zero when read.
 .PP
 The
 .B zero

+ 60 - 1
sys/src/9/port/devcons.c

@@ -92,6 +92,41 @@ prflush(void)
 			break;
 }
 
+struct {
+	Lock lk;
+	char buf[16384];
+	uint n;
+} kmesg;
+
+static void
+kmesgputs(char *str, int n)
+{
+	uint nn, d;
+
+	ilock(&kmesg.lk);
+	/* take the tail of huge writes */
+	if(n > sizeof kmesg.buf){
+		d = n - sizeof kmesg.buf;
+		str += d;
+		n -= d;
+	}
+
+	/* slide the buffer down to make room */
+	nn = kmesg.n;
+	if(nn + n >= sizeof kmesg.buf){
+		d = nn + n - sizeof kmesg.buf;
+		if(d)
+			memmove(kmesg.buf, kmesg.buf+d, sizeof kmesg.buf-d);
+		nn -= d;
+	}
+
+	/* copy the data in */
+	memmove(kmesg.buf+nn, str, n);
+	nn += n;
+	kmesg.n = nn;
+	iunlock(&kmesg.lk);
+}
+
 /*
  *   Print a string on the console.  Convert \n to \r\n for serial
  *   line consoles.  Locking of the queues is left up to the screen
@@ -104,6 +139,11 @@ putstrn0(char *str, int n, int usewrite)
 	int m;
 	char *t;
 
+	/*
+	 *  how many different output devices do we need?
+	 */
+	kmesgputs(str, n);
+
 	/*
 	 *  if someone is reading /dev/kprint,
 	 *  put the message there.
@@ -393,6 +433,7 @@ echo(char *buf, int n)
 	qproduce(kbdq, buf, n);
 	if(kbd.raw)
 		return;
+	kmesgputs(buf, n);
 	if(screenputs != nil)
 		echoscreen(buf, n);
 	if(serialoq)
@@ -462,6 +503,7 @@ static void
 kbdputcclock(void)
 {
 	char *iw;
+
 	/* this amortizes cost of qproduce */
 	if(kbd.iw != kbd.ir){
 		iw = kbd.iw;
@@ -481,6 +523,7 @@ enum{
 	Qconsctl,
 	Qcputime,
 	Qdrivers,
+	Qkmesg,
 	Qkprint,
 	Qhostdomain,
 	Qhostowner,
@@ -513,6 +556,7 @@ static Dirtab consdir[]={
 	"drivers",	{Qdrivers},	0,		0444,
 	"hostdomain",	{Qhostdomain},	DOMLEN,		0664,
 	"hostowner",	{Qhostowner},	0,	0664,
+	"kmesg",		{Qkmesg},	0,	0440,
 	"kprint",		{Qkprint, 0, QTEXCL},	0,	DMEXCL|0440,
 	"null",		{Qnull},	0,		0666,
 	"osversion",	{Qosversion},	0,		0444,
@@ -657,7 +701,6 @@ consread(Chan *c, void *buf, long n, vlong off)
 
 	if(n <= 0)
 		return n;
-
 	switch((ulong)c->qid.path){
 	case Qdir:
 		return devdirread(c, buf, n, consdir, nelem(consdir), devgen);
@@ -730,6 +773,22 @@ consread(Chan *c, void *buf, long n, vlong off)
 		memmove(buf, tmp+k, n);
 		return n;
 
+	case Qkmesg:
+		/*
+		 * This is unlocked to avoid tying up a process
+		 * that's writing to the buffer.  kmesg.n never 
+		 * gets smaller, so worst case the reader will
+		 * see a slurred buffer.
+		 */
+		if(off >= kmesg.n)
+			n = 0;
+		else{
+			if(off+n > kmesg.n)
+				n = kmesg.n - off;
+			memmove(buf, kmesg.buf+off, n);
+		}
+		return n;
+		
 	case Qkprint:
 		return qread(kprintoq, buf, n);
 

+ 30 - 0
sys/src/9/port/mkrootall

@@ -0,0 +1,30 @@
+#!/bin/rc
+
+rfork e
+n=`{echo $#*^'%3' | hoc}
+if(! ~ $n 0){
+	echo 'usage: mkrootall [name cname file]...' >[1=2]
+	exit usage
+}
+
+tmp=mkroot.$pid.out
+fn sigexit {
+	rm -f $tmp
+}
+
+allcname=()
+while(! ~ $#* 0){
+	name=$1
+	cname=$2
+	file=$3
+	shift
+	shift 
+	shift
+	allcname=($allcname $cname)
+	cp $file $tmp
+	t=`{file $tmp}
+	if(~ $"t *executable*)
+		strip $tmp
+	aux/data2s $cname < $tmp
+}
+exit 0

+ 54 - 0
sys/src/9/port/mkrootc

@@ -0,0 +1,54 @@
+#!/bin/rc
+
+rfork e
+n=`{echo $#*^'%3' | hoc}
+if(! ~ $n 0){
+	echo 'usage: mkrootc [name cname file]...' >[1=2]
+	exit usage
+}
+
+tmp=mkroot.$pid.out
+fn sigexit {
+	rm -f $tmp
+}
+
+allcname=()
+allname=()
+while(! ~ $#* 0){
+	name=$1
+	cname=$2
+	file=$3
+	shift
+	shift 
+	shift
+	allname=($allname $name)
+	allcname=($allcname $cname)
+}
+
+echo '
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "io.h"
+#include "../port/error.h"
+'
+
+for(i in $allcname){
+	echo 'extern uchar '$i'code[];'
+	echo 'extern ulong '$i'len;'
+}
+
+echo '
+void bootlinks(void){
+'
+x=($allname)
+for(i in $allcname){
+	name=$x(1)
+	*=($x); shift; x=($*)
+	echo '	addbootfile("'$name'", '$i'code, '$i'len);'
+}
+echo '
+}
+'