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

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

revision 16 by dpavlin, Mon Oct 8 16:19:01 2007 UTC revision 32 by dpavlin, Mon Oct 8 16:20:58 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2006  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_arm.c,v 1.29 2005/10/08 01:09:51 debug Exp $   *  $Id: cpu_arm.c,v 1.64 2006/09/09 09:04:32 debug Exp $
29   *   *
30   *  ARM CPU emulation.   *  ARM CPU emulation.
31   *   *
32     *
33   *  A good source of quick info on ARM instruction encoding:   *  A good source of quick info on ARM instruction encoding:
34   *   *
35   *      http://www.pinknoise.demon.co.uk/ARMinstrs/ARMinstrs.html   *      http://www.pinknoise.demon.co.uk/ARMinstrs/ARMinstrs.html
  *  
  *  (Most "xxxx0101..." and similar strings in this file are from that URL,  
  *  or from the ARM manual.)  
36   */   */
37    
38  #include <stdio.h>  #include <stdio.h>
# Line 47  Line 45 
45  #include "machine.h"  #include "machine.h"
46  #include "memory.h"  #include "memory.h"
47  #include "misc.h"  #include "misc.h"
48    #include "of.h"
49    #include "settings.h"
50  #include "symbol.h"  #include "symbol.h"
51    
52  #define DYNTRANS_32  #define DYNTRANS_32
# Line 62  static char *arm_dpiname[16] = ARM_DPI_N Line 62  static char *arm_dpiname[16] = ARM_DPI_N
62  static int arm_dpi_uses_d[16] = { 1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1 };  static int arm_dpi_uses_d[16] = { 1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1 };
63  static int arm_dpi_uses_n[16] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0 };  static int arm_dpi_uses_n[16] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0 };
64    
65  /*  Forward reference:  */  static int arm_exception_to_mode[N_ARM_EXCEPTIONS] = ARM_EXCEPTION_TO_MODE;
66    
67    /*  For quick_pc_to_pointers():  */
68  void arm_pc_to_pointers(struct cpu *cpu);  void arm_pc_to_pointers(struct cpu *cpu);
69    #include "quick_pc_to_pointers.h"
70    
71    
72  /*  /*
# Line 75  void arm_pc_to_pointers(struct cpu *cpu) Line 78  void arm_pc_to_pointers(struct cpu *cpu)
78  int arm_cpu_new(struct cpu *cpu, struct memory *mem,  int arm_cpu_new(struct cpu *cpu, struct memory *mem,
79          struct machine *machine, int cpu_id, char *cpu_type_name)          struct machine *machine, int cpu_id, char *cpu_type_name)
80  {  {
81          int any_cache = 0, i, found;          int i, found;
82          struct arm_cpu_type_def cpu_type_defs[] = ARM_CPU_TYPE_DEFS;          struct arm_cpu_type_def cpu_type_defs[] = ARM_CPU_TYPE_DEFS;
83    
84          /*  Scan the list for this cpu type:  */          /*  Scan the list for this cpu type:  */
# Line 90  int arm_cpu_new(struct cpu *cpu, struct Line 93  int arm_cpu_new(struct cpu *cpu, struct
93          if (found == -1)          if (found == -1)
94                  return 0;                  return 0;
95    
96            cpu->run_instr = arm_run_instr;
97          cpu->memory_rw = arm_memory_rw;          cpu->memory_rw = arm_memory_rw;
98          cpu->update_translation_table = arm_update_translation_table;          cpu->update_translation_table = arm_update_translation_table;
99          cpu->invalidate_translation_caches_paddr =          cpu->invalidate_translation_caches =
100              arm_invalidate_translation_caches_paddr;              arm_invalidate_translation_caches;
101          cpu->invalidate_code_translation = arm_invalidate_code_translation;          cpu->invalidate_code_translation = arm_invalidate_code_translation;
102          cpu->translate_address = arm_translate_address;          cpu->translate_v2p = arm_translate_v2p;
103    
104          cpu->cd.arm.cpu_type    = cpu_type_defs[found];          cpu->cd.arm.cpu_type = cpu_type_defs[found];
105          cpu->name               = cpu->cd.arm.cpu_type.name;          cpu->name            = cpu->cd.arm.cpu_type.name;
106          cpu->is_32bit           = 1;          cpu->is_32bit        = 1;
107            cpu->byte_order      = EMUL_LITTLE_ENDIAN;
108    
109          cpu->cd.arm.cpsr = ARM_FLAG_I | ARM_FLAG_F;          cpu->cd.arm.cpsr = ARM_FLAG_I | ARM_FLAG_F;
110          cpu->cd.arm.control = ARM_CONTROL_PROG32 | ARM_CONTROL_DATA32          cpu->cd.arm.control = ARM_CONTROL_PROG32 | ARM_CONTROL_DATA32
111              | ARM_CONTROL_CACHE | ARM_CONTROL_ICACHE | ARM_CONTROL_ALIGN;              | ARM_CONTROL_CACHE | ARM_CONTROL_ICACHE | ARM_CONTROL_ALIGN;
112            /*  TODO: default auxctrl contents  */
113    
114          if (cpu->machine->prom_emulation) {          if (cpu->machine->prom_emulation) {
115                  cpu->cd.arm.cpsr |= ARM_MODE_SVC32;                  cpu->cd.arm.cpsr |= ARM_MODE_SVC32;
116                  cpu->cd.arm.control |= ARM_CONTROL_S;                  cpu->cd.arm.control |= ARM_CONTROL_S;
117          } else {          } else {
118                  cpu->cd.arm.cpsr |= ARM_MODE_USR32;                  cpu->cd.arm.cpsr |= ARM_MODE_SVC32;
119                  cpu->cd.arm.control |= ARM_CONTROL_S | ARM_CONTROL_R;                  cpu->cd.arm.control |= ARM_CONTROL_R;
120          }          }
121    
122          /*  Only show name and caches etc for CPU nr 0:  */          /*  Only show name and caches etc for CPU nr 0:  */
123          if (cpu_id == 0) {          if (cpu_id == 0) {
124                  debug("%s", cpu->name);                  debug("%s", cpu->name);
125                  if (cpu->cd.arm.cpu_type.icache_shift != 0)                  if (cpu->cd.arm.cpu_type.icache_shift != 0 ||
126                          any_cache = 1;                      cpu->cd.arm.cpu_type.dcache_shift != 0) {
127                  if (cpu->cd.arm.cpu_type.dcache_shift != 0)                          int isize = cpu->cd.arm.cpu_type.icache_shift;
128                          any_cache = 1;                          int dsize = cpu->cd.arm.cpu_type.dcache_shift;
129                  if (any_cache) {                          if (isize != 0)
130                          debug(" (I+D = %i+%i KB",                                  isize = 1 << (isize - 10);
131                              (int)(1 << (cpu->cd.arm.cpu_type.icache_shift-10)),                          if (dsize != 0)
132                              (int)(1 << (cpu->cd.arm.cpu_type.dcache_shift-10)));                                  dsize = 1 << (dsize - 10);
133                          debug(")");                          debug(" (I+D = %i+%i KB)", isize, dsize);
134                  }                  }
135          }          }
136    
137            /*  TODO: Some of these values (iway and dway) aren't used yet:  */
138            cpu->cd.arm.cachetype =
139                  (5 << ARM_CACHETYPE_CLASS_SHIFT)
140                | (1 << ARM_CACHETYPE_HARVARD_SHIFT)
141                | ((cpu->cd.arm.cpu_type.dcache_shift - 9) <<
142                    ARM_CACHETYPE_DSIZE_SHIFT)
143                | (5 << ARM_CACHETYPE_DASSOC_SHIFT)         /*  32-way  */
144                | (2 << ARM_CACHETYPE_DLINE_SHIFT)          /*  8 words/line  */
145                | ((cpu->cd.arm.cpu_type.icache_shift - 9) <<
146                    ARM_CACHETYPE_ISIZE_SHIFT)
147                | (5 << ARM_CACHETYPE_IASSOC_SHIFT)         /*  32-way  */
148                | (2 << ARM_CACHETYPE_ILINE_SHIFT);         /*  8 words/line  */
149    
150          /*  Coprocessor 15 = the system control coprocessor.  */          /*  Coprocessor 15 = the system control coprocessor.  */
151          cpu->cd.arm.coproc[15] = arm_coproc_15;          cpu->cd.arm.coproc[15] = arm_coproc_15;
152    
153            /*  Coprocessor 14 for XScale:  */
154            if (cpu->cd.arm.cpu_type.flags & ARM_XSCALE)
155                    cpu->cd.arm.coproc[14] = arm_coproc_xscale_14;
156    
157          /*          /*
158           *  NOTE/TODO: Ugly hack for OpenFirmware emulation:           *  NOTE/TODO: Ugly hack for OpenFirmware emulation:
159           */           */
# Line 140  int arm_cpu_new(struct cpu *cpu, struct Line 163  int arm_cpu_new(struct cpu *cpu, struct
163                  store_32bit_word(cpu, cpu->cd.arm.of_emul_addr, 0xef8c64be);                  store_32bit_word(cpu, cpu->cd.arm.of_emul_addr, 0xef8c64be);
164          }          }
165    
166            cpu->cd.arm.flags = cpu->cd.arm.cpsr >> 28;
167    
168            CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc);
169            for (i=0; i<N_ARM_REGS - 1; i++)
170                    CPU_SETTINGS_ADD_REGISTER32(arm_regname[i], cpu->cd.arm.r[i]);
171    
172          return 1;          return 1;
173  }  }
174    
# Line 163  void arm_setup_initial_translation_table Line 192  void arm_setup_initial_translation_table
192          }          }
193    
194          cpu->cd.arm.control |= ARM_CONTROL_MMU;          cpu->cd.arm.control |= ARM_CONTROL_MMU;
195            cpu->translate_v2p = arm_translate_v2p_mmu;
196          cpu->cd.arm.dacr |= 0x00000003;          cpu->cd.arm.dacr |= 0x00000003;
197          cpu->cd.arm.ttb = ttb_addr;          cpu->cd.arm.ttb = ttb_addr;
198    
# Line 175  void arm_setup_initial_translation_table Line 205  void arm_setup_initial_translation_table
205                          uint32_t addr = cpu->cd.arm.ttb +                          uint32_t addr = cpu->cd.arm.ttb +
206                              (((j << 28) + (i << 20)) >> 18);                              (((j << 28) + (i << 20)) >> 18);
207                          uint32_t d = (1048576*i) | 0xc02;                          uint32_t d = (1048576*i) | 0xc02;
208    
209                            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
210                                    descr[0] = d;       descr[1] = d >> 8;
211                                    descr[2] = d >> 16; descr[3] = d >> 24;
212                            } else {
213                                    descr[3] = d;       descr[2] = d >> 8;
214                                    descr[1] = d >> 16; descr[0] = d >> 24;
215                            }
216                            cpu->memory_rw(cpu, cpu->mem, addr, &descr[0],
217                                sizeof(descr), MEM_WRITE, PHYSICAL | NO_EXCEPTIONS);
218                    }
219    }
220    
221    
222  /*  /*
223  d = (1048576 * (i + (j==12? 10 : j)*256)) | 2;   *  arm_translation_table_set_l1():
224  */   */
225    void arm_translation_table_set_l1(struct cpu *cpu, uint32_t vaddr,
226            uint32_t paddr)
227    {
228            unsigned int i, j, vhigh = vaddr >> 28, phigh = paddr >> 28;
229    
230            for (i=0; i<256; i++)
231                    for (j=vhigh; j<=vhigh; j++) {
232                            unsigned char descr[4];
233                            uint32_t addr = cpu->cd.arm.ttb +
234                                (((j << 28) + (i << 20)) >> 18);
235                            uint32_t d = ((phigh << 28) + 1048576*i) | 0xc02;
236    
237                            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
238                                    descr[0] = d;       descr[1] = d >> 8;
239                                    descr[2] = d >> 16; descr[3] = d >> 24;
240                            } else {
241                                    descr[3] = d;       descr[2] = d >> 8;
242                                    descr[1] = d >> 16; descr[0] = d >> 24;
243                            }
244                            cpu->memory_rw(cpu, cpu->mem, addr, &descr[0],
245                                sizeof(descr), MEM_WRITE, PHYSICAL | NO_EXCEPTIONS);
246                    }
247    }
248    
249    
250    /*
251     *  arm_translation_table_set_l1_b():
252     */
253    void arm_translation_table_set_l1_b(struct cpu *cpu, uint32_t vaddr,
254            uint32_t paddr)
255    {
256            unsigned int i, j, vhigh = vaddr >> 24, phigh = paddr >> 24;
257    
258            for (i=0; i<16; i++)
259                    for (j=vhigh; j<=vhigh; j++) {
260                            unsigned char descr[4];
261                            uint32_t addr = cpu->cd.arm.ttb +
262                                (((j << 24) + (i << 20)) >> 18);
263                            uint32_t d = ((phigh << 24) + 1048576*i) | 0xc02;
264    
265                          if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {                          if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
266                                  descr[0] = d;       descr[1] = d >> 8;                                  descr[0] = d;       descr[1] = d >> 8;
267                                  descr[2] = d >> 16; descr[3] = d >> 24;                                  descr[2] = d >> 16; descr[3] = d >> 24;
# Line 226  void arm_cpu_list_available_types(void) Line 310  void arm_cpu_list_available_types(void)
310    
311    
312  /*  /*
  *  arm_cpu_register_match():  
  */  
 void arm_cpu_register_match(struct machine *m, char *name,  
         int writeflag, uint64_t *valuep, int *match_register)  
 {  
         int i, cpunr = 0;  
   
         /*  CPU number:  */  
   
         /*  TODO  */  
   
         /*  Register names:  */  
         for (i=0; i<N_ARM_REGS; i++) {  
                 if (strcasecmp(name, arm_regname[i]) == 0) {  
                         if (writeflag) {  
                                 m->cpus[cpunr]->cd.arm.r[i] = *valuep;  
                                 if (i == ARM_PC)  
                                         m->cpus[cpunr]->pc = *valuep;  
                         } else  
                                 *valuep = m->cpus[cpunr]->cd.arm.r[i];  
                         *match_register = 1;  
                 }  
         }  
 }  
   
   
 /*  
313   *  arm_cpu_register_dump():   *  arm_cpu_register_dump():
314   *   *
315   *  Dump cpu registers in a relatively readable format.   *  Dump cpu registers in a relatively readable format.
# Line 267  void arm_cpu_register_dump(struct cpu *c Line 324  void arm_cpu_register_dump(struct cpu *c
324          int mode = cpu->cd.arm.cpsr & ARM_FLAG_MODE;          int mode = cpu->cd.arm.cpsr & ARM_FLAG_MODE;
325          int i, x = cpu->cpu_id;          int i, x = cpu->cpu_id;
326    
327            cpu->cd.arm.cpsr &= 0x0fffffff;
328            cpu->cd.arm.cpsr |= (cpu->cd.arm.flags << 28);
329    
330          if (gprs) {          if (gprs) {
331                  symbol = get_symbol_name(&cpu->machine->symbol_context,                  symbol = get_symbol_name(&cpu->machine->symbol_context,
332                      cpu->cd.arm.r[ARM_PC], &offset);                      cpu->pc, &offset);
333                  debug("cpu%i:  cpsr = ", x);                  debug("cpu%i:  cpsr = ", x);
334                  debug("%s%s%s%s%s%s",                  debug("%s%s%s%s%s%s",
335                      (cpu->cd.arm.cpsr & ARM_FLAG_N)? "N" : "n",                      (cpu->cd.arm.cpsr & ARM_FLAG_N)? "N" : "n",
# Line 279  void arm_cpu_register_dump(struct cpu *c Line 339  void arm_cpu_register_dump(struct cpu *c
339                      (cpu->cd.arm.cpsr & ARM_FLAG_I)? "I" : "i",                      (cpu->cd.arm.cpsr & ARM_FLAG_I)? "I" : "i",
340                      (cpu->cd.arm.cpsr & ARM_FLAG_F)? "F" : "f");                      (cpu->cd.arm.cpsr & ARM_FLAG_F)? "F" : "f");
341                  if (mode < ARM_MODE_USR32)                  if (mode < ARM_MODE_USR32)
342                          debug("   pc =  0x%07x",                          debug("   pc =  0x%07x", (int)(cpu->pc & 0x03ffffff));
                             (int)(cpu->cd.arm.r[ARM_PC] & 0x03ffffff));  
343                  else                  else
344                          debug("   pc = 0x%08x", (int)cpu->cd.arm.r[ARM_PC]);                          debug("   pc = 0x%08x", (int)cpu->pc);
345    
346                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");                  debug("  <%s>\n", symbol != NULL? symbol : " no symbol ");
347    
# Line 319  void arm_cpu_register_dump(struct cpu *c Line 378  void arm_cpu_register_dump(struct cpu *c
378                  }                  }
379    
380                  if (m != ARM_MODE_USR32 && m != ARM_MODE_SYS32) {                  if (m != ARM_MODE_USR32 && m != ARM_MODE_SYS32) {
381                          debug("cpu%i:  usr r8..r14 =", x);                          debug("cpu%i:  usr r8-14:", x);
382                          for (i=0; i<7; i++)                          for (i=0; i<7; i++)
383                                  debug(" %08x", cpu->cd.arm.default_r8_r14[i]);                                  debug(" %08x", cpu->cd.arm.default_r8_r14[i]);
384                          debug("\n");                          debug("\n");
385                  }                  }
386    
387                  if (m != ARM_MODE_FIQ32) {                  if (m != ARM_MODE_FIQ32) {
388                          debug("cpu%i:  fiq r8..r14 =", x);                          debug("cpu%i:  fiq r8-14:", x);
389                          for (i=0; i<7; i++)                          for (i=0; i<7; i++)
390                                  debug(" %08x", cpu->cd.arm.fiq_r8_r14[i]);                                  debug(" %08x", cpu->cd.arm.fiq_r8_r14[i]);
391                          debug("\n");                          debug("\n");
392                  }                  }
393    
394                  if (m != ARM_MODE_IRQ32) {                  if (m != ARM_MODE_IRQ32) {
395                          debug("cpu%i:  irq r13..r14 =", x);                          debug("cpu%i:  irq r13-14:", x);
396                          for (i=0; i<2; i++)                          for (i=0; i<2; i++)
397                                  debug(" %08x", cpu->cd.arm.irq_r13_r14[i]);                                  debug(" %08x", cpu->cd.arm.irq_r13_r14[i]);
398                          debug("\n");                          debug("\n");
399                  }                  }
400    
401                  if (m != ARM_MODE_SVC32) {                  if (m != ARM_MODE_SVC32) {
402                          debug("cpu%i:  svc r13..r14 =", x);                          debug("cpu%i:  svc r13-14:", x);
403                          for (i=0; i<2; i++)                          for (i=0; i<2; i++)
404                                  debug(" %08x", cpu->cd.arm.svc_r13_r14[i]);                                  debug(" %08x", cpu->cd.arm.svc_r13_r14[i]);
405                          debug("\n");                          debug("\n");
406                  }                  }
407    
408                  if (m != ARM_MODE_ABT32) {                  if (m != ARM_MODE_ABT32) {
409                          debug("cpu%i:  abt r13..r14 =", x);                          debug("cpu%i:  abt r13-14:", x);
410                          for (i=0; i<2; i++)                          for (i=0; i<2; i++)
411                                  debug(" %08x", cpu->cd.arm.abt_r13_r14[i]);                                  debug(" %08x", cpu->cd.arm.abt_r13_r14[i]);
412                          debug("\n");                          debug("\n");
413                  }                  }
414    
415                  if (m != ARM_MODE_UND32) {                  if (m != ARM_MODE_UND32) {
416                          debug("cpu%i:  und r13..r14 =", x);                          debug("cpu%i:  und r13-14:", x);
417                          for (i=0; i<2; i++)                          for (i=0; i<2; i++)
418                                  debug(" %08x", cpu->cd.arm.und_r13_r14[i]);                                  debug(" %08x", cpu->cd.arm.und_r13_r14[i]);
419                          debug("\n");                          debug("\n");
# Line 391  void arm_cpu_register_dump(struct cpu *c Line 450  void arm_cpu_register_dump(struct cpu *c
450                      cpu->cd.arm.control &                      cpu->cd.arm.control &
451                      ARM_CONTROL_V? "yes (0xffff0000)" : "no");                      ARM_CONTROL_V? "yes (0xffff0000)" : "no");
452    
453                    /*  TODO: auxctrl on which CPU types?  */
454                    if (cpu->cd.arm.cpu_type.flags & ARM_XSCALE) {
455                            debug("cpu%i:  auxctrl = 0x%08x\n", x,
456                                cpu->cd.arm.auxctrl);
457                            debug("cpu%i:      minidata cache attr = 0x%x\n", x,
458                                (cpu->cd.arm.auxctrl & ARM_AUXCTRL_MD)
459                                >> ARM_AUXCTRL_MD_SHIFT);
460                            debug("cpu%i:      page table memory attr: %i\n", x,
461                                (cpu->cd.arm.auxctrl & ARM_AUXCTRL_P)? 1 : 0);
462                            debug("cpu%i:      write buffer coalescing: %s\n", x,
463                                (cpu->cd.arm.auxctrl & ARM_AUXCTRL_K)?
464                                "disabled" : "enabled");
465                    }
466    
467                  debug("cpu%i:  ttb = 0x%08x  dacr = 0x%08x\n", x,                  debug("cpu%i:  ttb = 0x%08x  dacr = 0x%08x\n", x,
468                      cpu->cd.arm.ttb, cpu->cd.arm.dacr);                      cpu->cd.arm.ttb, cpu->cd.arm.dacr);
469                  debug("cpu%i:  fsr = 0x%08x  far = 0x%08x\n", x,                  debug("cpu%i:  fsr = 0x%08x  far = 0x%08x\n", x,
# Line 400  void arm_cpu_register_dump(struct cpu *c Line 473  void arm_cpu_register_dump(struct cpu *c
473    
474    
475  /*  /*
  *  arm_cpu_show_full_statistics():  
  *  
  *  Show detailed statistics on opcode usage on each cpu.  
  */  
 void arm_cpu_show_full_statistics(struct machine *m)  
 {  
         fatal("arm_cpu_show_full_statistics(): TODO\n");  
 }  
   
   
 /*  
  *  arm_cpu_tlbdump():  
  *  
  *  Called from the debugger to dump the TLB in a readable format.  
  *  x is the cpu number to dump, or -1 to dump all CPUs.  
  *  
  *  If rawflag is nonzero, then the TLB contents isn't formated nicely,  
  *  just dumped.  
  */  
 void arm_cpu_tlbdump(struct machine *m, int x, int rawflag)  
 {  
         fatal("arm_cpu_tlbdump(): TODO\n");  
 }  
   
   
 /*  
476   *  arm_save_register_bank():   *  arm_save_register_bank():
477   */   */
478  void arm_save_register_bank(struct cpu *cpu)  void arm_save_register_bank(struct cpu *cpu)
# Line 524  void arm_load_register_bank(struct cpu * Line 571  void arm_load_register_bank(struct cpu *
571   */   */
572  void arm_exception(struct cpu *cpu, int exception_nr)  void arm_exception(struct cpu *cpu, int exception_nr)
573  {  {
         int arm_exception_to_mode[N_ARM_EXCEPTIONS] = ARM_EXCEPTION_TO_MODE;  
574          int oldmode, newmode;          int oldmode, newmode;
575          uint32_t retaddr;          uint32_t retaddr;
576    
# Line 535  void arm_exception(struct cpu *cpu, int Line 581  void arm_exception(struct cpu *cpu, int
581    
582          retaddr = cpu->pc;          retaddr = cpu->pc;
583    
584          debug("[ arm_exception(): ");          if (!quiet_mode) {
585                    debug("[ arm_exception(): ");
586                    switch (exception_nr) {
587                    case ARM_EXCEPTION_RESET:
588                            fatal("RESET: TODO");
589                            break;
590                    case ARM_EXCEPTION_UND:
591                            debug("UNDEFINED");
592                            break;
593                    case ARM_EXCEPTION_SWI:
594                            debug("SWI");
595                            break;
596                    case ARM_EXCEPTION_PREF_ABT:
597                            debug("PREFETCH ABORT");
598                            break;
599                    case ARM_EXCEPTION_IRQ:
600                            debug("IRQ");
601                            break;
602                    case ARM_EXCEPTION_FIQ:
603                            debug("FIQ");
604                            break;
605                    case ARM_EXCEPTION_DATA_ABT:
606                            debug("DATA ABORT, far=0x%08x fsr=0x%02x",
607                                cpu->cd.arm.far, cpu->cd.arm.fsr);
608                            break;
609                    }
610                    debug(" ]\n");
611            }
612    
613          switch (exception_nr) {          switch (exception_nr) {
614          case ARM_EXCEPTION_RESET:          case ARM_EXCEPTION_RESET:
615                  cpu->running = 0;                  cpu->running = 0;
616                  fatal("RESET: TODO");                  fatal("ARM RESET: TODO");
617                  exit(1);                  exit(1);
         case ARM_EXCEPTION_UND:  
                 debug("UNDEFINED");  
                 retaddr += 4;  
                 break;  
         case ARM_EXCEPTION_SWI:  
                 debug("SWI");  
                 retaddr += 4;  
                 break;  
         case ARM_EXCEPTION_PREF_ABT:  
                 debug("PREFETCH ABORT");  
                 retaddr += 4;  
                 break;  
         case ARM_EXCEPTION_IRQ:  
                 debug("IRQ");  
                 retaddr += 4;  
                 break;  
         case ARM_EXCEPTION_FIQ:  
                 debug("FIQ");  
                 retaddr += 4;  
                 break;  
618          case ARM_EXCEPTION_DATA_ABT:          case ARM_EXCEPTION_DATA_ABT:
619                  debug("DATA ABORT, far=0x%08x fsr=0x%02x",                  retaddr += 4;
                     cpu->cd.arm.far, cpu->cd.arm.fsr);  
                 retaddr += 8;  
620                  break;                  break;
621          }          }
622    
623          debug(" ]\n");          retaddr += 4;
624    
625          arm_save_register_bank(cpu);          arm_save_register_bank(cpu);
626    
627            cpu->cd.arm.cpsr &= 0x0fffffff;
628            cpu->cd.arm.cpsr |= (cpu->cd.arm.flags << 28);
629    
630          switch (arm_exception_to_mode[exception_nr]) {          switch (arm_exception_to_mode[exception_nr]) {
631          case ARM_MODE_SVC32:          case ARM_MODE_SVC32:
632                  cpu->cd.arm.spsr_svc = cpu->cd.arm.cpsr; break;                  cpu->cd.arm.spsr_svc = cpu->cd.arm.cpsr; break;
# Line 599  void arm_exception(struct cpu *cpu, int Line 653  void arm_exception(struct cpu *cpu, int
653          cpu->cd.arm.cpsr &= ~ARM_FLAG_MODE;          cpu->cd.arm.cpsr &= ~ARM_FLAG_MODE;
654          cpu->cd.arm.cpsr |= arm_exception_to_mode[exception_nr];          cpu->cd.arm.cpsr |= arm_exception_to_mode[exception_nr];
655    
656            /*
657             *  Usually, an exception should change modes (so that saved status
658             *  bits don't get lost). However, Linux on ARM seems to use floating
659             *  point instructions in the kernel (!), and it emulates those using
660             *  its own fp emulation code. This leads to a situation where we
661             *  sometimes change from SVC32 to SVC32.
662             */
663          newmode = cpu->cd.arm.cpsr & ARM_FLAG_MODE;          newmode = cpu->cd.arm.cpsr & ARM_FLAG_MODE;
664          if (oldmode == newmode) {          if (oldmode == newmode && oldmode != ARM_MODE_SVC32) {
665                  fatal("Exception caused no mode change? TODO\n");                  fatal("[ WARNING! Exception caused no mode change? "
666                  exit(1);                      "mode 0x%02x (pc=0x%x) ]\n", newmode, (int)cpu->pc);
667                    /*  exit(1);  */
668          }          }
669    
670          cpu->cd.arm.cpsr |= ARM_FLAG_I;          cpu->cd.arm.cpsr |= ARM_FLAG_I;
# Line 613  void arm_exception(struct cpu *cpu, int Line 675  void arm_exception(struct cpu *cpu, int
675          /*  Load the new register bank, if we switched:  */          /*  Load the new register bank, if we switched:  */
676          arm_load_register_bank(cpu);          arm_load_register_bank(cpu);
677    
678          /*  Set the return address and new PC:  */          /*
679             *  Set the return address and new PC.
680             *
681             *  NOTE: r[ARM_PC] is also set; see cpu_arm_instr_loadstore.c for
682             *  details. (If an exception occurs during a load into the pc
683             *  register, the code in that file assumes that the r[ARM_PC]
684             *  was changed to the address of the exception handler.)
685             */
686          cpu->cd.arm.r[ARM_LR] = retaddr;          cpu->cd.arm.r[ARM_LR] = retaddr;
   
687          cpu->pc = cpu->cd.arm.r[ARM_PC] = exception_nr * 4 +          cpu->pc = cpu->cd.arm.r[ARM_PC] = exception_nr * 4 +
688              ((cpu->cd.arm.control & ARM_CONTROL_V)? 0xffff0000 : 0);              ((cpu->cd.arm.control & ARM_CONTROL_V)? 0xffff0000 : 0);
689          arm_pc_to_pointers(cpu);          quick_pc_to_pointers(cpu);
690    }
691    
692    
693    /*
694     *  arm_cpu_tlbdump():
695     *
696     *  Called from the debugger to dump the TLB in a readable format.
697     *  x is the cpu number to dump, or -1 to dump all CPUs.
698     *
699     *  If rawflag is nonzero, then the TLB contents isn't formated nicely,
700     *  just dumped.
701     */
702    void arm_cpu_tlbdump(struct machine *m, int x, int rawflag)
703    {
704    }
705    
706    
707    static void add_response_word(struct cpu *cpu, char *r, uint32_t value,
708            size_t maxlen)
709    {
710            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
711                    value = ((value & 0xff) << 24) +
712                            ((value & 0xff00) << 8) +
713                            ((value & 0xff0000) >> 8) +
714                            ((value & 0xff000000) >> 24);
715            }
716            snprintf(r + strlen(r), maxlen - strlen(r), "%08"PRIx32, value);
717    }
718    
719    
720    /*
721     *  arm_cpu_gdb_stub():
722     *
723     *  Execute a "remote GDB" command. Returns a newly allocated response string
724     *  on success, NULL on failure.
725     */
726    char *arm_cpu_gdb_stub(struct cpu *cpu, char *cmd)
727    {
728            if (strcmp(cmd, "g") == 0) {
729                    /*  15 gprs, pc, 8 fprs, fps, cpsr.  */
730                    int i;
731                    char *r;
732                    size_t len = 1 + 18 * sizeof(uint32_t);
733                    r = malloc(len);
734                    if (r == NULL) {
735                            fprintf(stderr, "out of memory\n");
736                            exit(1);
737                    }
738                    r[0] = '\0';
739                    for (i=0; i<15; i++)
740                            add_response_word(cpu, r, cpu->cd.arm.r[i], len);
741                    add_response_word(cpu, r, cpu->pc, len);
742                    /*  TODO: fprs:  */
743                    for (i=0; i<8; i++)
744                            add_response_word(cpu, r, 0, len);
745                    /*  TODO: fps  */
746                    add_response_word(cpu, r, 0, len);
747                    add_response_word(cpu, r, cpu->cd.arm.cpsr, len);
748                    return r;
749            }
750    
751            if (cmd[0] == 'p') {
752                    int regnr = strtol(cmd + 1, NULL, 16);
753                    size_t len = 2 * sizeof(uint32_t) + 1;
754                    char *r = malloc(len);
755                    r[0] = '\0';
756                    if (regnr == ARM_PC) {
757                            add_response_word(cpu, r, cpu->pc, len);
758                    } else if (regnr >= 0 && regnr < ARM_PC) {
759                            add_response_word(cpu, r, cpu->cd.arm.r[regnr], len);
760                    } else if (regnr >= 0x10 && regnr <= 0x17) {
761                            /*  TODO: fprs  */
762                            add_response_word(cpu, r, 0, len);
763                            add_response_word(cpu, r, 0, len);
764                            add_response_word(cpu, r, 0, len);
765                    } else if (regnr == 0x18) {
766                            /*  TODO: fps  */
767                            add_response_word(cpu, r, 0, len);
768                    } else if (regnr == 0x19) {
769                            add_response_word(cpu, r, cpu->cd.arm.cpsr, len);
770                    }
771                    return r;
772            }
773    
774            fatal("arm_cpu_gdb_stub(): TODO\n");
775            return NULL;
776  }  }
777    
778    
# Line 632  void arm_exception(struct cpu *cpu, int Line 786  void arm_exception(struct cpu *cpu, int
786   */   */
787  int arm_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  int arm_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)
788  {  {
789          /*  fatal("arm_cpu_interrupt(): 0x%llx\n", (int)irq_nr);  */          /*  fatal("arm_cpu_interrupt(): 0x%x\n", (int)irq_nr);  */
790          if (irq_nr <= 64) {          if (irq_nr <= 64) {
791                  if (cpu->machine->md_interrupt != NULL)                  if (cpu->machine->md_interrupt != NULL)
792                          cpu->machine->md_interrupt(cpu->machine,                          cpu->machine->md_interrupt(cpu->machine,
793                              cpu, irq_nr, 1);                              cpu, irq_nr, 1);
794                  else                  else
795                          fatal("arm_cpu_interrupt(): md_interrupt == NULL\n");                          fatal("arm_cpu_interrupt(): irq_nr=%i md_interrupt =="
796                                " NULL\n", (int)irq_nr);
797          } else {          } else {
798                  /*  Assert ARM IRQs:  */                  /*  Assert ARM IRQs:  */
799                  cpu->cd.arm.irq_asserted = 1;                  cpu->cd.arm.irq_asserted = 1;
# Line 679  int arm_cpu_interrupt_ack(struct cpu *cp Line 834  int arm_cpu_interrupt_ack(struct cpu *cp
834   *  cpu->pc for relative addresses.   *  cpu->pc for relative addresses.
835   */                       */                    
836  int arm_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,  int arm_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib,
837          int running, uint64_t dumpaddr, int bintrans)          int running, uint64_t dumpaddr)
838  {  {
839          uint32_t iw, tmp;          uint32_t iw, tmp;
840          int main_opcode, secondary_opcode, s_bit, r16, r12, r8;          int main_opcode, secondary_opcode, s_bit, r16, r12, r8;
# Line 752  int arm_cpu_disassemble_instr(struct cpu Line 907  int arm_cpu_disassemble_instr(struct cpu
907                          int a_bit = (iw >> 21) & 1;                          int a_bit = (iw >> 21) & 1;
908                          debug("%s%sl%s%s\t", u_bit? "s" : "u",                          debug("%s%sl%s%s\t", u_bit? "s" : "u",
909                              a_bit? "mla" : "mul", condition, s_bit? "s" : "");                              a_bit? "mla" : "mul", condition, s_bit? "s" : "");
910                          debug("%s,", arm_regname[r12]);                          debug("%s,%s,", arm_regname[r12], arm_regname[r16]);
911                          debug("%s,", arm_regname[r16]);                          debug("%s,%s\n", arm_regname[iw&15], arm_regname[r8]);
912                          debug("%s,", arm_regname[iw & 15]);                          break;
913                          debug("%s\n", arm_regname[r8]);                  }
914    
915                    /*
916                     *  xxxx0001 0000nnnn dddd0000 0101mmmm  qadd Rd,Rm,Rn
917                     *  xxxx0001 0010nnnn dddd0000 0101mmmm  qsub Rd,Rm,Rn
918                     *  xxxx0001 0100nnnn dddd0000 0101mmmm  qdadd Rd,Rm,Rn
919                     *  xxxx0001 0110nnnn dddd0000 0101mmmm  qdsub Rd,Rm,Rn
920                     */
921                    if ((iw & 0x0f900ff0) == 0x01000050) {
922                            debug("q%s%s%s\t", iw & 0x400000? "d" : "",
923                                iw & 0x200000? "sub" : "add", condition);
924                            debug("%s,%s,%s\n", arm_regname[r12],
925                                arm_regname[iw&15], arm_regname[r16]);
926                          break;                          break;
927                  }                  }
928    
# Line 813  int arm_cpu_disassemble_instr(struct cpu Line 980  int arm_cpu_disassemble_instr(struct cpu
980                  }                  }
981    
982                  /*                  /*
983                     *  xxxx0001 01101111 dddd1111 0001mmmm    CLZ Rd,Rm
984                     */
985                    if ((iw & 0x0fff0ff0) == 0x016f0f10) {
986                            debug("clz%s\t", condition);
987                            debug("%s,%s\n", arm_regname[r12], arm_regname[iw&15]);
988                            break;
989                    }
990    
991                    /*
992                     *  xxxx0001 0000dddd nnnnssss 1yx0mmmm  SMLAxy Rd,Rm,Rs,Rn
993                     *  xxxx0001 0100dddd DDDDssss 1yx0mmmm  SMLALxy RdL,RdH,Rm,Rs
994                     *  xxxx0001 0010dddd nnnnssss 1y00mmmm  SMLAWy Rd,Rm,Rs,Rn
995                     *  xxxx0001 0110dddd 0000ssss 1yx0mmmm  SMULxy Rd,Rm,Rs
996                     *  xxxx0001 0010dddd 0000ssss 1y10mmmm  SMULWy Rd,Rm,Rs
997                     */
998                    if ((iw & 0x0ff00090) == 0x01000080) {
999                            debug("smla%s%s%s\t",
1000                                iw & 0x20? "t" : "b", iw & 0x40? "t" : "b",
1001                                condition);
1002                            debug("%s,%s,%s,%s\n", arm_regname[r16],
1003                                arm_regname[iw&15], arm_regname[r8],
1004                                arm_regname[r12]);
1005                            break;
1006                    }
1007                    if ((iw & 0x0ff00090) == 0x01400080) {
1008                            debug("smlal%s%s%s\t",
1009                                iw & 0x20? "t" : "b", iw & 0x40? "t" : "b",
1010                                condition);
1011                            debug("%s,%s,%s,%s\n", arm_regname[r12],
1012                                arm_regname[r16], arm_regname[iw&15],
1013                                arm_regname[r8]);
1014                            break;
1015                    }
1016                    if ((iw & 0x0ff000b0) == 0x01200080) {
1017                            debug("smlaw%s%s\t", iw & 0x40? "t" : "b",
1018                                condition);
1019                            debug("%s,%s,%s,%s\n", arm_regname[r16],
1020                                arm_regname[iw&15], arm_regname[r8],
1021                                arm_regname[r12]);
1022                            break;
1023                    }
1024                    if ((iw & 0x0ff0f090) == 0x01600080) {
1025                            debug("smul%s%s%s\t",
1026                                iw & 0x20? "t" : "b", iw & 0x40? "t" : "b",
1027                                condition);
1028                            debug("%s,%s,%s\n", arm_regname[r16],
1029                                arm_regname[iw&15], arm_regname[r8]);
1030                            break;
1031                    }
1032                    if ((iw & 0x0ff0f0b0) == 0x012000a0) {
1033                            debug("smulw%s%s\t", iw & 0x40? "t" : "b",
1034                                condition);
1035                            debug("%s,%s,%s\n", arm_regname[r16],
1036                                arm_regname[iw&15], arm_regname[r8]);
1037                            break;
1038                    }
1039    
1040                    /*
1041                   *  xxxx000P U1WLnnnn ddddHHHH 1SH1LLLL load/store rd,imm(rn)                   *  xxxx000P U1WLnnnn ddddHHHH 1SH1LLLL load/store rd,imm(rn)
1042                   */                   */
1043                  if ((iw & 0x0e000090) == 0x00000090) {                  if ((iw & 0x0e000090) == 0x00000090) {
1044                            char *op = "st";
1045                          int imm = ((iw >> 4) & 0xf0) | (iw & 0xf);                          int imm = ((iw >> 4) & 0xf0) | (iw & 0xf);
1046                          int regform = !(iw & 0x00400000);                          int regform = !(iw & 0x00400000);
1047                          p_bit = main_opcode & 1;                          p_bit = main_opcode & 1;
# Line 828  int arm_cpu_disassemble_instr(struct cpu Line 1054  int arm_cpu_disassemble_instr(struct cpu
1054                                  break;                                  break;
1055                          }                          }
1056                          /*  Semi-generic case:  */                          /*  Semi-generic case:  */
1057                          debug("%sr%s", iw & 0x00100000? "ld" : "st",                          if (iw & 0x00100000)
1058                              condition);                                  op = "ld";
1059                            if (!l_bit && (iw & 0xd0) == 0xd0)
1060                                    op = iw & 0x20? "st" : "ld";
1061                            debug("%sr%s", op, condition);
1062                          if (!l_bit && (iw & 0xd0) == 0xd0) {                          if (!l_bit && (iw & 0xd0) == 0xd0) {
1063                                  debug("d");             /*  Double-register  */                                  debug("d");             /*  Double-register  */
1064                          } else {                          } else {
# Line 1029  int arm_cpu_disassemble_instr(struct cpu Line 1258  int arm_cpu_disassemble_instr(struct cpu
1258                                  } else {                                  } else {
1259                                          tmpw[0] = addr = cpu->cd.arm.r[r12];                                          tmpw[0] = addr = cpu->cd.arm.r[r12];
1260                                          if (r12 == ARM_PC)                                          if (r12 == ARM_PC)
1261                                                  addr += 8;                                                  addr = cpu->pc + 8;
1262                                  }                                  }
1263                                  debug(": ");                                  debug(": ");
1264                                  if (b_bit)                                  if (b_bit)
# Line 1093  int arm_cpu_disassemble_instr(struct cpu Line 1322  int arm_cpu_disassemble_instr(struct cpu
1322                  break;                  break;
1323          case 0xc:                               /*  Coprocessor  */          case 0xc:                               /*  Coprocessor  */
1324          case 0xd:                               /*  LDC/STC  */          case 0xd:                               /*  LDC/STC  */
1325                    /*
1326                     *  xxxx1100 0100nnnn ddddcccc oooommmm    MCRR c,op,Rd,Rn,CRm
1327                     *  xxxx1100 0101nnnn ddddcccc oooommmm    MRRC c,op,Rd,Rn,CRm
1328                     */
1329                    if ((iw & 0x0fe00fff) == 0x0c400000) {
1330                            debug("%s%s\t", iw & 0x100000? "mra" : "mar",
1331                                condition);
1332                            if (iw & 0x100000)
1333                                    debug("%s,%s,acc0\n",
1334                                        arm_regname[r12], arm_regname[r16]);
1335                            else
1336                                    debug("acc0,%s,%s\n",
1337                                        arm_regname[r12], arm_regname[r16]);
1338                            break;
1339                    }
1340                    if ((iw & 0x0fe00000) == 0x0c400000) {
1341                            debug("%s%s\t", iw & 0x100000? "mrrc" : "mcrr",
1342                                condition);
1343                            debug("%i,%i,%s,%s,cr%i\n", r8, (iw >> 4) & 15,
1344                                arm_regname[r12], arm_regname[r16], iw & 15);
1345                            break;
1346                    }
1347    
1348                  /*  xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC  */                  /*  xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC  */
1349                  debug("TODO: coprocessor LDC/STC\n");                  debug("TODO: coprocessor LDC/STC\n");
1350                  break;                  break;
# Line 1101  int arm_cpu_disassemble_instr(struct cpu Line 1353  int arm_cpu_disassemble_instr(struct cpu
1353                   *  xxxx1110 oooonnnn ddddpppp qqq0mmmm         CDP                   *  xxxx1110 oooonnnn ddddpppp qqq0mmmm         CDP
1354                   *  xxxx1110 oooLNNNN ddddpppp qqq1MMMM         MRC/MCR                   *  xxxx1110 oooLNNNN ddddpppp qqq1MMMM         MRC/MCR
1355                   */                   */
1356                    if ((iw & 0x0ff00ff0) == 0x0e200010) {
1357                            /*  Special case: mia* DSP instructions  */
1358                            switch ((iw >> 16) & 0xf) {
1359                            case  0: debug("mia"); break;
1360                            case  8: debug("miaph"); break;
1361                            case 12: debug("miaBB"); break;
1362                            case 13: debug("miaTB"); break;
1363                            case 14: debug("miaBT"); break;
1364                            case 15: debug("miaTT"); break;
1365                            default: debug("UNKNOWN mia vector instruction?");
1366                            }
1367                            debug("%s\t", condition);
1368                            debug("acc%i,%s,%s\n", ((iw >> 5) & 7),
1369                                arm_regname[iw & 15], arm_regname[r12]);
1370                            break;
1371                    }
1372                  if (iw & 0x10) {                  if (iw & 0x10) {
1373                          debug("%s%s\t",                          debug("%s%s\t",
1374                              (iw & 0x00100000)? "mrc" : "mcr", condition);                              (iw & 0x00100000)? "mrc" : "mcr", condition);
# Line 1157  void arm_mcr_mrc(struct cpu *cpu, uint32 Line 1425  void arm_mcr_mrc(struct cpu *cpu, uint32
1425                  cpu->cd.arm.coproc[cp_num](cpu, opcode1, opcode2, l_bit,                  cpu->cd.arm.coproc[cp_num](cpu, opcode1, opcode2, l_bit,
1426                      crn, crm, rd);                      crn, crm, rd);
1427          else {          else {
1428                  fatal("arm_mcr_mrc: pc=0x%08x, iword=0x%08x: "                  fatal("[ arm_mcr_mrc: pc=0x%08x, iword=0x%08x: "
1429                      "cp_num=%i\n", (int)cpu->pc, iword, cp_num);                      "cp_num=%i ]\n", (int)cpu->pc, iword, cp_num);
1430                  exit(1);                  arm_exception(cpu, ARM_EXCEPTION_UND);
1431                    /*  exit(1);  */
1432          }          }
1433  }  }
1434    
# Line 1174  void arm_mcr_mrc(struct cpu *cpu, uint32 Line 1443  void arm_mcr_mrc(struct cpu *cpu, uint32
1443   */   */
1444  void arm_cdp(struct cpu *cpu, uint32_t iword)  void arm_cdp(struct cpu *cpu, uint32_t iword)
1445  {  {
1446          fatal("arm_cdp: pc=0x%08x, iword=0x%08x\n", (int)cpu->pc, iword);          fatal("[ arm_cdp: pc=0x%08x, iword=0x%08x ]\n", (int)cpu->pc, iword);
1447          exit(1);          arm_exception(cpu, ARM_EXCEPTION_UND);
1448            /*  exit(1);  */
1449  }  }
1450    
1451    

Legend:
Removed from v.16  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26