1 |
/* |
/* |
2 |
* Copyright (C) 2005 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: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_arm.c,v 1.28 2005/10/07 10:26:03 debug Exp $ |
* $Id: cpu_arm.c,v 1.68 2007/03/26 02:01:35 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> |
42 |
|
|
43 |
#include "arm_cpu_types.h" |
#include "arm_cpu_types.h" |
44 |
#include "cpu.h" |
#include "cpu.h" |
45 |
|
#include "interrupt.h" |
46 |
#include "machine.h" |
#include "machine.h" |
47 |
#include "memory.h" |
#include "memory.h" |
48 |
#include "misc.h" |
#include "misc.h" |
49 |
|
#include "of.h" |
50 |
|
#include "settings.h" |
51 |
#include "symbol.h" |
#include "symbol.h" |
52 |
|
|
53 |
#define DYNTRANS_32 |
#define DYNTRANS_32 |
63 |
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 }; |
64 |
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 }; |
65 |
|
|
66 |
/* Forward reference: */ |
static int arm_exception_to_mode[N_ARM_EXCEPTIONS] = ARM_EXCEPTION_TO_MODE; |
67 |
|
|
68 |
|
/* For quick_pc_to_pointers(): */ |
69 |
void arm_pc_to_pointers(struct cpu *cpu); |
void arm_pc_to_pointers(struct cpu *cpu); |
70 |
|
#include "quick_pc_to_pointers.h" |
71 |
|
|
72 |
|
void arm_irq_interrupt_assert(struct interrupt *interrupt); |
73 |
|
void arm_irq_interrupt_deassert(struct interrupt *interrupt); |
74 |
|
|
75 |
|
|
76 |
/* |
/* |
82 |
int arm_cpu_new(struct cpu *cpu, struct memory *mem, |
int arm_cpu_new(struct cpu *cpu, struct memory *mem, |
83 |
struct machine *machine, int cpu_id, char *cpu_type_name) |
struct machine *machine, int cpu_id, char *cpu_type_name) |
84 |
{ |
{ |
85 |
int any_cache = 0, i, found; |
int i, found; |
86 |
struct arm_cpu_type_def cpu_type_defs[] = ARM_CPU_TYPE_DEFS; |
struct arm_cpu_type_def cpu_type_defs[] = ARM_CPU_TYPE_DEFS; |
87 |
|
|
88 |
/* Scan the list for this cpu type: */ |
/* Scan the list for this cpu type: */ |
97 |
if (found == -1) |
if (found == -1) |
98 |
return 0; |
return 0; |
99 |
|
|
100 |
|
cpu->run_instr = arm_run_instr; |
101 |
cpu->memory_rw = arm_memory_rw; |
cpu->memory_rw = arm_memory_rw; |
102 |
cpu->update_translation_table = arm_update_translation_table; |
cpu->update_translation_table = arm_update_translation_table; |
103 |
cpu->invalidate_translation_caches_paddr = |
cpu->invalidate_translation_caches = |
104 |
arm_invalidate_translation_caches_paddr; |
arm_invalidate_translation_caches; |
105 |
cpu->invalidate_code_translation = arm_invalidate_code_translation; |
cpu->invalidate_code_translation = arm_invalidate_code_translation; |
106 |
cpu->translate_address = arm_translate_address; |
cpu->translate_v2p = arm_translate_v2p; |
107 |
|
|
108 |
cpu->cd.arm.cpu_type = cpu_type_defs[found]; |
cpu->cd.arm.cpu_type = cpu_type_defs[found]; |
109 |
cpu->name = cpu->cd.arm.cpu_type.name; |
cpu->name = cpu->cd.arm.cpu_type.name; |
110 |
cpu->is_32bit = 1; |
cpu->is_32bit = 1; |
111 |
|
cpu->byte_order = EMUL_LITTLE_ENDIAN; |
112 |
|
|
113 |
cpu->cd.arm.cpsr = ARM_FLAG_I | ARM_FLAG_F; |
cpu->cd.arm.cpsr = ARM_FLAG_I | ARM_FLAG_F; |
114 |
cpu->cd.arm.control = ARM_CONTROL_PROG32 | ARM_CONTROL_DATA32 |
cpu->cd.arm.control = ARM_CONTROL_PROG32 | ARM_CONTROL_DATA32 |
115 |
| ARM_CONTROL_CACHE | ARM_CONTROL_ICACHE | ARM_CONTROL_ALIGN; |
| ARM_CONTROL_CACHE | ARM_CONTROL_ICACHE | ARM_CONTROL_ALIGN; |
116 |
|
/* TODO: default auxctrl contents */ |
117 |
|
|
118 |
if (cpu->machine->prom_emulation) { |
if (cpu->machine->prom_emulation) { |
119 |
cpu->cd.arm.cpsr |= ARM_MODE_SVC32; |
cpu->cd.arm.cpsr |= ARM_MODE_SVC32; |
120 |
cpu->cd.arm.control |= ARM_CONTROL_S; |
cpu->cd.arm.control |= ARM_CONTROL_S; |
121 |
} else { |
} else { |
122 |
cpu->cd.arm.cpsr |= ARM_MODE_USR32; |
cpu->cd.arm.cpsr |= ARM_MODE_SVC32; |
123 |
cpu->cd.arm.control |= ARM_CONTROL_S | ARM_CONTROL_R; |
cpu->cd.arm.control |= ARM_CONTROL_R; |
124 |
} |
} |
125 |
|
|
126 |
/* Only show name and caches etc for CPU nr 0: */ |
/* Only show name and caches etc for CPU nr 0: */ |
127 |
if (cpu_id == 0) { |
if (cpu_id == 0) { |
128 |
debug("%s", cpu->name); |
debug("%s", cpu->name); |
129 |
if (cpu->cd.arm.cpu_type.icache_shift != 0) |
if (cpu->cd.arm.cpu_type.icache_shift != 0 || |
130 |
any_cache = 1; |
cpu->cd.arm.cpu_type.dcache_shift != 0) { |
131 |
if (cpu->cd.arm.cpu_type.dcache_shift != 0) |
int isize = cpu->cd.arm.cpu_type.icache_shift; |
132 |
any_cache = 1; |
int dsize = cpu->cd.arm.cpu_type.dcache_shift; |
133 |
if (any_cache) { |
if (isize != 0) |
134 |
debug(" (I+D = %i+%i KB", |
isize = 1 << (isize - 10); |
135 |
(int)(1 << (cpu->cd.arm.cpu_type.icache_shift-10)), |
if (dsize != 0) |
136 |
(int)(1 << (cpu->cd.arm.cpu_type.dcache_shift-10))); |
dsize = 1 << (dsize - 10); |
137 |
debug(")"); |
debug(" (I+D = %i+%i KB)", isize, dsize); |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
141 |
|
/* TODO: Some of these values (iway and dway) aren't used yet: */ |
142 |
|
cpu->cd.arm.cachetype = |
143 |
|
(5 << ARM_CACHETYPE_CLASS_SHIFT) |
144 |
|
| (1 << ARM_CACHETYPE_HARVARD_SHIFT) |
145 |
|
| ((cpu->cd.arm.cpu_type.dcache_shift - 9) << |
146 |
|
ARM_CACHETYPE_DSIZE_SHIFT) |
147 |
|
| (5 << ARM_CACHETYPE_DASSOC_SHIFT) /* 32-way */ |
148 |
|
| (2 << ARM_CACHETYPE_DLINE_SHIFT) /* 8 words/line */ |
149 |
|
| ((cpu->cd.arm.cpu_type.icache_shift - 9) << |
150 |
|
ARM_CACHETYPE_ISIZE_SHIFT) |
151 |
|
| (5 << ARM_CACHETYPE_IASSOC_SHIFT) /* 32-way */ |
152 |
|
| (2 << ARM_CACHETYPE_ILINE_SHIFT); /* 8 words/line */ |
153 |
|
|
154 |
/* Coprocessor 15 = the system control coprocessor. */ |
/* Coprocessor 15 = the system control coprocessor. */ |
155 |
cpu->cd.arm.coproc[15] = arm_coproc_15; |
cpu->cd.arm.coproc[15] = arm_coproc_15; |
156 |
|
|
157 |
|
/* Coprocessor 14 for XScale: */ |
158 |
|
if (cpu->cd.arm.cpu_type.flags & ARM_XSCALE) |
159 |
|
cpu->cd.arm.coproc[14] = arm_coproc_xscale_14; |
160 |
|
|
161 |
/* |
/* |
162 |
* NOTE/TODO: Ugly hack for OpenFirmware emulation: |
* NOTE/TODO: Ugly hack for OpenFirmware emulation: |
163 |
*/ |
*/ |
167 |
store_32bit_word(cpu, cpu->cd.arm.of_emul_addr, 0xef8c64be); |
store_32bit_word(cpu, cpu->cd.arm.of_emul_addr, 0xef8c64be); |
168 |
} |
} |
169 |
|
|
170 |
|
cpu->cd.arm.flags = cpu->cd.arm.cpsr >> 28; |
171 |
|
|
172 |
|
CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc); |
173 |
|
for (i=0; i<N_ARM_REGS - 1; i++) |
174 |
|
CPU_SETTINGS_ADD_REGISTER32(arm_regname[i], cpu->cd.arm.r[i]); |
175 |
|
|
176 |
|
/* Register the CPU's "IRQ" and "FIQ" interrupts: */ |
177 |
|
{ |
178 |
|
struct interrupt template; |
179 |
|
char name[50]; |
180 |
|
snprintf(name, sizeof(name), "%s.irq", cpu->path); |
181 |
|
|
182 |
|
memset(&template, 0, sizeof(template)); |
183 |
|
template.line = 0; |
184 |
|
template.name = name; |
185 |
|
template.extra = cpu; |
186 |
|
template.interrupt_assert = arm_irq_interrupt_assert; |
187 |
|
template.interrupt_deassert = arm_irq_interrupt_deassert; |
188 |
|
interrupt_handler_register(&template); |
189 |
|
|
190 |
|
/* FIQ: TODO */ |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
return 1; |
return 1; |
195 |
} |
} |
196 |
|
|
214 |
} |
} |
215 |
|
|
216 |
cpu->cd.arm.control |= ARM_CONTROL_MMU; |
cpu->cd.arm.control |= ARM_CONTROL_MMU; |
217 |
|
cpu->translate_v2p = arm_translate_v2p_mmu; |
218 |
cpu->cd.arm.dacr |= 0x00000003; |
cpu->cd.arm.dacr |= 0x00000003; |
219 |
cpu->cd.arm.ttb = ttb_addr; |
cpu->cd.arm.ttb = ttb_addr; |
220 |
|
|
227 |
uint32_t addr = cpu->cd.arm.ttb + |
uint32_t addr = cpu->cd.arm.ttb + |
228 |
(((j << 28) + (i << 20)) >> 18); |
(((j << 28) + (i << 20)) >> 18); |
229 |
uint32_t d = (1048576*i) | 0xc02; |
uint32_t d = (1048576*i) | 0xc02; |
230 |
|
|
231 |
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
232 |
|
descr[0] = d; descr[1] = d >> 8; |
233 |
|
descr[2] = d >> 16; descr[3] = d >> 24; |
234 |
|
} else { |
235 |
|
descr[3] = d; descr[2] = d >> 8; |
236 |
|
descr[1] = d >> 16; descr[0] = d >> 24; |
237 |
|
} |
238 |
|
cpu->memory_rw(cpu, cpu->mem, addr, &descr[0], |
239 |
|
sizeof(descr), MEM_WRITE, PHYSICAL | NO_EXCEPTIONS); |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
/* |
245 |
|
* arm_translation_table_set_l1(): |
246 |
|
*/ |
247 |
|
void arm_translation_table_set_l1(struct cpu *cpu, uint32_t vaddr, |
248 |
|
uint32_t paddr) |
249 |
|
{ |
250 |
|
unsigned int i, j, vhigh = vaddr >> 28, phigh = paddr >> 28; |
251 |
|
|
252 |
|
for (i=0; i<256; i++) |
253 |
|
for (j=vhigh; j<=vhigh; j++) { |
254 |
|
unsigned char descr[4]; |
255 |
|
uint32_t addr = cpu->cd.arm.ttb + |
256 |
|
(((j << 28) + (i << 20)) >> 18); |
257 |
|
uint32_t d = ((phigh << 28) + 1048576*i) | 0xc02; |
258 |
|
|
259 |
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
260 |
|
descr[0] = d; descr[1] = d >> 8; |
261 |
|
descr[2] = d >> 16; descr[3] = d >> 24; |
262 |
|
} else { |
263 |
|
descr[3] = d; descr[2] = d >> 8; |
264 |
|
descr[1] = d >> 16; descr[0] = d >> 24; |
265 |
|
} |
266 |
|
cpu->memory_rw(cpu, cpu->mem, addr, &descr[0], |
267 |
|
sizeof(descr), MEM_WRITE, PHYSICAL | NO_EXCEPTIONS); |
268 |
|
} |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
/* |
/* |
273 |
d = (1048576 * (i + (j==12? 10 : j)*256)) | 2; |
* arm_translation_table_set_l1_b(): |
274 |
*/ |
*/ |
275 |
|
void arm_translation_table_set_l1_b(struct cpu *cpu, uint32_t vaddr, |
276 |
|
uint32_t paddr) |
277 |
|
{ |
278 |
|
unsigned int i, j, vhigh = vaddr >> 24, phigh = paddr >> 24; |
279 |
|
|
280 |
|
for (i=0; i<16; i++) |
281 |
|
for (j=vhigh; j<=vhigh; j++) { |
282 |
|
unsigned char descr[4]; |
283 |
|
uint32_t addr = cpu->cd.arm.ttb + |
284 |
|
(((j << 24) + (i << 20)) >> 18); |
285 |
|
uint32_t d = ((phigh << 24) + 1048576*i) | 0xc02; |
286 |
|
|
287 |
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
288 |
descr[0] = d; descr[1] = d >> 8; |
descr[0] = d; descr[1] = d >> 8; |
289 |
descr[2] = d >> 16; descr[3] = d >> 24; |
descr[2] = d >> 16; descr[3] = d >> 24; |
332 |
|
|
333 |
|
|
334 |
/* |
/* |
|
* 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; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
335 |
* arm_cpu_register_dump(): |
* arm_cpu_register_dump(): |
336 |
* |
* |
337 |
* Dump cpu registers in a relatively readable format. |
* Dump cpu registers in a relatively readable format. |
346 |
int mode = cpu->cd.arm.cpsr & ARM_FLAG_MODE; |
int mode = cpu->cd.arm.cpsr & ARM_FLAG_MODE; |
347 |
int i, x = cpu->cpu_id; |
int i, x = cpu->cpu_id; |
348 |
|
|
349 |
|
cpu->cd.arm.cpsr &= 0x0fffffff; |
350 |
|
cpu->cd.arm.cpsr |= (cpu->cd.arm.flags << 28); |
351 |
|
|
352 |
if (gprs) { |
if (gprs) { |
353 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
354 |
cpu->cd.arm.r[ARM_PC], &offset); |
cpu->pc, &offset); |
355 |
debug("cpu%i: cpsr = ", x); |
debug("cpu%i: cpsr = ", x); |
356 |
debug("%s%s%s%s%s%s", |
debug("%s%s%s%s%s%s", |
357 |
(cpu->cd.arm.cpsr & ARM_FLAG_N)? "N" : "n", |
(cpu->cd.arm.cpsr & ARM_FLAG_N)? "N" : "n", |
361 |
(cpu->cd.arm.cpsr & ARM_FLAG_I)? "I" : "i", |
(cpu->cd.arm.cpsr & ARM_FLAG_I)? "I" : "i", |
362 |
(cpu->cd.arm.cpsr & ARM_FLAG_F)? "F" : "f"); |
(cpu->cd.arm.cpsr & ARM_FLAG_F)? "F" : "f"); |
363 |
if (mode < ARM_MODE_USR32) |
if (mode < ARM_MODE_USR32) |
364 |
debug(" pc = 0x%07x", |
debug(" pc = 0x%07x", (int)(cpu->pc & 0x03ffffff)); |
|
(int)(cpu->cd.arm.r[ARM_PC] & 0x03ffffff)); |
|
365 |
else |
else |
366 |
debug(" pc = 0x%08x", (int)cpu->cd.arm.r[ARM_PC]); |
debug(" pc = 0x%08x", (int)cpu->pc); |
367 |
|
|
368 |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
369 |
|
|
400 |
} |
} |
401 |
|
|
402 |
if (m != ARM_MODE_USR32 && m != ARM_MODE_SYS32) { |
if (m != ARM_MODE_USR32 && m != ARM_MODE_SYS32) { |
403 |
debug("cpu%i: usr r8..r14 =", x); |
debug("cpu%i: usr r8-14:", x); |
404 |
for (i=0; i<7; i++) |
for (i=0; i<7; i++) |
405 |
debug(" %08x", cpu->cd.arm.default_r8_r14[i]); |
debug(" %08x", cpu->cd.arm.default_r8_r14[i]); |
406 |
debug("\n"); |
debug("\n"); |
407 |
} |
} |
408 |
|
|
409 |
if (m != ARM_MODE_FIQ32) { |
if (m != ARM_MODE_FIQ32) { |
410 |
debug("cpu%i: fiq r8..r14 =", x); |
debug("cpu%i: fiq r8-14:", x); |
411 |
for (i=0; i<7; i++) |
for (i=0; i<7; i++) |
412 |
debug(" %08x", cpu->cd.arm.fiq_r8_r14[i]); |
debug(" %08x", cpu->cd.arm.fiq_r8_r14[i]); |
413 |
debug("\n"); |
debug("\n"); |
414 |
} |
} |
415 |
|
|
416 |
if (m != ARM_MODE_IRQ32) { |
if (m != ARM_MODE_IRQ32) { |
417 |
debug("cpu%i: irq r13..r14 =", x); |
debug("cpu%i: irq r13-14:", x); |
418 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
419 |
debug(" %08x", cpu->cd.arm.irq_r13_r14[i]); |
debug(" %08x", cpu->cd.arm.irq_r13_r14[i]); |
420 |
debug("\n"); |
debug("\n"); |
421 |
} |
} |
422 |
|
|
423 |
if (m != ARM_MODE_SVC32) { |
if (m != ARM_MODE_SVC32) { |
424 |
debug("cpu%i: svc r13..r14 =", x); |
debug("cpu%i: svc r13-14:", x); |
425 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
426 |
debug(" %08x", cpu->cd.arm.svc_r13_r14[i]); |
debug(" %08x", cpu->cd.arm.svc_r13_r14[i]); |
427 |
debug("\n"); |
debug("\n"); |
428 |
} |
} |
429 |
|
|
430 |
if (m != ARM_MODE_ABT32) { |
if (m != ARM_MODE_ABT32) { |
431 |
debug("cpu%i: abt r13..r14 =", x); |
debug("cpu%i: abt r13-14:", x); |
432 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
433 |
debug(" %08x", cpu->cd.arm.abt_r13_r14[i]); |
debug(" %08x", cpu->cd.arm.abt_r13_r14[i]); |
434 |
debug("\n"); |
debug("\n"); |
435 |
} |
} |
436 |
|
|
437 |
if (m != ARM_MODE_UND32) { |
if (m != ARM_MODE_UND32) { |
438 |
debug("cpu%i: und r13..r14 =", x); |
debug("cpu%i: und r13-14:", x); |
439 |
for (i=0; i<2; i++) |
for (i=0; i<2; i++) |
440 |
debug(" %08x", cpu->cd.arm.und_r13_r14[i]); |
debug(" %08x", cpu->cd.arm.und_r13_r14[i]); |
441 |
debug("\n"); |
debug("\n"); |
472 |
cpu->cd.arm.control & |
cpu->cd.arm.control & |
473 |
ARM_CONTROL_V? "yes (0xffff0000)" : "no"); |
ARM_CONTROL_V? "yes (0xffff0000)" : "no"); |
474 |
|
|
475 |
|
/* TODO: auxctrl on which CPU types? */ |
476 |
|
if (cpu->cd.arm.cpu_type.flags & ARM_XSCALE) { |
477 |
|
debug("cpu%i: auxctrl = 0x%08x\n", x, |
478 |
|
cpu->cd.arm.auxctrl); |
479 |
|
debug("cpu%i: minidata cache attr = 0x%x\n", x, |
480 |
|
(cpu->cd.arm.auxctrl & ARM_AUXCTRL_MD) |
481 |
|
>> ARM_AUXCTRL_MD_SHIFT); |
482 |
|
debug("cpu%i: page table memory attr: %i\n", x, |
483 |
|
(cpu->cd.arm.auxctrl & ARM_AUXCTRL_P)? 1 : 0); |
484 |
|
debug("cpu%i: write buffer coalescing: %s\n", x, |
485 |
|
(cpu->cd.arm.auxctrl & ARM_AUXCTRL_K)? |
486 |
|
"disabled" : "enabled"); |
487 |
|
} |
488 |
|
|
489 |
debug("cpu%i: ttb = 0x%08x dacr = 0x%08x\n", x, |
debug("cpu%i: ttb = 0x%08x dacr = 0x%08x\n", x, |
490 |
cpu->cd.arm.ttb, cpu->cd.arm.dacr); |
cpu->cd.arm.ttb, cpu->cd.arm.dacr); |
491 |
debug("cpu%i: fsr = 0x%08x far = 0x%08x\n", x, |
debug("cpu%i: fsr = 0x%08x far = 0x%08x\n", x, |
495 |
|
|
496 |
|
|
497 |
/* |
/* |
|
* 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"); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
498 |
* arm_save_register_bank(): |
* arm_save_register_bank(): |
499 |
*/ |
*/ |
500 |
void arm_save_register_bank(struct cpu *cpu) |
void arm_save_register_bank(struct cpu *cpu) |
511 |
&cpu->cd.arm.r[8], sizeof(uint32_t) * 7); |
&cpu->cd.arm.r[8], sizeof(uint32_t) * 7); |
512 |
break; |
break; |
513 |
case ARM_MODE_IRQ32: |
case ARM_MODE_IRQ32: |
514 |
|
memcpy(cpu->cd.arm.default_r8_r14, |
515 |
|
&cpu->cd.arm.r[8], sizeof(uint32_t) * 5); |
516 |
cpu->cd.arm.irq_r13_r14[0] = cpu->cd.arm.r[13]; |
cpu->cd.arm.irq_r13_r14[0] = cpu->cd.arm.r[13]; |
517 |
cpu->cd.arm.irq_r13_r14[1] = cpu->cd.arm.r[14]; |
cpu->cd.arm.irq_r13_r14[1] = cpu->cd.arm.r[14]; |
518 |
break; |
break; |
519 |
case ARM_MODE_SVC32: |
case ARM_MODE_SVC32: |
520 |
if ((cpu->cd.arm.r[13] & 0xffff0000) == 0xffff0000) { |
memcpy(cpu->cd.arm.default_r8_r14, |
521 |
fatal("NEJ! pc=0x%08x\n", (int)cpu->pc); |
&cpu->cd.arm.r[8], sizeof(uint32_t) * 5); |
|
exit(1); |
|
|
} |
|
522 |
cpu->cd.arm.svc_r13_r14[0] = cpu->cd.arm.r[13]; |
cpu->cd.arm.svc_r13_r14[0] = cpu->cd.arm.r[13]; |
523 |
cpu->cd.arm.svc_r13_r14[1] = cpu->cd.arm.r[14]; |
cpu->cd.arm.svc_r13_r14[1] = cpu->cd.arm.r[14]; |
524 |
break; |
break; |
525 |
case ARM_MODE_ABT32: |
case ARM_MODE_ABT32: |
526 |
|
memcpy(cpu->cd.arm.default_r8_r14, |
527 |
|
&cpu->cd.arm.r[8], sizeof(uint32_t) * 5); |
528 |
cpu->cd.arm.abt_r13_r14[0] = cpu->cd.arm.r[13]; |
cpu->cd.arm.abt_r13_r14[0] = cpu->cd.arm.r[13]; |
529 |
cpu->cd.arm.abt_r13_r14[1] = cpu->cd.arm.r[14]; |
cpu->cd.arm.abt_r13_r14[1] = cpu->cd.arm.r[14]; |
530 |
break; |
break; |
531 |
case ARM_MODE_UND32: |
case ARM_MODE_UND32: |
532 |
|
memcpy(cpu->cd.arm.default_r8_r14, |
533 |
|
&cpu->cd.arm.r[8], sizeof(uint32_t) * 5); |
534 |
cpu->cd.arm.und_r13_r14[0] = cpu->cd.arm.r[13]; |
cpu->cd.arm.und_r13_r14[0] = cpu->cd.arm.r[13]; |
535 |
cpu->cd.arm.und_r13_r14[1] = cpu->cd.arm.r[14]; |
cpu->cd.arm.und_r13_r14[1] = cpu->cd.arm.r[14]; |
536 |
break; |
break; |
558 |
sizeof(uint32_t) * 7); |
sizeof(uint32_t) * 7); |
559 |
break; |
break; |
560 |
case ARM_MODE_IRQ32: |
case ARM_MODE_IRQ32: |
561 |
|
memcpy(&cpu->cd.arm.r[8], |
562 |
|
cpu->cd.arm.default_r8_r14, sizeof(uint32_t) * 5); |
563 |
cpu->cd.arm.r[13] = cpu->cd.arm.irq_r13_r14[0]; |
cpu->cd.arm.r[13] = cpu->cd.arm.irq_r13_r14[0]; |
564 |
cpu->cd.arm.r[14] = cpu->cd.arm.irq_r13_r14[1]; |
cpu->cd.arm.r[14] = cpu->cd.arm.irq_r13_r14[1]; |
565 |
break; |
break; |
566 |
case ARM_MODE_SVC32: |
case ARM_MODE_SVC32: |
567 |
|
memcpy(&cpu->cd.arm.r[8], |
568 |
|
cpu->cd.arm.default_r8_r14, sizeof(uint32_t) * 5); |
569 |
cpu->cd.arm.r[13] = cpu->cd.arm.svc_r13_r14[0]; |
cpu->cd.arm.r[13] = cpu->cd.arm.svc_r13_r14[0]; |
570 |
cpu->cd.arm.r[14] = cpu->cd.arm.svc_r13_r14[1]; |
cpu->cd.arm.r[14] = cpu->cd.arm.svc_r13_r14[1]; |
571 |
break; |
break; |
572 |
case ARM_MODE_ABT32: |
case ARM_MODE_ABT32: |
573 |
|
memcpy(&cpu->cd.arm.r[8], |
574 |
|
cpu->cd.arm.default_r8_r14, sizeof(uint32_t) * 5); |
575 |
cpu->cd.arm.r[13] = cpu->cd.arm.abt_r13_r14[0]; |
cpu->cd.arm.r[13] = cpu->cd.arm.abt_r13_r14[0]; |
576 |
cpu->cd.arm.r[14] = cpu->cd.arm.abt_r13_r14[1]; |
cpu->cd.arm.r[14] = cpu->cd.arm.abt_r13_r14[1]; |
577 |
break; |
break; |
578 |
case ARM_MODE_UND32: |
case ARM_MODE_UND32: |
579 |
|
memcpy(&cpu->cd.arm.r[8], |
580 |
|
cpu->cd.arm.default_r8_r14, sizeof(uint32_t) * 5); |
581 |
cpu->cd.arm.r[13] = cpu->cd.arm.und_r13_r14[0]; |
cpu->cd.arm.r[13] = cpu->cd.arm.und_r13_r14[0]; |
582 |
cpu->cd.arm.r[14] = cpu->cd.arm.und_r13_r14[1]; |
cpu->cd.arm.r[14] = cpu->cd.arm.und_r13_r14[1]; |
583 |
break; |
break; |
593 |
*/ |
*/ |
594 |
void arm_exception(struct cpu *cpu, int exception_nr) |
void arm_exception(struct cpu *cpu, int exception_nr) |
595 |
{ |
{ |
|
int arm_exception_to_mode[N_ARM_EXCEPTIONS] = ARM_EXCEPTION_TO_MODE; |
|
596 |
int oldmode, newmode; |
int oldmode, newmode; |
597 |
uint32_t retaddr; |
uint32_t retaddr; |
598 |
|
|
603 |
|
|
604 |
retaddr = cpu->pc; |
retaddr = cpu->pc; |
605 |
|
|
606 |
debug("[ arm_exception(): "); |
if (!quiet_mode) { |
607 |
|
debug("[ arm_exception(): "); |
608 |
|
switch (exception_nr) { |
609 |
|
case ARM_EXCEPTION_RESET: |
610 |
|
fatal("RESET: TODO"); |
611 |
|
break; |
612 |
|
case ARM_EXCEPTION_UND: |
613 |
|
debug("UNDEFINED"); |
614 |
|
break; |
615 |
|
case ARM_EXCEPTION_SWI: |
616 |
|
debug("SWI"); |
617 |
|
break; |
618 |
|
case ARM_EXCEPTION_PREF_ABT: |
619 |
|
debug("PREFETCH ABORT"); |
620 |
|
break; |
621 |
|
case ARM_EXCEPTION_IRQ: |
622 |
|
debug("IRQ"); |
623 |
|
break; |
624 |
|
case ARM_EXCEPTION_FIQ: |
625 |
|
debug("FIQ"); |
626 |
|
break; |
627 |
|
case ARM_EXCEPTION_DATA_ABT: |
628 |
|
debug("DATA ABORT, far=0x%08x fsr=0x%02x", |
629 |
|
cpu->cd.arm.far, cpu->cd.arm.fsr); |
630 |
|
break; |
631 |
|
} |
632 |
|
debug(" ]\n"); |
633 |
|
} |
634 |
|
|
635 |
switch (exception_nr) { |
switch (exception_nr) { |
636 |
case ARM_EXCEPTION_RESET: |
case ARM_EXCEPTION_RESET: |
637 |
cpu->running = 0; |
cpu->running = 0; |
638 |
fatal("RESET: TODO"); |
fatal("ARM RESET: TODO"); |
639 |
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; |
|
640 |
case ARM_EXCEPTION_DATA_ABT: |
case ARM_EXCEPTION_DATA_ABT: |
641 |
debug("DATA ABORT, far=0x%08x fsr=0x%02x", |
retaddr += 4; |
|
cpu->cd.arm.far, cpu->cd.arm.fsr); |
|
|
retaddr += 8; |
|
642 |
break; |
break; |
643 |
} |
} |
644 |
|
|
645 |
debug(" ]\n"); |
retaddr += 4; |
646 |
|
|
647 |
arm_save_register_bank(cpu); |
arm_save_register_bank(cpu); |
648 |
|
|
649 |
|
cpu->cd.arm.cpsr &= 0x0fffffff; |
650 |
|
cpu->cd.arm.cpsr |= (cpu->cd.arm.flags << 28); |
651 |
|
|
652 |
switch (arm_exception_to_mode[exception_nr]) { |
switch (arm_exception_to_mode[exception_nr]) { |
653 |
case ARM_MODE_SVC32: |
case ARM_MODE_SVC32: |
654 |
cpu->cd.arm.spsr_svc = cpu->cd.arm.cpsr; break; |
cpu->cd.arm.spsr_svc = cpu->cd.arm.cpsr; break; |
675 |
cpu->cd.arm.cpsr &= ~ARM_FLAG_MODE; |
cpu->cd.arm.cpsr &= ~ARM_FLAG_MODE; |
676 |
cpu->cd.arm.cpsr |= arm_exception_to_mode[exception_nr]; |
cpu->cd.arm.cpsr |= arm_exception_to_mode[exception_nr]; |
677 |
|
|
678 |
|
/* |
679 |
|
* Usually, an exception should change modes (so that saved status |
680 |
|
* bits don't get lost). However, Linux on ARM seems to use floating |
681 |
|
* point instructions in the kernel (!), and it emulates those using |
682 |
|
* its own fp emulation code. This leads to a situation where we |
683 |
|
* sometimes change from SVC32 to SVC32. |
684 |
|
*/ |
685 |
newmode = cpu->cd.arm.cpsr & ARM_FLAG_MODE; |
newmode = cpu->cd.arm.cpsr & ARM_FLAG_MODE; |
686 |
if (oldmode == newmode) { |
if (oldmode == newmode && oldmode != ARM_MODE_SVC32) { |
687 |
fatal("Exception caused no mode change? TODO\n"); |
fatal("[ WARNING! Exception caused no mode change? " |
688 |
exit(1); |
"mode 0x%02x (pc=0x%x) ]\n", newmode, (int)cpu->pc); |
689 |
|
/* exit(1); */ |
690 |
} |
} |
691 |
|
|
692 |
cpu->cd.arm.cpsr |= ARM_FLAG_I; |
cpu->cd.arm.cpsr |= ARM_FLAG_I; |
697 |
/* Load the new register bank, if we switched: */ |
/* Load the new register bank, if we switched: */ |
698 |
arm_load_register_bank(cpu); |
arm_load_register_bank(cpu); |
699 |
|
|
700 |
/* Set the return address and new PC: */ |
/* |
701 |
|
* Set the return address and new PC. |
702 |
|
* |
703 |
|
* NOTE: r[ARM_PC] is also set; see cpu_arm_instr_loadstore.c for |
704 |
|
* details. (If an exception occurs during a load into the pc |
705 |
|
* register, the code in that file assumes that the r[ARM_PC] |
706 |
|
* was changed to the address of the exception handler.) |
707 |
|
*/ |
708 |
cpu->cd.arm.r[ARM_LR] = retaddr; |
cpu->cd.arm.r[ARM_LR] = retaddr; |
|
|
|
709 |
cpu->pc = cpu->cd.arm.r[ARM_PC] = exception_nr * 4 + |
cpu->pc = cpu->cd.arm.r[ARM_PC] = exception_nr * 4 + |
710 |
((cpu->cd.arm.control & ARM_CONTROL_V)? 0xffff0000 : 0); |
((cpu->cd.arm.control & ARM_CONTROL_V)? 0xffff0000 : 0); |
711 |
arm_pc_to_pointers(cpu); |
quick_pc_to_pointers(cpu); |
712 |
} |
} |
713 |
|
|
714 |
|
|
715 |
/* |
/* |
716 |
* arm_cpu_interrupt(): |
* arm_cpu_tlbdump(): |
717 |
* |
* |
718 |
* 0..31 are used as footbridge interrupt numbers, 32..47 = ISA, |
* Called from the debugger to dump the TLB in a readable format. |
719 |
* 64 is used as a "re-assert" signal to cpu->machine->md_interrupt(). |
* x is the cpu number to dump, or -1 to dump all CPUs. |
720 |
* |
* |
721 |
* TODO: don't hardcode to footbridge! |
* If rawflag is nonzero, then the TLB contents isn't formated nicely, |
722 |
|
* just dumped. |
723 |
*/ |
*/ |
724 |
int arm_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
void arm_cpu_tlbdump(struct machine *m, int x, int rawflag) |
725 |
{ |
{ |
|
/* fatal("arm_cpu_interrupt(): 0x%llx\n", (int)irq_nr); */ |
|
|
if (irq_nr <= 64) { |
|
|
if (cpu->machine->md_interrupt != NULL) |
|
|
cpu->machine->md_interrupt(cpu->machine, |
|
|
cpu, irq_nr, 1); |
|
|
else |
|
|
fatal("arm_cpu_interrupt(): md_interrupt == NULL\n"); |
|
|
} else { |
|
|
/* Assert ARM IRQs: */ |
|
|
cpu->cd.arm.irq_asserted = 1; |
|
|
} |
|
|
|
|
|
return 1; |
|
726 |
} |
} |
727 |
|
|
728 |
|
|
729 |
/* |
/* |
730 |
* arm_cpu_interrupt_ack(): |
* arm_irq_interrupt_assert(): |
731 |
|
* arm_irq_interrupt_deassert(): |
732 |
*/ |
*/ |
733 |
int arm_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
void arm_irq_interrupt_assert(struct interrupt *interrupt) |
734 |
{ |
{ |
735 |
if (irq_nr <= 64) { |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
736 |
if (cpu->machine->md_interrupt != NULL) |
cpu->cd.arm.irq_asserted = 1; |
737 |
cpu->machine->md_interrupt(cpu->machine, |
} |
738 |
cpu, irq_nr, 0); |
void arm_irq_interrupt_deassert(struct interrupt *interrupt) |
739 |
} else { |
{ |
740 |
/* De-assert ARM IRQs: */ |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
741 |
cpu->cd.arm.irq_asserted = 0; |
cpu->cd.arm.irq_asserted = 0; |
|
} |
|
|
|
|
|
return 1; |
|
742 |
} |
} |
743 |
|
|
744 |
|
|
755 |
* cpu->pc for relative addresses. |
* cpu->pc for relative addresses. |
756 |
*/ |
*/ |
757 |
int arm_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
int arm_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
758 |
int running, uint64_t dumpaddr, int bintrans) |
int running, uint64_t dumpaddr) |
759 |
{ |
{ |
760 |
uint32_t iw, tmp; |
uint32_t iw, tmp; |
761 |
int main_opcode, secondary_opcode, s_bit, r16, r12, r8; |
int main_opcode, secondary_opcode, s_bit, r16, r12, r8; |
828 |
int a_bit = (iw >> 21) & 1; |
int a_bit = (iw >> 21) & 1; |
829 |
debug("%s%sl%s%s\t", u_bit? "s" : "u", |
debug("%s%sl%s%s\t", u_bit? "s" : "u", |
830 |
a_bit? "mla" : "mul", condition, s_bit? "s" : ""); |
a_bit? "mla" : "mul", condition, s_bit? "s" : ""); |
831 |
debug("%s,", arm_regname[r12]); |
debug("%s,%s,", arm_regname[r12], arm_regname[r16]); |
832 |
debug("%s,", arm_regname[r16]); |
debug("%s,%s\n", arm_regname[iw&15], arm_regname[r8]); |
833 |
debug("%s,", arm_regname[iw & 15]); |
break; |
834 |
debug("%s\n", arm_regname[r8]); |
} |
835 |
|
|
836 |
|
/* |
837 |
|
* xxxx0001 0000nnnn dddd0000 0101mmmm qadd Rd,Rm,Rn |
838 |
|
* xxxx0001 0010nnnn dddd0000 0101mmmm qsub Rd,Rm,Rn |
839 |
|
* xxxx0001 0100nnnn dddd0000 0101mmmm qdadd Rd,Rm,Rn |
840 |
|
* xxxx0001 0110nnnn dddd0000 0101mmmm qdsub Rd,Rm,Rn |
841 |
|
*/ |
842 |
|
if ((iw & 0x0f900ff0) == 0x01000050) { |
843 |
|
debug("q%s%s%s\t", iw & 0x400000? "d" : "", |
844 |
|
iw & 0x200000? "sub" : "add", condition); |
845 |
|
debug("%s,%s,%s\n", arm_regname[r12], |
846 |
|
arm_regname[iw&15], arm_regname[r16]); |
847 |
break; |
break; |
848 |
} |
} |
849 |
|
|
901 |
} |
} |
902 |
|
|
903 |
/* |
/* |
904 |
|
* xxxx0001 01101111 dddd1111 0001mmmm CLZ Rd,Rm |
905 |
|
*/ |
906 |
|
if ((iw & 0x0fff0ff0) == 0x016f0f10) { |
907 |
|
debug("clz%s\t", condition); |
908 |
|
debug("%s,%s\n", arm_regname[r12], arm_regname[iw&15]); |
909 |
|
break; |
910 |
|
} |
911 |
|
|
912 |
|
/* |
913 |
|
* xxxx0001 0000dddd nnnnssss 1yx0mmmm SMLAxy Rd,Rm,Rs,Rn |
914 |
|
* xxxx0001 0100dddd DDDDssss 1yx0mmmm SMLALxy RdL,RdH,Rm,Rs |
915 |
|
* xxxx0001 0010dddd nnnnssss 1y00mmmm SMLAWy Rd,Rm,Rs,Rn |
916 |
|
* xxxx0001 0110dddd 0000ssss 1yx0mmmm SMULxy Rd,Rm,Rs |
917 |
|
* xxxx0001 0010dddd 0000ssss 1y10mmmm SMULWy Rd,Rm,Rs |
918 |
|
*/ |
919 |
|
if ((iw & 0x0ff00090) == 0x01000080) { |
920 |
|
debug("smla%s%s%s\t", |
921 |
|
iw & 0x20? "t" : "b", iw & 0x40? "t" : "b", |
922 |
|
condition); |
923 |
|
debug("%s,%s,%s,%s\n", arm_regname[r16], |
924 |
|
arm_regname[iw&15], arm_regname[r8], |
925 |
|
arm_regname[r12]); |
926 |
|
break; |
927 |
|
} |
928 |
|
if ((iw & 0x0ff00090) == 0x01400080) { |
929 |
|
debug("smlal%s%s%s\t", |
930 |
|
iw & 0x20? "t" : "b", iw & 0x40? "t" : "b", |
931 |
|
condition); |
932 |
|
debug("%s,%s,%s,%s\n", arm_regname[r12], |
933 |
|
arm_regname[r16], arm_regname[iw&15], |
934 |
|
arm_regname[r8]); |
935 |
|
break; |
936 |
|
} |
937 |
|
if ((iw & 0x0ff000b0) == 0x01200080) { |
938 |
|
debug("smlaw%s%s\t", iw & 0x40? "t" : "b", |
939 |
|
condition); |
940 |
|
debug("%s,%s,%s,%s\n", arm_regname[r16], |
941 |
|
arm_regname[iw&15], arm_regname[r8], |
942 |
|
arm_regname[r12]); |
943 |
|
break; |
944 |
|
} |
945 |
|
if ((iw & 0x0ff0f090) == 0x01600080) { |
946 |
|
debug("smul%s%s%s\t", |
947 |
|
iw & 0x20? "t" : "b", iw & 0x40? "t" : "b", |
948 |
|
condition); |
949 |
|
debug("%s,%s,%s\n", arm_regname[r16], |
950 |
|
arm_regname[iw&15], arm_regname[r8]); |
951 |
|
break; |
952 |
|
} |
953 |
|
if ((iw & 0x0ff0f0b0) == 0x012000a0) { |
954 |
|
debug("smulw%s%s\t", iw & 0x40? "t" : "b", |
955 |
|
condition); |
956 |
|
debug("%s,%s,%s\n", arm_regname[r16], |
957 |
|
arm_regname[iw&15], arm_regname[r8]); |
958 |
|
break; |
959 |
|
} |
960 |
|
|
961 |
|
/* |
962 |
* xxxx000P U1WLnnnn ddddHHHH 1SH1LLLL load/store rd,imm(rn) |
* xxxx000P U1WLnnnn ddddHHHH 1SH1LLLL load/store rd,imm(rn) |
963 |
*/ |
*/ |
964 |
if ((iw & 0x0e000090) == 0x00000090) { |
if ((iw & 0x0e000090) == 0x00000090) { |
965 |
|
char *op = "st"; |
966 |
int imm = ((iw >> 4) & 0xf0) | (iw & 0xf); |
int imm = ((iw >> 4) & 0xf0) | (iw & 0xf); |
967 |
int regform = !(iw & 0x00400000); |
int regform = !(iw & 0x00400000); |
968 |
p_bit = main_opcode & 1; |
p_bit = main_opcode & 1; |
975 |
break; |
break; |
976 |
} |
} |
977 |
/* Semi-generic case: */ |
/* Semi-generic case: */ |
978 |
debug("%sr%s", iw & 0x00100000? "ld" : "st", |
if (iw & 0x00100000) |
979 |
condition); |
op = "ld"; |
980 |
|
if (!l_bit && (iw & 0xd0) == 0xd0) |
981 |
|
op = iw & 0x20? "st" : "ld"; |
982 |
|
debug("%sr%s", op, condition); |
983 |
if (!l_bit && (iw & 0xd0) == 0xd0) { |
if (!l_bit && (iw & 0xd0) == 0xd0) { |
984 |
debug("d"); /* Double-register */ |
debug("d"); /* Double-register */ |
985 |
} else { |
} else { |
1179 |
} else { |
} else { |
1180 |
tmpw[0] = addr = cpu->cd.arm.r[r12]; |
tmpw[0] = addr = cpu->cd.arm.r[r12]; |
1181 |
if (r12 == ARM_PC) |
if (r12 == ARM_PC) |
1182 |
addr += 8; |
addr = cpu->pc + 8; |
1183 |
} |
} |
1184 |
debug(": "); |
debug(": "); |
1185 |
if (b_bit) |
if (b_bit) |
1243 |
break; |
break; |
1244 |
case 0xc: /* Coprocessor */ |
case 0xc: /* Coprocessor */ |
1245 |
case 0xd: /* LDC/STC */ |
case 0xd: /* LDC/STC */ |
1246 |
|
/* |
1247 |
|
* xxxx1100 0100nnnn ddddcccc oooommmm MCRR c,op,Rd,Rn,CRm |
1248 |
|
* xxxx1100 0101nnnn ddddcccc oooommmm MRRC c,op,Rd,Rn,CRm |
1249 |
|
*/ |
1250 |
|
if ((iw & 0x0fe00fff) == 0x0c400000) { |
1251 |
|
debug("%s%s\t", iw & 0x100000? "mra" : "mar", |
1252 |
|
condition); |
1253 |
|
if (iw & 0x100000) |
1254 |
|
debug("%s,%s,acc0\n", |
1255 |
|
arm_regname[r12], arm_regname[r16]); |
1256 |
|
else |
1257 |
|
debug("acc0,%s,%s\n", |
1258 |
|
arm_regname[r12], arm_regname[r16]); |
1259 |
|
break; |
1260 |
|
} |
1261 |
|
if ((iw & 0x0fe00000) == 0x0c400000) { |
1262 |
|
debug("%s%s\t", iw & 0x100000? "mrrc" : "mcrr", |
1263 |
|
condition); |
1264 |
|
debug("%i,%i,%s,%s,cr%i\n", r8, (iw >> 4) & 15, |
1265 |
|
arm_regname[r12], arm_regname[r16], iw & 15); |
1266 |
|
break; |
1267 |
|
} |
1268 |
|
|
1269 |
/* xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC */ |
/* xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC */ |
1270 |
debug("TODO: coprocessor LDC/STC\n"); |
debug("TODO: coprocessor LDC/STC\n"); |
1271 |
break; |
break; |
1274 |
* xxxx1110 oooonnnn ddddpppp qqq0mmmm CDP |
* xxxx1110 oooonnnn ddddpppp qqq0mmmm CDP |
1275 |
* xxxx1110 oooLNNNN ddddpppp qqq1MMMM MRC/MCR |
* xxxx1110 oooLNNNN ddddpppp qqq1MMMM MRC/MCR |
1276 |
*/ |
*/ |
1277 |
|
if ((iw & 0x0ff00ff0) == 0x0e200010) { |
1278 |
|
/* Special case: mia* DSP instructions */ |
1279 |
|
switch ((iw >> 16) & 0xf) { |
1280 |
|
case 0: debug("mia"); break; |
1281 |
|
case 8: debug("miaph"); break; |
1282 |
|
case 12: debug("miaBB"); break; |
1283 |
|
case 13: debug("miaTB"); break; |
1284 |
|
case 14: debug("miaBT"); break; |
1285 |
|
case 15: debug("miaTT"); break; |
1286 |
|
default: debug("UNKNOWN mia vector instruction?"); |
1287 |
|
} |
1288 |
|
debug("%s\t", condition); |
1289 |
|
debug("acc%i,%s,%s\n", ((iw >> 5) & 7), |
1290 |
|
arm_regname[iw & 15], arm_regname[r12]); |
1291 |
|
break; |
1292 |
|
} |
1293 |
if (iw & 0x10) { |
if (iw & 0x10) { |
1294 |
debug("%s%s\t", |
debug("%s%s\t", |
1295 |
(iw & 0x00100000)? "mrc" : "mcr", condition); |
(iw & 0x00100000)? "mrc" : "mcr", condition); |
1346 |
cpu->cd.arm.coproc[cp_num](cpu, opcode1, opcode2, l_bit, |
cpu->cd.arm.coproc[cp_num](cpu, opcode1, opcode2, l_bit, |
1347 |
crn, crm, rd); |
crn, crm, rd); |
1348 |
else { |
else { |
1349 |
fatal("arm_mcr_mrc: pc=0x%08x, iword=0x%08x: " |
fatal("[ arm_mcr_mrc: pc=0x%08x, iword=0x%08x: " |
1350 |
"cp_num=%i\n", (int)cpu->pc, iword, cp_num); |
"cp_num=%i ]\n", (int)cpu->pc, iword, cp_num); |
1351 |
exit(1); |
arm_exception(cpu, ARM_EXCEPTION_UND); |
1352 |
|
/* exit(1); */ |
1353 |
} |
} |
1354 |
} |
} |
1355 |
|
|
1364 |
*/ |
*/ |
1365 |
void arm_cdp(struct cpu *cpu, uint32_t iword) |
void arm_cdp(struct cpu *cpu, uint32_t iword) |
1366 |
{ |
{ |
1367 |
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); |
1368 |
exit(1); |
arm_exception(cpu, ARM_EXCEPTION_UND); |
1369 |
|
/* exit(1); */ |
1370 |
} |
} |
1371 |
|
|
1372 |
|
|