Ejemplo n.º 1
0
static void g80_3d_disassemble(struct buffer *buf, const char *mode, uint32_t start_id)
{
	if (!buf)
		return;

	mmt_debug("%s_start id 0x%08x\n", mode, start_id);
	struct region *reg;
	for (reg = buf->written_regions.head; reg != NULL; reg = reg->next)
	{
		if (reg->start != start_id)
			continue;

		if (MMT_DEBUG)
		{
			uint32_t x;
			mmt_debug("CODE: %s", "");
			for (x = reg->start; x < reg->end; x += 4)
				mmt_debug_cont("0x%08x ", *(uint32_t *)(buf->data + x));
			mmt_debug_cont("%s\n", "");
		}

		if (!isa_g80)
			isa_g80 = ed_getisa("g80");

		struct varinfo *var = varinfo_new(isa_g80->vardata);

		if (chipset == 0x50)
			varinfo_set_variant(var, "g80");
		else if (chipset >= 0x84 && chipset <= 0x98)
			varinfo_set_variant(var, "g84");
		else if (chipset == 0xa0)
			varinfo_set_variant(var, "g200");
		else if (chipset >= 0xaa && chipset <= 0xac)
			varinfo_set_variant(var, "mcp77");
		else if ((chipset >= 0xa3 && chipset <= 0xa8) || chipset == 0xaf)
			varinfo_set_variant(var, "gt215");

		varinfo_set_mode(var, mode);

		envydis(isa_g80, stdout, buf->data + reg->start, 0,
				reg->end - reg->start, var, 0, NULL, 0, colors);
		varinfo_del(var);
		break;
	}
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
	FILE *infile = stdin;
	const struct disisa *isa = 0;
	struct label *labels = 0;
	int labelsnum = 0;
	int labelsmax = 0;
	int w = 0, bin = 0, quiet = 0;
	const char **varnames = 0;
	int varnamesnum = 0;
	int varnamesmax = 0;
	const char **modenames = 0;
	int modenamesnum = 0;
	int modenamesmax = 0;
	const char **featnames = 0;
	int featnamesnum = 0;
	int featnamesmax = 0;
	const struct envy_colors *cols = &envy_def_colors;
	argv[0] = basename(argv[0]);
	int len = strlen(argv[0]);
	if (len > 3 && !strcmp(argv[0] + len - 3, "dis")) {
		argv[0][len-3] = 0;
		isa = ed_getisa(argv[0]);
		if (isa && isa->opunit == 4)
			w = 1;
	}
	int c;
	unsigned base = 0, skip = 0, limit = 0;
	while ((c = getopt (argc, argv, "b:d:l:m:V:O:F:wWinqu:M:")) != -1)
		switch (c) {
			case 'b':
				sscanf(optarg, "%x", &base);
				break;
			case 'd':
				sscanf(optarg, "%x", &skip);
				break;
			case 'l':
				sscanf(optarg, "%x", &limit);
				break;
			case 'w':
				w = 1;
				break;
			case 'W':
				w = 2;
				break;
			case 'i':
				bin = 1;
				break;
			case 'q':
				quiet = 1;
				break;
			case 'n':
				cols = &envy_null_colors;
				break;
			case 'm':
				isa = ed_getisa(optarg);
				if (!isa) {
					fprintf (stderr, "Unknown architecture \"%s\"!\n", optarg);
					return 1;
				}
				break;
			case 'V':
				ADDARRAY(varnames, optarg);
				break;
			case 'O':
				ADDARRAY(modenames, optarg);
				break;
			case 'F':
				ADDARRAY(featnames, optarg);
				break;
			case 'M':
				{
					FILE *mapfile = fopen(optarg, "r");
					if (!mapfile) {
						perror(optarg);
						return 1;
					}
					struct label nl;
					char type;
					char buf[1000] = "";

					while(fgets(buf, sizeof(buf), mapfile)) {

						if (buf[0] == '#' || buf[0] == '\n')
							continue;

						char* tmp = strchr(buf, '#');
						if (tmp)
							tmp = '\0';

						char name[200];
						int comps = sscanf(buf, "%c%llx%s%x", &type, &nl.val, name, &nl.size);;
						if (comps < 2) {
							fprintf(stderr, "Malformated input: %s\n", buf);
							continue;
						}

						switch (type) {
							case 'B':
								nl.type = 1;
								break;
							case 'C':
								nl.type = 2;
								break;
							case 'E':
								nl.type = 4;
								break;
							case 'S':
								nl.type = 0x20;
								break;
							case 'N':
								nl.type = 0x42;
								break;
							case 'D':
								nl.type = 0x10;
								break;
							default:
								fprintf (stderr, "Unknown label type %c\n", type);
								return 1;
						}
						if (comps < 4)
							nl.size = 0;
						if (comps >= 3)
							nl.name = strdup(name);
						else
							nl.name = 0;
						ADDARRAY(labels, nl);
					}
					break;
				}
			case 'u':
				{
					struct label nl;
					sscanf(optarg, "%llx", &nl.val);
					nl.type = 1;
					nl.name = 0;
					ADDARRAY(labels, nl);
					break;
				}
		}
	if (optind < argc) {
		if (!(infile = fopen(argv[optind], "r"))) {
			perror(argv[optind]);
			return 1;
		}
		optind++;
		if (optind < argc) {
			fprintf (stderr, "Too many parameters!\n");
			return 1;
		}
	}
	if (!isa) {
		fprintf (stderr, "No architecture specified!\n");
		return 1;
	}
	struct varinfo *var = varinfo_new(isa->vardata);
	if (!var)
		return 1;
	int i;
	for (i = 0; i < varnamesnum; i++)
		if (varinfo_set_variant(var, varnames[i]))
			return 1;
	for (i = 0; i < featnamesnum; i++)
		if (varinfo_set_feature(var, featnames[i]))
			return 1;
	for (i = 0; i < modenamesnum; i++)
		if (varinfo_set_mode(var, modenames[i]))
			return 1;
	int num = 0;
	int maxnum = 16;
	uint8_t *code = malloc (maxnum);
	unsigned long long t;
	if (bin) {
		int c;
		while ((c = getc(infile)) != EOF) {
			if (num + 3 >= maxnum) maxnum *= 2, code = realloc (code, maxnum);
			code[num++] = c;
		}
	} else {
		while (!feof(infile) && fscanf (infile, "%llx", &t) == 1) {
			if (num + 3 >= maxnum) maxnum *= 2, code = realloc (code, maxnum);
			if (w == 2) {
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
			} else if (w) {
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
				t >>= 8;
				code[num++] = t & 0xff;
			} else