romloader.c
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#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;
}
}