--- trunk/src/emul.c 2007/10/08 16:17:52 3 +++ trunk/src/emul.c 2007/10/08 16:18:00 4 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: emul.c,v 1.179 2005/03/14 19:14:04 debug Exp $ + * $Id: emul.c,v 1.184 2005/04/20 04:43:52 debug Exp $ * * Emulation startup and misc. routines. */ @@ -41,7 +41,6 @@ #include "arcbios.h" #include "bintrans.h" #include "cpu.h" -#include "cpu_mips.h" #include "emul.h" #include "console.h" #include "debugger.h" @@ -244,6 +243,32 @@ debug(readofs == 0x18? ": no blocks?\n" : " blocks\n"); break; + + case MACHINE_X86: + cpu->cd.x86.mode = 16; + cpu->pc = 0x7c00; + + bootblock_buf = malloc(512); + if (bootblock_buf == NULL) { + fprintf(stderr, "Out of memory.\n"); + exit(1); + } + + res = diskimage_access(m, boot_disk_id, 0, 0, + bootblock_buf, 512); + if (!res) { + printf("Couldn't read the disk image. Aborting.\n"); + exit(1); + } + + debug("loading PC bootsector from disk %i\n", boot_disk_id); + if (bootblock_buf[510] != 0x55 || bootblock_buf[511] != 0xaa) + debug("WARNING! The 0x55,0xAA marker is missing! " + "Booting anyway.\n"); + store_buf(cpu, 0x7c00, (char *)bootblock_buf, 512); + free(bootblock_buf); + break; + default: fatal("Booting from disk without a separate kernel " "doesn't work in this emulation mode.\n"); @@ -604,17 +629,28 @@ cpu->cd.mips.gpr[MIPS_GPR_GP] |= 0xffffffff00000000ULL; break; + case ARCH_PPC: cpu->cd.ppc.gpr[2] = toc; break; + + case ARCH_ALPHA: + case ARCH_HPPA: case ARCH_SPARC: - break; case ARCH_URISC: break; - case ARCH_HPPA: - break; - case ARCH_ALPHA: + + case ARCH_X86: + /* + * NOTE: The toc field is used to indicate an ELF64 + * load, on AMD64! + */ + if (toc != 0) { + cpu->cd.x86.mode = 64; + } else + cpu->pc &= 0xffffffffULL; break; + default: fatal("emul_machine_setup(): Internal error: " "Unimplemented arch %i\n", m->arch); @@ -727,8 +763,17 @@ cpu->pc = entrypoint; } break; + case ARCH_X86: + if (cpu->cd.x86.mode == 16) + debug("0x%04x:0x%04x", cpu->cd.x86.s[X86_S_CS], + (int)cpu->pc); + else if (cpu->cd.x86.mode == 32) + debug("0x%08x", (int)cpu->pc); + else + debug("0x%016llx", (long long)cpu->pc); + break; default: - debug("0x%016llx", (long long)entrypoint); + debug("0x%016llx", (long long)cpu->pc); } debug("\n");