/[gxemul]/trunk/src/emul.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/emul.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul.c,v 1.225 2005/08/14 19:35:54 debug Exp $   *  $Id: emul.c,v 1.238 2005/11/19 18:53:06 debug Exp $
29   *   *
30   *  Emulation startup and misc. routines.   *  Emulation startup and misc. routines.
31   */   */
# Line 112  static void add_dump_points(struct machi Line 112  static void add_dump_points(struct machi
112                   *  were automatically converted into the correct address.                   *  were automatically converted into the correct address.
113                   */                   */
114    
115                  if ((dp >> 32) == 0 && ((dp >> 31) & 1))                  if (m->arch == ARCH_MIPS) {
116                          dp |= 0xffffffff00000000ULL;                          if ((dp >> 32) == 0 && ((dp >> 31) & 1))
117                                    dp |= 0xffffffff00000000ULL;
118                    }
119    
120                  m->breakpoint_addr[i] = dp;                  m->breakpoint_addr[i] = dp;
121    
122                  debug("breakpoint %i: 0x%016llx", i, (long long)dp);                  debug("breakpoint %i: 0x%llx", i, (long long)dp);
123                  if (string_flag)                  if (string_flag)
124                          debug(" (%s)", m->breakpoint_string[i]);                          debug(" (%s)", m->breakpoint_string[i]);
125                  debug("\n");                  debug("\n");
# Line 435  ret: Line 438  ret:
438    
439    
440  /*  /*
441     *  apple_load_bootblock():
442     *
443     *  Try to load a kernel from a disk image with an Apple Partition Table.
444     *
445     *  TODO: This function uses too many magic offsets and so on; it should be
446     *  cleaned up some day. See http://www.awprofessional.com/articles/
447     *      article.asp?p=376123&seqNum=3&rl=1  for some info on the Apple
448     *  partition format.
449     *
450     *  Returns 1 on success, 0 on failure.
451     */
452    static int apple_load_bootblock(struct machine *m, struct cpu *cpu,
453            int disk_id, int disk_type, int *n_loadp, char ***load_namesp)
454    {
455            unsigned char buf[0x8000];
456            int res, partnr, n_partitions = 0, n_hfs_partitions = 0;
457            uint64_t hfs_start, hfs_length;
458    
459            res = diskimage_access(m, disk_id, disk_type, 0, 0x0, buf, sizeof(buf));
460            if (!res) {
461                    fatal("apple_load_bootblock: couldn't read the disk "
462                        "image. Aborting.\n");
463                    return 0;
464            }
465    
466            partnr = 0;
467            do {
468                    int start, length;
469                    int ofs = 0x200 * (partnr + 1);
470                    if (partnr == 0)
471                            n_partitions = buf[ofs + 7];
472                    start = (buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +
473                        (buf[ofs + 10] << 8) + buf[ofs + 11];
474                    length = (buf[ofs + 12] << 24) + (buf[ofs + 13] << 16) +
475                        (buf[ofs + 14] << 8) + buf[ofs + 15];
476    
477                    debug("partition %i: '%s', type '%s', start %i, length %i\n",
478                        partnr, buf + ofs + 0x10, buf + ofs + 0x30,
479                        start, length);
480    
481                    if (strcmp((char *)buf + ofs + 0x30, "Apple_HFS") == 0) {
482                            n_hfs_partitions ++;
483                            hfs_start = 512 * start;
484                            hfs_length = 512 * length;
485                    }
486    
487                    /*  Any more partitions?  */
488                    partnr ++;
489            } while (partnr < n_partitions);
490    
491            if (n_hfs_partitions == 0) {
492                    fatal("Error: No HFS partition found! TODO\n");
493                    return 0;
494            }
495            if (n_hfs_partitions >= 2) {
496                    fatal("Error: Too many HFS partitions found! TODO\n");
497                    return 0;
498            }
499    
500            return 0;
501    }
502    
503    
504    /*
505   *  load_bootblock():   *  load_bootblock():
506   *   *
507   *  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
# Line 586  static int load_bootblock(struct machine Line 653  static int load_bootblock(struct machine
653    
654          /*          /*
655           *  Try reading a kernel manually from the disk. The code here           *  Try reading a kernel manually from the disk. The code here
656           *  does not rely on machine-dependant boot blocks etc.           *  does not rely on machine-dependent boot blocks etc.
657           */           */
658          /*  ISO9660: (0x800 bytes at 0x8000)  */          /*  ISO9660: (0x800 bytes at 0x8000)  */
659          bootblock_buf = malloc(0x800);          bootblock_buf = malloc(0x800);
# Line 623  static int load_bootblock(struct machine Line 690  static int load_bootblock(struct machine
690                              n_loadp, load_namesp);                              n_loadp, load_namesp);
691          }          }
692    
693            if (retval != 0)
694                    goto ret_ok;
695    
696            /*  Apple parition table:  */
697            res = diskimage_access(m, boot_disk_id, boot_disk_type,
698                0, 0x0, bootblock_buf, 0x800);
699            if (!res) {
700                    fatal("Couldn't read the disk image. Aborting.\n");
701                    return 0;
702            }
703            if (bootblock_buf[0x000] == 'E' && bootblock_buf[0x001] == 'R' &&
704                bootblock_buf[0x200] == 'P' && bootblock_buf[0x201] == 'M') {
705                    /*  We can't load a kernel if the name
706                        isn't specified.  */
707                    if (cpu->machine->boot_kernel_filename == NULL ||
708                        cpu->machine->boot_kernel_filename[0] == '\0')
709                            fatal("\nApple partition table, but no kernel "
710                                "specified? (Use the -j option.)\n");
711                    else
712                            retval = apple_load_bootblock(m, cpu, boot_disk_id,
713                                boot_disk_type, n_loadp, load_namesp);
714            }
715    
716    ret_ok:
717          free(bootblock_buf);          free(bootblock_buf);
718          return retval;          return retval;
719  }  }
# Line 1120  void emul_machine_setup(struct machine * Line 1211  void emul_machine_setup(struct machine *
1211                  cpu->pc = entrypoint;                  cpu->pc = entrypoint;
1212    
1213                  switch (m->arch) {                  switch (m->arch) {
1214    
1215                    case ARCH_ALPHA:
1216                            /*  For position-independent code:  */
1217                            cpu->cd.alpha.r[ALPHA_T12] = cpu->pc;
1218                            break;
1219    
1220                    case ARCH_ARM:
1221                            if (cpu->pc & 3) {
1222                                    fatal("ARM: lowest bits of pc set: TODO\n");
1223                                    exit(1);
1224                            }
1225                            cpu->pc &= 0xfffffffc;
1226                            break;
1227    
1228                    case ARCH_AVR:
1229                            cpu->pc &= 0xfffff;
1230                            if (cpu->pc & 1) {
1231                                    fatal("AVR: lowest bit of pc set: TODO\n");
1232                                    exit(1);
1233                            }
1234                            break;
1235    
1236                    case ARCH_HPPA:
1237                            break;
1238    
1239                    case ARCH_I960:
1240                            break;
1241    
1242                    case ARCH_IA64:
1243                            break;
1244    
1245                    case ARCH_M68K:
1246                            break;
1247    
1248                  case ARCH_MIPS:                  case ARCH_MIPS:
1249                          if ((cpu->pc >> 32) == 0                          if ((cpu->pc >> 32) == 0 && (cpu->pc & 0x80000000ULL))
                             && (cpu->pc & 0x80000000ULL))  
1250                                  cpu->pc |= 0xffffffff00000000ULL;                                  cpu->pc |= 0xffffffff00000000ULL;
1251    
1252                          cpu->cd.mips.gpr[MIPS_GPR_GP] = gp;                          cpu->cd.mips.gpr[MIPS_GPR_GP] = gp;
# Line 1138  void emul_machine_setup(struct machine * Line 1262  void emul_machine_setup(struct machine *
1262                              spec/x458.html for more info.  */                              spec/x458.html for more info.  */
1263                          cpu->cd.ppc.gpr[2] = toc;                          cpu->cd.ppc.gpr[2] = toc;
1264                          /*  TODO  */                          /*  TODO  */
1265                            if (cpu->cd.ppc.bits == 32)
1266                                    cpu->pc &= 0xffffffffULL;
1267                          break;                          break;
1268    
1269                  case ARCH_ALPHA:                  case ARCH_SH:
1270                          /*  For position-independant code:  */                          if (cpu->cd.sh.bits == 32)
1271                          cpu->cd.alpha.r[ALPHA_T12] = cpu->pc;                                  cpu->pc &= 0xffffffffULL;
1272                            cpu->pc &= ~1;
1273                          break;                          break;
1274    
1275                  case ARCH_SPARC:                  case ARCH_SPARC:
1276                          break;                          break;
1277    
                 case ARCH_IA64:  
                         break;  
   
                 case ARCH_M68K:  
                         break;  
   
                 case ARCH_ARM:  
                         cpu->pc &= 0xfffffffc;  
                         cpu->cd.arm.r[ARM_PC] = cpu->pc;  
                         break;  
   
1278                  case ARCH_X86:                  case ARCH_X86:
1279                          /*                          /*
1280                           *  NOTE: The toc field is used to indicate an ELF32                           *  NOTE: The toc field is used to indicate an ELF32
# Line 1241  void emul_machine_setup(struct machine * Line 1357  void emul_machine_setup(struct machine *
1357              m->machine_type == MACHINE_SGI) && m->prom_emulation)              m->machine_type == MACHINE_SGI) && m->prom_emulation)
1358                  add_arc_components(m);                  add_arc_components(m);
1359    
1360    
1361    #if 0
1362    if (m->machine_type == MACHINE_IQ80321) {
1363            store_32bit_word(cpu, 0xc0200000, 0);
1364            store_32bit_word(cpu, 0xc0200004, 0xd0000000);
1365    }
1366    #endif
1367    
1368    
1369          debug("starting cpu%i at ", m->bootstrap_cpu);          debug("starting cpu%i at ", m->bootstrap_cpu);
1370          switch (m->arch) {          switch (m->arch) {
1371    
1372            case ARCH_ARM:
1373                    /*  ARM cpus aren't 64-bit:  */
1374                    debug("0x%08x", (int)entrypoint);
1375                    break;
1376    
1377            case ARCH_AVR:
1378                    /*  Atmel AVR uses a 16-bit or 22-bit program counter:  */
1379                    debug("0x%04x", (int)entrypoint);
1380                    break;
1381    
1382          case ARCH_MIPS:          case ARCH_MIPS:
1383                  if (cpu->is_32bit) {                  if (cpu->is_32bit) {
1384                          debug("0x%08x", (int)m->cpus[                          debug("0x%08x", (int)m->cpus[
# Line 1259  void emul_machine_setup(struct machine * Line 1395  void emul_machine_setup(struct machine *
1395                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);
1396                  }                  }
1397                  break;                  break;
1398    
1399          case ARCH_PPC:          case ARCH_PPC:
1400                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
1401                          debug("0x%08x", (int)entrypoint);                          debug("0x%08x", (int)entrypoint);
1402                  else                  else
1403                          debug("0x%016llx", (long long)entrypoint);                          debug("0x%016llx", (long long)entrypoint);
1404                  break;                  break;
1405          case ARCH_ARM:  
                 /*  ARM cpus aren't 64-bit:  */  
                 debug("0x%08x", (int)entrypoint);  
                 break;  
1406          case ARCH_X86:          case ARCH_X86:
1407                  debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS],                  debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS],
1408                      (long long)cpu->pc);                      (long long)cpu->pc);
1409                  break;                  break;
1410    
1411          default:          default:
1412                  debug("0x%016llx", (long long)cpu->pc);                  debug("0x%016llx", (long long)cpu->pc);
1413          }          }

Legend:
Removed from v.12  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26