shithub: 9ferno

Download patch

ref: d820cecf3f0e00f02da03d85f6db118d989e140b
parent: 2dd98ec94ebe7429531ae99996841e46faa73e5c
author: 9ferno <gophone2015@gmail.com>
date: Fri Aug 6 17:58:45 EDT 2021

changes to have a common boot script across vmx and phsical machine

--- a/dis/init	Fri Aug  6 10:59:12 2021
+++ b/dis/init	Fri Aug  6 17:58:45 2021
@@ -4,45 +4,52 @@
 load std
 
 mount { mntgen } /n
-#disk/fdisk -p /dev/sdG0/data >/dev/sdG0/ctl
-#disk/prep -p /dev/sdG0/plan9 > /dev/sdG0/ctl
+
+## usually better than 1970
+#cat '#r/rtc' >/dev/time >[2]/dev/null
 #
-## for using the cd
-#9660srv /dev/sdF0/data /n/cd
-#bind -b /n/cd/dis /dis
-##bind -b /n/cd/Inferno/386 /
-#
-#### for formatting the disk
-####	bind -a '#S' /dev	# simple.b does this
-###disk/mbr -m mbr /dev/sdG0/data
-###disk/fdisk -baw /dev/sdG0/data
-###disk/prep -bw -a^(9fat fs) /dev/sdG0/plan9
-###disk/format -b pbs -d -r 2 /dev/sdG0/9fat 9bootfat /n/cd/cfg/plan9.ini
-##
-### for installing to a formatted disk
-##mount -c { disk/kfs -r -n root /dev/sdG0/fs } /n/rootdisk # ream
-##disk/kfscmd -n root sync
-##disk/mkfs -v -r -s /n/cd/ -d /n/rootdisk/ <{ echo + }
-##disk/kfscmd -n root sync
-#
-### starting inferno already installed to a disk
-##mount -c { disk/kfs -D -n rootdisk /dev/sdG0/fs } /n/rootdisk
-##disk/kfscmd -n rootdisk sync
-###bind -b /n/rootdisk/dis /dis
-##bind -a -c /n/rootdisk/ /
-###disk/mkfs -v -s /n/cd/ -d /n/rootdisk/ <{ echo + }
-#
-#ftest -f '#P'/archctl && {
-#	echo '#P'/archctl
-#	cat '#P'/archctl
+#fn showlocaldev {
+#	echo $1'	' $2
+#	if(~ $#bootargs 0){
+#		if(! ~ $#cdboot 0){
+#			if(~ $2 9660)
+#				bootargs=local!$1
+#		}
+#		if not {
+#			if(! ~ $2 '' dos)
+#				bootargs=local!$1
+#		}
+#	}
 #}
-#bind -b /n/cd/ /
-#ns
-#ndb/cs -v
-#<>/net/ipifc/clone {
-#	x=`{read}
-#	echo bind ether /net/ether0 > /net/ipifc/$x/ctl
-#	ip/dhcp -h vmx9ferno -p /net/ipifc/$x
+#
+#fn showlocaldevs{
+#	for(d in /dev/sd*) if(test -r $d/ctl){
+#		q=`{sed 's,(inquiry|geometry),\
+#\1,g' $d/ctl | grep inquiry}
+#		echo $d':' $q(2-)
+#		for(i in `{ls -p $d}){
+#			p=$d/$i
+#			switch($i){
+#			case ctl raw log led
+#				;
+#			case plan9 nvram swap
+#				echo $p
+#			case *
+#				showlocaldev $p `{fstype $p}
+#			}
+#		}
+#	}
+#	for(d in /shr/sd*) if(test -d $d) {
+#		echo $d':'
+#		for(p in $d/*.^(iso paq)) if(test -f $p){
+#			t=`{fstype $p}
+#			~ $#t 0 || showlocaldev $p $t
+#		}
+#	}
 #}
+#
+#showlocaldevs
+
+ftest -f `{cat /dev/user}^/lib/profile && `{cat /dev/user}^/lib/profile
 
 sh -n
--- /dev/null	Mon Oct 18 12:05:45 2021
+++ b/os/init/disinit.b	Fri Aug  6 17:58:45 2021
@@ -0,0 +1,121 @@
+#
+#	simple Init that calls /dis/init, a shell script to continue initialization
+#
+implement Init;
+
+include "sys.m";
+include "draw.m";
+
+sys: Sys;
+FD: import sys;
+print, fprint, bind: import sys;
+
+stderr:	ref sys->FD;						# standard error FD
+
+Init: module
+{
+	init:	fn(nil: ref Draw->Context, nil: list of string);
+};
+
+Sh: module
+{
+	init:	fn(ctxt: ref Draw->Context, argv: list of string);
+};
+
+init(nil: ref Draw->Context, nil: list of string)
+{
+	sys = load Sys Sys->PATH;
+	stderr = sys->fildes(2);
+
+	sys->print("Welcome to Inferno...\n");
+
+	# set up basic devices, ignoring errors
+	# 9front does this in the shell. Can move them to dis/init later
+	sys->bind("#c", "/dev", sys->MAFTER);	# console device
+	sys->bind("#d", "/fd", Sys->MREPL);		# dup(3)
+	sys->bind("#e", "/env", sys->MAFTER);	# env
+#	sys->bind("#i", "/dev", sys->MREPL);	# draw device
+	sys->bind("#l", "/net", sys->MAFTER);	# Network interfaces
+	sys->bind("#m","/dev",sys->MAFTER);     # pointer/mouse
+	sys->bind("#p", "/prog", sys->MREPL);	# prog device
+	sys->bind("#t", "/dev", sys->MAFTER);	# serial line
+#	sys->bind("#v","/dev",sys->MAFTER);     # VGA
+	sys->bind("#I", "/net", sys->MAFTER);	# IP
+	sys->bind("#P","/dev",sys->MAFTER);		# arch
+#	sys->bind("#P/realmode","/dev",sys->MAFTER); # not in the arch(3). What is this for?
+#	sys->bind("#P/realmodemem","/dev",sys->MAFTER);# not in the arch(3). What is this for?
+#	sys->bind("#O", "/dev", sys->MAFTER);	# Modem
+	sys->bind("#S", "/dev", sys->MAFTER);	# Disks
+#	sys->bind("#T","/dev",sys->MAFTER);		# Touchscreen
+#	sys->bind("#W","/dev",sys->MAFTER);		# Flash
+
+	srv();
+
+	#sys->print("after the binds\n");
+	sh := load Sh "/dis/sh.dis";
+	(s, nil) := sys->stat("/dis/init");
+	if(s == 0){
+		#sys->print("spawn sh -n /dis/init\n");
+		spawn sh->init(nil, "sh" :: "-n" :: "/dis/init" :: nil);
+	} else {
+		sys->fprint(stderr, "init: cannot find /dis/init: %r\n");
+		spawn sh->init(nil, "-n" :: nil);
+	}
+}
+
+srv()
+{
+	remotedebug := sysenv("remotedebug");
+	if(remotedebug != "1")
+		return;
+
+	sys->print("srv...");
+	if(echoto("#t/eia0ctl", "b38400") < 0)
+		return;
+
+	fd := sys->open("/dev/eia0", Sys->ORDWR);
+	if (fd == nil) {
+		sys->print("eia data open: %r\n");
+		return;
+	}
+	if (sys->export(fd, "/", Sys->EXPASYNC) < 0) {
+		sys->print("export: %r\n");
+		return;
+	}
+	sys->print("ok\n");
+}
+
+sysenv(param: string): string
+{
+	fd := sys->open("#c/sysenv", sys->OREAD);
+	if (fd == nil)
+		return(nil);
+	buf := array[4096] of byte;
+	nb := sys->read(fd, buf, len buf);
+	(nfl,fl) := sys->tokenize(string buf, "\n");
+	while (fl != nil) {
+		pair := hd fl;
+		(npl, pl) := sys->tokenize(pair, "=");
+		if (npl > 1) {
+			if ((hd pl) == param)
+				return hd tl pl;
+		}
+		fl = tl fl;
+	}
+	return nil ;
+}
+
+echoto(fname, str: string): int
+{
+	fd := sys->open(fname, Sys->OWRITE);
+	if(fd == nil) {
+		sys->print("%s: %r\n", fname);
+		return -1;
+	}
+	x := array of byte str;
+	if(sys->write(fd, x, len x) == -1) {
+		sys->print("write: %r\n");
+		return -1;
+	}
+	return 0;
+}
--- a/os/init/simple.b	Fri Aug  6 10:59:12 2021
+++ /dev/null	Mon Oct 18 12:05:45 2021
@@ -1,61 +0,0 @@
-#
-#	simple Init that calls /dis/init, a shell script to continue initialization
-#
-implement Init;
-
-include "sys.m";
-include "draw.m";
-
-sys: Sys;
-FD: import sys;
-print, fprint, bind: import sys;
-
-stderr:	ref sys->FD;						# standard error FD
-
-Init: module
-{
-	init:	fn(nil: ref Draw->Context, nil: list of string);
-};
-
-Sh: module
-{
-	init:	fn(ctxt: ref Draw->Context, argv: list of string);
-};
-
-init(nil: ref Draw->Context, nil: list of string)
-{
-	sys = load Sys Sys->PATH;
-	stderr = sys->fildes(2);
-
-	sys->print("Welcome to Inferno...\n");
-
-	# set up basic devices, ignoring errors
-	sys->bind("#d", "/fd", Sys->MREPL);		# dup(3)
-	sys->bind("#S", "/dev", sys->MAFTER);	# Disks
-	sys->bind("#l", "/net", sys->MAFTER);	# Network interfaces - hangs this program now
-	sys->bind("#I", "/net", sys->MAFTER);	# IP
-	sys->bind("#p", "/prog", sys->MREPL);	# prog device
-	sys->bind("#t", "/dev", sys->MAFTER);	# serial line
-	sys->bind("#c", "/dev", sys->MAFTER);	# console device
-	sys->bind("#e", "/env", sys->MAFTER);	# env
-	sys->bind("#P","/dev",sys->MAFTER);		# arch
-#	sys->bind("#P/realmode","/dev",sys->MAFTER); # not in the arch(3). What is this for?
-#	sys->bind("#P/realmodemem","/dev",sys->MAFTER);# not in the arch(3). What is this for?
-#	sys->bind("#i", "/dev", sys->MREPL);	# draw device
-#	sys->bind("#v","/dev",sys->MAFTER);     # VGA
-	sys->bind("#m","/dev",sys->MAFTER);     # pointer/mouse
-#	sys->bind("#W","/dev",sys->MAFTER);		# Flash
-#	sys->bind("#O", "/dev", sys->MAFTER);	# Modem
-#	sys->bind("#T","/dev",sys->MAFTER);		# Touchscreen
-
-	#sys->print("after the binds\n");
-	sh := load Sh "/dis/sh.dis";
-	(s, nil) := sys->stat("/dis/init");
-	if(s == 0){
-		#sys->print("spawn sh -n /dis/init\n");
-		spawn sh->init(nil, "sh" :: "-n" :: "/dis/init" :: nil);
-	} else {
-		sys->fprint(stderr, "init: cannot find /dis/init: %r\n");
-		spawn sh->init(nil, nil);
-	}
-}
--- a/os/pc64/pc64	Fri Aug  6 10:59:12 2021
+++ b/os/pc64/pc64	Fri Aug  6 17:58:45 2021
@@ -117,7 +117,7 @@
 	math
 
 init
-	simple
+	disinit
 	#shell
 	#wminit