/[gxemul]/trunk/src/cpus/cpu_ppc.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/cpus/cpu_ppc.c

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

revision 43 by dpavlin, Mon Oct 8 16:22:32 2007 UTC revision 44 by dpavlin, Mon Oct 8 16:22:56 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu_ppc.c,v 1.70 2007/06/15 00:41:21 debug Exp $   *  $Id: cpu_ppc.c,v 1.72 2007/06/28 13:36:46 debug Exp $
29   *   *
30   *  PowerPC/POWER CPU emulation.   *  PowerPC/POWER CPU emulation.
31   */   */
# Line 49  Line 49 
49  #include "ppc_spr_strings.h"  #include "ppc_spr_strings.h"
50  #include "settings.h"  #include "settings.h"
51  #include "symbol.h"  #include "symbol.h"
 #include "timer.h"  
52  #include "useremul.h"  #include "useremul.h"
53    
54    
# Line 57  Line 56 
56  #include "tmp_ppc_head.c"  #include "tmp_ppc_head.c"
57    
58    
 extern int native_code_translation_enabled;  
   
59  void ppc_pc_to_pointers(struct cpu *);  void ppc_pc_to_pointers(struct cpu *);
60  void ppc32_pc_to_pointers(struct cpu *);  void ppc32_pc_to_pointers(struct cpu *);
61    
# Line 238  int ppc_cpu_new(struct cpu *cpu, struct Line 235  int ppc_cpu_new(struct cpu *cpu, struct
235                  interrupt_handler_register(&template);                  interrupt_handler_register(&template);
236          }          }
237    
         if (native_code_translation_enabled)  
                 cpu->sampling_timer = timer_add(CPU_SAMPLE_TIMER_HZ,  
                     ppc_timer_sample_tick, cpu);  
   
238          return 1;          return 1;
239  }  }
240    
# Line 371  void ppc_exception(struct cpu *cpu, int Line 364  void ppc_exception(struct cpu *cpu, int
364                  cpu->cd.ppc.spr[SPR_SRR1] = (cpu->cd.ppc.msr & 0x87c0ffff);                  cpu->cd.ppc.spr[SPR_SRR1] = (cpu->cd.ppc.msr & 0x87c0ffff);
365    
366          if (!quiet_mode)          if (!quiet_mode)
367                  fatal("[ PPC Exception 0x%x; pc=0x%"PRIx64" ]\n", exception_nr,                  fatal("[ PPC Exception 0x%x; pc=0x%"PRIx64" ]\n",
368                      (long long)cpu->pc);                      exception_nr, cpu->pc);
369    
370          /*  Disable External Interrupts, Recoverable Interrupt Mode,          /*  Disable External Interrupts, Recoverable Interrupt Mode,
371              and go to Supervisor mode  */              and go to Supervisor mode  */
# Line 446  void ppc_cpu_register_dump(struct cpu *c Line 439  void ppc_cpu_register_dump(struct cpu *c
439                          for (i=0; i<PPC_NGPRS; i++) {                          for (i=0; i<PPC_NGPRS; i++) {
440                                  if ((i % 4) == 0)                                  if ((i % 4) == 0)
441                                          debug("cpu%i:", x);                                          debug("cpu%i:", x);
442                                  debug(" r%02i = 0x%08x ", i,                                  debug(" r%02i = 0x%08"PRIx32" ", i,
443                                      (int)cpu->cd.ppc.gpr[i]);                                      (uint32_t) cpu->cd.ppc.gpr[i]);
444                                  if ((i % 4) == 3)                                  if ((i % 4) == 3)
445                                          debug("\n");                                          debug("\n");
446                          }                          }
# Line 457  void ppc_cpu_register_dump(struct cpu *c Line 450  void ppc_cpu_register_dump(struct cpu *c
450                                  int r = (i >> 1) + ((i & 1) << 4);                                  int r = (i >> 1) + ((i & 1) << 4);
451                                  if ((i % 2) == 0)                                  if ((i % 2) == 0)
452                                          debug("cpu%i:", x);                                          debug("cpu%i:", x);
453                                  debug(" r%02i = 0x%016llx ", r,                                  debug(" r%02i = 0x%016"PRIx64" ", r,
454                                      (long long)cpu->cd.ppc.gpr[r]);                                      (uint64_t) cpu->cd.ppc.gpr[r]);
455                                  if ((i % 2) == 1)                                  if ((i % 2) == 1)
456                                          debug("\n");                                          debug("\n");
457                          }                          }
# Line 466  void ppc_cpu_register_dump(struct cpu *c Line 459  void ppc_cpu_register_dump(struct cpu *c
459    
460                  /*  Other special registers:  */                  /*  Other special registers:  */
461                  if (bits32) {                  if (bits32) {
462                          debug("cpu%i: srr0 = 0x%08x srr1 = 0x%08x\n", x,                          debug("cpu%i: srr0 = 0x%08"PRIx32
463                              (int)cpu->cd.ppc.spr[SPR_SRR0],                              " srr1 = 0x%08"PRIx32"\n", x,
464                              (int)cpu->cd.ppc.spr[SPR_SRR1]);                              (uint32_t) cpu->cd.ppc.spr[SPR_SRR0],
465                                (uint32_t) cpu->cd.ppc.spr[SPR_SRR1]);
466                  } else {                  } else {
467                          debug("cpu%i: srr0 = 0x%016llx  srr1 = 0x%016llx\n", x,                          debug("cpu%i: srr0 = 0x%016"PRIx64
468                              (long long)cpu->cd.ppc.spr[SPR_SRR0],                              "  srr1 = 0x%016"PRIx64"\n", x,
469                              (long long)cpu->cd.ppc.spr[SPR_SRR1]);                              (uint64_t) cpu->cd.ppc.spr[SPR_SRR0],
470                                (uint64_t) cpu->cd.ppc.spr[SPR_SRR1]);
471                  }                  }
472    
473                  debug("cpu%i: msr = ", x);                  debug("cpu%i: msr = ", x);
474                  reg_access_msr(cpu, &tmp, 0, 0);                  reg_access_msr(cpu, &tmp, 0, 0);
475                  if (bits32)                  if (bits32)
476                          debug("0x%08x  ", (int)tmp);                          debug("0x%08"PRIx32, (uint32_t) tmp);
477                  else                  else
478                          debug("0x%016llx  ", (long long)tmp);                          debug("0x%016"PRIx64, (uint64_t) tmp);
479                  debug("tb  = 0x%08x%08x\n", (int)cpu->cd.ppc.spr[SPR_TBU],  
480                      (int)cpu->cd.ppc.spr[SPR_TBL]);                  debug("  tb  = 0x%08"PRIx32"%08"PRIx32"\n",
481                  debug("cpu%i: dec = 0x%08x", x, (int)cpu->cd.ppc.spr[SPR_DEC]);                      (uint32_t) cpu->cd.ppc.spr[SPR_TBU],
482                        (uint32_t) cpu->cd.ppc.spr[SPR_TBL]);
483    
484                    debug("cpu%i: dec = 0x%08"PRIx32,
485                        x, (uint32_t) cpu->cd.ppc.spr[SPR_DEC]);
486                  if (!bits32)                  if (!bits32)
487                          debug("  hdec = 0x%08x\n",                          debug("  hdec = 0x%08"PRIx32"\n",
488                              (int)cpu->cd.ppc.spr[SPR_HDEC]);                              (uint32_t) cpu->cd.ppc.spr[SPR_HDEC]);
489    
490                  debug("\n");                  debug("\n");
491          }          }
492    
493          if (coprocs & 1) {          if (coprocs & 1) {
494                  debug("cpu%i: fpscr = 0x%08x\n", x, (int)cpu->cd.ppc.fpscr);                  debug("cpu%i: fpscr = 0x%08"PRIx32"\n",
495                        x, (uint32_t) cpu->cd.ppc.fpscr);
496    
497                  /*  TODO: show floating-point values :-)  */                  /*  TODO: show floating-point values :-)  */
498    
# Line 499  void ppc_cpu_register_dump(struct cpu *c Line 501  void ppc_cpu_register_dump(struct cpu *c
501                  for (i=0; i<PPC_NFPRS; i++) {                  for (i=0; i<PPC_NFPRS; i++) {
502                          if ((i % 2) == 0)                          if ((i % 2) == 0)
503                                  debug("cpu%i:", x);                                  debug("cpu%i:", x);
504                          debug(" f%02i = 0x%016llx ", i,                          debug(" f%02i = 0x%016"PRIx64" ", i,
505                              (long long)cpu->cd.ppc.fpr[i]);                              (uint64_t) cpu->cd.ppc.fpr[i]);
506                          if ((i % 2) == 1)                          if ((i % 2) == 1)
507                                  debug("\n");                                  debug("\n");
508                  }                  }
509          }          }
510    
511          if (coprocs & 2) {          if (coprocs & 2) {
512                  debug("cpu%i:  sdr1 = 0x%llx\n", x,                  debug("cpu%i:  sdr1 = 0x%"PRIx64"\n", x,
513                      (long long)cpu->cd.ppc.spr[SPR_SDR1]);                      (uint64_t) cpu->cd.ppc.spr[SPR_SDR1]);
514                  if (cpu->cd.ppc.cpu_type.flags & PPC_601)                  if (cpu->cd.ppc.cpu_type.flags & PPC_601)
515                          debug("cpu%i:  PPC601-style, TODO!\n");                          debug("cpu%i:  PPC601-style, TODO!\n");
516                  else {                  else {
# Line 518  void ppc_cpu_register_dump(struct cpu *c Line 520  void ppc_cpu_register_dump(struct cpu *c
520                                  uint32_t lower = cpu->cd.ppc.spr[spr+1];                                  uint32_t lower = cpu->cd.ppc.spr[spr+1];
521                                  uint32_t len = (((upper & BAT_BL) << 15)                                  uint32_t len = (((upper & BAT_BL) << 15)
522                                      | 0x1ffff) + 1;                                      | 0x1ffff) + 1;
523                                  debug("cpu%i:  %sbat%i: u=0x%08x l=0x%08x ",                                  debug("cpu%i:  %sbat%i: u=0x%08"PRIx32
524                                        " l=0x%08"PRIx32" ",
525                                      x, i<4? "i" : "d", i&3, upper, lower);                                      x, i<4? "i" : "d", i&3, upper, lower);
526                                  if (!(upper & BAT_V)) {                                  if (!(upper & BAT_V)) {
527                                          debug(" (not valid)\n");                                          debug(" (not valid)\n");
# Line 553  void ppc_cpu_register_dump(struct cpu *c Line 556  void ppc_cpu_register_dump(struct cpu *c
556          if (coprocs & 4) {          if (coprocs & 4) {
557                  for (i=0; i<16; i++) {                  for (i=0; i<16; i++) {
558                          uint32_t s = cpu->cd.ppc.sr[i];                          uint32_t s = cpu->cd.ppc.sr[i];
559    
560                          debug("cpu%i:", x);                          debug("cpu%i:", x);
561                          debug("  sr%-2i = 0x%08x", i, (int)s);                          debug("  sr%-2i = 0x%08"PRIx32, i, s);
562    
563                          s &= (SR_TYPE | SR_SUKEY | SR_PRKEY | SR_NOEXEC);                          s &= (SR_TYPE | SR_SUKEY | SR_PRKEY | SR_NOEXEC);
564                          if (s != 0) {                          if (s != 0) {
565                                  debug("  (");                                  debug("  (");
# Line 651  int ppc_cpu_disassemble_instr(struct cpu Line 656  int ppc_cpu_disassemble_instr(struct cpu
656                  debug("cpu%i: ", cpu->cpu_id);                  debug("cpu%i: ", cpu->cpu_id);
657    
658          if (cpu->cd.ppc.bits == 32)          if (cpu->cd.ppc.bits == 32)
659                  debug("%08x", (int)dumpaddr);                  debug("%08"PRIx32, (uint32_t) dumpaddr);
660          else          else
661                  debug("%016llx", (long long)dumpaddr);                  debug("%016"PRIx64, (uint64_t) dumpaddr);
662    
663          /*  NOTE: Fixed to big-endian.  */          /*  NOTE: Fixed to big-endian.  */
664          iword = (instr[0] << 24) + (instr[1] << 16) + (instr[2] << 8)          iword = (instr[0] << 24) + (instr[1] << 16) + (instr[2] << 8)
665              + instr[3];              + instr[3];
666    
667          debug(": %08x\t", iword);          debug(": %08"PRIx32"\t", iword);
668    
669          /*          /*
670           *  Decode the instruction:           *  Decode the instruction:
# Line 760  int ppc_cpu_disassemble_instr(struct cpu Line 765  int ppc_cpu_disassemble_instr(struct cpu
765                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
766                          addr &= 0xffffffff;                          addr &= 0xffffffff;
767                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
768                          debug("0x%x", (int)addr);                          debug("0x%"PRIx32, (uint32_t) addr);
769                  else                  else
770                          debug("0x%llx", (long long)addr);                          debug("0x%"PRIx64, (uint64_t) addr);
771                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
772                      addr, &offset);                      addr, &offset);
773                  if (symbol != NULL)                  if (symbol != NULL)
# Line 793  int ppc_cpu_disassemble_instr(struct cpu Line 798  int ppc_cpu_disassemble_instr(struct cpu
798                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
799                          addr &= 0xffffffff;                          addr &= 0xffffffff;
800                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
801                          debug("\t0x%x", (int)addr);                          debug("\t0x%"PRIx32, (uint32_t) addr);
802                  else                  else
803                          debug("\t0x%llx", (long long)addr);                          debug("\t0x%"PRIx64, (uint64_t) addr);
804                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
805                      addr, &offset);                      addr, &offset);
806                  if (symbol != NULL)                  if (symbol != NULL)
# Line 1084  int ppc_cpu_disassemble_instr(struct cpu Line 1089  int ppc_cpu_disassemble_instr(struct cpu
1089                          if (symbol != NULL)                          if (symbol != NULL)
1090                                  debug(" \t<%s", symbol);                                  debug(" \t<%s", symbol);
1091                          else                          else
1092                                  debug(" \t<0x%llx", (long long)addr);                                  debug(" \t<0x%"PRIx64, (uint64_t) addr);
1093                          if (wlen > 0 && !fpreg /* && !reverse */) {                          if (wlen > 0 && !fpreg /* && !reverse */) {
1094                                  /*  TODO  */                                  /*  TODO  */
1095                          }                          }
# Line 1255  int ppc_cpu_disassemble_instr(struct cpu Line 1260  int ppc_cpu_disassemble_instr(struct cpu
1260                              ppc_spr_names[spr]==NULL? "?" : ppc_spr_names[spr]);                              ppc_spr_names[spr]==NULL? "?" : ppc_spr_names[spr]);
1261                          if (running) {                          if (running) {
1262                                  if (cpu->cd.ppc.bits == 32)                                  if (cpu->cd.ppc.bits == 32)
1263                                          debug(": 0x%x", (int)                                          debug(": 0x%"PRIx32, (uint32_t)
1264                                              cpu->cd.ppc.spr[spr]);                                              cpu->cd.ppc.spr[spr]);
1265                                  else                                  else
1266                                          debug(": 0x%llx", (long long)                                          debug(": 0x%"PRIx64, (uint64_t)
1267                                              cpu->cd.ppc.spr[spr]);                                              cpu->cd.ppc.spr[spr]);
1268                          }                          }
1269                          debug(">");                          debug(">");
# Line 1415  int ppc_cpu_disassemble_instr(struct cpu Line 1420  int ppc_cpu_disassemble_instr(struct cpu
1420                              ppc_spr_names[spr]==NULL? "?" : ppc_spr_names[spr]);                              ppc_spr_names[spr]==NULL? "?" : ppc_spr_names[spr]);
1421                          if (running) {                          if (running) {
1422                                  if (cpu->cd.ppc.bits == 32)                                  if (cpu->cd.ppc.bits == 32)
1423                                          debug(": 0x%x", (int)                                          debug(": 0x%"PRIx32, (uint32_t)
1424                                              cpu->cd.ppc.gpr[rs]);                                              cpu->cd.ppc.gpr[rs]);
1425                                  else                                  else
1426                                          debug(": 0x%llx", (long long)                                          debug(": 0x%"PRIx64, (uint64_t)
1427                                              cpu->cd.ppc.gpr[rs]);                                              cpu->cd.ppc.gpr[rs]);
1428                          }                          }
1429                          debug(">");                          debug(">");
# Line 1571  int ppc_cpu_disassemble_instr(struct cpu Line 1576  int ppc_cpu_disassemble_instr(struct cpu
1576                  if (symbol != NULL)                  if (symbol != NULL)
1577                          debug(" \t<%s", symbol);                          debug(" \t<%s", symbol);
1578                  else                  else
1579                          debug(" \t<0x%llx", (long long)addr);                          debug(" \t<0x%"PRIx64, (uint64_t) addr);
1580                  if (wlen > 0 && load && wlen > 0) {                  if (wlen > 0 && load && wlen > 0) {
1581                          unsigned char tw[8];                          unsigned char tw[8];
1582                          uint64_t tdata = 0;                          uint64_t tdata = 0;
# Line 1595  int ppc_cpu_disassemble_instr(struct cpu Line 1600  int ppc_cpu_disassemble_instr(struct cpu
1600                                          if (symbol != NULL)                                          if (symbol != NULL)
1601                                                  debug("%s", symbol);                                                  debug("%s", symbol);
1602                                          else                                          else
1603                                                  debug("0x%llx",                                                  debug("0x%"PRIx64,
1604                                                      (long long)tdata);                                                      (uint64_t) tdata);
1605                                  } else {                                  } else {
1606                                          /*  TODO: if load==2, then this is                                          /*  TODO: if load==2, then this is
1607                                              a _signed_ load.  */                                              a _signed_ load.  */
1608                                          debug("0x%llx", (long long)tdata);                                          debug("0x%"PRIx64, (uint64_t) tdata);
1609                                  }                                  }
1610                          } else                          } else
1611                                  debug(": unreadable");                                  debug(": unreadable");
# Line 1618  int ppc_cpu_disassemble_instr(struct cpu Line 1623  int ppc_cpu_disassemble_instr(struct cpu
1623                                  if (symbol != NULL)                                  if (symbol != NULL)
1624                                          debug("%s", symbol);                                          debug("%s", symbol);
1625                                  else                                  else
1626                                          debug("0x%llx", (long long)tdata);                                          debug("0x%"PRIx64, (uint64_t) tdata);
1627                          } else {                          } else {
1628                                  if (tdata > -256 && tdata < 256)                                  if (tdata > -256 && tdata < 256)
1629                                          debug("%i", (int)tdata);                                          debug("%i", (int)tdata);
1630                                  else                                  else
1631                                          debug("0x%llx", (long long)tdata);                                          debug("0x%"PRIx64, (uint64_t) tdata);
1632                          }                          }
1633                  }                  }
1634                  debug(">");                  debug(">");
# Line 1815  static void debug_spr_usage(uint64_t pc, Line 1820  static void debug_spr_usage(uint64_t pc,
1820                          break;                          break;
1821                  } else                  } else
1822                          fatal("[ using UNIMPLEMENTED spr %i (%s), pc = "                          fatal("[ using UNIMPLEMENTED spr %i (%s), pc = "
1823                              "0x%llx ]\n", spr, ppc_spr_names[spr] == NULL?                              "0x%"PRIx64" ]\n", spr, ppc_spr_names[spr] == NULL?
1824                              "UNKNOWN" : ppc_spr_names[spr], (long long)pc);                              "UNKNOWN" : ppc_spr_names[spr], (uint64_t) pc);
1825          }          }
1826    
1827          spr_used[spr >> 2] |= (1 << (spr & 3));          spr_used[spr >> 2] |= (1 << (spr & 3));

Legend:
Removed from v.43  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.26