view target-utils/dspdump/dumpops.c @ 904:5041bcb8140f

tchtools/fc-vm2hex.c: update header comment for new situation
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Dec 2022 08:41:57 +0000
parents 451d8b545b11
children
line wrap: on
line source

#include <sys/types.h>
#include "types.h"
#include "leadapi.h"

void
cmd_dump(argbulk)
	char *argbulk;
{
	char *argv[4];
	u_long mode, addr, len;
	int rc;
	volatile u16 *api;
	unsigned n;

	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
		return;
	if (parse_hexarg(argv[0], 4, &mode) < 0) {
		printf("ERROR: mode must be a valid 16-bit hex value\n");
		return;
	}
	if (parse_hexarg(argv[1], 8, &addr) < 0) {
		printf("ERROR: addr must be a valid 32-bit hex value\n");
		return;
	}
	if (parse_hexarg(argv[2], 4, &len) < 0) {
		printf("ERROR: len must be a valid 16-bit hex value\n");
		return;
	}
	rc = boot_dsp_dump_agent();
	if (rc < 0)
		return;		/* error msg already printed */
	rc = dsp_read_op((u16)mode, (u32)addr, (u16)len);
	if (rc < 0) {
		printf("ERROR: DSP timeout on read operation\n");
		return;
	}
	api = (volatile u16 *) APIF_ADDR;
	for (n = 0; n < len; n++)
		printf("%04X\n", *api++);
}

dump_large_section(mode, addr, len)
	u16 mode;
	u32 addr, len;
{
	u32 chunk, remain, n;
	volatile u16 *api;
	int rc;

	for (remain = len; remain; remain -= chunk) {
		chunk = remain;
		if (chunk > MAX_BLOCK_SIZE)
			chunk = MAX_BLOCK_SIZE;
		rc = dsp_read_op(mode, addr, chunk);
		if (rc < 0) {
			printf("ERROR: DSP timeout on read operation\n");
			return(rc);
		}
		api = (volatile u16 *) APIF_ADDR;
		for (n = chunk; n; n--) {
			if (!(addr & 0xF))
				printf("%05x : ", addr);
			printf("%04x%c", *api++, ((addr&15)==15)?'\n':' ');
			addr++;
		}
	}
	putchar('\n');
	return(0);
}

void
cmd_bigdump(argbulk)
	char *argbulk;
{
	char *argv[4];
	u_long mode, addr, len;
	int rc;

	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
		return;
	if (parse_hexarg(argv[0], 4, &mode) < 0) {
		printf("ERROR: mode must be a valid 16-bit hex value\n");
		return;
	}
	if (parse_hexarg(argv[1], 8, &addr) < 0) {
		printf("ERROR: addr must be a valid 32-bit hex value\n");
		return;
	}
	if (parse_hexarg(argv[2], 8, &len) < 0) {
		printf("ERROR: len must be a valid 32-bit hex value\n");
		return;
	}
	rc = boot_dsp_dump_agent();
	if (rc < 0)
		return;		/* error msg already printed */
	dump_large_section((u16)mode, (u32)addr, (u32)len);
}

static struct rom_section {
	char *name;
	u32 addr;
	u32 size;
	int mode;
} rom_sections[] = {
	{ "Registers",	0x00000, 0x0060, BL_MODE_DATA_READ },
	{ "DROM",	0x09000, 0x5000, BL_MODE_DROM_READ },
	{ "PDROM",	0x0e000, 0x2000, BL_MODE_PROM_READ },
	{ "PROM0",	0x07000, 0x7000, BL_MODE_PROM_READ },
	{ "PROM1",	0x18000, 0x8000, BL_MODE_PROM_READ },
	{ "PROM2",	0x28000, 0x8000, BL_MODE_PROM_READ },
	{ "PROM3",	0x38000, 0x2000, BL_MODE_PROM_READ },
	{ 0, 0, 0, -1 }
};

void
cmd_fulldump()
{
	struct rom_section *tp;
	int rc;

	rc = boot_dsp_dump_agent();
	if (rc < 0)
		return;		/* error msg already printed */
	for (tp = rom_sections; tp->name; tp++) {
		printf("DSP dump: %s [%05x-%05x]\n", tp->name, tp->addr,
			tp->addr + tp->size - 1);
		rc = dump_large_section(tp->mode, tp->addr, tp->size);
		if (rc < 0)
			return;		/* error msg already printed */
	}
}