From ceb1bdff4106003e9916372ed002c7fa62df935f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 10 Jun 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-06-10 --- boot/aux.c | 19 +++++++-- boot/boot.c | 8 +++- boot/boot.h | 2 +- gnot/fns.h | 1 + pc/main.c | 5 --- port/portfns.h | 1 - power/fns.h | 1 + power/io.h | 7 ++++ power/l.s | 4 +- power/main.c | 112 +++++++++++++++++++++++++------------------------ ss/main.c | 6 --- 11 files changed, 91 insertions(+), 75 deletions(-) diff --git a/boot/aux.c b/boot/aux.c index 927975d19bf4ce8bf9f14173e41b7fe0d3e1f8fc..778de67eebbc52d89cd431e702f2b30c5eb9b8ba 100644 --- a/boot/aux.c +++ b/boot/aux.c @@ -71,14 +71,12 @@ fatal(char *s) } int -readenv(char *name, char *buf, int len) +readfile(char *name, char *buf, int len) { int f, n; - char ename[2*NAMELEN]; - sprint(ename, "#e/%s", name); buf[0] = 0; - f = open(ename, OREAD); + f = open(name, OREAD); if(f < 0) return -1; n = read(f, buf, len-1); @@ -146,11 +144,18 @@ outin(char *prompt, char *def, int len) return n; } +/* + * get second word of the terminal environment variable. If it + * ends in "boot", get work of that part. + */ void getconffile(char *conffile, char *terminal) { char *p, *q; + char *s; + int n; + s = conffile; *conffile = 0; p = terminal; if((p = strchr(p, ' ')) == 0 || p[1] == ' ' || p[1] == 0) @@ -160,4 +165,10 @@ getconffile(char *conffile, char *terminal) ; while(p < q) *conffile++ = *p++; + *conffile = 0; + + /* dump a trailig boot */ + n = strlen(s); + if(n > 4 && strcmp(s + n - 4, "boot") == 0) + *(s+n-4) = 0; } diff --git a/boot/boot.c b/boot/boot.c index 7237b7fd49441ea898a33efc7a74d86cdd0e1419..ae27dd472ecf27f1a51166b226b1f4d9a29c5258 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -40,6 +40,10 @@ boot(int argc, char *argv[]) open("#c/cons", OWRITE); open("#c/cons", OWRITE); +/* for(fd = 0; fd < argc; fd++) + print("%s ", argv[fd]); + print("\n");/**/ + ARGBEGIN{ case 'a': aflag = 1; @@ -62,8 +66,8 @@ boot(int argc, char *argv[]) break; }ARGEND - readenv("cputype", cputype, sizeof(cputype)); - readenv("terminal", terminal, sizeof(cputype)); + readfile("#e/cputype", cputype, sizeof(cputype)); + readfile("#e/terminal", terminal, sizeof(cputype)); getconffile(conffile, terminal); /* diff --git a/boot/boot.h b/boot/boot.h index cba6f095f2fd98026218e62e34e0c82211c61308..07a4fa7d1a984b24b1c2347a0db2ea45e8781bd6 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -36,7 +36,7 @@ extern void newkernel(void); extern void nop(int); extern int outin(char*, char*, int); extern int plumb(char*, char*, int*, char*); -extern int readenv(char*, char*, int); +extern int readfile(char*, char*, int); extern int sendmsg(int, char*); extern void session(int); extern void setenv(char*, char*); diff --git a/gnot/fns.h b/gnot/fns.h index 75b6db193e635c2f82f86fd48389d22fefe89983..89e68c97342a43cb5c573b3ed086ee46af91d5f9 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -15,6 +15,7 @@ void duartstarttimer(void); void duartstoptimer(void); #define evenaddr(x) /* 68020 doesn't care */ void fault68020(Ureg*, FFrame*); +void firmware(void); #define flushapage(x) void flushcpucache(void); #define flushpage(x) if(x) diff --git a/pc/main.c b/pc/main.c index ae3296dad98c86db7be9942b6804c13d01adbce9..bd7a6768dd46f79ea3f39bbea2cb51f92def4f64 100644 --- a/pc/main.c +++ b/pc/main.c @@ -390,11 +390,6 @@ procrestore(Proc *p) { } -void -firmware(void) -{ - panic("firmware"); -} /* * the following functions all are slightly different from diff --git a/port/portfns.h b/port/portfns.h index 158a28a231138cda8d48b816830f6b5e10d9b8f8..8f9cb8e2871858f4596b7557e8160cdfcc91e72f 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -67,7 +67,6 @@ Block* expandb(Block*, int); int fault(ulong, int); void fdclose(int, int); Chan* fdtochan(int, int, int); -void firmware(void); int fixfault(Segment*, ulong, int, int); void flowctl(Queue*, Block*); void flushmmu(void); diff --git a/power/fns.h b/power/fns.h index 6f889924fb87ba2348a1b4c5e50c535b15aa25ef..c74a3c37a57214355d5115e76829b90a66ad1508 100644 --- a/power/fns.h +++ b/power/fns.h @@ -20,6 +20,7 @@ void duartxmit(int); void evenaddr(ulong); void faultmips(Ureg*, int, int); ulong fcr31(void); +void firmware(int); void flushmmu(void); #define flushpage(s) icflush((void*)(s), BY2PG) void gettlb(int, ulong*); diff --git a/power/io.h b/power/io.h index b5c7c6fafd888a39724ddb79327a78d8b0f57032..50085853c8cbefe8d1b1683c93e0e2f5b6276749 100644 --- a/power/io.h +++ b/power/io.h @@ -110,3 +110,10 @@ struct INTVEC { #define RTC (NVRAM+0x3ff8) #define SBEADDR ((ulong *)(UNCACHED|0x1F080000)) + +#define PROM_RESET 0 /* run diags, check bootmode, reinit */ +#define PROM_EXEC 1 /* load new program image */ +#define PROM_RESTART 2 /* re-enter monitor command loop */ +#define PROM_REINIT 3 /* re-init monitor, then cmd loop */ +#define PROM_REBOOT 4 /* check bootmode, no config */ +#define PROM_AUTOBOOT 5 /* autoboot the system */ diff --git a/power/l.s b/power/l.s index ef7c241fbc327984a10d7044ec916b589212e8cd..bb7ad8ac12bede3512a3bbe4f3a8552ef0392ef4 100644 --- a/power/l.s +++ b/power/l.s @@ -93,8 +93,8 @@ TEXT newstart(SB), $0 TEXT firmware(SB), $0 - MOVW $(PROM+0x18), R1 /**/ -/* MOVW $(PROM+0x00), R1 /**/ + SLL $3, R1 + ADD $PROM, R1 JMP (R1) TEXT splhi(SB), $0 diff --git a/power/main.c b/power/main.c index 772836a13262440b65d616584eaafe6ba4e18cc3..858c48afcfd41e61e594b55d0ce6f8e9f616db33 100644 --- a/power/main.c +++ b/power/main.c @@ -19,14 +19,14 @@ int _argc; char **_argv; char **_env; /* * arguments passed to initcode */ -char argbuf[512]; +char argbuf[128]; int argsize; /* - * environment passed to any kernel started by this kernel + * environment variables extracted from NVRAM */ -char envbuf[64]; -char *env[2]; +char consname[NAMELEN]; +char diskless[NAMELEN]; /* * configuration file read by boot program @@ -44,8 +44,8 @@ main(void) machinit(); active.exiting = 0; active.machs = 1; - confinit(); arginit(); + confinit(); lockinit(); printinit(); duartspecial(0, &printq, &kbdq, 9600); @@ -61,7 +61,6 @@ main(void) streaminit(); swapinit(); pageinit(); -print("userinit\n"); userinit(); launchinit(); schedinit(); @@ -204,7 +203,6 @@ void init0(void) { int i; - ulong *sp; Chan *c; m->proc = u->p; @@ -228,8 +226,7 @@ init0(void) } kproc("alarm", alarmkproc, 0); - sp = (ulong*)(USTKTOP - argsize); - touser(sp); + touser((uchar*)(USTKTOP - sizeof(argbuf))); } FPsave initfp; @@ -279,13 +276,11 @@ userinit(void) p->seg[SSEG] = s; pg = newpage(1, 0, USTKTOP-BY2PG); segpage(s, pg); - - memmove((ulong*)(pg->pa|KZERO|(BY2PG-argsize)), - argbuf + sizeof(argbuf) - argsize, argsize); - - av = (char **)(pg->pa|KZERO|(BY2PG-argsize)); - for(i = 0; i < _argc; i++) - av[i] += (char *)USTKTOP - (argbuf + sizeof(argbuf)); + k = kmap(pg); + for(av = (char**)argbuf; *av; av++) + *av += (USTKTOP - sizeof(argbuf)) - (ulong)argbuf; + memmove((uchar*)VA(k) + BY2PG - sizeof(argbuf), argbuf, sizeof argbuf); + kunmap(k); /* * Text @@ -377,7 +372,7 @@ exit(void) for(i=0; i<2000000; i++) ; duartenable0(); - firmware(); + firmware(conf.cntrlp ? PROM_AUTOBOOT : PROM_REINIT); } typedef struct Conftab { @@ -599,59 +594,68 @@ confinit(void) * copy arguments passed by the boot kernel (or ROM) into a temporary buffer. * we do this because the arguments are in memory that may be allocated * to processes or kernel buffers. + * + * also grab any environment variables that might be useful */ -#define IPADDRENV "netaddr=" +struct{ + char *name; + char *val; +}bootenv[] = { + {"netaddr=", sysname}, + {"console=", consname}, + {"diskless=", diskless}, +}; +char *sp; + +char * +pusharg(char *p) +{ + int n; + + n = strlen(p)+1; + sp -= n; + memmove(sp, p, n); + return sp; +} + void arginit(void) { int i, n; - int nbytes; - int ssize; - char *p; - char **argv; - char *charp; + char **av; /* - * get the system name from the environment + * get boot env variables */ - strcpy(envbuf, IPADDRENV); - for(argv = _env; *argv; argv++){ - if(strncmp(*argv, IPADDRENV, sizeof(IPADDRENV)-1)==0){ - strcat(envbuf, (*argv) + sizeof(IPADDRENV)-1); - break; - } - } - env[0] = envbuf; - env[1] = 0; + if(*sysname == 0) + for(av = _env; *av; av++) + for(i=0; i < sizeof bootenv/sizeof bootenv[0]; i++){ + n = strlen(bootenv[i].name); + if(strncmp(*av, bootenv[i].name, n) == 0){ + strncpy(bootenv[i].val, (*av)+n, NAMELEN); + bootenv[i].val[NAMELEN-1] = '\0'; + break; + } + } /* - * trim arguments to make them fit in the buffer (argv[0] is sysname) + * pack args into buffer */ - nbytes = 0; - _argv[0] = sysname; + av = (char**)argbuf; + sp = argbuf + sizeof(argbuf); for(i = 0; i < _argc; i++){ - n = strlen(_argv[i]) + 1; - ssize = BY2WD*(i+2) + ((nbytes+n+(BY2WD-1)) & ~(BY2WD-1)); - if(ssize > sizeof(argbuf)) - break; - nbytes += n; + if(i && *(_argv[i]) != '-') + diskless[0] = 0; + av[i] = pusharg(_argv[i]); } - _argc = i; - ssize = BY2WD*(i+1) + ((nbytes+(BY2WD-1)) & ~(BY2WD-1)); /* - * copy arguments into the buffer + * if no boot method is specified, look for + * a default in the diskless environment variable */ - argv = (char**)(argbuf + sizeof(argbuf) - ssize); - charp = (char*)(argbuf + sizeof(argbuf) - nbytes); - for(i=0; i<_argc; i++){ - argv[i] = charp; - n = strlen(_argv[i]) + 1; - memmove(charp, _argv[i], n); - charp += n; - } - _argv = argv; - argsize = ssize; + if(diskless[0] > '1') + av[i++] = pusharg(diskless); + av[i] = 0; } /* diff --git a/ss/main.c b/ss/main.c index 7f6e58b5620f28a3fff23933fbfacb075ebb771c..b064f1eaf02966d72f9bfad2cdd325501bc8dc86 100644 --- a/ss/main.c +++ b/ss/main.c @@ -307,9 +307,3 @@ lancesetup(Lance *lp) lp->ltp = lp->lrp+lp->nrrb; lp->tp = lp->rp+lp->nrrb; } - -void -firmware(void) -{ - systemreset(); -}