1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: emul.c,v 1.211 2005/06/26 11:36:28 debug Exp $ |
* $Id: emul.c,v 1.247 2006/02/04 12:27:12 debug Exp $ |
29 |
* |
* |
30 |
* Emulation startup and misc. routines. |
* Emulation startup and misc. routines. |
31 |
*/ |
*/ |
70 |
static char *diskimage_types[] = DISKIMAGE_TYPES; |
static char *diskimage_types[] = DISKIMAGE_TYPES; |
71 |
|
|
72 |
|
|
73 |
|
static void print_separator(void) |
74 |
|
{ |
75 |
|
int i = 79; |
76 |
|
while (i-- > 0) |
77 |
|
debug("-"); |
78 |
|
debug("\n"); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
/* |
/* |
83 |
* add_dump_points(): |
* add_dump_points(): |
84 |
* |
* |
121 |
* were automatically converted into the correct address. |
* were automatically converted into the correct address. |
122 |
*/ |
*/ |
123 |
|
|
124 |
if ((dp >> 32) == 0 && ((dp >> 31) & 1)) |
if (m->arch == ARCH_MIPS) { |
125 |
dp |= 0xffffffff00000000ULL; |
if ((dp >> 32) == 0 && ((dp >> 31) & 1)) |
126 |
|
dp |= 0xffffffff00000000ULL; |
127 |
|
} |
128 |
|
|
129 |
m->breakpoint_addr[i] = dp; |
m->breakpoint_addr[i] = dp; |
130 |
|
|
131 |
debug("breakpoint %i: 0x%016llx", i, (long long)dp); |
debug("breakpoint %i: 0x%llx", i, (long long)dp); |
132 |
if (string_flag) |
if (string_flag) |
133 |
debug(" (%s)", m->breakpoint_string[i]); |
debug(" (%s)", m->breakpoint_string[i]); |
134 |
debug("\n"); |
debug("\n"); |
161 |
int *n_loadp, char ***load_namesp) |
int *n_loadp, char ***load_namesp) |
162 |
{ |
{ |
163 |
char str[35]; |
char str[35]; |
164 |
int filenr, i, ofs, dirlen, res = 0, res2, iadd = 4; |
int filenr, i, ofs, dirlen, res = 0, res2, iadd = DEBUG_INDENTATION; |
165 |
int found_dir; |
int found_dir; |
166 |
uint64_t dirofs; |
uint64_t dirofs; |
167 |
uint64_t fileofs, filelen; |
uint64_t fileofs, filelen; |
170 |
char *p, *filename_orig; |
char *p, *filename_orig; |
171 |
char *filename = strdup(cpu->machine->boot_kernel_filename); |
char *filename = strdup(cpu->machine->boot_kernel_filename); |
172 |
unsigned char *filebuf = NULL; |
unsigned char *filebuf = NULL; |
173 |
char *tmpfilename = NULL; |
char *tmpfname = NULL; |
174 |
char **new_array; |
char **new_array; |
175 |
int tmpfile_handle; |
int tmpfile_handle; |
176 |
|
|
216 |
fatal("WARNING: Root directory length mismatch?\n"); |
fatal("WARNING: Root directory length mismatch?\n"); |
217 |
|
|
218 |
dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) + |
dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) + |
219 |
(buf[0x8f] << 24)) * 2048; |
((uint64_t)buf[0x8f] << 24)) * 2048; |
220 |
|
|
221 |
/* debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs); */ |
/* debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs); */ |
222 |
|
|
237 |
dp = dirbuf; filenr = 1; |
dp = dirbuf; filenr = 1; |
238 |
p = NULL; |
p = NULL; |
239 |
while (dp < dirbuf + dirlen) { |
while (dp < dirbuf + dirlen) { |
240 |
int i, nlen = dp[0]; |
size_t i, nlen = dp[0]; |
241 |
int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + (dp[5] << 24); |
int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + |
242 |
|
((uint64_t)dp[5] << 24); |
243 |
int y = dp[6] + (dp[7] << 8); |
int y = dp[6] + (dp[7] << 8); |
244 |
char direntry[65]; |
char direntry[65]; |
245 |
|
|
309 |
} |
} |
310 |
|
|
311 |
for (;;) { |
for (;;) { |
312 |
int len, i; |
size_t len, i; |
313 |
|
|
314 |
/* Too close to another sector? Then realign. */ |
/* Too close to another sector? Then realign. */ |
315 |
if ((dirofs & 2047) + 70 > 2047) { |
if ((dirofs & 2047) + 70 > 2047) { |
374 |
} |
} |
375 |
|
|
376 |
fileofs = match_entry[2] + (match_entry[3] << 8) + |
fileofs = match_entry[2] + (match_entry[3] << 8) + |
377 |
(match_entry[4] << 16) + (match_entry[5] << 24); |
(match_entry[4] << 16) + ((uint64_t)match_entry[5] << 24); |
378 |
filelen = match_entry[10] + (match_entry[11] << 8) + |
filelen = match_entry[10] + (match_entry[11] << 8) + |
379 |
(match_entry[12] << 16) + (match_entry[13] << 24); |
(match_entry[12] << 16) + ((uint64_t)match_entry[13] << 24); |
380 |
fileofs *= 2048; |
fileofs *= 2048; |
381 |
|
|
382 |
/* debug("filelen=%llx fileofs=%llx\n", (long long)filelen, |
/* debug("filelen=%llx fileofs=%llx\n", (long long)filelen, |
389 |
goto ret; |
goto ret; |
390 |
} |
} |
391 |
|
|
392 |
tmpfilename = strdup("/tmp/gxemul.XXXXXXXXXXXX"); |
tmpfname = strdup("/tmp/gxemul.XXXXXXXXXXXX"); |
|
|
|
|
debug("extracting %lli bytes into %s\n", |
|
|
(long long)filelen, tmpfilename); |
|
393 |
|
|
394 |
res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf, |
res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf, |
395 |
filelen); |
filelen); |
398 |
goto ret; |
goto ret; |
399 |
} |
} |
400 |
|
|
401 |
tmpfile_handle = mkstemp(tmpfilename); |
tmpfile_handle = mkstemp(tmpfname); |
402 |
if (tmpfile_handle < 0) { |
if (tmpfile_handle < 0) { |
403 |
fatal("could not create %s\n", tmpfilename); |
fatal("could not create %s\n", tmpfname); |
404 |
exit(1); |
exit(1); |
405 |
} |
} |
406 |
write(tmpfile_handle, filebuf, filelen); |
write(tmpfile_handle, filebuf, filelen); |
407 |
close(tmpfile_handle); |
close(tmpfile_handle); |
408 |
|
|
409 |
|
debug("extracted %lli bytes into %s\n", (long long)filelen, tmpfname); |
410 |
|
|
411 |
/* Add the temporary filename to the load_namesp array: */ |
/* Add the temporary filename to the load_namesp array: */ |
412 |
(*n_loadp)++; |
(*n_loadp)++; |
413 |
new_array = malloc(sizeof(char *) * (*n_loadp)); |
new_array = malloc(sizeof(char *) * (*n_loadp)); |
421 |
/* This adds a Backspace char in front of the filename; this |
/* This adds a Backspace char in front of the filename; this |
422 |
is a special hack which causes the file to be removed once |
is a special hack which causes the file to be removed once |
423 |
it has been loaded. */ |
it has been loaded. */ |
424 |
tmpfilename = realloc(tmpfilename, strlen(tmpfilename) + 2); |
tmpfname = realloc(tmpfname, strlen(tmpfname) + 2); |
425 |
memmove(tmpfilename + 1, tmpfilename, strlen(tmpfilename) + 1); |
memmove(tmpfname + 1, tmpfname, strlen(tmpfname) + 1); |
426 |
tmpfilename[0] = 8; |
tmpfname[0] = 8; |
427 |
|
|
428 |
(*load_namesp)[*n_loadp - 1] = tmpfilename; |
(*load_namesp)[*n_loadp - 1] = tmpfname; |
429 |
|
|
430 |
res = 1; |
res = 1; |
431 |
|
|
447 |
|
|
448 |
|
|
449 |
/* |
/* |
450 |
|
* apple_load_bootblock(): |
451 |
|
* |
452 |
|
* Try to load a kernel from a disk image with an Apple Partition Table. |
453 |
|
* |
454 |
|
* TODO: This function uses too many magic offsets and so on; it should be |
455 |
|
* cleaned up some day. See http://www.awprofessional.com/articles/ |
456 |
|
* article.asp?p=376123&seqNum=3&rl=1 for some info on the Apple |
457 |
|
* partition format. |
458 |
|
* |
459 |
|
* Returns 1 on success, 0 on failure. |
460 |
|
*/ |
461 |
|
static int apple_load_bootblock(struct machine *m, struct cpu *cpu, |
462 |
|
int disk_id, int disk_type, int *n_loadp, char ***load_namesp) |
463 |
|
{ |
464 |
|
unsigned char buf[0x8000]; |
465 |
|
int res, partnr, n_partitions = 0, n_hfs_partitions = 0; |
466 |
|
uint64_t hfs_start, hfs_length; |
467 |
|
|
468 |
|
res = diskimage_access(m, disk_id, disk_type, 0, 0x0, buf, sizeof(buf)); |
469 |
|
if (!res) { |
470 |
|
fatal("apple_load_bootblock: couldn't read the disk " |
471 |
|
"image. Aborting.\n"); |
472 |
|
return 0; |
473 |
|
} |
474 |
|
|
475 |
|
partnr = 0; |
476 |
|
do { |
477 |
|
int start, length; |
478 |
|
int ofs = 0x200 * (partnr + 1); |
479 |
|
if (partnr == 0) |
480 |
|
n_partitions = buf[ofs + 7]; |
481 |
|
start = ((uint64_t)buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) + |
482 |
|
(buf[ofs + 10] << 8) + buf[ofs + 11]; |
483 |
|
length = ((uint64_t)buf[ofs+12] << 24) + (buf[ofs + 13] << 16) + |
484 |
|
(buf[ofs + 14] << 8) + buf[ofs + 15]; |
485 |
|
|
486 |
|
debug("partition %i: '%s', type '%s', start %i, length %i\n", |
487 |
|
partnr, buf + ofs + 0x10, buf + ofs + 0x30, |
488 |
|
start, length); |
489 |
|
|
490 |
|
if (strcmp((char *)buf + ofs + 0x30, "Apple_HFS") == 0) { |
491 |
|
n_hfs_partitions ++; |
492 |
|
hfs_start = 512 * start; |
493 |
|
hfs_length = 512 * length; |
494 |
|
} |
495 |
|
|
496 |
|
/* Any more partitions? */ |
497 |
|
partnr ++; |
498 |
|
} while (partnr < n_partitions); |
499 |
|
|
500 |
|
if (n_hfs_partitions == 0) { |
501 |
|
fatal("Error: No HFS partition found! TODO\n"); |
502 |
|
return 0; |
503 |
|
} |
504 |
|
if (n_hfs_partitions >= 2) { |
505 |
|
fatal("Error: Too many HFS partitions found! TODO\n"); |
506 |
|
return 0; |
507 |
|
} |
508 |
|
|
509 |
|
return 0; |
510 |
|
} |
511 |
|
|
512 |
|
|
513 |
|
/* |
514 |
* load_bootblock(): |
* load_bootblock(): |
515 |
* |
* |
516 |
* For some emulation modes, it is possible to boot from a harddisk image by |
* For some emulation modes, it is possible to boot from a harddisk image by |
535 |
return 0; |
return 0; |
536 |
|
|
537 |
switch (m->machine_type) { |
switch (m->machine_type) { |
538 |
case MACHINE_DEC: |
case MACHINE_PMAX: |
539 |
/* |
/* |
540 |
* The first few bytes of a disk contains information about |
* The first few bytes of a disk contains information about |
541 |
* where the bootblock(s) are located. (These are all 32-bit |
* where the bootblock(s) are located. (These are all 32-bit |
556 |
minibuf, sizeof(minibuf)); |
minibuf, sizeof(minibuf)); |
557 |
|
|
558 |
bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8) |
bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8) |
559 |
+ (minibuf[0x12] << 16) + (minibuf[0x13] << 24); |
+ (minibuf[0x12] << 16) + ((uint64_t)minibuf[0x13] << 24); |
560 |
|
|
561 |
/* Convert loadaddr to uncached: */ |
/* Convert loadaddr to uncached: */ |
562 |
if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 && |
if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 && |
567 |
bootblock_loadaddr |= 0xffffffffa0000000ULL; |
bootblock_loadaddr |= 0xffffffffa0000000ULL; |
568 |
|
|
569 |
bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8) |
bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8) |
570 |
+ (minibuf[0x16] << 16) + (minibuf[0x17] << 24); |
+ (minibuf[0x16] << 16) + ((uint64_t)minibuf[0x17] << 24); |
571 |
|
|
572 |
bootblock_pc &= 0x0fffffffULL; |
bootblock_pc &= 0x0fffffffULL; |
573 |
bootblock_pc |= 0xffffffffa0000000ULL; |
bootblock_pc |= 0xffffffffa0000000ULL; |
588 |
} |
} |
589 |
|
|
590 |
n_blocks = minibuf[0] + (minibuf[1] << 8) |
n_blocks = minibuf[0] + (minibuf[1] << 8) |
591 |
+ (minibuf[2] << 16) + (minibuf[3] << 24); |
+ (minibuf[2] << 16) + ((uint64_t)minibuf[3] << 24); |
592 |
|
|
593 |
bootblock_offset = (minibuf[4] + (minibuf[5] << 8) |
bootblock_offset = (minibuf[4] + (minibuf[5] << 8) + |
594 |
+ (minibuf[6] << 16) + (minibuf[7] << 24)) * 512; |
(minibuf[6]<<16) + ((uint64_t)minibuf[7]<<24)) * 512; |
595 |
|
|
596 |
if (n_blocks < 1) |
if (n_blocks < 1) |
597 |
break; |
break; |
662 |
|
|
663 |
/* |
/* |
664 |
* Try reading a kernel manually from the disk. The code here |
* Try reading a kernel manually from the disk. The code here |
665 |
* does not rely on machine-dependant boot blocks etc. |
* does not rely on machine-dependent boot blocks etc. |
666 |
*/ |
*/ |
667 |
/* ISO9660: (0x800 bytes at 0x8000) */ |
/* ISO9660: (0x800 bytes at 0x8000) */ |
668 |
bootblock_buf = malloc(0x800); |
bootblock_buf = malloc(0x800); |
699 |
n_loadp, load_namesp); |
n_loadp, load_namesp); |
700 |
} |
} |
701 |
|
|
702 |
|
if (retval != 0) |
703 |
|
goto ret_ok; |
704 |
|
|
705 |
|
/* Apple parition table: */ |
706 |
|
res = diskimage_access(m, boot_disk_id, boot_disk_type, |
707 |
|
0, 0x0, bootblock_buf, 0x800); |
708 |
|
if (!res) { |
709 |
|
fatal("Couldn't read the disk image. Aborting.\n"); |
710 |
|
return 0; |
711 |
|
} |
712 |
|
if (bootblock_buf[0x000] == 'E' && bootblock_buf[0x001] == 'R' && |
713 |
|
bootblock_buf[0x200] == 'P' && bootblock_buf[0x201] == 'M') { |
714 |
|
/* We can't load a kernel if the name |
715 |
|
isn't specified. */ |
716 |
|
if (cpu->machine->boot_kernel_filename == NULL || |
717 |
|
cpu->machine->boot_kernel_filename[0] == '\0') |
718 |
|
fatal("\nApple partition table, but no kernel " |
719 |
|
"specified? (Use the -j option.)\n"); |
720 |
|
else |
721 |
|
retval = apple_load_bootblock(m, cpu, boot_disk_id, |
722 |
|
boot_disk_type, n_loadp, load_namesp); |
723 |
|
} |
724 |
|
|
725 |
|
ret_ok: |
726 |
free(bootblock_buf); |
free(bootblock_buf); |
727 |
return retval; |
return retval; |
728 |
} |
} |
809 |
|
|
810 |
len += 1048576 * m->memory_offset_in_mb; |
len += 1048576 * m->memory_offset_in_mb; |
811 |
|
|
812 |
/* NOTE/TODO: magic 12MB end of load program area */ |
/* |
813 |
|
* NOTE/TODO: magic 12MB end of load program area |
814 |
|
* |
815 |
|
* Hm. This breaks the old FreeBSD/MIPS snapshots... |
816 |
|
*/ |
817 |
|
#if 0 |
818 |
arcbios_add_memory_descriptor(cpu, |
arcbios_add_memory_descriptor(cpu, |
819 |
0x60000 + m->memory_offset_in_mb * 1048576, |
0x60000 + m->memory_offset_in_mb * 1048576, |
820 |
start-0x60000 - m->memory_offset_in_mb * 1048576, |
start-0x60000 - m->memory_offset_in_mb * 1048576, |
821 |
ARCBIOS_MEM_FreeMemory); |
ARCBIOS_MEM_FreeMemory); |
822 |
|
#endif |
823 |
arcbios_add_memory_descriptor(cpu, |
arcbios_add_memory_descriptor(cpu, |
824 |
start, len, ARCBIOS_MEM_LoadedProgram); |
start, len, ARCBIOS_MEM_LoadedProgram); |
825 |
|
|
912 |
void emul_machine_setup(struct machine *m, int n_load, char **load_names, |
void emul_machine_setup(struct machine *m, int n_load, char **load_names, |
913 |
int n_devices, char **device_names) |
int n_devices, char **device_names) |
914 |
{ |
{ |
|
struct emul *emul; |
|
915 |
struct cpu *cpu; |
struct cpu *cpu; |
916 |
int i, iadd=4; |
int i, iadd = DEBUG_INDENTATION; |
917 |
uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0; |
uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0; |
918 |
int byte_order; |
int byte_order; |
919 |
|
|
|
emul = m->emul; |
|
|
|
|
920 |
debug("machine \"%s\":\n", m->name); |
debug("machine \"%s\":\n", m->name); |
921 |
debug_indentation(iadd); |
debug_indentation(iadd); |
922 |
|
|
937 |
|
|
938 |
m->cpu_family = cpu_family_ptr_by_number(m->arch); |
m->cpu_family = cpu_family_ptr_by_number(m->arch); |
939 |
|
|
940 |
|
if (m->arch == ARCH_ALPHA) |
941 |
|
m->arch_pagesize = 8192; |
942 |
|
|
943 |
if (m->arch != ARCH_MIPS) |
if (m->arch != ARCH_MIPS) |
944 |
m->bintrans_enable = 0; |
m->bintrans_enable = 0; |
945 |
|
|
963 |
debug(" (offset by %iMB)", m->memory_offset_in_mb); |
debug(" (offset by %iMB)", m->memory_offset_in_mb); |
964 |
memory_amount += 1048576 * m->memory_offset_in_mb; |
memory_amount += 1048576 * m->memory_offset_in_mb; |
965 |
} |
} |
966 |
m->memory = memory_new(memory_amount); |
m->memory = memory_new(memory_amount, m->arch); |
967 |
if (m->machine_type != MACHINE_USERLAND) |
if (m->machine_type != MACHINE_USERLAND) |
968 |
debug("\n"); |
debug("\n"); |
969 |
|
|
1030 |
if (m->userland_emul != NULL) { |
if (m->userland_emul != NULL) { |
1031 |
useremul_name_to_useremul(cpu, |
useremul_name_to_useremul(cpu, |
1032 |
m->userland_emul, NULL, NULL, NULL); |
m->userland_emul, NULL, NULL, NULL); |
1033 |
cpu->memory_rw = userland_memory_rw; |
|
1034 |
|
switch (m->arch) { |
1035 |
|
#ifdef ENABLE_ALPHA |
1036 |
|
case ARCH_ALPHA: |
1037 |
|
cpu->memory_rw = alpha_userland_memory_rw; |
1038 |
|
break; |
1039 |
|
#endif |
1040 |
|
default:cpu->memory_rw = userland_memory_rw; |
1041 |
|
} |
1042 |
} |
} |
1043 |
|
|
1044 |
if (m->use_x11) |
if (m->use_x11) |
1069 |
} |
} |
1070 |
|
|
1071 |
diskimage_dump_info(m); |
diskimage_dump_info(m); |
1072 |
|
console_debug_dump(m); |
1073 |
|
|
1074 |
/* Load files (ROM code, boot code, ...) into memory: */ |
/* Load files (ROM code, boot code, ...) into memory: */ |
1075 |
if (n_load == 0) { |
if (n_load == 0) { |
1218 |
cpu->pc = entrypoint; |
cpu->pc = entrypoint; |
1219 |
|
|
1220 |
switch (m->arch) { |
switch (m->arch) { |
1221 |
|
|
1222 |
|
case ARCH_ALPHA: |
1223 |
|
/* For position-independent code: */ |
1224 |
|
cpu->cd.alpha.r[ALPHA_T12] = cpu->pc; |
1225 |
|
break; |
1226 |
|
|
1227 |
|
case ARCH_ARM: |
1228 |
|
if (cpu->pc & 3) { |
1229 |
|
fatal("ARM: lowest bits of pc set: TODO\n"); |
1230 |
|
exit(1); |
1231 |
|
} |
1232 |
|
cpu->pc &= 0xfffffffc; |
1233 |
|
break; |
1234 |
|
|
1235 |
|
case ARCH_AVR: |
1236 |
|
cpu->pc &= 0xfffff; |
1237 |
|
if (cpu->pc & 1) { |
1238 |
|
fatal("AVR: lowest bit of pc set: TODO\n"); |
1239 |
|
exit(1); |
1240 |
|
} |
1241 |
|
break; |
1242 |
|
|
1243 |
|
case ARCH_HPPA: |
1244 |
|
break; |
1245 |
|
|
1246 |
|
case ARCH_I960: |
1247 |
|
break; |
1248 |
|
|
1249 |
|
case ARCH_IA64: |
1250 |
|
break; |
1251 |
|
|
1252 |
|
case ARCH_M68K: |
1253 |
|
break; |
1254 |
|
|
1255 |
case ARCH_MIPS: |
case ARCH_MIPS: |
1256 |
if ((cpu->pc >> 32) == 0 |
if ((cpu->pc >> 32) == 0 && (cpu->pc & 0x80000000ULL)) |
|
&& (cpu->pc & 0x80000000ULL)) |
|
1257 |
cpu->pc |= 0xffffffff00000000ULL; |
cpu->pc |= 0xffffffff00000000ULL; |
1258 |
|
|
1259 |
cpu->cd.mips.gpr[MIPS_GPR_GP] = gp; |
cpu->cd.mips.gpr[MIPS_GPR_GP] = gp; |
1269 |
spec/x458.html for more info. */ |
spec/x458.html for more info. */ |
1270 |
cpu->cd.ppc.gpr[2] = toc; |
cpu->cd.ppc.gpr[2] = toc; |
1271 |
/* TODO */ |
/* TODO */ |
1272 |
|
if (cpu->cd.ppc.bits == 32) |
1273 |
|
cpu->pc &= 0xffffffffULL; |
1274 |
break; |
break; |
1275 |
|
|
1276 |
case ARCH_ALPHA: |
case ARCH_SH: |
1277 |
case ARCH_HPPA: |
if (cpu->cd.sh.bits == 32) |
1278 |
case ARCH_SPARC: |
cpu->pc &= 0xffffffffULL; |
1279 |
case ARCH_URISC: |
cpu->pc &= ~1; |
1280 |
break; |
break; |
1281 |
|
|
1282 |
case ARCH_ARM: |
case ARCH_SPARC: |
|
cpu->pc &= 0xfffffffc; |
|
|
cpu->cd.arm.r[ARM_PC] = cpu->pc; |
|
1283 |
break; |
break; |
1284 |
|
|
1285 |
case ARCH_X86: |
case ARCH_X86: |
1348 |
add_dump_points(m); |
add_dump_points(m); |
1349 |
|
|
1350 |
/* TODO: This is MIPS-specific! */ |
/* TODO: This is MIPS-specific! */ |
1351 |
if (m->machine_type == MACHINE_DEC && |
if (m->machine_type == MACHINE_PMAX && |
1352 |
cpu->cd.mips.cpu_type.mmu_model == MMU3K) |
cpu->cd.mips.cpu_type.mmu_model == MMU3K) |
1353 |
add_symbol_name(&m->symbol_context, |
add_symbol_name(&m->symbol_context, |
1354 |
0x9fff0000, 0x10000, "r2k3k_cache", 0); |
0x9fff0000, 0x10000, "r2k3k_cache", 0, 0); |
1355 |
|
|
1356 |
symbol_recalc_sizes(&m->symbol_context); |
symbol_recalc_sizes(&m->symbol_context); |
1357 |
|
|
1366 |
|
|
1367 |
debug("starting cpu%i at ", m->bootstrap_cpu); |
debug("starting cpu%i at ", m->bootstrap_cpu); |
1368 |
switch (m->arch) { |
switch (m->arch) { |
1369 |
|
|
1370 |
|
case ARCH_ARM: |
1371 |
|
/* ARM cpus aren't 64-bit: */ |
1372 |
|
debug("0x%08x", (int)entrypoint); |
1373 |
|
break; |
1374 |
|
|
1375 |
|
case ARCH_AVR: |
1376 |
|
/* Atmel AVR uses a 16-bit or 22-bit program counter: */ |
1377 |
|
debug("0x%04x", (int)entrypoint); |
1378 |
|
break; |
1379 |
|
|
1380 |
case ARCH_MIPS: |
case ARCH_MIPS: |
1381 |
if (cpu->cd.mips.cpu_type.isa_level < 3 || |
if (cpu->is_32bit) { |
|
cpu->cd.mips.cpu_type.isa_level == 32) { |
|
1382 |
debug("0x%08x", (int)m->cpus[ |
debug("0x%08x", (int)m->cpus[ |
1383 |
m->bootstrap_cpu]->pc); |
m->bootstrap_cpu]->pc); |
1384 |
if (cpu->cd.mips.gpr[MIPS_GPR_GP] != 0) |
if (cpu->cd.mips.gpr[MIPS_GPR_GP] != 0) |
1393 |
cpu->cd.mips.gpr[MIPS_GPR_GP]); |
cpu->cd.mips.gpr[MIPS_GPR_GP]); |
1394 |
} |
} |
1395 |
break; |
break; |
1396 |
|
|
1397 |
case ARCH_PPC: |
case ARCH_PPC: |
1398 |
if (cpu->cd.ppc.bits == 32) |
if (cpu->cd.ppc.bits == 32) |
1399 |
debug("0x%08x", (int)entrypoint); |
debug("0x%08x", (int)entrypoint); |
1400 |
else |
else |
1401 |
debug("0x%016llx", (long long)entrypoint); |
debug("0x%016llx", (long long)entrypoint); |
1402 |
break; |
break; |
|
case ARCH_ARM: |
|
|
/* ARM cpus aren't 64-bit: */ |
|
|
debug("0x%08x", (int)entrypoint); |
|
|
break; |
|
|
case ARCH_URISC: |
|
|
{ |
|
|
char tmps[100]; |
|
|
unsigned char buf[sizeof(uint64_t)]; |
|
|
|
|
|
cpu->memory_rw(cpu, m->memory, 0, buf, sizeof(buf), |
|
|
MEM_READ, CACHE_NONE | NO_EXCEPTIONS); |
|
|
|
|
|
entrypoint = 0; |
|
|
for (i=0; i<cpu->cd.urisc.wordlen/8; i++) { |
|
|
entrypoint <<= 8; |
|
|
if (cpu->byte_order == EMUL_BIG_ENDIAN) |
|
|
entrypoint += buf[i]; |
|
|
else |
|
|
entrypoint += buf[cpu-> |
|
|
cd.urisc.wordlen/8 - 1 - i]; |
|
|
} |
|
1403 |
|
|
|
snprintf(tmps, sizeof(tmps), "0x%%0%illx", |
|
|
cpu->cd.urisc.wordlen / 4); |
|
|
debug(tmps, (long long)entrypoint); |
|
|
cpu->pc = entrypoint; |
|
|
} |
|
|
break; |
|
1404 |
case ARCH_X86: |
case ARCH_X86: |
1405 |
debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS], |
debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS], |
1406 |
(long long)cpu->pc); |
(long long)cpu->pc); |
1407 |
break; |
break; |
1408 |
|
|
1409 |
default: |
default: |
1410 |
debug("0x%016llx", (long long)cpu->pc); |
if (cpu->is_32bit) |
1411 |
|
debug("0x%08x", (int)cpu->pc); |
1412 |
|
else |
1413 |
|
debug("0x%016llx", (long long)cpu->pc); |
1414 |
} |
} |
1415 |
debug("\n"); |
debug("\n"); |
1416 |
|
|
1425 |
*/ |
*/ |
1426 |
void emul_dumpinfo(struct emul *e) |
void emul_dumpinfo(struct emul *e) |
1427 |
{ |
{ |
1428 |
int j, nm, iadd = 4; |
int j, nm, iadd = DEBUG_INDENTATION; |
1429 |
|
|
1430 |
if (e->net != NULL) |
if (e->net != NULL) |
1431 |
net_dumpinfo(e->net); |
net_dumpinfo(e->net); |
1454 |
*/ |
*/ |
1455 |
void emul_simple_init(struct emul *emul) |
void emul_simple_init(struct emul *emul) |
1456 |
{ |
{ |
1457 |
int iadd=4; |
int iadd = DEBUG_INDENTATION; |
1458 |
struct machine *m; |
struct machine *m; |
1459 |
|
|
1460 |
if (emul->n_machines != 1) { |
if (emul->n_machines != 1) { |
1491 |
*/ |
*/ |
1492 |
struct emul *emul_create_from_configfile(char *fname) |
struct emul *emul_create_from_configfile(char *fname) |
1493 |
{ |
{ |
1494 |
int iadd = 4; |
int iadd = DEBUG_INDENTATION; |
1495 |
struct emul *e = emul_new(fname); |
struct emul *e = emul_new(fname); |
1496 |
FILE *f; |
FILE *f; |
1497 |
char buf[128]; |
char buf[128]; |
1545 |
|
|
1546 |
atexit(fix_console); |
atexit(fix_console); |
1547 |
|
|
|
i = 79; |
|
|
while (i-- > 0) |
|
|
debug("-"); |
|
|
debug("\n\n"); |
|
|
|
|
1548 |
/* Initialize the interactive debugger: */ |
/* Initialize the interactive debugger: */ |
1549 |
debugger_init(emuls, n_emuls); |
debugger_init(emuls, n_emuls); |
1550 |
|
|
1551 |
|
/* Run any additional debugger commands before starting: */ |
1552 |
|
for (i=0; i<n_emuls; i++) { |
1553 |
|
struct emul *emul = emuls[i]; |
1554 |
|
if (emul->n_debugger_cmds > 0) { |
1555 |
|
int j; |
1556 |
|
if (i == 0) |
1557 |
|
print_separator(); |
1558 |
|
for (j = 0; j < emul->n_debugger_cmds; j ++) { |
1559 |
|
debug("> %s\n", emul->debugger_cmds[j]); |
1560 |
|
debugger_execute_cmd(emul->debugger_cmds[j], |
1561 |
|
strlen(emul->debugger_cmds[j])); |
1562 |
|
} |
1563 |
|
} |
1564 |
|
} |
1565 |
|
|
1566 |
|
print_separator(); |
1567 |
|
debug("\n"); |
1568 |
|
|
1569 |
|
|
1570 |
/* |
/* |
1571 |
* console_init_main() makes sure that the terminal is in a |
* console_init_main() makes sure that the terminal is in a |
1572 |
* reasonable state. |
* reasonable state. |
1591 |
if (e == NULL) |
if (e == NULL) |
1592 |
continue; |
continue; |
1593 |
for (j=0; j<e->n_machines; j++) |
for (j=0; j<e->n_machines; j++) |
1594 |
cpu_run_init(e, e->machines[j]); |
cpu_run_init(e->machines[j]); |
1595 |
} |
} |
1596 |
|
|
1597 |
|
/* TODO: Generalize: */ |
1598 |
|
if (emuls[0]->machines[0]->show_trace_tree) |
1599 |
|
cpu_functioncall_trace(emuls[0]->machines[0]->cpus[0], |
1600 |
|
emuls[0]->machines[0]->cpus[0]->pc); |
1601 |
|
|
1602 |
/* |
/* |
1603 |
* MAIN LOOP: |
* MAIN LOOP: |
1604 |
* |
* |
1631 |
if (e == NULL) |
if (e == NULL) |
1632 |
continue; |
continue; |
1633 |
for (j=0; j<e->n_machines; j++) |
for (j=0; j<e->n_machines; j++) |
1634 |
cpu_run_deinit(e, e->machines[j]); |
cpu_run_deinit(e->machines[j]); |
1635 |
} |
} |
1636 |
|
|
1637 |
/* force_debugger_at_exit flag set? Then enter the debugger: */ |
/* force_debugger_at_exit flag set? Then enter the debugger: */ |