romloader.c 1.6 KB
#include "romloader.h"
#include <os.h>
#include <rom.h>
#include <ramrom.h>
#include <R4300.h>
#include <string.h>
#include "arcs.h"

#define KSEG0_BASE      0x88000000
#define ROM_BASE        (KSEG0_BASE + 0x900000)
extern int icache_size, dcache_size;
void DmaCopy(int *, int *, int);


void
romloader(int argc, char *argv[])
{
	char *equals, *paren, *colon, *romName = NULL;
	char romPath[80];
	unsigned long romFD, count;
	long error;
	int i;
	void (*init_pc)(void);


	for (i = 1; i < argc; i++) {
		if ((equals = strchr(argv[i], '=')) == NULL)
			continue;
		*equals = '\0';
		if (strcmp(argv[i], "rom") == 0)
			romName = equals + 1;
	}
	if (romName == NULL)
		romName = "rom";
	strcpy(romPath, argv[0]);
	if ((colon = strchr(romPath, ':')) != NULL)
		strcpy(colon+1, romName);
	else if ((paren = strchr(romPath, ')')) != NULL)
		strcpy(paren+1, romName);
	else
		strcpy(romPath, romName);

	if (((error = _ArcsOpen(romPath, OpenReadOnly, &romFD)) != 0) ||
	    ((error = _ArcsRead(romFD,
			        (void *)ROM_BASE, ROM_SIZE, &count)) != 0)) {
		_ArcsPerror(error, romPath);
		for (;;);
	}
	_ArcsClose(romFD);
	_CacheConfigure();
	InvalDCache((void *)KSEG0_BASE, ROM_SIZE);
	InvalICache((void *)KSEG0_BASE, ROM_SIZE);
#ifdef _SYMMON
	_SetupDebugger(romPath);
	_ExceptionInitialize();
	debug();
#endif /* _SYMMON */

	/* copy to rdram address */

	DmaCopy((int *)(ROM_BASE+RAMROM_GAME_OFFSET),
		(int *)K0_TO_K1(BOOT_ADDRESS_INDY), 0x200000);
	init_pc = (void *)BOOT_ADDRESS_INDY;
	(*init_pc)();
}


void
DmaCopy(int *from, int *to, int nbytes)
{

        while (nbytes > 0) {
                *to++ = *from++;
		nbytes -= 4;
	}
}