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: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_avr.c,v 1.18 2006/06/16 18:31:25 debug Exp $ |
* $Id: cpu_avr.c,v 1.22 2006/12/30 13:30:53 debug Exp $ |
29 |
* |
* |
30 |
* Atmel AVR (8-bit) CPU emulation. |
* Atmel AVR (8-bit) CPU emulation. |
31 |
*/ |
*/ |
39 |
#include "machine.h" |
#include "machine.h" |
40 |
#include "memory.h" |
#include "memory.h" |
41 |
#include "misc.h" |
#include "misc.h" |
42 |
|
#include "settings.h" |
43 |
#include "symbol.h" |
#include "symbol.h" |
44 |
|
|
45 |
|
|
59 |
int avr_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, |
int avr_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, |
60 |
int cpu_id, char *cpu_type_name) |
int cpu_id, char *cpu_type_name) |
61 |
{ |
{ |
62 |
int type = 0; |
int type = 0, i; |
63 |
|
|
64 |
if (strcasecmp(cpu_type_name, "AVR") == 0 || |
if (strcasecmp(cpu_type_name, "AVR") == 0 || |
65 |
strcasecmp(cpu_type_name, "AVR16") == 0 || |
strcasecmp(cpu_type_name, "AVR16") == 0 || |
72 |
if (type == 0) |
if (type == 0) |
73 |
return 0; |
return 0; |
74 |
|
|
75 |
|
cpu->run_instr = avr_run_instr; |
76 |
cpu->memory_rw = avr_memory_rw; |
cpu->memory_rw = avr_memory_rw; |
77 |
cpu->update_translation_table = avr_update_translation_table; |
cpu->update_translation_table = avr_update_translation_table; |
78 |
cpu->invalidate_translation_caches = |
cpu->invalidate_translation_caches = |
93 |
debug("%s", cpu->name); |
debug("%s", cpu->name); |
94 |
} |
} |
95 |
|
|
96 |
|
CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc); |
97 |
|
CPU_SETTINGS_ADD_REGISTER16("sp", cpu->cd.avr.sp); |
98 |
|
CPU_SETTINGS_ADD_REGISTER8("sreg", cpu->cd.avr.sreg); |
99 |
|
for (i=0; i<N_AVR_REGS; i++) { |
100 |
|
char tmpstr[5]; |
101 |
|
snprintf(tmpstr, sizeof(tmpstr), "r%i", i); |
102 |
|
CPU_SETTINGS_ADD_REGISTER8(tmpstr, cpu->cd.avr.r[i]); |
103 |
|
} |
104 |
|
|
105 |
return 1; |
return 1; |
106 |
} |
} |
107 |
|
|
165 |
int r = (i >> 3) + ((i & 7) << 2); |
int r = (i >> 3) + ((i & 7) << 2); |
166 |
if ((i % 8) == 0) |
if ((i % 8) == 0) |
167 |
debug("cpu%i:", x); |
debug("cpu%i:", x); |
168 |
debug(" r%02i=0x%02x", r, cpu->cd.avr.r[r]); |
debug(" r%-2i=0x%02x", r, cpu->cd.avr.r[r]); |
169 |
if ((i % 8) == 7) |
if ((i % 8) == 7) |
170 |
debug("\n"); |
debug("\n"); |
171 |
} |
} |
178 |
} |
} |
179 |
|
|
180 |
debug("cpu%i: nr of instructions: %lli\n", x, |
debug("cpu%i: nr of instructions: %lli\n", x, |
181 |
(long long)cpu->machine->ncycles); |
(long long)cpu->machine->ninstrs); |
182 |
debug("cpu%i: nr of cycles: %lli\n", x, |
debug("cpu%i: nr of cycles: %lli\n", x, |
183 |
(long long)(cpu->machine->ncycles + cpu->cd.avr.extra_cycles)); |
(long long)(cpu->machine->ninstrs + cpu->cd.avr.extra_cycles)); |
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* avr_cpu_register_match(): |
|
|
*/ |
|
|
void avr_cpu_register_match(struct machine *m, char *name, |
|
|
int writeflag, uint64_t *valuep, int *match_register) |
|
|
{ |
|
|
int cpunr = 0; |
|
|
|
|
|
/* CPU number: */ |
|
|
/* TODO */ |
|
|
|
|
|
if (strcasecmp(name, "pc") == 0) { |
|
|
if (writeflag) { |
|
|
m->cpus[cpunr]->pc = *valuep; |
|
|
} else |
|
|
*valuep = m->cpus[cpunr]->pc; |
|
|
*match_register = 1; |
|
|
} else if (name[0] == 'r' && isdigit((int)name[1])) { |
|
|
int nr = atoi(name + 1); |
|
|
if (nr >= 0 && nr < N_AVR_REGS) { |
|
|
if (writeflag) |
|
|
m->cpus[cpunr]->cd.avr.r[nr] = *valuep; |
|
|
else |
|
|
*valuep = m->cpus[cpunr]->cd.avr.r[nr]; |
|
|
*match_register = 1; |
|
|
} |
|
|
} |
|
184 |
} |
} |
185 |
|
|
186 |
|
|