66 int *n_loadp,
char ***load_namesp)
68 int boot_disk_id, boot_disk_type = 0, n_blocks, res, readofs,
70 unsigned char minibuf[0x20];
71 unsigned char *bootblock_buf;
72 uint64_t bootblock_offset, base_offset;
73 uint64_t bootblock_loadaddr, bootblock_pc;
86 fatal(
"The Dreamcast emulation mode can only boot"
87 " from CD images, not from other disk types.\n");
93 debug(
"loading Dreamcast IP.BIN from %s id %i to 0x8c008000\n",
94 diskimage_types[boot_disk_type], boot_disk_id);
97 0, base_offset, bootblock_buf, 0x8000);
99 fatal(
"Couldn't read the first 32 KB from the disk image. Aborting.\n");
103 if (strncmp((
char *)bootblock_buf,
"SEGA ", 5) != 0) {
104 fatal(
"This is not a Dreamcast IP.BIN header.\n");
131 store_buf(
cpu, 0x8c008000, (
char *)bootblock_buf, 32768);
132 cpu->
pc = 0x8c000140;
139 if (bootblock_buf[i] ==
' ')
140 bootblock_buf[i] = 0;
144 strdup((
char *)bootblock_buf + 0x60));
147 debug(
"Dreamcast boot filename: %s (to be loaded to 0x8c010000)\n",
172 minibuf,
sizeof(minibuf));
174 bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8)
175 + (minibuf[0x12] << 16) + ((uint64_t)minibuf[0x13] << 24);
178 if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 &&
179 (bootblock_loadaddr & 0xf0000000ULL) != 0xa0000000) {
180 fatal(
"\nWARNING! Weird load address 0x%08" PRIx32
181 " for SCSI id %i.\n\n",
182 (uint32_t)bootblock_loadaddr, boot_disk_id);
183 if (bootblock_loadaddr == 0) {
184 fatal(
"I'm assuming that this is _not_ a "
185 "DEC bootblock.\nAre you sure you are"
186 " booting from the correct disk?\n");
191 bootblock_loadaddr &= 0x0fffffffULL;
192 bootblock_loadaddr |= 0xffffffffa0000000ULL;
194 bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8)
195 + (minibuf[0x16] << 16) + ((uint64_t)minibuf[0x17] << 24);
197 bootblock_pc &= 0x0fffffffULL;
198 bootblock_pc |= 0xffffffffa0000000ULL;
199 cpu->
pc = bootblock_pc;
201 debug(
"DEC boot: loadaddr=0x%08" PRIx32
", pc=0x%08" PRIx32,
202 (uint32_t) bootblock_loadaddr, (uint32_t) bootblock_pc);
208 0, readofs, minibuf,
sizeof(minibuf));
210 fatal(
"Couldn't read the disk image. "
215 n_blocks = minibuf[0] + (minibuf[1] << 8)
216 + (minibuf[2] << 16) + ((uint64_t)minibuf[3] << 24);
218 bootblock_offset = (minibuf[4] + (minibuf[5] << 8) +
219 (minibuf[6]<<16) + ((uint64_t)minibuf[7]<<24)) * 512;
224 debug(readofs == 0x18?
": %i" :
" + %i", n_blocks);
226 if (n_blocks * 512 > 65536)
227 fatal(
"\nWARNING! Unusually large bootblock "
228 "(%i bytes)\n\n", n_blocks * 512);
233 0, bootblock_offset, bootblock_buf, n_blocks * 512);
235 fatal(
"WARNING: could not load bootblocks from"
236 " disk offset 0x%llx\n",
237 (
long long)bootblock_offset);
241 (
char *)bootblock_buf, n_blocks * 512);
243 bootblock_loadaddr += 512*n_blocks;
248 debug(readofs == 0x18?
": no blocks?\n" :
" blocks\n");
260 0, base_offset + 0x8000, bootblock_buf, 0x800);
262 fatal(
"Couldn't read the ISO header from the disk image. Aborting.\n");
267 if (strncmp((
char *)bootblock_buf+1,
"CD001", 5) == 0)
269 if (strncmp((
char *)bootblock_buf+1,
"CDW01", 5) == 0)
271 if (strncmp((
char *)bootblock_buf+1,
"CDROM", 5) == 0)
281 fatal(
"\nISO9660 filesystem, but no kernel "
282 "specified? (Use the -j option.)\n");
285 boot_disk_type, iso_type, bootblock_buf,
286 n_loadp, load_namesp);
294 0, 0x0, bootblock_buf, 0x800);
296 fatal(
"Couldn't read the disk image. Aborting.\n");
299 if (bootblock_buf[0x000] ==
'E' && bootblock_buf[0x001] ==
'R' &&
300 bootblock_buf[0x200] ==
'P' && bootblock_buf[0x201] ==
'M') {
303 fatal(
"\nApple partition table, but no kernel "
304 "specified? (Use the -j option.)\n");
307 boot_disk_type, n_loadp, load_namesp);