20IRX_ID(
"ROM_file_driver", 2, 1);
39static struct RomImg images[ROMDRV_MAX_IMAGES];
41static struct RomFileSlot fileSlots[ROMDRV_MAX_FILES];
45static int romOpen(
iop_file_t *fd,
const char *path,
int mode);
47static int romRead(
iop_file_t *fd,
void *buffer,
int size);
48static int romLseek(
iop_file_t *fd,
int offset,
int whence);
49static struct RomImg *romGetImageStat(
const void *start,
const void *end,
struct RomImg *ImageStat);
52IOMAN_RETURN_VALUE_IMPL(0);
53IOMAN_RETURN_VALUE_IMPL(
EIO);
56 IOMAN_RETURN_VALUE(0),
57 IOMAN_RETURN_VALUE(0),
58 IOMAN_RETURN_VALUE(0),
62 IOMAN_RETURN_VALUE(
EIO),
64 IOMAN_RETURN_VALUE(0),
65 IOMAN_RETURN_VALUE(0),
66 IOMAN_RETURN_VALUE(0),
67 IOMAN_RETURN_VALUE(0),
68 IOMAN_RETURN_VALUE(0),
69 IOMAN_RETURN_VALUE(0),
70 IOMAN_RETURN_VALUE(0),
71 IOMAN_RETURN_VALUE(0),
72 IOMAN_RETURN_VALUE(0),
82int _start(
int argc,
char **argv)
87 if (RegisterLibraryEntries(&_exp_romdrv) != 0) {
88 return MODULE_NO_RESIDENT_END;
91#ifdef ROMDRV_EXPORT_DEVICES
92 if (RegisterLibraryEntries(&_exp_romdrvX) != 0) {
93 return MODULE_NO_RESIDENT_END;
99 DelDrv(DeviceOps.name);
101 return (AddDrv(&DeviceOps) < 0) ? MODULE_NO_RESIDENT_END : MODULE_RESIDENT_END;
106 memset(images, 0,
sizeof(images));
107 memset(fileStats, 0,
sizeof(fileStats));
108 memset(fileSlots, 0,
sizeof(fileSlots));
110 romGetImageStat((
const void *)0xbfc00000, (
const void *)0xbfc40000, &images[0]);
114int romAddDevice(
int unit,
const void *image)
116 int result, OldState;
119 if (unit < ROMDRV_MAX_IMAGES) {
122 if (images[unit].ImageStart == NULL) {
123 stat = romGetImageStat(image, (
const void *)((
const u8 *)image + 0x8000), &images[unit]);
126 result = stat != NULL ? 0 : ROMDRV_ADD_BAD_IMAGE;
128 result = ROMDRV_ADD_FAILED;
132 result = ROMDRV_ADD_FAILED;
138int romDelDevice(
int unit)
140 int result, OldState;
142 if (unit < ROMDRV_MAX_IMAGES) {
145 if (images[unit].ImageStart != NULL) {
146 images[unit].ImageStart = 0;
151 result = ROMDRV_DEL_FAILED;
154 result = ROMDRV_DEL_FAILED;
160static int romOpen(
iop_file_t *fd,
const char *path,
int mode)
164 if (fd->unit < ROMDRV_MAX_IMAGES) {
167 image = &images[fd->unit];
169 if (image->ImageStart != NULL) {
173 if (mode != O_RDONLY) {
180 for (slotNum = 0; slotNum < ROMDRV_MAX_FILES; slotNum++) {
181 if (fileStats[slotNum].data == NULL) {
185 if (slotNum == ROMDRV_MAX_FILES) {
190 stat = GetFileStatFromImage(image, path, &fileStats[slotNum]);
195 fileSlots[slotNum].slotNum = slotNum;
196 fileSlots[slotNum].offset = 0;
197 fd->privdata = &fileSlots[slotNum];
216 if (slot->slotNum < ROMDRV_MAX_FILES) {
219 stat = &fileStats[slot->slotNum];
221 if (stat->data != NULL) {
234static int romRead(
iop_file_t *fd,
void *buffer,
int size)
239 stat = &fileStats[slot->slotNum];
242 if (stat->romdirent->size < (u32)(slot->offset + size)) {
243 size = stat->romdirent->size - slot->offset;
251 memcpy(buffer, (
const u8 *)stat->data + slot->offset, size);
252 slot->offset += size;
257static int romLseek(
iop_file_t *fd,
int offset,
int whence)
264 stat = &fileStats[slot->slotNum];
265 size = stat->romdirent->size;
272 newOffset = slot->offset + offset;
275 newOffset = size + offset;
282 slot->offset = (size < (u32)newOffset) ? size : (u32)newOffset;
287static struct RomImg *romGetImageStat(
const void *start,
const void *end,
struct RomImg *ImageStat)
298 ptr = (u32 *)file->name;
299 if (ptr[0] == 0x45534552 && ptr[1] == 0x54 && (*(u16 *)&ptr[2] == 0) && (((file->size + 15) & ~15) == offset)) {
300 ImageStat->ImageStart = start;
301 ImageStat->RomdirStart = ptr;
303 ImageStat->RomdirEnd = (
const void *)((
const u8 *)ptr + size);
308 ImageStat->ImageStart = NULL;
315 unsigned int i, offset, ExtInfoOffset;
316 u8 filename_temp[12];
322 ((u32 *)filename_temp)[0] = 0;
323 ((u32 *)filename_temp)[1] = 0;
324 ((u32 *)filename_temp)[2] = 0;
325 for (i = 0; *filename >= 0x21 && i <
sizeof(filename_temp); i++) {
326 filename_temp[i] = *filename;
330 if (ImageStat->RomdirStart != NULL) {
331 RomdirEntry = ImageStat->RomdirStart;
334 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])) {
336 stat->romdirent = RomdirEntry;
337 stat->data = ImageStat->ImageStart + offset;
338 stat->extinfo = NULL;
340 if (RomdirEntry->ExtInfoEntrySize != 0) {
341 stat->extinfo = (
void *)((u8 *)ImageStat->RomdirEnd + ExtInfoOffset);
348 offset += (RomdirEntry->size + 15) & ~15;
349 ExtInfoOffset += RomdirEntry->ExtInfoEntrySize;
351 }
while (((u32 *)RomdirEntry->name)[0] != 0x00000000);
362#ifdef ROMDRV_EXPORT_DEVICES
363const struct RomImg *romGetDevice(
int unit)
366 const struct RomImg *result;
368 if (unit < ROMDRV_MAX_IMAGES) {
371 if (images[unit].ImageStart != NULL) {
372 result = &images[unit];
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)