9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] changes in 9load
@ 2003-05-21 14:31 Fco.J.Ballesteros
  2003-05-21 14:58 ` Russ Cox
  0 siblings, 1 reply; 30+ messages in thread
From: Fco.J.Ballesteros @ 2003-05-21 14:31 UTC (permalink / raw)
  To: 9fans

Hi,

	this change makes two things:

	1- lets you use sections in 9load to define environment variables
	2- pass the boot information already parsed form 9load to the kernel.
	   *** This means that this 9load wont boot properly an old kernel.
	   *** An old 9load wont work with a kernel changed by these diffs.
	   *** An old kernel wont work with a 9load changed by these diffs.



Regarding 1, It's useful for things like:

plan9.ini:
...
[!venticonf]
# A file in $venticonf for the boot program
index oldworm
isect /dev/fs/other1
arenas /dev/fs/other

boot.rc:
...
# start venti from conf in plan9.ini
venti -c /env/venticonf

Regarding 2, I thought it was a good time to make the change.

I include first the changes for 9load. Near the end you can find
the changes for /sys/src/9/pc/main.c.

hth

diff -n /n/dump/2003/0515/sys/src/boot/pc /sys/src/boot/pc
diff -n /n/dump/2003/0515/sys/src/boot/pc/apm.c /sys/src/boot/pc/apm.c
/n/dump/2003/0515/sys/src/boot/pc/apm.c:13,14 c /sys/src/boot/pc/apm.c:13,17
< 	if(getconf("apm0") && apm.haveinfo)
< 		changeconf("apm0=ax=%x ebx=%x cx=%x dx=%x di=%x esi=%x\n",
---
> 	char buf[128];
> 	char* p;
>
> 	if(getconf("apm0") && apm.haveinfo){
> 		p = buf + sprint(buf, "ax=%x ebx=%x cx=%x dx=%x di=%x esi=%x",
/n/dump/2003/0515/sys/src/boot/pc/apm.c:15 a /sys/src/boot/pc/apm.c:19,21
> 		*p = 0;
> 		changeconf("apm0", buf);
> 	}
diff -n /n/dump/2003/0515/sys/src/boot/pc/bcom.c /sys/src/boot/pc/bcom.c
/n/dump/2003/0515/sys/src/boot/pc/bcom.c:439 c /sys/src/boot/pc/bcom.c:439
< addconf(char*, ...)
---
> addconf(char*, char*)
diff -n /n/dump/2003/0515/sys/src/boot/pc/conf.c /sys/src/boot/pc/conf.c
/n/dump/2003/0515/sys/src/boot/pc/conf.c:14 c /sys/src/boot/pc/conf.c:14
<  * There are 3584 bytes available at CONFADDR.
---
>  * There are 0x800 bytes available at CONFADDR (up to CPU0PDB).
/n/dump/2003/0515/sys/src/boot/pc/conf.c:18 a /sys/src/boot/pc/conf.c:19
>
/n/dump/2003/0515/sys/src/boot/pc/conf.c:21,22 c /sys/src/boot/pc/conf.c:22
< #define	BOOTARGSLEN	(3584-0x200-BOOTLINELEN)
< #define	MAXCONF		100
---
> #define	BOOTARGSLEN	(0x800-BOOTLINELEN)
/n/dump/2003/0515/sys/src/boot/pc/conf.c:24,26 c /sys/src/boot/pc/conf.c:24,37
< static char *confname[MAXCONF];
< static char *confval[MAXCONF];
< static int nconf;
---
> /*
>  * This must match the struct of the same name in the loaded kernel
>  */
> #define	MAXCONF		64
> typedef struct Bootconf {
> 	char	id[8];
> 	int	nconf;
> 	char	*name[MAXCONF];
> 	char	*val[MAXCONF];
> 	char	args[1];
> } Bootconf;
> static char*	bootargsend;
> static Bootconf*bootargs = (Bootconf*)BOOTARGS;
> static int	confparsed= 0;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:221 c /sys/src/boot/pc/conf.c:232,246
<
---
> 		// add blocks to define environment files
> 		for(i=0; i < nmblock; i++){
> 			mb = &mblock[i];
> 			if (mb->name[0] != '!')
> 				continue;
> 			p += sprint(p, "%s=", mb->name);
> 			// ugly hack: we later translate any \1
> 			// to a \n. Thats how we get multiple lines into
> 			// a single environment variable.
> 			for(n = mb->start; n < mb->end; n++){
> 				p += sprint(p, "%s", line[n]);
> 				*p++ = 1;
> 			}
> 			p += sprint(p, "\n");
> 		}
/n/dump/2003/0515/sys/src/boot/pc/conf.c:274 a /sys/src/boot/pc/conf.c:300,304
> 	if (!confparsed){
> 		if (debug)
> 			print("warning: ignored getconf: %s\n", name);
> 		return nil;
> 	}
/n/dump/2003/0515/sys/src/boot/pc/conf.c:276,277 c /sys/src/boot/pc/conf.c:306,307
< 	for(i = 0; i < nconf; i++)
< 		if(cistrcmp(confname[i], name) == 0)
---
> 	for(i = 0; i < bootargs->nconf; i++)
> 		if(cistrcmp(bootargs->name[i], name) == 0)
/n/dump/2003/0515/sys/src/boot/pc/conf.c:284,286 c /sys/src/boot/pc/conf.c:314,316
< 		for(i = 0; i < nconf; i++)
< 			if(cistrcmp(confname[i], name) == 0)
< 				print("%d. %s\n", ++nmatch, confval[i]);
---
> 		for(i = 0; i < bootargs->nconf; i++)
> 			if(cistrcmp(bootargs->name[i], name) == 0)
> 				print("%d. %s\n", ++nmatch, bootargs->val[i]);
/n/dump/2003/0515/sys/src/boot/pc/conf.c:293,294 c /sys/src/boot/pc/conf.c:323,324
< 		for(i = 0; i < nconf; i++)
< 			if(cistrcmp(confname[i], name) == 0)
---
> 		for(i = 0; i < bootargs->nconf; i++)
> 			if(cistrcmp(bootargs->name[i], name) == 0)
/n/dump/2003/0515/sys/src/boot/pc/conf.c:296 c /sys/src/boot/pc/conf.c:326
< 					return confval[i];
---
> 					return bootargs->val[i];
/n/dump/2003/0515/sys/src/boot/pc/conf.c:300,302 c /sys/src/boot/pc/conf.c:330,332
< 		for(i = 0; i < nconf; i++)
< 			if(cistrcmp(confname[i], name) == 0)
< 				return confval[i];
---
> 		for(i = 0; i < bootargs->nconf; i++)
> 			if(cistrcmp(bootargs->name[i], name) == 0)
> 				return bootargs->val[i];
/n/dump/2003/0515/sys/src/boot/pc/conf.c:312 c /sys/src/boot/pc/conf.c:342
< addconf(char *fmt, ...)
---
> addconf(char* var, char *val)
/n/dump/2003/0515/sys/src/boot/pc/conf.c:314 c /sys/src/boot/pc/conf.c:344,354
< 	donprint(BOOTARGS+strlen(BOOTARGS), BOOTARGS+BOOTARGSLEN, fmt, (&fmt+1));
---
> 	if (!confparsed){
> 		print("warning: ignored addconf: %s=%s\n", var, val);
> 		return;
> 	}
> 	bootargs->name[bootargs->nconf] = bootargsend;
> 	bootargsend += sprint(bootargsend, "%s", var);
> 	*bootargsend++ = 0;
> 	bootargs->val[bootargs->nconf] = bootargsend;
> 	bootargsend += sprint(bootargsend, "%s", val);
> 	*bootargsend++ = 0;
> 	bootargs->nconf++;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:318 c /sys/src/boot/pc/conf.c:358
< changeconf(char *fmt, ...)
---
> changeconf(char *var, char* val)
/n/dump/2003/0515/sys/src/boot/pc/conf.c:320 c /sys/src/boot/pc/conf.c:360
< 	char *p, *q, pref[20], buf[128];
---
> 	int	i;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:322,344 c /sys/src/boot/pc/conf.c:362,378
< 	donprint(buf, buf+sizeof buf, fmt, (&fmt+1));
< 	strncpy(pref+1, buf, 19);
< 	pref[19] = '\0';
< 	if(p = strchr(pref, '='))
< 		*(p+1) = '\0';
< 	else
< 		print("warning: did not change %s in plan9.ini\n", buf);
<
< 	/* find old line by looking for \nwhat= */
< 	pref[0] = '\n';
< 	if(strncmp(BOOTARGS, pref+1, strlen(pref+1)) == 0)
< 		p = BOOTARGS;
< 	else if(p = strstr(BOOTARGS, pref))
< 		p++;
< 	else
< 		p = nil;
<
< 	/* move rest of args up, deleting what= line. */
< 	if(p != nil && (q = strchr(p, '\n')) != nil)
< 		memmove(p, q+1, strlen(q+1)+1);
<
< 	/* add replacement to end */
< 	addconf("%s", buf);
---
> 	if (!confparsed){
> 		print("warning: ignored changeconf: %s=%s\n", var, val);
> 		return;
> 	}
> 	for(i = 0; i < bootargs->nconf; i++){
> 		if (strcmp(bootargs->name[i], var) == 0)
> 			break;
> 	}
> 	if (i == bootargs->nconf){
> 		bootargs->name[i] = bootargsend;
> 		bootargsend += sprint(bootargsend, "%s", var);
> 		*bootargsend++ = 0;
> 		bootargs->nconf++;
> 	}
> 	bootargs->val[i] = bootargsend;
> 	bootargsend += sprint(bootargsend, "%s", val);
> 	*bootargsend++ = 0;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:420,435 c /sys/src/boot/pc/conf.c:454,458
<
< 	/*
< 	 * Keep a copy.
< 	 * We could change this to pass the parsed strings
< 	 * to the booted programme instead of the raw
< 	 * string, then it only gets done once.
< 	 */
< 	if(strncmp(cp, id, sizeof(id))){
< 		memmove(BOOTARGS, id, sizeof(id));
< 		if(n+1+sizeof(id) >= BOOTARGSLEN)
< 			n -= sizeof(id);
< 		memmove(BOOTARGS+sizeof(id), cp, n+1);
< 	}
< 	else
< 		memmove(BOOTARGS, cp, n+1);
<
---
> 	memmove(bootargs->id, id, sizeof(id));
> 	memmove(bootargs->args, cp, n+1);
> 	bootargsend = bootargs->args + n+1;
> 	bootargs->nconf = 0;
> 	cp = bootargs->args;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:437 a /sys/src/boot/pc/conf.c:461,466
> 		if(*line[i] == '!'){			// a file in a
> 			line[i]++;			// variable.
> 			for(q = line[i]; *q; q++)
> 				if (*q == 1)		// ugly hack
> 					*q = '\n';	// see parsemenu.
> 		}
/n/dump/2003/0515/sys/src/boot/pc/conf.c:444,446 c /sys/src/boot/pc/conf.c:473,475
< 		confname[nconf] = line[i];
< 		confval[nconf] = cp;
< 		nconf++;
---
> 		bootargs->name[bootargs->nconf] = line[i];
> 		bootargs->val[bootargs->nconf] = cp;
> 		bootargs->nconf++;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:447 a /sys/src/boot/pc/conf.c:477
> 	confparsed = 1;
/n/dump/2003/0515/sys/src/boot/pc/conf.c:483,484 c /sys/src/boot/pc/conf.c:513,514
< 	for(n = 0; n < nconf; n++){
< 		if(cistrncmp(confname[n], cc, NAMELEN))
---
> 	for(n = 0; n < bootargs->nconf; n++){
> 		if(cistrncmp(bootargs->name[n], cc, NAMELEN))
/n/dump/2003/0515/sys/src/boot/pc/conf.c:487 c /sys/src/boot/pc/conf.c:517
< 		p = confval[n];
---
> 		p = bootargs->val[n];
diff -n /n/dump/2003/0515/sys/src/boot/pc/devsd.c /sys/src/boot/pc/devsd.c
/n/dump/2003/0515/sys/src/boot/pc/devsd.c:431 a /sys/src/boot/pc/devsd.c:432,434
> 	char	name[48];
> 	char	val[128];
> 	char   *bp;
/n/dump/2003/0515/sys/src/boot/pc/devsd.c:440,441 c /sys/src/boot/pc/devsd.c:443,445
<
< 	addconf("%spart=", unit->name);
---
> 	bp = name + sprint(name, "%spart", unit->name);
> 	*bp = 0;
> 	bp = val;
/n/dump/2003/0515/sys/src/boot/pc/devsd.c:443 c /sys/src/boot/pc/devsd.c:447
< 		addconf("%s%s %ld %ld", i==1 ? "" : "/", pp->name,
---
> 		bp += sprint(bp, "%s%s %ld %ld", i==1 ? "" : "/", pp->name,
/n/dump/2003/0515/sys/src/boot/pc/devsd.c:445 c /sys/src/boot/pc/devsd.c:449,450
< 	addconf("\n");
---
> 	*bp = 0;
> 	addconf(name,val);
diff -n /n/dump/2003/0515/sys/src/boot/pc/fns.h /sys/src/boot/pc/fns.h
/n/dump/2003/0515/sys/src/boot/pc/fns.h:2 c /sys/src/boot/pc/fns.h:2
< void	addconf(char*, ...);
---
> void	addconf(char*, char*);
/n/dump/2003/0515/sys/src/boot/pc/fns.h:15 c /sys/src/boot/pc/fns.h:15
< void	changeconf(char*, ...);
---
> void	changeconf(char*, char*);
diff -n /n/dump/2003/0515/sys/src/boot/pc/load.c /sys/src/boot/pc/load.c
/n/dump/2003/0515/sys/src/boot/pc/load.c:209 c /sys/src/boot/pc/load.c:209
< 			if(mp->flag & Fini){
---
> 			if((mp->flag & Fini)){
/n/dump/2003/0515/sys/src/boot/pc/load.c:214 d /sys/src/boot/pc/load.c:213
<
/n/dump/2003/0515/sys/src/boot/pc/load.c:238 a /sys/src/boot/pc/load.c:238
> 	Medium *inimp;
/n/dump/2003/0515/sys/src/boot/pc/load.c:242 a /sys/src/boot/pc/load.c:243
> 	mp = nil;
/n/dump/2003/0515/sys/src/boot/pc/load.c:255 a /sys/src/boot/pc/load.c:257
> 	inimp = nil;
/n/dump/2003/0515/sys/src/boot/pc/load.c:260,262 c /sys/src/boot/pc/load.c:262,263
< 			print("using %s!%s!%s\n", mp->name, mp->part, mp->ini);
< 			dotini(mp->inifs);
< 			break;
---
> 			if (inimp == nil)
> 				inimp = mp;
/n/dump/2003/0515/sys/src/boot/pc/load.c:263 a /sys/src/boot/pc/load.c:265,268
> 	}
> 	if (inimp != nil){
> 		print("using %s!%s!%s\n", mp->name, mp->part, mp->ini);
> 		dotini(inimp->inifs);

This is a change in the manual page.

diff -n /n/dump/2003/0515/sys/man/8/plan9.ini /sys/man/8/plan9.ini
/n/dump/2003/0515/sys/man/8/plan9.ini:770 a /sys/man/8/plan9.ini:771,775
> .LP
> Any block whose name begins with "!" is special. It defines
> a environment variable of the same name (without the "!"). The value
> of the variable is the text of the block. This feature can be
> used to supply small configuration files via environment variables.

These are the diffs for main.c :

diff -n /n/dump/2003/0515/sys/src/9/pc/main.c /sys/src/9/pc/main.c
/n/dump/2003/0515/sys/src/9/pc/main.c:16,18 c /sys/src/9/pc/main.c:16
<  * This will turn into a structure as more is done by the boot loader
<  * (e.g. why parse the .ini file twice?).
<  * There are 3584 bytes available at CONFADDR.
---
>  * There are 0x800 bytes available at CONFADDR.
/n/dump/2003/0515/sys/src/9/pc/main.c:19 a /sys/src/9/pc/main.c:18
>
/n/dump/2003/0515/sys/src/9/pc/main.c:23 c /sys/src/9/pc/main.c:22,26
< #define	BOOTARGSLEN	(4096-0x200-BOOTLINELEN)
---
> #define	BOOTARGSLEN	(0x800-BOOTLINELEN)
>
> /*
>  * This must match the struct of the same name in the loaded kernel
>  */
/n/dump/2003/0515/sys/src/9/pc/main.c:24 a /sys/src/9/pc/main.c:28,34
> typedef struct Bootconf {
> 	char	id[8];
> 	int	nconf;
> 	char	*name[MAXCONF];
> 	char	*val[MAXCONF];
> 	char	args[1];
> } Bootconf;
/n/dump/2003/0515/sys/src/9/pc/main.c:25 a /sys/src/9/pc/main.c:36,37
> static Bootconf*	bootconf = (Bootconf*)BOOTARGS;
>
/n/dump/2003/0515/sys/src/9/pc/main.c:28,30 d /sys/src/9/pc/main.c:39
< char *confname[MAXCONF];
< char *confval[MAXCONF];
< int nconf;
/n/dump/2003/0515/sys/src/9/pc/main.c:33,37 d /sys/src/9/pc/main.c:41
< static void
< options(void)
< {
< 	long i, n;
< 	char *cp, *line[MAXCONF], *p, *q;
/n/dump/2003/0515/sys/src/9/pc/main.c:39,71 d /sys/src/9/pc/main.c:42
< 	/*
< 	 *  parse configuration args from dos file plan9.ini
< 	 */
< 	cp = BOOTARGS;	/* where b.com leaves its config */
< 	cp[BOOTARGSLEN-1] = 0;
<
< 	/*
< 	 * Strip out '\r', change '\t' -> ' '.
< 	 */
< 	p = cp;
< 	for(q = cp; *q; q++){
< 		if(*q == '\r')
< 			continue;
< 		if(*q == '\t')
< 			*q = ' ';
< 		*p++ = *q;
< 	}
< 	*p = 0;
<
< 	n = getfields(cp, line, MAXCONF, 1, "\n");
< 	for(i = 0; i < n; i++){
< 		if(*line[i] == '#')
< 			continue;
< 		cp = strchr(line[i], '=');
< 		if(cp == nil)
< 			continue;
< 		*cp++ = '\0';
< 		confname[nconf] = line[i];
< 		confval[nconf] = cp;
< 		nconf++;
< 	}
< }
<
/n/dump/2003/0515/sys/src/9/pc/main.c:76 d /sys/src/9/pc/main.c:46
< 	options();
/n/dump/2003/0515/sys/src/9/pc/main.c:182,185 c /sys/src/9/pc/main.c:152,155
< 		for(i = 0; i < nconf; i++){
< 			if(confname[i][0] != '*')
< 				ksetenv(confname[i], confval[i], 0);
< 			ksetenv(confname[i], confval[i], 1);
---
> 		for(i = 0; i < bootconf->nconf; i++){
> 			if(bootconf->name[i][0] != '*')
> 				ksetenv(bootconf->name[i], bootconf->val[i], 0);
> 			ksetenv(bootconf->name[i], bootconf->val[i], 1);
/n/dump/2003/0515/sys/src/9/pc/main.c:307,309 c /sys/src/9/pc/main.c:277,279
< 	for(i = 0; i < nconf; i++)
< 		if(cistrcmp(confname[i], name) == 0)
< 			return confval[i];
---
> 	for(i = 0; i < bootconf->nconf; i++)
> 		if(cistrcmp(bootconf->name[i], name) == 0)
> 			return bootconf->val[i];



^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2003-05-23 15:24 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-21 14:31 [9fans] changes in 9load Fco.J.Ballesteros
2003-05-21 14:58 ` Russ Cox
2003-05-21 15:00   ` Fco.J.Ballesteros
2003-05-21 15:22     ` Russ Cox
2003-05-21 15:46       ` [9fans] VAIO ATI RAGE MOBILITY-M1 AGP 1024x768x16 lcd display boyd, rounin
2003-05-21 17:45         ` Russ Cox
2003-05-22  8:46           ` boyd, rounin
2003-05-22  9:32             ` Philippe Anel
2003-05-22 17:49             ` Russ Cox
2003-05-23  8:37             ` Adrian Tritschler
2003-05-23 14:04               ` Russ Cox
2003-05-23 14:53                 ` Sape Mullender
2003-05-23 15:11                 ` Dan Cross
2003-05-23 15:17                   ` Russ Cox
2003-05-23 15:24                     ` Dan Cross
2003-05-21 15:57       ` [9fans] changes in 9load Fco.J.Ballesteros
2003-05-21 17:24         ` Russ Cox
2003-05-21 16:26       ` northern snowfall
2003-05-21 17:06       ` Lucio De Re
2003-05-21 17:15         ` Fco.J.Ballesteros
2003-05-21 17:25           ` Lucio De Re
2003-05-21 17:32             ` Fco.J.Ballesteros
2003-05-21 17:35             ` Russ Cox
2003-05-21 17:39               ` Fco.J.Ballesteros
2003-05-21 18:03                 ` Lucio De Re
2003-05-21 18:11                   ` Fco.J.Ballesteros
2003-05-21 18:39                     ` Lucio De Re
2003-05-21 17:47               ` Lucio De Re
2003-05-21 17:51                 ` Russ Cox
2003-05-21 17:56                   ` Lucio De Re

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).