/[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 18 by dpavlin, Mon Oct 8 16:19:11 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.235 2005/10/26 14:37:02 debug Exp $
29   *   *
30   *  Emulation startup and misc. routines.   *  Emulation startup and misc. routines.
31   */   */
# Line 435  ret: Line 435  ret:
435    
436    
437  /*  /*
438     *  apple_load_bootblock():
439     *
440     *  Try to load a kernel from a disk image with an Apple Partition Table.
441     *
442     *  TODO: This function uses too many magic offsets and so on; it should be
443     *  cleaned up some day. See http://www.awprofessional.com/articles/
444     *      article.asp?p=376123&seqNum=3&rl=1  for some info on the Apple
445     *  partition format.
446     *
447     *  Returns 1 on success, 0 on failure.
448     */
449    static int apple_load_bootblock(struct machine *m, struct cpu *cpu,
450            int disk_id, int disk_type, int *n_loadp, char ***load_namesp)
451    {
452            unsigned char buf[0x8000];
453            int res, partnr, n_partitions = 0, n_hfs_partitions = 0;
454            uint64_t hfs_start, hfs_length;
455    
456            res = diskimage_access(m, disk_id, disk_type, 0, 0x0, buf, sizeof(buf));
457            if (!res) {
458                    fatal("apple_load_bootblock: couldn't read the disk "
459                        "image. Aborting.\n");
460                    return 0;
461            }
462    
463            partnr = 0;
464            do {
465                    int start, length;
466                    int ofs = 0x200 * (partnr + 1);
467                    if (partnr == 0)
468                            n_partitions = buf[ofs + 7];
469                    start = (buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +
470                        (buf[ofs + 10] << 8) + buf[ofs + 11];
471                    length = (buf[ofs + 12] << 24) + (buf[ofs + 13] << 16) +
472                        (buf[ofs + 14] << 8) + buf[ofs + 15];
473    
474                    debug("partition %i: '%s', type '%s', start %i, length %i\n",
475                        partnr, buf + ofs + 0x10, buf + ofs + 0x30,
476                        start, length);
477    
478                    if (strcmp((char *)buf + ofs + 0x30, "Apple_HFS") == 0) {
479                            n_hfs_partitions ++;
480                            hfs_start = 512 * start;
481                            hfs_length = 512 * length;
482                    }
483    
484                    /*  Any more partitions?  */
485                    partnr ++;
486            } while (partnr < n_partitions);
487    
488            if (n_hfs_partitions == 0) {
489                    fatal("Error: No HFS partition found! TODO\n");
490                    return 0;
491            }
492            if (n_hfs_partitions >= 2) {
493                    fatal("Error: Too many HFS partitions found! TODO\n");
494                    return 0;
495            }
496    
497            return 0;
498    }
499    
500    
501    /*
502   *  load_bootblock():   *  load_bootblock():
503   *   *
504   *  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 650  static int load_bootblock(struct machine
650    
651          /*          /*
652           *  Try reading a kernel manually from the disk. The code here           *  Try reading a kernel manually from the disk. The code here
653           *  does not rely on machine-dependant boot blocks etc.           *  does not rely on machine-dependent boot blocks etc.
654           */           */
655          /*  ISO9660: (0x800 bytes at 0x8000)  */          /*  ISO9660: (0x800 bytes at 0x8000)  */
656          bootblock_buf = malloc(0x800);          bootblock_buf = malloc(0x800);
# Line 623  static int load_bootblock(struct machine Line 687  static int load_bootblock(struct machine
687                              n_loadp, load_namesp);                              n_loadp, load_namesp);
688          }          }
689    
690            if (retval != 0)
691                    goto ret_ok;
692    
693            /*  Apple parition table:  */
694            res = diskimage_access(m, boot_disk_id, boot_disk_type,
695                0, 0x0, bootblock_buf, 0x800);
696            if (!res) {
697                    fatal("Couldn't read the disk image. Aborting.\n");
698                    return 0;
699            }
700            if (bootblock_buf[0x000] == 'E' && bootblock_buf[0x001] == 'R' &&
701                bootblock_buf[0x200] == 'P' && bootblock_buf[0x201] == 'M') {
702                    /*  We can't load a kernel if the name
703                        isn't specified.  */
704                    if (cpu->machine->boot_kernel_filename == NULL ||
705                        cpu->machine->boot_kernel_filename[0] == '\0')
706                            fatal("\nApple partition table, but no kernel "
707                                "specified? (Use the -j option.)\n");
708                    else
709                            retval = apple_load_bootblock(m, cpu, boot_disk_id,
710                                boot_disk_type, n_loadp, load_namesp);
711            }
712    
713    ret_ok:
714          free(bootblock_buf);          free(bootblock_buf);
715          return retval;          return retval;
716  }  }
# Line 1120  void emul_machine_setup(struct machine * Line 1208  void emul_machine_setup(struct machine *
1208                  cpu->pc = entrypoint;                  cpu->pc = entrypoint;
1209    
1210                  switch (m->arch) {                  switch (m->arch) {
1211    
1212                    case ARCH_ALPHA:
1213                            /*  For position-independent code:  */
1214                            cpu->cd.alpha.r[ALPHA_T12] = cpu->pc;
1215                            break;
1216    
1217                    case ARCH_ARM:
1218                            cpu->pc &= 0xfffffffc;
1219                            cpu->cd.arm.r[ARM_PC] = cpu->pc;
1220                            break;
1221    
1222                    case ARCH_AVR:
1223                            cpu->pc &= 0xfffff;
1224                            if (cpu->pc & 1) {
1225                                    fatal("AVR: lowest bit of pc set: TODO\n");
1226                                    exit(1);
1227                            }
1228                            break;
1229    
1230                    case ARCH_HPPA:
1231                            break;
1232    
1233                    case ARCH_I960:
1234                            break;
1235    
1236                    case ARCH_IA64:
1237                            break;
1238    
1239                    case ARCH_M68K:
1240                            break;
1241    
1242                  case ARCH_MIPS:                  case ARCH_MIPS:
1243                          if ((cpu->pc >> 32) == 0                          if ((cpu->pc >> 32) == 0
1244                              && (cpu->pc & 0x80000000ULL))                              && (cpu->pc & 0x80000000ULL))
# Line 1138  void emul_machine_setup(struct machine * Line 1257  void emul_machine_setup(struct machine *
1257                              spec/x458.html for more info.  */                              spec/x458.html for more info.  */
1258                          cpu->cd.ppc.gpr[2] = toc;                          cpu->cd.ppc.gpr[2] = toc;
1259                          /*  TODO  */                          /*  TODO  */
1260                            if (cpu->cd.ppc.bits == 32)
1261                                    cpu->pc &= 0xffffffffULL;
1262                          break;                          break;
1263    
1264                  case ARCH_ALPHA:                  case ARCH_SH:
1265                          /*  For position-independant code:  */                          if (cpu->cd.sh.bits == 32)
1266                          cpu->cd.alpha.r[ALPHA_T12] = cpu->pc;                                  cpu->pc &= 0xffffffffULL;
1267                            cpu->pc &= ~1;
1268                          break;                          break;
1269    
1270                  case ARCH_SPARC:                  case ARCH_SPARC:
1271                          break;                          break;
1272    
                 case ARCH_IA64:  
                         break;  
   
                 case ARCH_M68K:  
                         break;  
   
                 case ARCH_ARM:  
                         cpu->pc &= 0xfffffffc;  
                         cpu->cd.arm.r[ARM_PC] = cpu->pc;  
                         break;  
   
1273                  case ARCH_X86:                  case ARCH_X86:
1274                          /*                          /*
1275                           *  NOTE: The toc field is used to indicate an ELF32                           *  NOTE: The toc field is used to indicate an ELF32
# Line 1243  void emul_machine_setup(struct machine * Line 1354  void emul_machine_setup(struct machine *
1354    
1355          debug("starting cpu%i at ", m->bootstrap_cpu);          debug("starting cpu%i at ", m->bootstrap_cpu);
1356          switch (m->arch) {          switch (m->arch) {
1357    
1358            case ARCH_ARM:
1359                    /*  ARM cpus aren't 64-bit:  */
1360                    debug("0x%08x", (int)entrypoint);
1361                    break;
1362    
1363            case ARCH_AVR:
1364                    /*  Atmel AVR uses a 16-bit or 22-bit program counter:  */
1365                    debug("0x%04x", (int)entrypoint);
1366                    break;
1367    
1368          case ARCH_MIPS:          case ARCH_MIPS:
1369                  if (cpu->is_32bit) {                  if (cpu->is_32bit) {
1370                          debug("0x%08x", (int)m->cpus[                          debug("0x%08x", (int)m->cpus[
# Line 1259  void emul_machine_setup(struct machine * Line 1381  void emul_machine_setup(struct machine *
1381                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);
1382                  }                  }
1383                  break;                  break;
1384    
1385          case ARCH_PPC:          case ARCH_PPC:
1386                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
1387                          debug("0x%08x", (int)entrypoint);                          debug("0x%08x", (int)entrypoint);
1388                  else                  else
1389                          debug("0x%016llx", (long long)entrypoint);                          debug("0x%016llx", (long long)entrypoint);
1390                  break;                  break;
1391          case ARCH_ARM:  
                 /*  ARM cpus aren't 64-bit:  */  
                 debug("0x%08x", (int)entrypoint);  
                 break;  
1392          case ARCH_X86:          case ARCH_X86:
1393                  debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS],                  debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS],
1394                      (long long)cpu->pc);                      (long long)cpu->pc);
1395                  break;                  break;
1396    
1397          default:          default:
1398                  debug("0x%016llx", (long long)cpu->pc);                  debug("0x%016llx", (long long)cpu->pc);
1399          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26