Ejemplo n.º 1
0
int main(int argc, char **argv) {
	char *file = "nv_mmio.xml";
	char *name = "NV_MMIO";
	char *variant = NULL;
	char c, mode = 'd';
	uint64_t reg, colors=1, val = 0;
	struct rnndeccontext *vc;

	rnn_init();
	if (argc < 2) {
		usage();
	}
	struct rnndb *db = rnn_newdb();

	/* Arguments parsing */
	while ((c = getopt (argc, argv, "f:a:d:e:b:c")) != -1) {
		switch (c) {
			case 'f':
				file = strdup(optarg);
				break;
			case 'e':
				mode = 'e';
				name = strdup(optarg);
				break;
			case 'b':
				mode = 'b';
				name = strdup(optarg);
				break;
			case 'd':
				mode = 'd';
				name = strdup(optarg);
				break;
			case 'a':
				if (!strncasecmp(optarg, "NV", 2))
					variant = strdup(optarg);
				else
					asprintf(&variant, "NV%s", optarg);
				break;
			case 'c':
				colors = 0;
				break;
			default: usage();
		}
	}

	rnn_parsefile (db, file);
	rnn_prepdb (db);
	vc = rnndec_newcontext(db);
	if(colors)
		vc->colors = &rnndec_colorsterm;

	if (variant)
		rnndec_varadd(vc, "chipset", variant);

	/* Parse extra arguments */
	while (!strcmp (argv[optind], "-v")) {
		rnndec_varadd(vc, argv[optind+1], argv[optind+2]);
		optind+=3;
	}

	if (optind >= argc) {
		fprintf (stderr, "No address specified.\n");
		return 1;
	}

	reg = strtoull(argv[optind], 0, 16);
	if (optind + 1 < argc)
		val = strtoull(argv[optind + 1], 0, 16);

	if (mode == 'e') {
		struct rnnenum *en = rnn_findenum (db, name);
		if (en) {
			int i;
			int dec = 0;
			for (i = 0; i < en->valsnum; i++)
				if (en->vals[i]->valvalid && en->vals[i]->value == reg) {
					printf ("%s\n", en->vals[i]->name);
					dec = 1;
					break;
				}
			if (!dec)
				printf ("%#"PRIx64"\n", reg);

			return 0;
		} else {
			fprintf(stderr, "Not an enum: '%s'\n", name);
			return 1;
		}
	} else if (mode == 'b') {
		struct rnnbitset *bs = rnn_findbitset (db, name);

		if (bs) {
			printf("TODO\n");
			return 0;
		} else {
			fprintf(stderr, "Not a bitset: '%s'\n", name);
			return 1;
		}

	} else if (mode == 'd') {
		struct rnndomain *dom = rnn_finddomain (db, name);

		if (dom) {
			struct rnndecaddrinfo *info = rnndec_decodeaddr(vc, dom, reg, 0);
			if (info && info->typeinfo)
				printf ("%s => %s\n", info->name, rnndec_decodeval(vc, info->typeinfo, val, info->width));
			else if (info)
				printf ("%s\n", info->name);
			else
				return 1;
			return 0;
		} else {
			fprintf(stderr, "Not a domain: '%s'\n", name);
			return 1;
		}
	} else {
		return 1;
	}
}
Ejemplo n.º 2
0
static void preptypeinfo(struct rnndb *db, struct rnntypeinfo *ti, char *prefix, struct rnnvarinfo *vi, int width, char *file) {
	int i;
	if (ti->name) {
		struct rnnenum *en = rnn_findenum (db, ti->name);
		struct rnnbitset *bs = rnn_findbitset (db, ti->name);
		struct rnnspectype *st = rnn_findspectype (db, ti->name);
		if (en) {
			if (en->isinline) {
				ti->type = RNN_TTYPE_INLINE_ENUM;
				int j;
				for (j = 0; j < en->valsnum; j++)
					ADDARRAY(ti->vals, copyvalue(en->vals[j], file));
			} else {
				ti->type = RNN_TTYPE_ENUM;
				ti->eenum = en;
			}
		} else if (bs) {
			if (bs->isinline) {
				ti->type = RNN_TTYPE_INLINE_BITSET;
				int j;
				for (j = 0; j < bs->bitfieldsnum; j++)
					ADDARRAY(ti->bitfields, copybitfield(bs->bitfields[j], file));
			} else {
				ti->type = RNN_TTYPE_BITSET;
				ti->ebitset = bs;
			}
		} else if (st) {
			ti->type = RNN_TTYPE_SPECTYPE;
			ti->spectype = st;
		} else if (!strcmp(ti->name, "hex")) {
			ti->type = RNN_TTYPE_HEX;
		} else if (!strcmp(ti->name, "float")) {
			ti->type = RNN_TTYPE_FLOAT;
		} else if (!strcmp(ti->name, "uint")) {
			ti->type = RNN_TTYPE_UINT;
		} else if (!strcmp(ti->name, "int")) {
			ti->type = RNN_TTYPE_INT;
		} else if (!strcmp(ti->name, "boolean")) {
			ti->type = RNN_TTYPE_BOOLEAN;
		} else if (!strcmp(ti->name, "bitfield")) {
			ti->type = RNN_TTYPE_INLINE_BITSET;
		} else if (!strcmp(ti->name, "enum")) {
			ti->type = RNN_TTYPE_INLINE_ENUM;
		} else if (!strcmp(ti->name, "fixed")) {
			ti->type = RNN_TTYPE_FIXED;
		} else if (!strcmp(ti->name, "ufixed")) {
			ti->type = RNN_TTYPE_UFIXED;
		} else {
			ti->type = RNN_TTYPE_HEX;
			fprintf (stderr, "%s: unknown type %s\n", prefix, ti->name);
			db->estatus = 1;
		}
	} else if (ti->bitfieldsnum) {
		ti->name = "bitfield";
		ti->type = RNN_TTYPE_INLINE_BITSET;
	} else if (ti->valsnum) {
		ti->name = "enum";
		ti->type = RNN_TTYPE_INLINE_ENUM;
	} else if (width == 1) {
		ti->name = "boolean";
		ti->type = RNN_TTYPE_BOOLEAN;
	} else {
		ti->name = "hex";
		ti->type = RNN_TTYPE_HEX;
	}
	for (i = 0; i < ti->bitfieldsnum; i++)
		prepbitfield(db,  ti->bitfields[i], prefix, vi);
	for (i = 0; i < ti->valsnum; i++)
		prepvalue(db, ti->vals[i], prefix, vi);
}