Skip to content

Commit 5c2bd31

Browse files
committed
AVR: rework ARCH/CPU models.
Separate AVR architectures ("avr5", "avr51", "avr6", etc.) from actual MCU models. Only list the most representative MCU models. Signed-off-by: Glenn Baker <[email protected]>
1 parent 59c1ae7 commit 5c2bd31

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

include/unicorn/avr.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,36 @@ extern "C" {
1717
#pragma warning(disable : 4201)
1818
#endif
1919

20+
//> AVR architectures
21+
typedef enum uc_avr_arch {
22+
UC_AVR_ARCH_AVR1 = 10,
23+
UC_AVR_ARCH_AVR2 = 20,
24+
UC_AVR_ARCH_AVR25 = 25,
25+
UC_AVR_ARCH_AVR3 = 30,
26+
UC_AVR_ARCH_AVR4 = 40,
27+
UC_AVR_ARCH_AVR5 = 50,
28+
UC_AVR_ARCH_AVR51 = 51,
29+
UC_AVR_ARCH_AVR6 = 60,
30+
} uc_avr_arch;
31+
32+
#define UC_CPU_AVR_ARCH 1000
33+
2034
//> AVR CPU
2135
typedef enum uc_cpu_avr {
22-
UC_CPU_AVR_AVR5 = 5,
23-
UC_CPU_AVR_AVR51 = 51,
24-
UC_CPU_AVR_AVR6 = 6,
36+
// Enhanced Core with 16K up to 64K of program memory ("AVR5")
37+
UC_CPU_AVR_ATMEGA16 = UC_AVR_ARCH_AVR5*UC_CPU_AVR_ARCH + 16,
38+
UC_CPU_AVR_ATMEGA32 = UC_AVR_ARCH_AVR5*UC_CPU_AVR_ARCH + 32,
39+
UC_CPU_AVR_ATMEGA64 = UC_AVR_ARCH_AVR5*UC_CPU_AVR_ARCH + 64,
40+
41+
// Enhanced Core with 128K of program memory ("AVR5.1")
42+
UC_CPU_AVR_ATMEGA128 = UC_AVR_ARCH_AVR51*UC_CPU_AVR_ARCH + 128,
43+
UC_CPU_AVR_ATMEGA128RFR2,
44+
UC_CPU_AVR_ATMEGA1280,
45+
46+
// Enhanced Core with 128K+ of program memory, i.e. 3-byte PC ("AVR6")
47+
UC_CPU_AVR_ATMEGA256 = UC_AVR_ARCH_AVR6*UC_CPU_AVR_ARCH + 256,
48+
UC_CPU_AVR_ATMEGA256RFR2,
49+
UC_CPU_AVR_ATMEGA2560,
2550
} uc_cpu_avr;
2651

2752
//> AVR memory

qemu/target/avr/cpu.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,19 @@ typedef struct AVRCPUInfo {
343343
} AVRCPUInfo;
344344

345345
static const AVRCPUInfo avr_cpu_info[] ={
346-
{UC_CPU_AVR_AVR5, "avr5", avr_avr5_initfn},
347-
{UC_CPU_AVR_AVR51, "avr51", avr_avr51_initfn},
348-
{UC_CPU_AVR_AVR6, "avr6", avr_avr6_initfn},
346+
{UC_CPU_AVR_ATMEGA16, "arch:avr5", avr_avr5_initfn},
347+
{UC_CPU_AVR_ATMEGA16, "atmega16", avr_avr5_initfn},
348+
{UC_CPU_AVR_ATMEGA32, "atmega32", avr_avr5_initfn},
349+
{UC_CPU_AVR_ATMEGA64, "atmega64", avr_avr5_initfn},
350+
351+
{UC_CPU_AVR_ATMEGA128, "arch:avr51", avr_avr51_initfn},
352+
{UC_CPU_AVR_ATMEGA128, "atmega128", avr_avr51_initfn},
353+
{UC_CPU_AVR_ATMEGA128RFR2, "atmega128rfr2", avr_avr51_initfn},
354+
{UC_CPU_AVR_ATMEGA1280, "atmega1280", avr_avr51_initfn},
355+
356+
{UC_CPU_AVR_ATMEGA256, "arch:avr6", avr_avr6_initfn},
357+
{UC_CPU_AVR_ATMEGA256RFR2, "atmega256rfr2", avr_avr6_initfn},
358+
{UC_CPU_AVR_ATMEGA2560, "atmega2560", avr_avr6_initfn},
349359
};
350360

351361
static const AVRCPUInfo *avr_cpu_info_get(int cpu_model)
@@ -412,7 +422,7 @@ AVRCPU *cpu_avr_init(struct uc_struct *uc)
412422
}
413423

414424
if (uc->cpu_model == INT_MAX)
415-
uc->cpu_model = UC_CPU_AVR_AVR6;
425+
uc->cpu_model = UC_CPU_AVR_ATMEGA128;
416426
const AVRCPUInfo *const cip = avr_cpu_info_get(uc->cpu_model);
417427
if (!cip) {
418428
free(cpu);

0 commit comments

Comments
 (0)