20IRX_ID(
"ROM_file_driver", 2, 1);
39static struct RomImg images[ROMDRV_MAX_IMAGES];
41static struct RomFileSlot fileSlots[ROMDRV_MAX_FILES];
45static int romUnsupported(
void);
47static int romOpen(
iop_file_t *fd,
const char *path,
int mode);
49static int romRead(
iop_file_t *fd,
void *buffer,
int size);
50static int romWrite(
iop_file_t *fd,
void *buffer,
int size);
51static int romLseek(
iop_file_t *fd,
int offset,
int whence);
52static struct RomImg *romGetImageStat(
const void *start,
const void *end,
struct RomImg *ImageStat);
57 (
void *)&romUnsupported,
58 (
void *)&romUnsupported,
64 (
void *)&romUnsupported,
65 (
void *)&romUnsupported,
66 (
void *)&romUnsupported,
67 (
void *)&romUnsupported,
68 (
void *)&romUnsupported,
69 (
void *)&romUnsupported,
70 (
void *)&romUnsupported,
71 (
void *)&romUnsupported,
72 (
void *)&romUnsupported};
81int _start(
int argc,
char **argv)
86 if (RegisterLibraryEntries(&_exp_romdrv) != 0) {
87 return MODULE_NO_RESIDENT_END;
90#ifdef ROMDRV_EXPORT_DEVICES
91 if (RegisterLibraryEntries(&_exp_romdrvX) != 0) {
92 return MODULE_NO_RESIDENT_END;
98 DelDrv(DeviceOps.name);
100 return (AddDrv(&DeviceOps) < 0) ? MODULE_NO_RESIDENT_END : MODULE_RESIDENT_END;
105 memset(images, 0,
sizeof(images));
106 memset(fileStats, 0,
sizeof(fileStats));
107 memset(fileSlots, 0,
sizeof(fileSlots));
109 romGetImageStat((
const void *)0xbfc00000, (
const void *)0xbfc40000, &images[0]);
113static int romUnsupported(
void)
125int romAddDevice(
int unit,
const void *image)
127 int result, OldState;
130 if (unit < ROMDRV_MAX_IMAGES) {
133 if (images[unit].ImageStart == NULL) {
134 stat = romGetImageStat(image, (
const void *)((
const u8 *)image + 0x8000), &images[unit]);
137 result = stat != NULL ? 0 : ROMDRV_ADD_BAD_IMAGE;
139 result = ROMDRV_ADD_FAILED;
143 result = ROMDRV_ADD_FAILED;
149int romDelDevice(
int unit)
151 int result, OldState;
153 if (unit < ROMDRV_MAX_IMAGES) {
156 if (images[unit].ImageStart != NULL) {
157 images[unit].ImageStart = 0;
162 result = ROMDRV_DEL_FAILED;
165 result = ROMDRV_DEL_FAILED;
171static int romOpen(
iop_file_t *fd,
const char *path,
int mode)
175 if (fd->unit < ROMDRV_MAX_IMAGES) {
178 image = &images[fd->unit];
180 if (image->ImageStart != NULL) {
184 if (mode != O_RDONLY) {
191 for (slotNum = 0; slotNum < ROMDRV_MAX_FILES; slotNum++) {
192 if (fileStats[slotNum].data == NULL) {
196 if (slotNum == ROMDRV_MAX_FILES) {
201 stat = GetFileStatFromImage(image, path, &fileStats[slotNum]);
206 fileSlots[slotNum].slotNum = slotNum;
207 fileSlots[slotNum].offset = 0;
208 fd->privdata = &fileSlots[slotNum];
227 if (slot->slotNum < ROMDRV_MAX_FILES) {
230 stat = &fileStats[slot->slotNum];
232 if (stat->data != NULL) {
245static int romRead(
iop_file_t *fd,
void *buffer,
int size)
250 stat = &fileStats[slot->slotNum];
253 if (stat->romdirent->size < (u32)(slot->offset + size)) {
254 size = stat->romdirent->size - slot->offset;
262 memcpy(buffer, (
const u8 *)stat->data + slot->offset, size);
263 slot->offset += size;
268static int romWrite(
iop_file_t *fd,
void *buffer,
int size)
277static int romLseek(
iop_file_t *fd,
int offset,
int whence)
284 stat = &fileStats[slot->slotNum];
285 size = stat->romdirent->size;
292 newOffset = slot->offset + offset;
295 newOffset = size + offset;
302 slot->offset = (size < (u32)newOffset) ? size : (u32)newOffset;
307static struct RomImg *romGetImageStat(
const void *start,
const void *end,
struct RomImg *ImageStat)
318 ptr = (u32 *)file->name;
319 if (ptr[0] == 0x45534552 && ptr[1] == 0x54 && (*(u16 *)&ptr[2] == 0) && (((file->size + 15) & ~15) == offset)) {
320 ImageStat->ImageStart = start;
321 ImageStat->RomdirStart = ptr;
323 ImageStat->RomdirEnd = (
const void *)((
const u8 *)ptr + size);
328 ImageStat->ImageStart = NULL;
335 unsigned int i, offset, ExtInfoOffset;
336 u8 filename_temp[12];
342 ((u32 *)filename_temp)[0] = 0;
343 ((u32 *)filename_temp)[1] = 0;
344 ((u32 *)filename_temp)[2] = 0;
345 for (i = 0; *filename >= 0x21 && i <
sizeof(filename_temp); i++) {
346 filename_temp[i] = *filename;
350 if (ImageStat->RomdirStart != NULL) {
351 RomdirEntry = ImageStat->RomdirStart;
354 if (((u32 *)filename_temp)[0] == ((u32 *)RomdirEntry->name)[0] && ((u32 *)filename_temp)[1] == ((u32 *)RomdirEntry->name)[1] && (*(u16 *)&((u32 *)filename_temp)[2] == *(u16 *)&((u32 *)RomdirEntry->name)[2])) {
356 stat->romdirent = RomdirEntry;
357 stat->data = ImageStat->ImageStart + offset;
358 stat->extinfo = NULL;
360 if (RomdirEntry->ExtInfoEntrySize != 0) {
361 stat->extinfo = (
void *)((u8 *)ImageStat->RomdirEnd + ExtInfoOffset);
368 offset += (RomdirEntry->size + 15) & ~15;
369 ExtInfoOffset += RomdirEntry->ExtInfoEntrySize;
371 }
while (((u32 *)RomdirEntry->name)[0] != 0x00000000);
382#ifdef ROMDRV_EXPORT_DEVICES
383const struct RomImg *romGetDevice(
int unit)
386 const struct RomImg *result;
388 if (unit < ROMDRV_MAX_IMAGES) {
391 if (images[unit].ImageStart != NULL) {
392 result = &images[unit];
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)