view dspanal/coffout.c @ 361:5d1c186cc3cf

fluid-mnf/target-bin/cmd39.m0: hand-crafted by copying cmd.m0 and manually patching the S3 record that contains the 16-bit word at 0x1140, the literal pool DPLL init constant used by hardware_init_calypso()
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 14 Mar 2020 19:33:52 +0000
parents 493f73198267
children
line wrap: on
line source

#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "coffout.h"

static FILE *outF;

static void
write16(val)
	unsigned val;
{
	putc(val, outF);
	putc(val >> 8, outF);
}

static void
write32(val)
	unsigned val;
{
	putc(val, outF);
	putc(val >> 8, outF);
	putc(val >> 16, outF);
	putc(val >> 24, outF);
}

emit_coff_output(filename, sections, nsect)
	char *filename;
	struct coff_section *sections;
	unsigned nsect;
{
	uint32_t dataptr;
	unsigned n;
	char section_name[32];

	outF = fopen(filename, "w");
	if (!outF) {
		perror(filename);
		exit(1);
	}
	write16(0x00C1);
	write16(nsect);
	write32(0);
	write32(0);
	write32(0);
	write16(0);
	write16(0x0117);
	write16(0x0098);
	dataptr = 0x16 + 0x28 * nsect;
	for (n = 0; n < nsect; n++) {
		sprintf(section_name, "chunk%03u", n);
		fwrite(section_name, 1, 8, outF);
		write32(sections[n].addr);
		write32(sections[n].addr);
		write32(sections[n].size);
		write32(dataptr);
		dataptr += sections[n].size << 1;
		write32(0);
		write32(0);
		write32(0);
		write16(sections[n].flags);
		putc(0, outF);
		putc(sections[n].mempage, outF);
	}
	for (n = 0; n < nsect; n++)
		fwrite(sections[n].data, 2, sections[n].size, outF);
	fclose(outF);
	return(0);
}