/* * starting place for first process */ void init0(void) { up->nerrlab = 0; spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(!waserror()){ ksetenv("terminal", "bitsy", 0); ksetenv("cputype", "arm", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); poperror(); } kproc("alarm", alarmkproc, 0); kproc("power", powerkproc, 0); touser(sp); }
void confsetenv(void) { int i; for(i = 0; i < nconf; i++){ if(confname[i][0] != '*') ksetenv(confname[i], confval[i], 0); ksetenv(confname[i], confval[i], 1); } }
void init0(void) { // char **p, *q, name[KNAMELEN]; // int n; char buf[2*KNAMELEN]; up->nerrlab = 0; spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(!waserror()){ snprint(buf, sizeof(buf), "power %s mtx", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "power", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); /* for(p = confenv; *p; p++) { q = strchr(p[0], '='); if(q == 0) continue; n = q-p[0]; if(n >= KNAMELEN) n = KNAMELEN-1; memmove(name, p[0], n); name[n] = 0; if(name[0] != '*') ksetenv(name, q+1, 0); ksetenv(name, q+1, 1); } */ poperror(); } kproc("alarm", alarmkproc, 0); kproc("mmusweep", mmusweep, 0); touser((void*)(USTKTOP-8)); }
void putenvq(char *name, char *val, int conf) { val = smprint("%q", val); ksetenv(name, val, conf); free(val); }
void init0(void) { Osenv *o; int i; char buf[2*KNAMELEN]; up->nerrlab = 0; spllo(); if(waserror()) panic("init0"); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ o = up->env; o->pgrp->slash = namec("#/", Atodir, 0, 0); cnameclose(o->pgrp->slash->name); o->pgrp->slash->name = newcname("/"); o->pgrp->dot = cclone(o->pgrp->slash); chandevinit(); if(!waserror()){ ksetenv("cputype", "power", 0); snprint(buf, sizeof(buf), "power %s", conffile); ksetenv("terminal", buf, 0); poperror(); } for(i = 0; i < nconf; i++) if(confname[i][0] != '*'){ if(!waserror()){ ksetenv(confname[i], confval[i], 0); poperror(); } } poperror(); disinit("/osinit.dis"); }
void init0(void) { Mach *m = machp(); char buf[2*KNAMELEN]; m->externup->nerrlab = 0; /* * if(consuart == nil) * i8250console("0"); */ spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ m->externup->slash = namec("#/", Atodir, 0, 0); pathclose(m->externup->slash->path); m->externup->slash->path = newpath("/"); m->externup->dot = cclone(m->externup->slash); devtabinit(); if(!waserror()){ snprint(buf, sizeof(buf), "%s %s", "AMD64", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", cputype, 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); ksetenv("pgsz", "2097152", 0); // no longer. confsetenv(); poperror(); } kproc("alarm", alarmkproc, 0); //debugtouser((void *)UTZERO); touser(sp); }
void init0(void) { Osenv *o; char buf[2*KNAMELEN]; up->nerrlab = 0; //print("Starting init0()\n"); spllo(); if(waserror()) panic("init0 %r"); /* These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ o = up->env; o->pgrp->slash = namec("#/", Atodir, 0, 0); cnameclose(o->pgrp->slash->name); o->pgrp->slash->name = newcname("/"); o->pgrp->dot = cclone(o->pgrp->slash); chandevinit(); if(!waserror()){ ksetenv("cputype", "arm", 0); snprint(buf, sizeof(buf), "arm %s", conffile); ksetenv("terminal", buf, 0); snprint(buf, sizeof(buf), "%s", getethermac()); ksetenv("ethermac", buf, 0); poperror(); } poperror(); disinit("/osinit.dis"); }
void putenvqv(char *name, char **v, int n, int conf) { Fmt f; int i; char *val; fmtstrinit(&f); for(i=0; i<n; i++) fmtprint(&f, "%s%q", i?" ":"", v[i]); val = fmtstrflush(&f); ksetenv(name, val, conf); free(val); }
void rebootcmd(int argc, char *argv[]) { Chan *c; Exec exec; ulong magic, text, rtext, entry, data, size; uchar *p; if(argc == 0) exit(0); c = namec(argv[0], Aopen, OEXEC, 0); if(waserror()){ cclose(c); nexterror(); } readn(c, &exec, sizeof(Exec)); magic = l2be(exec.magic); entry = l2be(exec.entry); text = l2be(exec.text); data = l2be(exec.data); if(magic != AOUT_MAGIC) error(Ebadexec); /* round text out to page boundary */ rtext = ROUNDUP(entry+text, PGSZ)-entry; size = rtext + data; p = malloc(size); if(p == nil) error(Enomem); if(waserror()){ free(p); nexterror(); } memset(p, 0, size); readn(c, p, text); readn(c, p + rtext, data); ksetenv("bootfile", argv[0], 1); setbootcmd(argc-1, argv+1); reboot((void*)entry, p, size); panic("return from reboot!"); }
static void setbootcmd(int argc, char *argv[]) { char *buf, *p, *ep; int i; buf = malloc(1024); if(buf == nil) error(Enomem); p = buf; ep = buf + 1024; for(i=0; i<argc; i++) p = seprint(p, ep, "%q ", argv[i]); *p = 0; ksetenv("bootcmd", buf, 1); free(buf); }
/* * starting place for first process */ void init0(void) { int i; char buf[2*KNAMELEN]; up->nerrlab = 0; coherence(); spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(!waserror()){ snprint(buf, sizeof(buf), "%s %s", "ARM", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "arm", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); snprint(buf, sizeof(buf), "-a %s", getethermac()); ksetenv("etherargs", buf, 0); /* convert plan9.ini variables to #e and #ec */ for(i = 0; i < nconf; i++) { ksetenv(confname[i], confval[i], 0); ksetenv(confname[i], confval[i], 1); } poperror(); } kproc("alarm", alarmkproc, 0); touser(sp); assert(0); /* shouldn't have returned */ }
void init0(void) { int i; char buf[2*KNAMELEN]; up->nerrlab = 0; spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(0 && !waserror()){ /* not needed by boot */ snprint(buf, sizeof(buf), "%s %s", arch->id, conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "386", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); for(i = 0; i < nconf; i++){ if(confname[i][0] != '*') ksetenv(confname[i], confval[i], 0); ksetenv(confname[i], confval[i], 1); } poperror(); } kproc("alarm", alarmkproc, 0); conschan = enamecopen("#c/cons", ORDWR); bootloadproc(0); panic("bootloadproc returned"); }
void init0(void) { int i; char buf[2*KNAMELEN]; up->nerrlab = 0; spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(!waserror()){ snprint(buf, sizeof(buf), "alpha %s alphapc", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "alpha", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); for(i = 0; i < nconf; i++) if(confname[i]){ if(confname[i][0] != '*') ksetenv(confname[i], confval[i], 0); ksetenv(confname[i], confval[i], 1); } poperror(); } kproc("alarm", alarmkproc, 0); touser((uchar*)(USTKTOP - sizeof(argbuf))); }
void init0(void) { // char **p, *q, name[KNAMELEN]; int i; char buf[2*KNAMELEN]; up->nerrlab = 0; spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); chandevinit(); if(!waserror()){ snprint(buf, sizeof(buf), "power %s mtx", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "power", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); for(i = 0; i < nconf; i++){ if(plan9ini[i].name[0] != '*') ksetenv(plan9ini[i].name, plan9ini[i].val, 0); ksetenv(plan9ini[i].name, plan9ini[i].val, 1); } poperror(); } kproc("alarm", alarmkproc, 0); kproc("mmusweep", mmusweep, 0); touser((void*)(USTKTOP-sizeof(Tos))); }
void rebootcmd(int argc, char *argv[]) { Chan *c; Exec exec; Execvals ev; ulong magic, text, rtext, entry, data, size; uchar *p; if(argc == 0) exit(0); c = namec(argv[0], Aopen, OEXEC, 0); if(waserror()){ cclose(c); nexterror(); } readn(c, &exec, sizeof(Exec)); magic = l2be(exec.magic); /* * AOUT_MAGIC is sometimes defined like this: * #define AOUT_MAGIC V_MAGIC || magic==M_MAGIC * so we can only use it in a fairly stylized manner. */ if(magic == AOUT_MAGIC) { entry = l2be(exec.entry); text = l2be(exec.text); data = l2be(exec.data); } else if(parseboothdr && (*parseboothdr)(c, magic, &ev) >= 0 || readelfhdr(c, magic, &ev) >= 0 || readelf64hdr(c, magic, &ev) >= 0){ entry = ev.entry; text = ev.textsize; data = ev.datasize; } else { error(Ebadexec); return; /* for the compiler */ } /* round text out to page boundary */ rtext = ROUNDUP(entry+text, BY2PG) - entry; size = rtext + data; p = malloc(size); if(p == nil) error(Enomem); if(waserror()){ free(p); nexterror(); } memset(p, 0, size); readn(c, p, text); readn(c, p + rtext, data); ksetenv("bootfile", argv[0], 1); setbootcmd(argc-1, argv+1); reboot((void*)entry, p, size); panic("return from reboot!"); }
void init0(void) { int i; char buf[2*KNAMELEN]; assert(up != nil); up->nerrlab = 0; barriers(); intrack(~0); clrmchk(); barriers(); spllo(); /* * These are o.k. because rootinit is null. * Then early kproc's will have a root and dot. */ up->slash = namec("#/", Atodir, 0, 0); pathclose(up->slash->path); up->slash->path = newpath("/"); up->dot = cclone(up->slash); dmainit(); /* starts dma kprocs */ devtabinit(); if(!waserror()){ snprint(buf, sizeof(buf), "power %s", conffile); ksetenv("terminal", buf, 0); ksetenv("cputype", "power", 0); if(cpuserver) ksetenv("service", "cpu", 0); else ksetenv("service", "terminal", 0); /* virtex configuration */ ksetenv("nvram", "/boot/nvram", 0); ksetenv("nvroff", "0", 0); ksetenv("nvrlen", "512", 0); ksetenv("nobootprompt", "tcp", 0); poperror(); } for(i = 0; i < nconf; i++){ if(confval[i] == nil) continue; if(confname[i][0] != '*'){ if(!waserror()){ ksetenv(confname[i], confval[i], 0); poperror(); } } if(!waserror()){ ksetenv(confname[i], confval[i], 1); poperror(); } } kproc("alarm", alarmkproc, 0); if (securemem) kproc("mutate", mutateproc, 0); else print("no secure memory found\n"); /* * The initial value of the user stack must be such * that the total used is larger than the maximum size * of the argument list checked in syscall. */ sync(); isync(); touser(sp); }
void emuinit(void *imod) { Osenv *e; char *wdir; e = up->env; e->pgrp = newpgrp(); e->fgrp = newfgrp(nil); e->egrp = newegrp(); e->errstr = e->errbuf0; e->syserrstr = e->errbuf1; e->user = strdup(""); links(); chandevinit(); if(waserror()) panic("setting root and dot"); e->pgrp->slash = namec("#/", Atodir, 0, 0); cnameclose(e->pgrp->slash->name); e->pgrp->slash->name = newcname("/"); e->pgrp->dot = cclone(e->pgrp->slash); poperror(); strcpy(up->text, "main"); if(kopen("#c/cons", OREAD) != 0) fprint(2, "failed to make fd0 from #c/cons: %r\n"); kopen("#c/cons", OWRITE); kopen("#c/cons", OWRITE); /* the setid cannot precede the bind of #U */ kbind("#U", "/", MAFTER|MCREATE); setid(eve, 0); kbind("#^", "/dev", MBEFORE); /* snarf */ kbind("#^", "/chan", MBEFORE); kbind("#m", "/dev", MBEFORE); /* pointer */ kbind("#c", "/dev", MBEFORE); kbind("#p", "/prog", MREPL); kbind("#d", "/fd", MREPL); kbind("#I", "/net", MAFTER); /* will fail on Plan 9 */ /* BUG: we actually only need to do these on Plan 9 */ kbind("#U/dev", "/dev", MAFTER); kbind("#U/net", "/net", MAFTER); kbind("#U/net.alt", "/net.alt", MAFTER); if(cputype != nil) ksetenv("cputype", cputype, 1); putenvqv("emuargs", rebootargv, rebootargc, 1); putenvq("emuroot", rootdir, 1); ksetenv("emuhost", hosttype, 1); wdir = malloc(1024); if(wdir != nil){ if(getwd(wdir, 1024) != nil) putenvq("emuwdir", wdir, 1); free(wdir); } kproc("main", disinit, imod, KPDUPFDG|KPDUPPG|KPDUPENVG); for(;;) ospause(); }
int main(int argc, char **argv) { char *env, *eq, *val; int ch, error; error = 0; val = NULL; env = NULL; while ((ch = getopt(argc, argv, "hNquv")) != -1) { switch (ch) { case 'h': hflag++; break; case 'N': Nflag++; break; case 'q': qflag++; break; case 'u': uflag++; break; case 'v': vflag++; break; default: usage(); } } argc -= optind; argv += optind; if (argc > 0) { env = argv[0]; eq = strchr(env, '='); if (eq != NULL) { *eq++ = '\0'; val = eq; } argv++; argc--; } if ((hflag || Nflag) && env != NULL) usage(); if (argc > 0 || ((uflag || vflag) && env == NULL)) usage(); if (env == NULL) { error = kdumpenv(); if (error && !qflag) warn("kdumpenv"); } else if (val == NULL) { if (uflag) { error = kunsetenv(env); if (error && !qflag) warnx("unable to unset %s", env); } else { error = kgetenv(env); if (error && !qflag) warnx("unable to get %s", env); } } else { error = ksetenv(env, val); if (error && !qflag) warnx("unable to set %s to %s", env, val); } return (error); }