/[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 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2007  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:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu_ppc.c,v 1.45 2006/01/24 21:26:01 debug Exp $   *  $Id: cpu_ppc.c,v 1.67 2006/12/30 13:30:54 debug Exp $
29   *   *
30   *  PowerPC/POWER CPU emulation.   *  PowerPC/POWER CPU emulation.
31   */   */
# Line 37  Line 37 
37    
38  #include "cpu.h"  #include "cpu.h"
39  #include "devices.h"  #include "devices.h"
40    #include "interrupt.h"
41  #include "machine.h"  #include "machine.h"
42  #include "memory.h"  #include "memory.h"
43  #include "misc.h"  #include "misc.h"
# Line 46  Line 47 
47  #include "ppc_pte.h"  #include "ppc_pte.h"
48  #include "ppc_spr.h"  #include "ppc_spr.h"
49  #include "ppc_spr_strings.h"  #include "ppc_spr_strings.h"
50    #include "settings.h"
51  #include "symbol.h"  #include "symbol.h"
52    
53  #define DYNTRANS_DUALMODE_32  #define DYNTRANS_DUALMODE_32
# Line 55  Line 57 
57  void ppc_pc_to_pointers(struct cpu *);  void ppc_pc_to_pointers(struct cpu *);
58  void ppc32_pc_to_pointers(struct cpu *);  void ppc32_pc_to_pointers(struct cpu *);
59    
60    void ppc_irq_interrupt_assert(struct interrupt *interrupt);
61    void ppc_irq_interrupt_deassert(struct interrupt *interrupt);
62    
63    
64  /*  /*
65   *  ppc_cpu_new():   *  ppc_cpu_new():
# Line 86  int ppc_cpu_new(struct cpu *cpu, struct Line 91  int ppc_cpu_new(struct cpu *cpu, struct
91    
92          cpu->memory_rw = ppc_memory_rw;          cpu->memory_rw = ppc_memory_rw;
93    
94          cpu->cd.ppc.cpu_type    = cpu_type_defs[found];          cpu->cd.ppc.cpu_type = cpu_type_defs[found];
95          cpu->name               = cpu->cd.ppc.cpu_type.name;          cpu->name            = cpu->cd.ppc.cpu_type.name;
96          cpu->byte_order         = EMUL_BIG_ENDIAN;          cpu->byte_order      = EMUL_BIG_ENDIAN;
97          cpu->cd.ppc.mode        = MODE_PPC;     /*  TODO  */          cpu->cd.ppc.mode     = MODE_PPC;        /*  TODO  */
98    
99          /*  Current operating mode:  */          /*  Current operating mode:  */
100          cpu->cd.ppc.bits = cpu->cd.ppc.cpu_type.bits;          cpu->cd.ppc.bits = cpu->cd.ppc.cpu_type.bits;
101          cpu->cd.ppc.spr[SPR_PVR] = cpu->cd.ppc.cpu_type.pvr;          cpu->cd.ppc.spr[SPR_PVR] = cpu->cd.ppc.cpu_type.pvr;
102    
103            /*  cpu->cd.ppc.msr = PPC_MSR_IR | PPC_MSR_DR |
104                PPC_MSR_SF | PPC_MSR_FP;  */
105    
106          cpu->cd.ppc.spr[SPR_IBAT0U] = 0x00001ffc | BAT_Vs;          cpu->cd.ppc.spr[SPR_IBAT0U] = 0x00001ffc | BAT_Vs;
107          cpu->cd.ppc.spr[SPR_IBAT0L] = 0x00000000 | BAT_PP_RW;          cpu->cd.ppc.spr[SPR_IBAT0L] = 0x00000000 | BAT_PP_RW;
108          cpu->cd.ppc.spr[SPR_IBAT1U] = 0xc0001ffc | BAT_Vs;          cpu->cd.ppc.spr[SPR_IBAT1U] = 0xc0001ffc | BAT_Vs;
# Line 113  int ppc_cpu_new(struct cpu *cpu, struct Line 121  int ppc_cpu_new(struct cpu *cpu, struct
121          cpu->is_32bit = (cpu->cd.ppc.bits == 32)? 1 : 0;          cpu->is_32bit = (cpu->cd.ppc.bits == 32)? 1 : 0;
122    
123          if (cpu->is_32bit) {          if (cpu->is_32bit) {
124                    cpu->run_instr = ppc32_run_instr;
125                  cpu->update_translation_table = ppc32_update_translation_table;                  cpu->update_translation_table = ppc32_update_translation_table;
126                  cpu->invalidate_translation_caches =                  cpu->invalidate_translation_caches =
127                      ppc32_invalidate_translation_caches;                      ppc32_invalidate_translation_caches;
128                  cpu->invalidate_code_translation =                  cpu->invalidate_code_translation =
129                      ppc32_invalidate_code_translation;                      ppc32_invalidate_code_translation;
130          } else {          } else {
131                    cpu->run_instr = ppc_run_instr;
132                  cpu->update_translation_table = ppc_update_translation_table;                  cpu->update_translation_table = ppc_update_translation_table;
133                  cpu->invalidate_translation_caches =                  cpu->invalidate_translation_caches =
134                      ppc_invalidate_translation_caches;                      ppc_invalidate_translation_caches;
# Line 126  int ppc_cpu_new(struct cpu *cpu, struct Line 136  int ppc_cpu_new(struct cpu *cpu, struct
136                      ppc_invalidate_code_translation;                      ppc_invalidate_code_translation;
137          }          }
138    
139          cpu->translate_address = ppc_translate_address;          cpu->translate_v2p = ppc_translate_v2p;
140    
141          /*  Only show name and caches etc for CPU nr 0 (in SMP machines):  */          /*  Only show name and caches etc for CPU nr 0 (in SMP machines):  */
142          if (cpu_id == 0) {          if (cpu_id == 0) {
# Line 163  int ppc_cpu_new(struct cpu *cpu, struct Line 173  int ppc_cpu_new(struct cpu *cpu, struct
173          if (cpu->machine->prom_emulation)          if (cpu->machine->prom_emulation)
174                  cpu->cd.ppc.of_emul_addr = 0xfff00000;                  cpu->cd.ppc.of_emul_addr = 0xfff00000;
175    
176            /*  Add all register names to the settings:  */
177            CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc);
178            CPU_SETTINGS_ADD_REGISTER64("msr", cpu->cd.ppc.msr);
179            CPU_SETTINGS_ADD_REGISTER64("ctr", cpu->cd.ppc.spr[SPR_CTR]);
180            CPU_SETTINGS_ADD_REGISTER64("xer", cpu->cd.ppc.spr[SPR_XER]);
181            CPU_SETTINGS_ADD_REGISTER64("dec", cpu->cd.ppc.spr[SPR_DEC]);
182            CPU_SETTINGS_ADD_REGISTER64("hdec", cpu->cd.ppc.spr[SPR_HDEC]);
183            CPU_SETTINGS_ADD_REGISTER64("srr0", cpu->cd.ppc.spr[SPR_SRR0]);
184            CPU_SETTINGS_ADD_REGISTER64("srr1", cpu->cd.ppc.spr[SPR_SRR1]);
185            CPU_SETTINGS_ADD_REGISTER64("sdr1", cpu->cd.ppc.spr[SPR_SDR1]);
186            CPU_SETTINGS_ADD_REGISTER64("ibat0u", cpu->cd.ppc.spr[SPR_IBAT0U]);
187            CPU_SETTINGS_ADD_REGISTER64("ibat0l", cpu->cd.ppc.spr[SPR_IBAT0L]);
188            CPU_SETTINGS_ADD_REGISTER64("ibat1u", cpu->cd.ppc.spr[SPR_IBAT1U]);
189            CPU_SETTINGS_ADD_REGISTER64("ibat1l", cpu->cd.ppc.spr[SPR_IBAT1L]);
190            CPU_SETTINGS_ADD_REGISTER64("ibat2u", cpu->cd.ppc.spr[SPR_IBAT2U]);
191            CPU_SETTINGS_ADD_REGISTER64("ibat2l", cpu->cd.ppc.spr[SPR_IBAT2L]);
192            CPU_SETTINGS_ADD_REGISTER64("ibat3u", cpu->cd.ppc.spr[SPR_IBAT3U]);
193            CPU_SETTINGS_ADD_REGISTER64("ibat3l", cpu->cd.ppc.spr[SPR_IBAT3L]);
194            CPU_SETTINGS_ADD_REGISTER64("dbat0u", cpu->cd.ppc.spr[SPR_DBAT0U]);
195            CPU_SETTINGS_ADD_REGISTER64("dbat0l", cpu->cd.ppc.spr[SPR_DBAT0L]);
196            CPU_SETTINGS_ADD_REGISTER64("dbat1u", cpu->cd.ppc.spr[SPR_DBAT1U]);
197            CPU_SETTINGS_ADD_REGISTER64("dbat1l", cpu->cd.ppc.spr[SPR_DBAT1L]);
198            CPU_SETTINGS_ADD_REGISTER64("dbat2u", cpu->cd.ppc.spr[SPR_DBAT2U]);
199            CPU_SETTINGS_ADD_REGISTER64("dbat2l", cpu->cd.ppc.spr[SPR_DBAT2L]);
200            CPU_SETTINGS_ADD_REGISTER64("dbat3u", cpu->cd.ppc.spr[SPR_DBAT3U]);
201            CPU_SETTINGS_ADD_REGISTER64("dbat3l", cpu->cd.ppc.spr[SPR_DBAT3L]);
202            CPU_SETTINGS_ADD_REGISTER64("lr", cpu->cd.ppc.spr[SPR_LR]);
203            CPU_SETTINGS_ADD_REGISTER32("cr", cpu->cd.ppc.cr);
204            CPU_SETTINGS_ADD_REGISTER32("fpscr", cpu->cd.ppc.fpscr);
205            /*  Integer GPRs, floating point registers, and segment registers:  */
206            for (i=0; i<PPC_NGPRS; i++) {
207                    char tmpstr[5];
208                    snprintf(tmpstr, sizeof(tmpstr), "r%i", i);
209                    CPU_SETTINGS_ADD_REGISTER64(tmpstr, cpu->cd.ppc.gpr[i]);
210            }
211            for (i=0; i<PPC_NFPRS; i++) {
212                    char tmpstr[5];
213                    snprintf(tmpstr, sizeof(tmpstr), "f%i", i);
214                    CPU_SETTINGS_ADD_REGISTER64(tmpstr, cpu->cd.ppc.fpr[i]);
215            }
216            for (i=0; i<16; i++) {
217                    char tmpstr[5];
218                    snprintf(tmpstr, sizeof(tmpstr), "sr%i", i);
219                    CPU_SETTINGS_ADD_REGISTER32(tmpstr, cpu->cd.ppc.sr[i]);
220            }
221    
222            /*  Register the CPU as an interrupt handler:  */
223            {
224                    struct interrupt template;
225                    char name[150];
226                    snprintf(name, sizeof(name), "%s", cpu->path);
227                    memset(&template, 0, sizeof(template));
228                    template.line = 0;
229                    template.name = name;
230                    template.extra = cpu;
231                    template.interrupt_assert = ppc_irq_interrupt_assert;
232                    template.interrupt_deassert = ppc_irq_interrupt_deassert;
233                    interrupt_handler_register(&template);
234            }
235    
236          return 1;          return 1;
237  }  }
238    
# Line 267  void reg_access_msr(struct cpu *cpu, uin Line 337  void reg_access_msr(struct cpu *cpu, uin
337                  *valuep = cpu->cd.ppc.msr;                  *valuep = cpu->cd.ppc.msr;
338    
339          if (check_for_interrupts && cpu->cd.ppc.msr & PPC_MSR_EE) {          if (check_for_interrupts && cpu->cd.ppc.msr & PPC_MSR_EE) {
340                  if (cpu->cd.ppc.dec_intr_pending) {                  if (cpu->cd.ppc.dec_intr_pending &&
341                        !(cpu->cd.ppc.cpu_type.flags & PPC_NO_DEC)) {
342                          ppc_exception(cpu, PPC_EXCEPTION_DEC);                          ppc_exception(cpu, PPC_EXCEPTION_DEC);
343                          cpu->cd.ppc.dec_intr_pending = 0;                          cpu->cd.ppc.dec_intr_pending = 0;
344                  } else if (cpu->cd.ppc.irq_asserted)                  } else if (cpu->cd.ppc.irq_asserted)
# Line 291  void ppc_exception(struct cpu *cpu, int Line 362  void ppc_exception(struct cpu *cpu, int
362                  cpu->cd.ppc.spr[SPR_SRR1] = (cpu->cd.ppc.msr & 0x87c0ffff);                  cpu->cd.ppc.spr[SPR_SRR1] = (cpu->cd.ppc.msr & 0x87c0ffff);
363    
364          if (!quiet_mode)          if (!quiet_mode)
365                  fatal("[ PPC Exception 0x%x; pc=0x%llx ]\n", exception_nr,                  fatal("[ PPC Exception 0x%x; pc=0x%"PRIx64" ]\n", exception_nr,
366                      (long long)cpu->pc);                      (long long)cpu->pc);
367    
368          /*  Disable External Interrupts, Recoverable Interrupt Mode,          /*  Disable External Interrupts, Recoverable Interrupt Mode,
# Line 331  void ppc_cpu_register_dump(struct cpu *c Line 402  void ppc_cpu_register_dump(struct cpu *c
402    
403                  debug("cpu%i: pc  = 0x", x);                  debug("cpu%i: pc  = 0x", x);
404                  if (bits32)                  if (bits32)
405                          debug("%08x", (int)cpu->pc);                          debug("%08"PRIx32, (uint32_t)cpu->pc);
406                  else                  else
407                          debug("%016llx", (long long)cpu->pc);                          debug("%016"PRIx64, (uint64_t)cpu->pc);
408                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
409    
410                  debug("cpu%i: lr  = 0x", x);                  debug("cpu%i: lr  = 0x", x);
411                  if (bits32)                  if (bits32)
412                          debug("%08x", (int)cpu->cd.ppc.spr[SPR_LR]);                          debug("%08"PRIx32, (uint32_t)cpu->cd.ppc.spr[SPR_LR]);
413                  else                  else
414                          debug("%016llx", (long long)cpu->cd.ppc.spr[SPR_LR]);                          debug("%016"PRIx64, (uint64_t)cpu->cd.ppc.spr[SPR_LR]);
415                  debug("  cr  = 0x%08x", (int)cpu->cd.ppc.cr);                  debug("  cr  = 0x%08"PRIx32, (uint32_t)cpu->cd.ppc.cr);
416    
417                  if (bits32)                  if (bits32)
418                          debug("  ");                          debug("  ");
# Line 349  void ppc_cpu_register_dump(struct cpu *c Line 420  void ppc_cpu_register_dump(struct cpu *c
420                          debug("\ncpu%i: ", x);                          debug("\ncpu%i: ", x);
421                  debug("ctr = 0x", x);                  debug("ctr = 0x", x);
422                  if (bits32)                  if (bits32)
423                          debug("%08x", (int)cpu->cd.ppc.spr[SPR_CTR]);                          debug("%08"PRIx32, (uint32_t)cpu->cd.ppc.spr[SPR_CTR]);
424                  else                  else
425                          debug("%016llx", (long long)cpu->cd.ppc.spr[SPR_CTR]);                          debug("%016"PRIx64, (uint64_t)cpu->cd.ppc.spr[SPR_CTR]);
426    
427                  debug("  xer = 0x", x);                  debug("  xer = 0x", x);
428                  if (bits32)                  if (bits32)
429                          debug("%08x\n", (int)cpu->cd.ppc.spr[SPR_XER]);                          debug("%08"PRIx32, (uint32_t)cpu->cd.ppc.spr[SPR_XER]);
430                  else                  else
431                          debug("%016llx\n", (long long)cpu->cd.ppc.spr[SPR_XER]);                          debug("%016"PRIx64, (uint64_t)cpu->cd.ppc.spr[SPR_XER]);
432    
433                    debug("\n");
434    
435                  if (bits32) {                  if (bits32) {
436                          /*  32-bit:  */                          /*  32-bit:  */
# Line 472  void ppc_cpu_register_dump(struct cpu *c Line 545  void ppc_cpu_register_dump(struct cpu *c
545                  for (i=0; i<16; i++) {                  for (i=0; i<16; i++) {
546                          uint32_t s = cpu->cd.ppc.sr[i];                          uint32_t s = cpu->cd.ppc.sr[i];
547                          debug("cpu%i:", x);                          debug("cpu%i:", x);
548                          debug("  sr%2i = 0x%08x", i, (int)s);                          debug("  sr%-2i = 0x%08x", i, (int)s);
549                          s &= (SR_TYPE | SR_SUKEY | SR_PRKEY | SR_NOEXEC);                          s &= (SR_TYPE | SR_SUKEY | SR_PRKEY | SR_NOEXEC);
550                          if (s != 0) {                          if (s != 0) {
551                                  debug("  (");                                  debug("  (");
# Line 505  void ppc_cpu_register_dump(struct cpu *c Line 578  void ppc_cpu_register_dump(struct cpu *c
578    
579    
580  /*  /*
581   *  ppc_cpu_register_match():   *  ppc_cpu_tlbdump():
582     *
583     *  Not currently used for PPC.
584   */   */
585  void ppc_cpu_register_match(struct machine *m, char *name,  void ppc_cpu_tlbdump(struct machine *m, int x, int rawflag)
         int writeflag, uint64_t *valuep, int *match_register)  
586  {  {
587          int cpunr = 0;  }
   
         /*  CPU number:  */  
588    
         /*  TODO  */  
589    
590          /*  Register name:  */  static void add_response_word(struct cpu *cpu, char *r, uint64_t value,
591          if (strcasecmp(name, "pc") == 0) {          size_t maxlen, int len)
592                  if (writeflag) {  {
593                          m->cpus[cpunr]->pc = *valuep;          char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64;
594                  } else          if (len == 4)
595                          *valuep = m->cpus[cpunr]->pc;                  value &= 0xffffffffULL;
596                  *match_register = 1;          if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
597          } else if (strcasecmp(name, "msr") == 0) {                  if (len == 4) {
598                  if (writeflag)                          value = ((value & 0xff) << 24) +
599                          m->cpus[cpunr]->cd.ppc.msr = *valuep;                                  ((value & 0xff00) << 8) +
600                  else                                  ((value & 0xff0000) >> 8) +
601                          *valuep = m->cpus[cpunr]->cd.ppc.msr;                                  ((value & 0xff000000) >> 24);
602                  *match_register = 1;                  } else {
603          } else if (strcasecmp(name, "lr") == 0) {                          value = ((value & 0xff) << 56) +
604                  if (writeflag)                                  ((value & 0xff00) << 40) +
605                          m->cpus[cpunr]->cd.ppc.spr[SPR_LR] = *valuep;                                  ((value & 0xff0000) << 24) +
606                  else                                  ((value & 0xff000000ULL) << 8) +
607                          *valuep = m->cpus[cpunr]->cd.ppc.spr[SPR_LR];                                  ((value & 0xff00000000ULL) >> 8) +
608                  *match_register = 1;                                  ((value & 0xff0000000000ULL) >> 24) +
609          } else if (strcasecmp(name, "cr") == 0) {                                  ((value & 0xff000000000000ULL) >> 40) +
610                  if (writeflag)                                  ((value & 0xff00000000000000ULL) >> 56);
                         m->cpus[cpunr]->cd.ppc.cr = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.cr;  
                 *match_register = 1;  
         } else if (strcasecmp(name, "dec") == 0) {  
                 if (writeflag)  
                         m->cpus[cpunr]->cd.ppc.spr[SPR_DEC] = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.spr[SPR_DEC];  
                 *match_register = 1;  
         } else if (strcasecmp(name, "hdec") == 0) {  
                 if (writeflag)  
                         m->cpus[cpunr]->cd.ppc.spr[SPR_HDEC] = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.spr[SPR_HDEC];  
                 *match_register = 1;  
         } else if (strcasecmp(name, "ctr") == 0) {  
                 if (writeflag)  
                         m->cpus[cpunr]->cd.ppc.spr[SPR_CTR] = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.spr[SPR_CTR];  
                 *match_register = 1;  
         } else if (name[0] == 'r' && isdigit((int)name[1])) {  
                 int nr = atoi(name + 1);  
                 if (nr >= 0 && nr < PPC_NGPRS) {  
                         if (writeflag) {  
                                 m->cpus[cpunr]->cd.ppc.gpr[nr] = *valuep;  
                         } else  
                                 *valuep = m->cpus[cpunr]->cd.ppc.gpr[nr];  
                         *match_register = 1;  
                 }  
         } else if (strcasecmp(name, "xer") == 0) {  
                 if (writeflag)  
                         m->cpus[cpunr]->cd.ppc.spr[SPR_XER] = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.spr[SPR_XER];  
                 *match_register = 1;  
         } else if (strcasecmp(name, "fpscr") == 0) {  
                 if (writeflag)  
                         m->cpus[cpunr]->cd.ppc.fpscr = *valuep;  
                 else  
                         *valuep = m->cpus[cpunr]->cd.ppc.fpscr;  
                 *match_register = 1;  
         } else if (name[0] == 'f' && isdigit((int)name[1])) {  
                 int nr = atoi(name + 1);  
                 if (nr >= 0 && nr < PPC_NFPRS) {  
                         if (writeflag) {  
                                 m->cpus[cpunr]->cd.ppc.fpr[nr] = *valuep;  
                         } else  
                                 *valuep = m->cpus[cpunr]->cd.ppc.fpr[nr];  
                         *match_register = 1;  
611                  }                  }
612          }          }
613            snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value);
614  }  }
615    
616    
617  /*  /*
618   *  ppc_cpu_interrupt():   *  ppc_cpu_gdb_stub():
  *  
  *  0..31 are used as BeBox interrupt numbers, 32..47 = ISA,  
  *  64 is used as a "re-assert" signal to cpu->machine->md_interrupt().  
619   *   *
620   *  TODO: don't hardcode to BeBox!   *  Execute a "remote GDB" command. Returns a newly allocated response string
621     *  on success, NULL on failure.
622   */   */
623  int ppc_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  char *ppc_cpu_gdb_stub(struct cpu *cpu, char *cmd)
624  {  {
625          /*  fatal("ppc_cpu_interrupt(): 0x%x\n", (int)irq_nr);  */          if (strcmp(cmd, "g") == 0) {
626          if (irq_nr <= 64) {                  int i;
627                  if (cpu->machine->md_interrupt != NULL)                  char *r;
628                          cpu->machine->md_interrupt(                  size_t wlen = cpu->is_32bit?
629                              cpu->machine, cpu, irq_nr, 1);                      sizeof(uint32_t) : sizeof(uint64_t);
630                  else                  size_t len = 1 + 76 * wlen;
631                          fatal("ppc_cpu_interrupt(): md_interrupt == NULL\n");                  r = malloc(len);
632          } else {                  if (r == NULL) {
633                  /*  Assert PPC IRQ:  */                          fprintf(stderr, "out of memory\n");
634                  cpu->cd.ppc.irq_asserted = 1;                          exit(1);
635                    }
636                    r[0] = '\0';
637                    for (i=0; i<128; i++)
638                            add_response_word(cpu, r, i, len, wlen);
639                    return r;
640          }          }
641          return 1;  
642            if (cmd[0] == 'p') {
643                    int regnr = strtol(cmd + 1, NULL, 16);
644                    size_t wlen = cpu->is_32bit?
645                        sizeof(uint32_t) : sizeof(uint64_t);
646                    size_t len = 2 * wlen + 1;
647                    char *r = malloc(len);
648                    r[0] = '\0';
649                    if (regnr >= 0 && regnr <= 31) {
650                            add_response_word(cpu, r,
651                                cpu->cd.ppc.gpr[regnr], len, wlen);
652                    } else if (regnr == 0x40) {
653                            add_response_word(cpu, r, cpu->pc, len, wlen);
654                    } else if (regnr == 0x42) {
655                            add_response_word(cpu, r, cpu->cd.ppc.cr, len, wlen);
656                    } else if (regnr == 0x43) {
657                            add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_LR],
658                                len, wlen);
659                    } else if (regnr == 0x44) {
660                            add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_CTR],
661                                len, wlen);
662                    } else if (regnr == 0x45) {
663                            add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_XER],
664                                len, wlen);
665                    } else {
666                            /*  Unimplemented:  */
667                            add_response_word(cpu, r, 0xcc000 + regnr, len, wlen);
668                    }
669                    return r;
670            }
671    
672            fatal("ppc_cpu_gdb_stub(): TODO\n");
673            return NULL;
674  }  }
675    
676    
677  /*  /*
678   *  ppc_cpu_interrupt_ack():   *  ppc_irq_interrupt_assert():
679   */   */
680  int ppc_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr)  void ppc_irq_interrupt_assert(struct interrupt *interrupt)
681  {  {
682          if (irq_nr <= 64) {          struct cpu *cpu = (struct cpu *) interrupt->extra;
683                  if (cpu->machine->md_interrupt != NULL)          cpu->cd.ppc.irq_asserted = 1;
684                          cpu->machine->md_interrupt(cpu->machine,  }
685                              cpu, irq_nr, 0);  
686          } else {  
687                  /*  De-assert PPC IRQ:  */  /*
688                  cpu->cd.ppc.irq_asserted = 0;   *  ppc_irq_interrupt_deassert():
689          }   */
690          return 1;  void ppc_irq_interrupt_deassert(struct interrupt *interrupt)
691    {
692            struct cpu *cpu = (struct cpu *) interrupt->extra;
693            cpu->cd.ppc.irq_asserted = 0;
694  }  }
695    
696    
# Line 648  int ppc_cpu_interrupt_ack(struct cpu *cp Line 707  int ppc_cpu_interrupt_ack(struct cpu *cp
707   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
708   */   */
709  int ppc_cpu_disassemble_instr(struct cpu *cpu, unsigned char *instr,  int ppc_cpu_disassemble_instr(struct cpu *cpu, unsigned char *instr,
710          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
711  {  {
712          int hi6, xo, lev, rt, rs, ra, rb, imm, sh, me, rc, l_bit, oe_bit;          int hi6, xo, lev, rt, rs, ra, rb, imm, sh, me, rc, l_bit, oe_bit;
713          int spr, aa_bit, lk_bit, bf, bh, bi, bo, mb, nb, bt, ba, bb, fpreg;          int spr, aa_bit, lk_bit, bf, bh, bi, bo, mb, nb, bt, ba, bb, fpreg;
# Line 942  int ppc_cpu_disassemble_instr(struct cpu Line 1001  int ppc_cpu_disassemble_instr(struct cpu
1001          case PPC_HI6_30:          case PPC_HI6_30:
1002                  xo = (iword >> 2) & 7;                  xo = (iword >> 2) & 7;
1003                  switch (xo) {                  switch (xo) {
1004                    case PPC_30_RLDICL:
1005                  case PPC_30_RLDICR:                  case PPC_30_RLDICR:
1006                    case PPC_30_RLDIMI:     /*  mb, not me  */
1007                            mnem = NULL;
1008                            switch (xo) {
1009                            case PPC_30_RLDICL: mnem = "rldicl"; break;
1010                            case PPC_30_RLDICR: mnem = "rldicr"; break;
1011                            case PPC_30_RLDIMI: mnem = "rldimi"; break;
1012                            }
1013                          rs = (iword >> 21) & 31;                          rs = (iword >> 21) & 31;
1014                          ra = (iword >> 16) & 31;                          ra = (iword >> 16) & 31;
1015                          sh = ((iword >> 11) & 31) | ((iword & 2) << 4);                          sh = ((iword >> 11) & 31) | ((iword & 2) << 4);
1016                          me = ((iword >> 6) & 31) | (iword & 0x20);                          me = ((iword >> 6) & 31) | (iword & 0x20);
1017                          rc = iword & 1;                          rc = iword & 1;
1018                          debug("rldicr%s\tr%i,r%i,%i,%i",                          debug("%s%s\tr%i,r%i,%i,%i",
1019                              rc?".":"", ra, rs, sh, me);                              mnem, rc?".":"", ra, rs, sh, me);
1020                          break;                          break;
1021                  default:                  default:
1022                          debug("unimplemented hi6_30, xo = 0x%x", xo);                          debug("unimplemented hi6_30, xo = 0x%x", xo);
# Line 1116  int ppc_cpu_disassemble_instr(struct cpu Line 1183  int ppc_cpu_disassemble_instr(struct cpu
1183                  case PPC_31_WRTEEI:                  case PPC_31_WRTEEI:
1184                          debug("wrteei\t%i", iword & 0x8000? 1 : 0);                          debug("wrteei\t%i", iword & 0x8000? 1 : 0);
1185                          break;                          break;
1186                    case PPC_31_MTMSRD:
1187                            /*  TODO: Just a guess based on MTMSR  */
1188                            rs = (iword >> 21) & 31;
1189                            l_bit = (iword >> 16) & 1;
1190                            debug("mtmsrd\tr%i", rs);
1191                            if (l_bit)
1192                                    debug(",%i", l_bit);
1193                            break;
1194                  case PPC_31_ADDZE:                  case PPC_31_ADDZE:
1195                  case PPC_31_ADDZEO:                  case PPC_31_ADDZEO:
1196                          rt = (iword >> 21) & 31;                          rt = (iword >> 21) & 31;
# Line 1336  int ppc_cpu_disassemble_instr(struct cpu Line 1411  int ppc_cpu_disassemble_instr(struct cpu
1411                          debug("%s\tr%i,r%i", mnem, ra, rb);                          debug("%s\tr%i,r%i", mnem, ra, rb);
1412                          break;                          break;
1413                  case PPC_31_SLW:                  case PPC_31_SLW:
1414                    case PPC_31_SLD:
1415                  case PPC_31_SRAW:                  case PPC_31_SRAW:
1416                  case PPC_31_SRW:                  case PPC_31_SRW:
1417                  case PPC_31_AND:                  case PPC_31_AND:
1418                  case PPC_31_ANDC:                  case PPC_31_ANDC:
1419                  case PPC_31_NOR:                  case PPC_31_NOR:
1420                    case PPC_31_EQV:
1421                  case PPC_31_OR:                  case PPC_31_OR:
1422                  case PPC_31_ORC:                  case PPC_31_ORC:
1423                  case PPC_31_XOR:                  case PPC_31_XOR:
# Line 1355  int ppc_cpu_disassemble_instr(struct cpu Line 1432  int ppc_cpu_disassemble_instr(struct cpu
1432                                  switch (xo) {                                  switch (xo) {
1433                                  case PPC_31_SLW:  mnem =                                  case PPC_31_SLW:  mnem =
1434                                          power? "sl" : "slw"; break;                                          power? "sl" : "slw"; break;
1435                                    case PPC_31_SLD:  mnem = "sld"; break;
1436                                  case PPC_31_SRAW:  mnem =                                  case PPC_31_SRAW:  mnem =
1437                                          power? "sra" : "sraw"; break;                                          power? "sra" : "sraw"; break;
1438                                  case PPC_31_SRW:  mnem =                                  case PPC_31_SRW:  mnem =
# Line 1363  int ppc_cpu_disassemble_instr(struct cpu Line 1441  int ppc_cpu_disassemble_instr(struct cpu
1441                                  case PPC_31_NAND: mnem = "nand"; break;                                  case PPC_31_NAND: mnem = "nand"; break;
1442                                  case PPC_31_ANDC: mnem = "andc"; break;                                  case PPC_31_ANDC: mnem = "andc"; break;
1443                                  case PPC_31_NOR:  mnem = "nor"; break;                                  case PPC_31_NOR:  mnem = "nor"; break;
1444                                    case PPC_31_EQV:  mnem = "eqv"; break;
1445                                  case PPC_31_OR:   mnem = "or"; break;                                  case PPC_31_OR:   mnem = "or"; break;
1446                                  case PPC_31_ORC:  mnem = "orc"; break;                                  case PPC_31_ORC:  mnem = "orc"; break;
1447                                  case PPC_31_XOR:  mnem = "xor"; break;                                  case PPC_31_XOR:  mnem = "xor"; break;
# Line 1447  int ppc_cpu_disassemble_instr(struct cpu Line 1526  int ppc_cpu_disassemble_instr(struct cpu
1526                          debug("%s%s\tr%i,r%i,%i", mnem,                          debug("%s%s\tr%i,r%i,%i", mnem,
1527                              rc? "." : "", ra, rs, sh);                              rc? "." : "", ra, rs, sh);
1528                          break;                          break;
1529                    case PPC_31_DSSALL:
1530                            debug("dssall");
1531                            break;
1532                  case PPC_31_EIEIO:                  case PPC_31_EIEIO:
1533                          debug("%s", power? "eieio?" : "eieio");                          debug("%s", power? "eieio?" : "eieio");
1534                          break;                          break;
# Line 1469  int ppc_cpu_disassemble_instr(struct cpu Line 1551  int ppc_cpu_disassemble_instr(struct cpu
1551                          }                          }
1552                          debug("%s%s\tr%i,r%i", mnem, rc? "." : "", ra, rs);                          debug("%s%s\tr%i,r%i", mnem, rc? "." : "", ra, rs);
1553                          break;                          break;
                 case 359:  
                         debug("TODO: ALTIVEC 359");  
                         break;  
1554                  case PPC_31_LVX:                  case PPC_31_LVX:
1555                          debug("lvx\tTODO: ALTIVEC");                  case PPC_31_LVXL:
                         break;  
1556                  case PPC_31_STVX:                  case PPC_31_STVX:
                         debug("stvx\tTODO: ALTIVEC");  
                         break;  
1557                  case PPC_31_STVXL:                  case PPC_31_STVXL:
1558                          debug("stvxl\tTODO: ALTIVEC");                          rs = (iword >> 21) & 31;        /*  vs for stores,  */
1559                            ra = (iword >> 16) & 31;        /*  rs=vl for loads  */
1560                            rb = (iword >> 11) & 31;
1561                            rc = iword & 1;
1562                            switch (xo) {
1563                            case PPC_31_LVX:   mnem = "lvx";  break;
1564                            case PPC_31_LVXL:  mnem = "lvxl"; break;
1565                            case PPC_31_STVX:  mnem = "stvx";  break;
1566                            case PPC_31_STVXL: mnem = "stvxl"; break;
1567                            }
1568                            debug("%s%s\tv%i,r%i,r%i", mnem, rc? "." : "",
1569                                rs, ra, rb);
1570                          break;                          break;
1571                  default:                  default:
1572                          debug("unimplemented hi6_31, xo = 0x%x", xo);                          debug("unimplemented hi6_31, xo = 0x%x", xo);
# Line 1852  void update_cr0(struct cpu *cpu, uint64_ Line 1939  void update_cr0(struct cpu *cpu, uint64_
1939    
1940  #include "tmp_ppc_tail.c"  #include "tmp_ppc_tail.c"
1941    
1942    

Legend:
Removed from v.22  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26