⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
📖 第 1 页 / 共 2 页
字号:
voidremoveselect(name)        const char *name;{	register const char *n;	register char *p, c;	char low[500];	/* make lowercase, then remove from select table */	for (n = name, p = low; (c = *n) != '\0'; n++)		*p++ = isupper(c) ? tolower(c) : c;	*p = 0;	n = intern(low);	(void)ht_remove(selecttab, n);}/* * Add a "make" option. */voidaddmkoption(name, value)	const char *name, *value;{	(void)do_option(mkopttab, &nextmkopt, name, value, "mkoptions");}/* * Add a name=value pair to an option list.  The value may be NULL. */static intdo_option(ht, nppp, name, value, type)	struct hashtab *ht;	struct nvlist ***nppp;	const char *name, *value, *type;{	register struct nvlist *nv;	/* assume it will work */	nv = newnv(name, value, NULL, 0, NULL);	if (ht_insert(ht, name, nv) == 0) {		**nppp = nv;		*nppp = &nv->nv_next;		return (0);	}	/* oops, already got that option */	nvfree(nv);	if ((nv = ht_lookup(ht, name)) == NULL)		panic("do_option");	if (nv->nv_str != NULL)		error("already have %s `%s=%s'", type, name, nv->nv_str);	else		error("already have %s `%s'", type, name);	return (1);}/* * Return true if there is at least one instance of the given unit * on the given device attachment (or any units, if unit == WILD). */intdeva_has_instances(deva, unit)	register struct deva *deva;	int unit;{	register struct devi *i;	if (unit == WILD)		return (deva->d_ihead != NULL);	for (i = deva->d_ihead; i != NULL; i = i->i_asame)		if (unit == i->i_unit)			return (1);	return (0);}/* * Return true if there is at least one instance of the given unit * on the given base (or any units, if unit == WILD). */intdevbase_has_instances(dev, unit)	register struct devbase *dev;	int unit;{	register struct deva *da;	for (da = dev->d_ahead; da != NULL; da = da->d_bsame)		if (deva_has_instances(da, unit))			return (1);	return (0);}static inthasparent(i)	register struct devi *i;{	register struct nvlist *nv;	int atunit = i->i_atunit;	/*	 * We determine whether or not a device has a parent in in one	 * of two ways:	 *	(1) If a parent device was named in the config file,	 *	    i.e. cases (2) and (3) in sem.c:adddev(), then	 *	    we search its devbase for a matching unit number.	 *	(2) If the device was attach to an attribute, then we	 *	    search all attributes the device can be attached to	 *	    for parents (with appropriate unit numebrs) that	 *	    may be able to attach the device.	 */	/*	 * Case (1): A parent was named.  Either it's configured, or not.	 */	if (i->i_atdev != NULL)		return (devbase_has_instances(i->i_atdev, atunit));	/*	 * Case (2): No parent was named.  Look for devs that provide the attr.	 */	if (i->i_atattr != NULL)		for (nv = i->i_atattr->a_refs; nv != NULL; nv = nv->nv_next)			if (devbase_has_instances(nv->nv_ptr, atunit))				return (1);	return (0);}static intcfcrosscheck(cf, what, nv)	register struct config *cf;	const char *what;	register struct nvlist *nv;{	register struct devbase *dev;	register struct devi *pd;	int errs, devminor;	for (errs = 0; nv != NULL; nv = nv->nv_next) {		if (nv->nv_name == NULL)			continue;		dev = ht_lookup(devbasetab, nv->nv_name);		if (dev == NULL)			panic("cfcrosscheck(%s)", nv->nv_name);		devminor = minor(nv->nv_int) / 16;		if (devbase_has_instances(dev, devminor))			continue;		if (devbase_has_instances(dev, STAR) &&		    devminor >= dev->d_umax)			continue;		for (pd = allpseudo; pd != NULL; pd = pd->i_next)			if (pd->i_base == dev && devminor < dev->d_umax &&			    devminor >= 0)				goto loop;		(void)fprintf(stderr,		    "%s:%d: %s says %s on %s, but there's no %s\n",		    conffile, cf->cf_lineno,		    cf->cf_name, what, nv->nv_str, nv->nv_str);		errs++;loop:	}	return (errs);}/* * Cross-check the configuration: make sure that each target device * or attribute (`at foo[0*?]') names at least one real device.  Also * see that the root, swap, and dump devices for all configurations * are there. */intcrosscheck(){	register struct devi *i;	register struct config *cf;	int errs;	errs = 0;	for (i = alldevi; i != NULL; i = i->i_next) {		if (i->i_at == NULL || hasparent(i))			continue;		xerror(conffile, i->i_lineno,		    "%s at %s is orphaned", i->i_name, i->i_at);		(void)fprintf(stderr, " (%s %s declared)\n",		    i->i_atunit == WILD ? "nothing matching" : "no",		    i->i_at);		errs++;	}	if (allcf == NULL) {		(void)fprintf(stderr, "%s has no configurations!\n",		    conffile);		errs++;	}	for (cf = allcf; cf != NULL; cf = cf->cf_next) {		if (cf->cf_root != NULL) {	/* i.e., not swap generic */			errs += cfcrosscheck(cf, "root", cf->cf_root);			errs += cfcrosscheck(cf, "swap", cf->cf_swap);			errs += cfcrosscheck(cf, "dumps", cf->cf_dump);		}	}	return (errs);}/* * Check to see if there is a *'d unit with a needs-count file. */intbadstar(){	register struct devbase *d;	register struct deva *da;	register struct devi *i;	register int errs, n;	errs = 0;	for (d = allbases; d != NULL; d = d->d_next) {		for (da = d->d_ahead; da != NULL; da = da->d_bsame)			for (i = da->d_ihead; i != NULL; i = i->i_asame) {				if (i->i_unit == STAR)					goto foundstar;			}		continue;	foundstar:		if (ht_lookup(needcnttab, d->d_name)) {			(void)fprintf(stderr,		    "config: %s's cannot be *'d until its driver is fixed\n",			    d->d_name);			errs++;			continue;		}		for (n = 0; i != NULL; i = i->i_alias)			if (!i->i_collapsed)				n++;		if (n < 1)			panic("badstar() n<1");	}	return (errs);}/* * Verify/create builddir if necessary, change to it, and verify srcdir. * This will be called when we see the first include. */voidsetupdirs(){	struct stat st;	/* srcdir must be specified if builddir is not specified or if	 * no configuration filename was specified. */	if ((builddir || strcmp(defbuilddir, ".") == 0) && !srcdir) {		error("source directory must be specified");		exit(1);	}	if (srcdir == NULL)		srcdir = "../../../..";	if (builddir == NULL)		builddir = defbuilddir;	if (stat(builddir, &st) != 0) {		if (mkdir(builddir, 0777)) {			(void)fprintf(stderr, "config: cannot create %s: %s\n",			    builddir, strerror(errno));			exit(2);		}		madedir = 1;	} else if (!S_ISDIR(st.st_mode)) {		(void)fprintf(stderr, "config: %s is not a directory\n",			      builddir);		exit(2);	}	if (chdir(builddir) != 0) {		(void)fprintf(stderr, "config: cannot change to %s\n",			      builddir);		exit(2);	}	if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) {		(void)fprintf(stderr, "config: %s is not a directory\n",			      srcdir);		exit(2);	}}struct opt {	const char *name;	const char *val;};intoptcmp(sp1, sp2)	struct opt *sp1, *sp2;{	int r;	r = strcmp(sp1->name, sp2->name);	if (r == 0) {		if (!sp1->val && !sp2->val)			r = 0;			else if (sp1->val && !sp2->val)			r = -1;		else if (sp2->val && !sp1->val)			r = 1;		else r = strcmp(sp1->val, sp2->val);	}	return (r);}voidoptiondelta(){	register struct nvlist *nv;	char nbuf[BUFSIZ], obuf[BUFSIZ];	/* XXX size */	int nnewopts, ret = 0, i;	struct opt *newopts;	FILE *fp;	for (nnewopts = 0, nv = options; nv != NULL; nv = nv->nv_next)		nnewopts++;	newopts = (struct opt *)malloc(nnewopts * sizeof(struct opt));	if (newopts == NULL)		ret = 0;	for (i = 0, nv = options; nv != NULL; nv = nv->nv_next, i++) {		newopts[i].name = nv->nv_name;		newopts[i].val = nv->nv_str;	}	qsort(newopts, nnewopts, sizeof (struct opt), optcmp);	/* compare options against previous config */	if ((fp = fopen("options", "r"))) {		for (i = 0; !feof(fp) && i < nnewopts && ret == 0; i++) {			if (newopts[i].val)				snprintf(nbuf, sizeof nbuf, "%s=%s\n",				    newopts[i].name, newopts[i].val);			else				snprintf(nbuf, sizeof nbuf, "%s\n",				    newopts[i].name);			if (fgets(obuf, sizeof obuf, fp) == NULL ||			    strcmp(nbuf, obuf))				ret = 1;		}		fclose(fp);		fp = NULL;	} else		ret = 1;	/* replace with the new list of options */	if ((fp = fopen("options", "w+"))) {		rewind(fp);		for (i = 0; i < nnewopts; i++) {			if (newopts[i].val)				fprintf(fp, "%s=%s\n", newopts[i].name,				    newopts[i].val);			else				fprintf(fp, "%s\n", newopts[i].name);		}		fclose(fp);	}	free(newopts);	if (ret == 0 || madedir == 1)		return;	(void)printf("Kernel options have changed -- you must run \"make clean\"\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -