Skip to contentSkip to conversation

target/avr merger

PATCH In review Aleksandar Markovic 8 participants 70 messages Jan 31, 2020 – Jun 29, 2020 Page 1 of 2

lore
Share & tools
lore
#0 lore raw

cover target/avr merger

From: Aleksandar Markovic <[email protected]>

This is the AVR port from Michael, release (merge) candidate 4.

The series can be found also in this repository:

https://github.com/AMarkovic/qemu-avr-merger-rc4

History:

Since v3:

- Removed a patch on load_elf() modification, since it has been merged
- Removed references to CONFIG_USER_ONLY and provided a guard against building lunux user mode for AVR
- Removed all references to 'Atmel' (including file renames)
- Rebased the code (there was common interface change regarding 'props')
- Various corrections of commit messages
- A bit field for AVRFeatures is nor 64 bit long
- Other minor fixes

Since v2:

- First patch is split into six smaller logical units (net result remains the same)
- Patch "hw/core/loader: Let load_elf populate the processor-specific flags" was redone to reflect the original intent that was lost in transalation between multiple autors
- Patch "hw/avr: Add helper to load raw/ELF firmware binaries" was corrected only in one line to rectify type of "e_flags"
- Patch "target/avr: Add section about AVR into QEMU documentation"
- Spurious <message-Id:> elements were removed
- The series was rebased to the latest code

Since v1:

- Addressed Thomas comments
- Fixed a non-critical bug in ATmega (incorrect SRAM base address)
- Added ELF parsing requested by Aleksandar
- Dropped default machine (as with the ARM port)

Michael Rolnik (25):
target/avr: Add basic parameters for new AVR platform target/avr: Introduce AVR CPU class object
target/avr: Add migration support
target/avr: Add GDB support
target/avr: Introduce enumeration AVRFeature
target/avr: Add defintions of AVR core types
target/avr: Add instruction helpers
target/avr: Add instruction translation - Register definitions target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Data Transfer Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function
hw/char: Add limited support for AVR USART peripheral hw/timer: Add limited support for AVR 16-bit timer peripheral hw/misc: Add limited support for AVR power device target/avr: Add section about AVR into QEMU documentation target/avr: Register AVR support with the rest of QEMU target/avr: Add machine none test
target/avr: Update MAINTAINERS file
target/avr: Update build system
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board

Philippe Mathieu-Daudé (4):
hw/avr: Add helper to load raw/ELF firmware binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add some Arduino boards .travis.yml: Run the AVR acceptance tests

 .travis.yml                      |    2 +-
 MAINTAINERS                      |   31 +
 arch_init.c                      |    2 +
 configure                        |    7 +
 default-configs/avr-softmmu.mak  |    5 +
 gdb-xml/avr-cpu.xml              |   49 +
 hw/avr/Kconfig                   |    9 +
 hw/avr/Makefile.objs             |    3 +
 hw/avr/arduino.c                 |  151 ++
 hw/avr/atmega.c                  |  470 ++++++
 hw/avr/atmega.h                  |   48 +
 hw/avr/boot.c                    |   74 +
 hw/avr/boot.h                    |   33 +
 hw/char/Kconfig                  |    3 +
 hw/char/Makefile.objs            |    1 +
 hw/char/avr_usart.c              |  320 ++++
 hw/misc/Kconfig                  |    3 +
 hw/misc/Makefile.objs            |    2 +
 hw/misc/avr_power.c              |  112 ++
 hw/timer/Kconfig                 |    3 +
 hw/timer/Makefile.objs           |    2 +
 hw/timer/avr_timer16.c           |  604 ++++++++
 include/disas/dis-asm.h          |   19 +
 include/elf.h                    |    2 +
 include/hw/char/avr_usart.h      |   93 ++
 include/hw/misc/avr_power.h      |   46 +
 include/hw/timer/avr_timer16.h   |   94 ++
 include/sysemu/arch_init.h       |    1 +
 qapi/machine.json                |    3 +-
 qemu-doc.texi                    |   51 +
 target/avr/Makefile.objs         |   34 +
 target/avr/cpu-param.h           |   37 +
 target/avr/cpu-qom.h             |   54 +
 target/avr/cpu.c                 |  818 +++++++++++
 target/avr/cpu.h                 |  259 ++++
 target/avr/disas.c               |  246 ++++
 target/avr/gdbstub.c             |   84 ++
 target/avr/helper.c              |  342 +++++
 target/avr/helper.h              |   29 +
 target/avr/insn.decode           |  182 +++
 target/avr/machine.c             |  121 ++
 target/avr/translate.c           | 2997 ++++++++++++++++++++++++++++++++++++++
 tests/acceptance/machine_avr6.py |   50 +
 tests/qtest/Makefile.include     |    2 +
 tests/qtest/boot-serial-test.c   |   11 +
 tests/qtest/machine-none-test.c  |    1 +
 46 files changed, 7508 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 gdb-xml/avr-cpu.xml
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/Makefile.objs
 create mode 100644 hw/avr/arduino.c
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
 create mode 100644 hw/avr/boot.c
 create mode 100644 hw/avr/boot.h
 create mode 100644 hw/char/avr_usart.c
 create mode 100644 hw/misc/avr_power.c
 create mode 100644 hw/timer/avr_timer16.c
 create mode 100644 include/hw/char/avr_usart.h
 create mode 100644 include/hw/misc/avr_power.h
 create mode 100644 include/hw/timer/avr_timer16.h
 create mode 100644 target/avr/Makefile.objs
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu-qom.h
 create mode 100644 target/avr/cpu.c
 create mode 100644 target/avr/cpu.h
 create mode 100644 target/avr/disas.c
 create mode 100644 target/avr/gdbstub.c
 create mode 100644 target/avr/helper.c
 create mode 100644 target/avr/helper.h
 create mode 100644 target/avr/insn.decode
 create mode 100644 target/avr/machine.c
 create mode 100644 target/avr/translate.c
 create mode 100644 tests/acceptance/machine_avr6.py
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/29 target/avr: Add basic parameters for new AVR platform

From: Michael Rolnik <[email protected]>

This includes definitions of various basic parameters needed for integration of a new platform into QEMU.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++
 target/avr/cpu.h       | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +37 -0
new file mode 100644
index 0000000..0c29ce4
@@ -0,0 +1,37 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef AVR_CPU_PARAM_H
+#define AVR_CPU_PARAM_H
+
+#define TARGET_LONG_BITS 32
+/*
+ * TARGET_PAGE_BITS cannot be more than 8 bits because
+ * 1.  all IO registers occupy [0x0000 .. 0x00ff] address range, and they
+ *     should be implemented as a device and not memory
+ * 2.  SRAM starts at the address 0x0100
+ */
+#define TARGET_PAGE_BITS 8
+#define TARGET_PHYS_ADDR_SPACE_BITS 24
+#define TARGET_VIRT_ADDR_SPACE_BITS 24
+#define NB_MMU_MODES 2
+
+
+#endif
target/avr/cpu.h new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH rc4 01/29] target/avr: Add basic parameters for new AVR platform

Quoted 88 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes definitions of various basic parameters needed for integration of a new platform into QEMU.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++
 target/avr/cpu.h       | 72 ++++++++++++++++++++++++++++++
++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +37 -0
new file mode 100644
index 0000000..0c29ce4
@@ -0,0 +1,37 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef AVR_CPU_PARAM_H
+#define AVR_CPU_PARAM_H
+
+#define TARGET_LONG_BITS 32
+/*
+ * TARGET_PAGE_BITS cannot be more than 8 bits because
+ * 1.  all IO registers occupy [0x0000 .. 0x00ff] address range, and they
+ *     should be implemented as a device and not memory
+ * 2.  SRAM starts at the address 0x0100
+ */
+#define TARGET_PAGE_BITS 8
+#define TARGET_PHYS_ADDR_SPACE_BITS 24
+#define TARGET_VIRT_ADDR_SPACE_BITS 24
+#define NB_MMU_MODES 2
+
+
+#endif
target/avr/cpu.h new file +14 -0
new file mode 100644
index 0000000..d122611
@@ -0,0 +1,72 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.

target/avr/cpu.h line 24

Quoted 10 lines
target/avr/cpu.h new file +10 -0
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef QEMU_AVR_CPU_H
+#define QEMU_AVR_CPU_H
+
+#include "cpu-qom.h"

This line should be a part of the next patch.

target/avr/cpu.h line 30

Quoted 6 lines
target/avr/cpu.h new file +6 -0
+#include "exec/cpu-defs.h"
+
+#define TCG_GUEST_DEFAULT_MO 0
+#define AVR_CPU_TYPE_SUFFIX "-" TYPE_AVR_CPU
+#define AVR_CPU_TYPE_NAME(name) (name AVR_CPU_TYPE_SUFFIX)
+#define CPU_RESOLVING_TYPE TYPE_AVR_CPU

Last three lines should be a part of the next patch.

+

Quoted 45 lines
target/avr/cpu.h new file +41 -1
+/*
+ * AVR has two memory spaces, data & code.
+ * e.g. both have 0 address
+ * ST/LD instructions access data space
+ * LPM/SPM and instruction fetching access code memory space
+ */
+#define MMU_CODE_IDX 0
+#define MMU_DATA_IDX 1
+
+#define EXCP_RESET 1
+#define EXCP_INT(n) (EXCP_RESET + (n) + 1)
+
+/* Number of CPU registers */
+#define NUMBER_OF_CPU_REGISTERS 32
+/* Number of IO registers accessible by ld/st/in/out */
+#define NUMBER_OF_IO_REGISTERS 64
+
+/*
+ * Offsets of AVR memory regions in host memory space.
+ *
+ * This is needed because the AVR has separate code and data address
+ * spaces that both have start from zero but have to go somewhere in
+ * host memory.
+ *
+ * It's also useful to know where some things are, like the IO registers.
+ */
+/* Flash program memory */
+#define OFFSET_CODE 0x00000000
+/* CPU registers, IO registers, and SRAM */
+#define OFFSET_DATA 0x00800000
+/* CPU registers specifically, these are mapped at the start of data */
+#define OFFSET_CPU_REGISTERS OFFSET_DATA
+/*
+ * IO registers, including status register, stack pointer, and memory
+ * mapped peripherals, mapped just after CPU registers
+ */
+#define OFFSET_IO_REGISTERS (OFFSET_DATA + NUMBER_OF_CPU_REGISTERS)
+
+#define EF_AVR_MACH 0x7F
+
+#endif /* !defined (QEMU_AVR_CPU_H) */
--

2.7.4

#3 lore raw

Re: [PATCH rc4 01/29] target/avr: Add basic parameters for new AVR platform

In reply to Aleksandar Markovic
Quoted 134 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes definitions of various basic parameters needed for integration of a new platform into QEMU.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++
 target/avr/cpu.h       | 72 ++++++++++++++++++++++++++++++
++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +37 -0
new file mode 100644
index 0000000..0c29ce4
@@ -0,0 +1,37 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef AVR_CPU_PARAM_H
+#define AVR_CPU_PARAM_H
+
+#define TARGET_LONG_BITS 32
+/*
+ * TARGET_PAGE_BITS cannot be more than 8 bits because
+ * 1.  all IO registers occupy [0x0000 .. 0x00ff] address range, and they
+ *     should be implemented as a device and not memory
+ * 2.  SRAM starts at the address 0x0100
+ */
+#define TARGET_PAGE_BITS 8
+#define TARGET_PHYS_ADDR_SPACE_BITS 24
+#define TARGET_VIRT_ADDR_SPACE_BITS 24
+#define NB_MMU_MODES 2
+
+
+#endif
target/avr/cpu.h new file +60 -0
new file mode 100644
index 0000000..d122611
@@ -0,0 +1,72 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef QEMU_AVR_CPU_H
+#define QEMU_AVR_CPU_H
+
+#include "cpu-qom.h"
+#include "exec/cpu-defs.h"
+
+#define TCG_GUEST_DEFAULT_MO 0
+#define AVR_CPU_TYPE_SUFFIX "-" TYPE_AVR_CPU
+#define AVR_CPU_TYPE_NAME(name) (name AVR_CPU_TYPE_SUFFIX)
+#define CPU_RESOLVING_TYPE TYPE_AVR_CPU
+
+/*
+ * AVR has two memory spaces, data & code.
+ * e.g. both have 0 address
+ * ST/LD instructions access data space
+ * LPM/SPM and instruction fetching access code memory space
+ */
+#define MMU_CODE_IDX 0
+#define MMU_DATA_IDX 1
+
+#define EXCP_RESET 1
+#define EXCP_INT(n) (EXCP_RESET + (n) + 1)
+
+/* Number of CPU registers */
+#define NUMBER_OF_CPU_REGISTERS 32
+/* Number of IO registers accessible by ld/st/in/out */
+#define NUMBER_OF_IO_REGISTERS 64
+
+/*
+ * Offsets of AVR memory regions in host memory space.
+ *
+ * This is needed because the AVR has separate code and data address
+ * spaces that both have start from zero but have to go somewhere in
+ * host memory.
+ *
+ * It's also useful to know where some things are, like the IO registers.
+ */
+/* Flash program memory */
+#define OFFSET_CODE 0x00000000
+/* CPU registers, IO registers, and SRAM */

target/avr/cpu.h line 70

Quoted 10 lines
target/avr/cpu.h new file +10 -0
+#define OFFSET_DATA 0x00800000
+/* CPU registers specifically, these are mapped at the start of data */
+#define OFFSET_CPU_REGISTERS OFFSET_DATA
+/*
+ * IO registers, including status register, stack pointer, and memory
+ * mapped peripherals, mapped just after CPU registers
+ */
+#define OFFSET_IO_REGISTERS (OFFSET_DATA + NUMBER_OF_CPU_REGISTERS)
+
+#define EF_AVR_MACH 0x7F

This line seems to belong more to patch 6, where it basically extracts bits 6..0 from e_flags.

+

Quoted 5 lines
target/avr/cpu.h new file +1 -1
+#endif /* !defined (QEMU_AVR_CPU_H) */
--

2.7.4

#4 lore raw

Re: [PATCH rc4 01/29] target/avr: Add basic parameters for new AVR platform

In reply to Aleksandar Markovic
Quoted 6 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes definitions of various basic parameters needed for integration of a new platform into QEMU.

Hi, all.

Just to keep everyone in the loop:

I'll try to put together rc5 in next few days, with a number of relatvely minor changes (Alex/Philippe improvments and some more). Let me know if this doesn't work for you for any reason.

Igor, a special question to you:

You already gave Acked-by for former patch 1, which is now transformed to patches 1-6. I gather you are familiar with all topics involved. Could you perhaps taje a closer look at patches 1-6 now, and, if you are happy with what you see, perhaps you can give Reviewed-by to them?

Thanks, Aleksandar

Quoted 145 lines
[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++
 target/avr/cpu.h       | 72 ++++++++++++++++++++++++++++++
++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +37 -0
new file mode 100644
index 0000000..0c29ce4
@@ -0,0 +1,37 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef AVR_CPU_PARAM_H
+#define AVR_CPU_PARAM_H
+
+#define TARGET_LONG_BITS 32
+/*
+ * TARGET_PAGE_BITS cannot be more than 8 bits because
+ * 1.  all IO registers occupy [0x0000 .. 0x00ff] address range, and they
+ *     should be implemented as a device and not memory
+ * 2.  SRAM starts at the address 0x0100
+ */
+#define TARGET_PAGE_BITS 8
+#define TARGET_PHYS_ADDR_SPACE_BITS 24
+#define TARGET_VIRT_ADDR_SPACE_BITS 24
+#define NB_MMU_MODES 2
+
+
+#endif
target/avr/cpu.h new file +72 -1
new file mode 100644
index 0000000..d122611
@@ -0,0 +1,72 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef QEMU_AVR_CPU_H
+#define QEMU_AVR_CPU_H
+
+#include "cpu-qom.h"
+#include "exec/cpu-defs.h"
+
+#define TCG_GUEST_DEFAULT_MO 0
+#define AVR_CPU_TYPE_SUFFIX "-" TYPE_AVR_CPU
+#define AVR_CPU_TYPE_NAME(name) (name AVR_CPU_TYPE_SUFFIX)
+#define CPU_RESOLVING_TYPE TYPE_AVR_CPU
+
+/*
+ * AVR has two memory spaces, data & code.
+ * e.g. both have 0 address
+ * ST/LD instructions access data space
+ * LPM/SPM and instruction fetching access code memory space
+ */
+#define MMU_CODE_IDX 0
+#define MMU_DATA_IDX 1
+
+#define EXCP_RESET 1
+#define EXCP_INT(n) (EXCP_RESET + (n) + 1)
+
+/* Number of CPU registers */
+#define NUMBER_OF_CPU_REGISTERS 32
+/* Number of IO registers accessible by ld/st/in/out */
+#define NUMBER_OF_IO_REGISTERS 64
+
+/*
+ * Offsets of AVR memory regions in host memory space.
+ *
+ * This is needed because the AVR has separate code and data address
+ * spaces that both have start from zero but have to go somewhere in
+ * host memory.
+ *
+ * It's also useful to know where some things are, like the IO registers.
+ */
+/* Flash program memory */
+#define OFFSET_CODE 0x00000000
+/* CPU registers, IO registers, and SRAM */
+#define OFFSET_DATA 0x00800000
+/* CPU registers specifically, these are mapped at the start of data */
+#define OFFSET_CPU_REGISTERS OFFSET_DATA
+/*
+ * IO registers, including status register, stack pointer, and memory
+ * mapped peripherals, mapped just after CPU registers
+ */
+#define OFFSET_IO_REGISTERS (OFFSET_DATA + NUMBER_OF_CPU_REGISTERS)
+
+#define EF_AVR_MACH 0x7F
+
+#endif /* !defined (QEMU_AVR_CPU_H) */
--

2.7.4

#5 lore raw

PATCH 2/29 target/avr: Introduce AVR CPU class object

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This patch introduces AVR CPU class object and its basic elements and functions.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu-qom.h |  54 +++++++++++++
 target/avr/cpu.c     | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++
 target/avr/cpu.h     | 136 +++++++++++++++++++++++++++++++++
 target/avr/helper.c  | 139 +++++++++++++++++++++++++++++++++
 4 files changed, 541 insertions(+)
 create mode 100644 target/avr/cpu-qom.h
 create mode 100644 target/avr/cpu.c
 create mode 100644 target/avr/helper.c
target/avr/cpu-qom.h new file +54 -0
new file mode 100644
index 0000000..e28b58c
@@ -0,0 +1,54 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#ifndef QEMU_AVR_QOM_H
+#define QEMU_AVR_QOM_H
+
+#include "hw/core/cpu.h"
+
+#define TYPE_AVR_CPU "avr-cpu"
+
+#define AVR_CPU_CLASS(klass) \
+    OBJECT_CLASS_CHECK(AVRCPUClass, (klass), TYPE_AVR_CPU)
+#define AVR_CPU(obj) \
+    OBJECT_CHECK(AVRCPU, (obj), TYPE_AVR_CPU)
+#define AVR_CPU_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(AVRCPUClass, (obj), TYPE_AVR_CPU)
+
+/**
+ *  AVRCPUClass:
+ *  @parent_realize: The parent class' realize handler.
+ *  @parent_reset: The parent class' reset handler.
+ *  @vr: Version Register value.
+ *
+ *  A AVR CPU model.
+ */
+typedef struct AVRCPUClass {
+    /*< private >*/
+    CPUClass parent_class;
+    /*< public >*/
+    DeviceRealize parent_realize;
+    void (*parent_reset)(CPUState *cpu);
+} AVRCPUClass;
+
+typedef struct AVRCPU AVRCPU;
+
+
+#endif /* !defined (QEMU_AVR_CPU_QOM_H) */
target/avr/cpu.c new file +212 -0

212 lines not on this page · raw message

target/avr/cpu.h +136 -0

146 lines not on this page · raw message

target/avr/helper.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.7.4
#6 lore raw

PATCH 3/29 target/avr: Add migration support

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add migration functions for AVR cores.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu.c     |   1 +
 target/avr/cpu.h     |   2 +
 target/avr/machine.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 target/avr/machine.c
target/avr/cpu.c +1 -0
index beda91e..49e32af 100644
@@ -205,6 +205,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
     cc->set_pc = avr_cpu_set_pc;
     cc->memory_rw_debug = avr_cpu_memory_rw_debug;
     cc->get_phys_page_debug = avr_cpu_get_phys_page_debug;
+    cc->vmsd = &vms_avr_cpu;
     cc->disas_set_info = avr_cpu_disas_set_info;
     cc->tlb_fill = avr_cpu_tlb_fill;
     cc->tcg_initialize = avr_cpu_tcg_init;
target/avr/cpu.h +2 -0
index 08f4415..2907a37 100644
@@ -119,6 +119,8 @@ typedef struct AVRCPU {
     CPUAVRState env;
 } AVRCPU;
 
+extern const struct VMStateDescription vms_avr_cpu;
+
 void avr_cpu_do_interrupt(CPUState *cpu);
 bool avr_cpu_exec_interrupt(CPUState *cpu, int int_req);
 hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
target/avr/machine.c new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.7.4
#7 lore raw

PATCH 4/29 target/avr: Add GDB support

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes GDB hooks for reading from wnd wrtiting to AVR registers, and xml register definition file as well.

[AM: Split a larger AVR introduction patch into logical units]
---
 gdb-xml/avr-cpu.xml  | 49 ++++++++++++++++++++++++++++++
 target/avr/cpu.c     |  4 +++
 target/avr/cpu.h     |  2 ++
 target/avr/gdbstub.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
 create mode 100644 gdb-xml/avr-cpu.xml
 create mode 100644 target/avr/gdbstub.c
gdb-xml/avr-cpu.xml new file +49 -0
new file mode 100644
index 0000000..c4747f5
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2018-2019 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!-- Register numbers are hard-coded in order to maintain backward
+     compatibility with older versions of tools that didn't use xml
+     register descriptions.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.riscv.cpu">
+  <reg name="r0" bitsize="8" type="int" regnum="0"/>
+  <reg name="r1" bitsize="8" type="int"/>
+  <reg name="r2" bitsize="8" type="int"/>
+  <reg name="r3" bitsize="8" type="int"/>
+  <reg name="r4" bitsize="8" type="int"/>
+  <reg name="r5" bitsize="8" type="int"/>
+  <reg name="r6" bitsize="8" type="int"/>
+  <reg name="r7" bitsize="8" type="int"/>
+  <reg name="r8" bitsize="8" type="int"/>
+  <reg name="r9" bitsize="8" type="int"/>
+  <reg name="r10" bitsize="8" type="int"/>
+  <reg name="r11" bitsize="8" type="int"/>
+  <reg name="r12" bitsize="8" type="int"/>
+  <reg name="r13" bitsize="8" type="int"/>
+  <reg name="r14" bitsize="8" type="int"/>
+  <reg name="r15" bitsize="8" type="int"/>
+  <reg name="r16" bitsize="8" type="int"/>
+  <reg name="r17" bitsize="8" type="int"/>
+  <reg name="r18" bitsize="8" type="int"/>
+  <reg name="r19" bitsize="8" type="int"/>
+  <reg name="r20" bitsize="8" type="int"/>
+  <reg name="r21" bitsize="8" type="int"/>
+  <reg name="r22" bitsize="8" type="int"/>
+  <reg name="r23" bitsize="8" type="int"/>
+  <reg name="r24" bitsize="8" type="int"/>
+  <reg name="r25" bitsize="8" type="int"/>
+  <reg name="r26" bitsize="8" type="int"/>
+  <reg name="r27" bitsize="8" type="int"/>
+  <reg name="r28" bitsize="8" type="int"/>
+  <reg name="r29" bitsize="8" type="int"/>
+  <reg name="r30" bitsize="8" type="int"/>
+  <reg name="r31" bitsize="8" type="int"/>
+  <reg name="sreg" bitsize="8" type="int"/>
+  <reg name="sp" bitsize="8" type="int"/>
+  <reg name="pc" bitsize="8" type="int"/>
+</feature>
target/avr/cpu.c +4 -0
index 49e32af..f41a887 100644
@@ -210,4 +210,8 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
     cc->tlb_fill = avr_cpu_tlb_fill;
     cc->tcg_initialize = avr_cpu_tcg_init;
     cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
+    cc->gdb_read_register = avr_cpu_gdb_read_register;
+    cc->gdb_write_register = avr_cpu_gdb_write_register;
+    cc->gdb_num_core_regs = 35;
+    cc->gdb_core_xml_file = "avr-cpu.xml";
 }
target/avr/cpu.h +2 -0
index 2907a37..91dfa0f 100644
@@ -124,6 +124,8 @@ extern const struct VMStateDescription vms_avr_cpu;
 void avr_cpu_do_interrupt(CPUState *cpu);
 bool avr_cpu_exec_interrupt(CPUState *cpu, int int_req);
 hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
+int avr_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
+int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 
 #define cpu_list avr_cpu_list
 #define cpu_signal_handler cpu_avr_signal_handler
target/avr/gdbstub.c new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH 5/29 target/avr: Introduce enumeration AVRFeature

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This patch introduces enumeration "AVRFeature" that will be used for defining various AVR core types.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
target/avr/cpu.h +46 -0
index 91dfa0f..e94dab3 100644
@@ -73,6 +73,42 @@
 
 #define EF_AVR_MACH 0x7F
 
+typedef enum AVRFeature {
+    AVR_FEATURE_SRAM,
+
+    AVR_FEATURE_1_BYTE_PC,
+    AVR_FEATURE_2_BYTE_PC,
+    AVR_FEATURE_3_BYTE_PC,
+
+    AVR_FEATURE_1_BYTE_SP,
+    AVR_FEATURE_2_BYTE_SP,
+
+    AVR_FEATURE_BREAK,
+    AVR_FEATURE_DES,
+    AVR_FEATURE_RMW, /* Read Modify Write - XCH LAC LAS LAT */
+
+    AVR_FEATURE_EIJMP_EICALL,
+    AVR_FEATURE_IJMP_ICALL,
+    AVR_FEATURE_JMP_CALL,
+
+    AVR_FEATURE_ADIW_SBIW,
+
+    AVR_FEATURE_SPM,
+    AVR_FEATURE_SPMX,
+
+    AVR_FEATURE_ELPMX,
+    AVR_FEATURE_ELPM,
+    AVR_FEATURE_LPMX,
+    AVR_FEATURE_LPM,
+
+    AVR_FEATURE_MOVW,
+    AVR_FEATURE_MUL,
+    AVR_FEATURE_RAMPD,
+    AVR_FEATURE_RAMPX,
+    AVR_FEATURE_RAMPY,
+    AVR_FEATURE_RAMPZ,
+} AVRFeature;
+
 typedef struct CPUAVRState CPUAVRState;
 
 struct CPUAVRState {
@@ -127,6 +163,16 @@ hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 int avr_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
 int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
 
+static inline int avr_feature(CPUAVRState *env, AVRFeature feature)
+{
+    return (env->features & (1U << feature)) != 0;
+}
+
+static inline void set_avr_feature(CPUAVRState *env, int feature)
+{
+    env->features |= (1U << feature);
+}
+
 #define cpu_list avr_cpu_list
 #define cpu_signal_handler cpu_avr_signal_handler
 #define cpu_mmu_index avr_cpu_mmu_index
Signature · 1 line
2.7.4
#9 lore raw

PATCH 6/29 target/avr: Add defintions of AVR core types

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
 target/avr/cpu.c | 601 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 601 insertions(+)
target/avr/cpu.c +601 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
     cc->gdb_num_core_regs = 35;
     cc->gdb_core_xml_file = "avr-cpu.xml";
 }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2, atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48, atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4, atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417, attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u, atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char *def_cpu_type)
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Quoted 644 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
  target/avr/cpu.c | 601 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 601 insertions(+)
target/avr/cpu.c +591 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2, atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48, atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4, atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417, attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u, atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char *def_cpu_type)
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data) · line 818

Quoted 10 lines
target/avr/cpu.c +10 -0
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)

Hi! me again. Following the RC2 discussion. I've being looking in the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

avr_arch_types[] =
{
/* unknown device specified */
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0, 32, NULL,
AVR_MMCU_DEFAULT },
/*

     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "1",   "avr1"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"  },
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25" },
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"  },
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31" },
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35" },
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"  },
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"  },
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51" },
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"  },

{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100", "avrtiny"},
{ 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0, 0, "102", "avrxmega2" },
{ 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103", "avrxmega3" },

   { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0, "104", "avrxmega4" },
   { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0, "105", "avrxmega5" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0, "106", "avrxmega6" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0, "107", "avrxmega7"  }

};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and microcontroller definition. Only looking at the family definition:

AVR_MCU ("avr2", ARCH_AVR2, AVR_ERRATA_SKIP, NULL,

             0x0060, 0x0, 0x60000, 0)
 AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE, NULL, 
            0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE, NULL, 
            0x0060, 0x0, 0x6000, 0)
 AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP, NULL, 
            0x0060, 0x0, 0x20000, 0)
 AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE, NULL, 
            0x0100, 0x0, 0x4000, 0)
 AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE,  NULL, 
            0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE, NULL, 
            0x0060, 0x0, 0x4000, 0)
 AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE, NULL, 
            0x0100, 0x0, 0x20000, 0)
 AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE, NULL, 
            0x0200, 0x0, 0x40000, 0)
 AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE, NULL, 
            0x2000, 0x0, 0x9000, 0)
 AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3, AVR_ISA_NONE,  NULL, 
            0x3f00, 0x0, 0x8000, 0)
 AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE, NULL, 
            0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL, 
            0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE, NULL, 
                0x2000, 0x0, 0x60000, 0)
 AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE, NULL, 
                0x2000, 0x0, 0x22000, 0)
 AVR_MCU ("avrtiny",          ARCH_AVRTINY, AVR_ISA_NONE, NULL, 
            0x0040, 0x0, 0x400, 0)
 AVR_MCU ("avr1",             ARCH_AVR1, AVR_ISA_NONE, NULL, 
            0x0060, 0x0, 0x400, 0)

I don't really understand how do you get to the proposed family definition for qemu. Probably is my fault but if you can help me to understand will be grate!

Regards,
--joa

#11 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Quoted 760 lines · Joaquin de Andres
Quoted 672 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
  target/avr/cpu.c | 601 ++++++++++++++++++++++++++++++
+++++++++++++++++++++++++
  1 file changed, 601 insertions(+)
target/avr/cpu.c +26 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc,
 void *data)
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,

at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */

target/avr/cpu.c +22 -0
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a,

attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */

target/avr/cpu.c +74 -0
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2,

atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */

target/avr/cpu.c +25 -0
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48,

atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */

target/avr/cpu.c +25 -0
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831,

ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */

target/avr/cpu.c +26 -0
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284,

atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */

target/avr/cpu.c +81 -0
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4,

atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */

target/avr/cpu.c +27 -0
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417,

attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */

target/avr/cpu.c +93 -0
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u,

atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */

target/avr/cpu.c +117 -0
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char

*def_cpu_type)

target/avr/cpu.c +32 -0
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data) · line 818

Quoted 10 lines
target/avr/cpu.c +10 -0
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)

Hi! me again. Following the RC2 discussion. I've being looking in the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL,
AVR_MMCU_DEFAULT },
   /*
     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "1",   "avr1"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"  },
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25" },
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"  },
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31" },
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35" },
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"  },
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"  },
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51" },
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100", "avrtiny"},
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102", "avrxmega2" },
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103", "avrxmega3" },
   { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0, "104", "avrxmega4" },
   { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0, "105", "avrxmega5" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0, "106", "avrxmega6" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0, "107", "avrxmega7"  }

};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and microcontroller definition. Only looking at the family definition:

AVR_MCU ("avr2", ARCH_AVR2, AVR_ERRATA_SKIP, NULL,
0x0060, 0x0, 0x60000, 0)
AVR_MCU ("avr25", ARCH_AVR25, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x2000, 0)
AVR_MCU ("avr3", ARCH_AVR3, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x6000, 0)
AVR_MCU ("avr31", ARCH_AVR31, AVR_ERRATA_SKIP, NULL,
0x0060, 0x0, 0x20000, 0)
AVR_MCU ("avr35", ARCH_AVR35, AVR_ISA_NONE, NULL,
0x0100, 0x0, 0x4000, 0)
AVR_MCU ("avr4", ARCH_AVR4, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x2000, 0)
AVR_MCU ("avr5", ARCH_AVR5, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x4000, 0)
AVR_MCU ("avr51", ARCH_AVR51, AVR_ISA_NONE, NULL,
0x0100, 0x0, 0x20000, 0)
AVR_MCU ("avr6", ARCH_AVR6, AVR_ISA_NONE, NULL,
0x0200, 0x0, 0x40000, 0)
AVR_MCU ("avrxmega2", ARCH_AVRXMEGA2, AVR_ISA_NONE, NULL,
0x2000, 0x0, 0x9000, 0)
AVR_MCU ("avrxmega3", ARCH_AVRXMEGA3, AVR_ISA_NONE, NULL,

     0x3f00, 0x0, 0x8000, 0)
 AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE, NULL,
   0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL,
   0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE, NULL,
       0x2000, 0x0, 0x60000, 0)
 AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE, NULL,
       0x2000, 0x0, 0x22000, 0)
Quoted 10 lines

AVR_MCU ("avrtiny", ARCH_AVRTINY, AVR_ISA_NONE, NULL,
0x0040, 0x0, 0x400, 0)
AVR_MCU ("avr1", ARCH_AVR1, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x400, 0)

I don't really understand how do you get to the proposed family definition for qemu. Probably is my fault but if you can help me to understand will be grate!

Michal, can you really give us more details on how this mapping is done?

I alredy asked a similar question a while ago, and then you said you used wikipedia article + avr datasheets. Can you give us more detailed info of the whole process of creating ABRFeature list for a particular AVR core type, and how that compares with the corresponding content in gcc, as Joakin brought to our attention?

Thanks, Aleksandar

Quoted 3 lines

Regards,
--joa

#12 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Hi all.

When I decided to implement AVR 8 bit CPU support for QEMU I found this document
<http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf>
which
listed all AVR instructions.
After that I learned that there are several CPU flavours, I looked into this GCC file
<https://github.com/gcc-mirror/gcc/blob/master/gcc/config/avr/avr-devices.c> to figure out what are they as I could not find any official document explaining it.
Then I downloaded several datasheets and created a list of instructions by CPU type (attached).It turned out that there are some variations e.g.
- AVTTINY - some have LDS, some don't
- AVR1, AVR25 - some have short SP, some don't
- AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 - some have RMW, some don't
- AVRXMEGA3 - some have RCALL, some don't

I decided to leave CPU flavour definition as suggested by GCC gcc/config/avr/avr-devices.c
<https://github.com/gcc-mirror/gcc/blob/master/gcc/config/avr/avr-devices.c>
file and when a specific MCU is created it will set / reset CPU features relevant to it.

I hope this helps.

Best Regards,
Michael Rolnik

Quoted 802 lines · Aleksandar Markovic
Quoted 770 lines · Joaquin de Andres
Quoted 676 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
  target/avr/cpu.c | 601
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 601 insertions(+)
target/avr/cpu.c +26 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc,
 void *data)
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,

at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */

target/avr/cpu.c +22 -0
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a,

attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */

target/avr/cpu.c +74 -0
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2,

atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */

target/avr/cpu.c +25 -0
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48,

atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */

target/avr/cpu.c +25 -0
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831,

ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */

target/avr/cpu.c +26 -0
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284,

atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */

target/avr/cpu.c +81 -0
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4,

atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */

target/avr/cpu.c +27 -0
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417,

attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */

target/avr/cpu.c +93 -0
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u,

atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */

target/avr/cpu.c +117 -0
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char

*def_cpu_type)

target/avr/cpu.c +32 -0
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data) · line 818

Quoted 10 lines
target/avr/cpu.c +10 -0
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)

Hi! me again. Following the RC2 discussion. I've being looking in the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL,
AVR_MMCU_DEFAULT },
   /*
     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "1",   "avr1"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"  },
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25" },
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"  },
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31" },
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35" },
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"  },
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"  },
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51" },
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100", "avrtiny"},
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102", "avrxmega2"
},

{ 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103", "avrxmega3"
},
{ 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0, 0, "104", "avrxmega4"
},
{ 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0, 0, "105", "avrxmega5"
},
{ 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0, 0, "106", "avrxmega6"
},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0, 0, "107", "avrxmega7"
}
};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and microcontroller definition. Only looking at the family definition:

AVR_MCU ("avr2", ARCH_AVR2, AVR_ERRATA_SKIP, NULL,

    0x0060, 0x0, 0x60000, 0)
 AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x6000, 0)
 AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP, NULL,
   0x0060, 0x0, 0x20000, 0)
 AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE, NULL,
 0x0100, 0x0, 0x4000, 0)
 AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE,  NULL,
 0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x4000, 0)
 AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE, NULL,
 0x0100, 0x0, 0x20000, 0)
 AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE, NULL,
 0x0200, 0x0, 0x40000, 0)
 AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x9000, 0)
 AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3, AVR_ISA_NONE,  NULL,
     0x3f00, 0x0, 0x8000, 0)
 AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE, NULL,
         0x2000, 0x0, 0x60000, 0)
 AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE, NULL,
         0x2000, 0x0, 0x22000, 0)
Quoted 10 lines

AVR_MCU ("avrtiny", ARCH_AVRTINY, AVR_ISA_NONE, NULL,
0x0040, 0x0, 0x400, 0)
AVR_MCU ("avr1", ARCH_AVR1, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x400, 0)

I don't really understand how do you get to the proposed family definition for qemu. Probably is my fault but if you can help me to understand will be grate!

Michal, can you really give us more details on how this mapping is done?

I alredy asked a similar question a while ago, and then you said you used wikipedia article + avr datasheets. Can you give us more detailed info of the whole process of creating ABRFeature list for a particular AVR core type, and how that compares with the corresponding content in gcc, as Joakin brought to our attention?

Thanks, Aleksandar

Quoted 3 lines

Regards,
--joa

Signature · 2 lines
Best Regards,
Michael Rolnik
| MCU   | DATASHEET URL   |
|-------|-----------------|
|ALL	|http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf										
|AVR1	|http://ww1.microchip.com/downloads/en/devicedoc/doc0838.pdf										
|AVR2	|http://ww1.microchip.com/downloads/en/DeviceDoc/DOC0839.PDF										
|AVR25	|http://ww1.microchip.com/downloads/en/DeviceDoc/doc8371.pdf										
|AVR3	|										
|AVR31	|http://ww1.microchip.com/downloads/en/DeviceDoc/doc0945.pdf										
|AVR35	|http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8303-8-bit-AVR-Microcontroller-tinyAVR-ATtiny1634_Datasheet.pdf										
|AVR4	|http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7530-Automotive-Microcontrollers-ATmega48-ATmega88-ATmega168_Datasheet.pdf										
|AVR5	|http://ww1.microchip.com/downloads/en/DeviceDoc/doc7734.pdf										
|AVR51	|http://ww1.microchip.com/downloads/en/DeviceDoc/doc2467.pdf										
|AVR6	|https://cdn.sparkfun.com/datasheets/Components/General%20IC/2549S.pdf										
|XMEGA2	|http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8069-8-and-16-bit-AVR-AMEGA-A4-Microcontrollers_Datasheet.pdf										
|XMEGA3	|http://ww1.microchip.com/downloads/en/DeviceDoc/40001911A.pdf										
|XMEGA4	|http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8068-8-and16-bit-AVR-XMEGA-A3-Microcontrollers_Datasheet.pdf										
|XMEGA5	|http://ww1.microchip.com/downloads/en/DeviceDoc/atmel-8385-8-and-16-bit-avr-microcontroller-atxmega64a1u-atxmega128a1u_datasheet.pdf										
|XMEGA6	|http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8068-8-and16-bit-AVR-XMEGA-A3-Microcontrollers_Datasheet.pdf										
|XMEGA7	|http://ww1.microchip.com/downloads/en/DeviceDoc/doc8077.pdf										
|AVRTINY	|http://ww1.microchip.com/downloads/en/DeviceDoc/atmel-8127-avr-8-bit-microcontroller-attiny4-attiny5-attiny9-attiny10_datasheet.pdf

----

| ALL | AVR1 | AVR2 | AVR25 |AVR3 | AVR31 | AVR35 | AVR4 | AVR5 | AVR6 | AVRTINY | XMEGA2 | XMAGA3 | XMAGA4 | XMAGA5 | XMAGA6 | XMAGA7 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| 
|ADC	|ADC	|ADC	|ADC	|	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC	|ADC
|ADD	|ADD	|ADD	|ADD	|	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD	|ADD
|ADIW	|	|ADIW	|ADIW	|	|ADIW	|ADIW	|ADIW	|ADIW	|ADIW	|ADIW	|	|ADIW	|ADIW	|ADIW	|ADIW	|ADIW	|ADIW
|AND	|AND	|AND	|AND	|	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND	|AND
|ANDI	|ANDI	|ANDI	|ANDI	|	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI	|ANDI
|ASR	|ASR	|ASR	|ASR	|	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR	|ASR
|BCLR	|BCLR	|BCLR	|BCLR	|	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR	|BCLR
|BLD	|BLD	|BLD	|BLD	|	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD	|BLD
|BRBC	|BRBC	|BRBC	|BRBC	|	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC	|BRBC
|BRBS	|BRBS	|BRBS	|BRBS	|	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS	|BRBS
|BRCC	|BRCC	|BRCC	|BRCC	|	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC	|BRCC
|BRCS	|BRCS	|BRCS	|BRCS	|	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS	|BRCS
|BREAK	|	|	|BREAK	|	|	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK	|BREAK
|BREQ	|BREQ	|BREQ	|BREQ	|	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ	|BREQ
|BRGE	|BRGE	|BRGE	|BRGE	|	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE	|BRGE
|BRHC	|BRHC	|BRHC	|BRHC	|	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC	|BRHC
|BRHS	|BRHS	|BRHS	|BRHS	|	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS	|BRHS
|BRID	|BRID	|BRID	|BRID	|	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID	|BRID
|BRIE	|BRIE	|BRIE	|BRIE	|	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE	|BRIE
|BRLO	|BRLO	|BRLO	|BRLO	|	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO	|BRLO
|BRLT	|BRLT	|BRLT	|BRLT	|	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT	|BRLT
|BRMI	|BRMI	|BRMI	|BRMI	|	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI	|BRMI
|BRNE	|BRNE	|BRNE	|BRNE	|	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE	|BRNE
|BRPL	|BRPL	|BRPL	|BRPL	|	|BRPL	|BRPL	|BRPL	|BRPL	|BRPL	|BRPL	|BRPL	|BRPL	|	|BRPL	|BRPL	|BRPL	|BRPL
|BRSH	|BRSH	|BRSH	|BRSH	|	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH	|BRSH
|BRTC	|BRTC	|BRTC	|BRTC	|	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC	|BRTC
|BRTS	|BRTS	|BRTS	|BRTS	|	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS	|BRTS
|BRVC	|BRVC	|BRVC	|BRVC	|	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC	|BRVC
|BRVS	|BRVS	|BRVS	|BRVS	|	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS	|BRVS
|BSET	|BSET	|BSET	|BSET	|	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET	|BSET
|BST	|BST	|BST	|BST	|	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST	|BST
|CALL	|	|	|	|	|CALL	|CALL	|CALL	|CALL	|CALL	|CALL	|	|CALL	|CALL	|CALL	|CALL	|CALL	|CALL
|CBI	|CBI	|CBI	|CBI	|	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI	|CBI
|CBR	|CBR	|CBR	|CBR	|	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR	|CBR
|CLC	|CLC	|CLC	|CLC	|	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC	|CLC
|CLH	|CLH	|CLH	|CLH	|	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH	|CLH
|CLI	|CLI	|CLI	|CLI	|	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI	|CLI
|CLN	|CLN	|CLN	|CLN	|	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN	|CLN
|CLR	|CLR	|CLR	|CLR	|	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR	|CLR
|CLS	|CLS	|CLS	|CLS	|	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS	|CLS
|CLT	|CLT	|CLT	|CLT	|	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT	|CLT
|CLV	|CLV	|CLV	|CLV	|	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV	|CLV
|CLZ	|CLZ	|CLZ	|CLZ	|	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ	|CLZ
|COM	|COM	|COM	|COM	|	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM	|COM
|CP	|CP	|CP	|CP	|	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP	|CP
|CPC	|CPC	|CPC	|CPC	|	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC	|CPC
|CPI	|CPI	|CPI	|CPI	|	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI	|CPI
|CPSE	|CPSE	|CPSE	|CPSE	|	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE	|CPSE
|DEC	|DEC	|DEC	|DEC	|	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC	|DEC
|DES	|	|	|	|	|	|	|	|	|	|	|	|DES	|	|DES	|DES	|DES	|DES
|EICALL	|	|	|	|	|	|	|	|	|	|EICALL	|	|EICALL	|	|EICALL	|EICALL	|EICALL	|EICALL
|EIJMP	|	|	|	|	|	|	|	|	|	|EIJMP	|	|EIJMP	|	|EIJMP	|EIJMP	|EIJMP	|EIJMP
|EIND	|	|	|	|	|	|	|	|	|	|	|	|EIND	|	|EIND	|EIND	|EIND	|EIND
|ELPM	|	|	|	|	|ELPM	|	|	|	|ELPM	|ELPM	|	|ELPM	|	|ELPM	|ELPM	|ELPM	|ELPM
|EOR	|EOR	|EOR	|EOR	|	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR	|EOR
|FMUL	|	|	|	|	|	|	|FMUL	|FMUL	|FMUL	|FMUL	|	|FMUL	|FMUL	|FMUL	|FMUL	|FMUL	|FMUL
|FMULS	|	|	|	|	|	|	|FMULS	|FMULS	|FMULS	|FMULS	|	|FMULS	|FMULS	|FMULS	|FMULS	|FMULS	|FMULS
|FMULSU	|	|	|	|	|	|	|FMULSU	|FMULSU	|FMULSU	|FMULSU	|	|FMULSU	|FMULSU	|FMULSU	|FMULSU	|FMULSU	|FMULSU
|ICALL	|	|ICALL	|ICALL	|	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL	|ICALL
|IJMP	|	|IJMP	|IJMP	|	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP	|IJMP
|IN	|IN	|IN	|IN	|	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN	|IN
|INC	|INC	|INC	|INC	|	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC	|INC
|JMP	|	|	|	|	|JMP	|JMP	|JMP	|JMP	|JMP	|JMP	|	|JMP	|JMP	|JMP	|JMP	|JMP	|JMP
|LAC	|	|	|	|	|	|	|	|	|	|	|	|	|	|	|LAC	|	|
|LAS	|	|	|	|	|	|	|	|	|	|	|	|	|	|	|LAS	|	|
|LAT	|	|	|	|	|	|	|	|	|	|	|	|	|	|	|LAT	|	|
|LD	|LD	|LD	|LD	|	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD	|LD
|LDD	|	|LDD	|LDD	|	|LDD	|LDD	|LDD	|LDD	|LDD	|LDD	|	|LDD	|LDD	|LDD	|LDD	|LDD	|LDD
|LDI	|LDI	|LDI	|LDI	|	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI	|LDI
|LDS	|	|LDS	|LDS	|	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS	|LDS
|LPM	|	|LPM	|LPM	|	|LPM	|LPM	|LPM	|LPM	|LPM	|LPM	|	|LPM	|LPM	|LPM	|LPM	|LPM	|LPM
|LSL	|LSL	|LSL	|LSL	|	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL	|LSL
|LSR	|LSR	|LSR	|LSR	|	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR	|LSR
|MOV	|MOV	|MOV	|MOV	|	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV	|MOV
|MOVW	|	|	|MOVW	|	|	|MOVW	|MOVW	|MOVW	|MOVW	|MOVW	|	|MOVW	|MOVW	|MOVW	|MOVW	|MOVW	|MOVW
|MUL	|	|	|	|	|	|	|MUL	|MUL	|MUL	|MUL	|	|MUL	|MUL	|MUL	|MUL	|MUL	|MUL
|MULS	|	|	|	|	|	|	|MULS	|MULS	|MULS	|MULS	|	|MULS	|MULS	|MULS	|MULS	|MULS	|MULS
|MULSU	|	|	|	|	|	|	|MULSU	|MULSU	|MULSU	|MULSU	|	|MULSU	|MULSU	|MULSU	|MULSU	|MULSU	|MULSU
|NEG	|NEG	|NEG	|NEG	|	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG	|NEG
|NOP	|NOP	|NOP	|NOP	|	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP	|NOP
|OR	|OR	|OR	|OR	|	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR	|OR
|ORI	|ORI	|ORI	|ORI	|	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI	|ORI
|OUT	|OUT	|OUT	|OUT	|	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT	|OUT
|POP	|	|POP	|POP	|	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP	|POP
|PUSH	|	|PUSH	|PUSH	|	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH	|PUSH
|RCALL	|RCALL	|RCALL	|RCALL	|	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL	|RCALL
|RET	|RET	|RET	|RET	|	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET	|RET
|RETI	|RETI	|RETI	|RETI	|	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI	|RETI
|RJMP	|RJMP	|RJMP	|RJMP	|	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP	|RJMP
|ROL	|ROL	|ROL	|ROL	|	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL	|ROL
|ROR	|ROR	|ROR	|ROR	|	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR	|ROR
|SBC	|SBC	|SBC	|SBC	|	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC	|SBC
|SBCI	|SBCI	|SBCI	|SBCI	|	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI	|SBCI
|SBI	|SBI	|SBI	|SBI	|	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI	|SBI
|SBIC	|SBIC	|SBIC	|SBIC	|	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC	|SBIC
|SBIS	|SBIS	|SBIS	|SBIS	|	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS	|SBIS
|SBIW	|	|SBIW	|SBIW	|	|SBIW	|SBIW	|SBIW	|SBIW	|SBIW	|SBIW	|	|SBIW	|SBIW	|SBIW	|SBIW	|SBIW	|SBIW
|SBR	|SBR	|SBR	|SBR	|	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR	|SBR
|SBRC	|SBRC	|SBRC	|SBRC	|	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC	|SBRC
|SBRS	|SBRS	|SBRS	|SBRS	|	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS	|SBRS
|SEC	|SEC	|SEC	|SEC	|	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC	|SEC
|SEH	|SEH	|SEH	|SEH	|	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH	|SEH
|SEI	|SEI	|SEI	|SEI	|	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI	|SEI
|SEN	|SEN	|SEN	|SEN	|	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN	|SEN
|SER	|SER	|SER	|SER	|	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER	|SER
|SES	|SES	|SES	|SES	|	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES	|SES
|SET	|SET	|SET	|SET	|	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET	|SET
|SEV	|SEV	|SEV	|SEV	|	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV	|SEV
|SEZ	|SEZ	|SEZ	|SEZ	|	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ	|SEZ
|SLEEP	|SLEEP	|SLEEP	|SLEEP	|	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP	|SLEEP
|SPM	|	|	|SPM	|	|	|SPM	|SPM	|SPM	|SPM	|SPM	|	|SPM	|	|SPM	|SPM	|SPM	|SPM
|ST	|ST	|ST	|ST	|	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST	|ST
|STD	|	|STD	|STD	|	|STD	|STD	|STD	|STD	|STD	|STD	|	|STD	|STD	|STD	|STD	|STD	|STD
|STS	|	|STS	|STS	|	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS	|STS
|SUB	|SUB	|SUB	|SUB	|	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB	|SUB
|SUBI	|SUBI	|SUBI	|SUBI	|	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI	|SUBI
|SWAP	|SWAP	|SWAP	|SWAP	|	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP	|SWAP
|TST	|TST	|TST	|TST	|	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST	|TST
|WDR	|WDR	|WDR	|WDR	|	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR	|WDR
|XCH	|	|	|	|	|	|	|	|	|	|	|	|	|	|	|XCH	|	|
#13 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Hi all.

How is it going?

Regards,
Michael.

Quoted 851 lines · Michael Rolnik

Hi all.

When I decided to implement AVR 8 bit CPU support for QEMU I found this
document
<http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf> which listed all AVR instructions.
After that I learned that there are several CPU flavours, I looked into
this GCC file
<https://github.com/gcc-mirror/gcc/blob/master/gcc/config/avr/avr-devices.c> to figure out what are they as I could not find any official document
explaining it.
Then I downloaded several datasheets and created a list of instructions by
CPU type (attached).It turned out that there are some variations
e.g.
- AVTTINY - some have LDS, some don't
- AVR1, AVR25 - some have short SP, some don't
- AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 - some have RMW,
some don't
- AVRXMEGA3 - some have RCALL, some don't

I decided to leave CPU flavour definition as suggested by GCC gcc/config/avr/avr-devices.c
<https://github.com/gcc-mirror/gcc/blob/master/gcc/config/avr/avr-devices.c>
file and when a specific MCU is created it will set / reset CPU features relevant to it.

I hope this helps.

Best Regards,
Michael Rolnik

Quoted 791 lines · Aleksandar Markovic
Quoted 774 lines · Joaquin de Andres
Quoted 680 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
  target/avr/cpu.c | 601
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 601 insertions(+)
target/avr/cpu.c +26 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc,
 void *data)
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,

at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */

target/avr/cpu.c +22 -0
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a,

attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */

target/avr/cpu.c +74 -0
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2,

atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */

target/avr/cpu.c +25 -0
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48,

atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */

target/avr/cpu.c +25 -0
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831,

ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */

target/avr/cpu.c +26 -0
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284,

atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */

target/avr/cpu.c +81 -0
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4,

atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */

target/avr/cpu.c +27 -0
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417,

attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */

target/avr/cpu.c +92 -0
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3,

atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u, atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */

target/avr/cpu.c +117 -0
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char

*def_cpu_type)

target/avr/cpu.c +32 -0
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data) · line 818

Quoted 10 lines
target/avr/cpu.c +10 -0
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)

Hi! me again. Following the RC2 discussion. I've being looking in the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL,
AVR_MMCU_DEFAULT },
   /*
     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "1",   "avr1"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"  },
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25" },
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"  },
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31" },
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35" },
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"  },
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"  },
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51" },
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100", "avrtiny"},
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102", "avrxmega2"
},

{ 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103", "avrxmega3"
},
{ 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0, 0, "104", "avrxmega4"
},
{ 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0, 0, "105", "avrxmega5"
},
{ 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0, 0, "106", "avrxmega6"
},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0, 0, "107",
"avrxmega7" }
};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and microcontroller definition. Only looking at the family definition:

AVR_MCU ("avr2", ARCH_AVR2, AVR_ERRATA_SKIP, NULL,

    0x0060, 0x0, 0x60000, 0)
 AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x6000, 0)
 AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP, NULL,
     0x0060, 0x0, 0x20000, 0)
 AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE, NULL,
 0x0100, 0x0, 0x4000, 0)
 AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE,  NULL,
 0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE, NULL,
 0x0060, 0x0, 0x4000, 0)
 AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE, NULL,
 0x0100, 0x0, 0x20000, 0)
 AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE, NULL,
 0x0200, 0x0, 0x40000, 0)
 AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x9000, 0)
 AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3, AVR_ISA_NONE,  NULL,
       0x3f00, 0x0, 0x8000, 0)
 AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL,
     0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE, NULL,
         0x2000, 0x0, 0x60000, 0)
 AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE, NULL,
         0x2000, 0x0, 0x22000, 0)
Quoted 10 lines

AVR_MCU ("avrtiny", ARCH_AVRTINY, AVR_ISA_NONE, NULL,
0x0040, 0x0, 0x400, 0)
AVR_MCU ("avr1", ARCH_AVR1, AVR_ISA_NONE, NULL,
0x0060, 0x0, 0x400, 0)

I don't really understand how do you get to the proposed family definition for qemu. Probably is my fault but if you can help me to understand will be grate!

Michal, can you really give us more details on how this mapping is done?

Quoted 15 lines

I alredy asked a similar question a while ago, and then you said you used wikipedia article + avr datasheets. Can you give us more detailed info of the whole process of creating ABRFeature list for a particular AVR core type, and how that compares with the corresponding content in gcc, as Joakin brought to our attention?

Thanks, Aleksandar

Quoted 3 lines

Regards,
--joa

--
Best Regards,
Michael Rolnik

Signature · 2 lines
Best Regards,
Michael Rolnik
#14 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Quoted 8 lines · Michael Rolnik

Hi all.

How is it going?

Regards,
Michael.

Michael,

I think we are very close to merging.

There is absolutely no need to support ALL AVR mcus or AVR core types in the first version that will be merged.

But this issue (recently discovered during Jaoquin's review) about the fact that an avr core type doesn't determine in a complete way the instruction set of a particular MCU is thorny.

Should we switch from "-cpu <avr core type>" to "-cpu <mcu>" (but keep the current avr core type organization for internal purpose)? Or something else?

This is a high-level AVR suppot design issue. Let's think about it without a rush.

The problem is that once one organization/meaning of that switch is upstreamed, it is very difficult to switch to other. There is a procedural rule that deprecation process lasts at least 8 months, plus there may be some technical obstacles and difficulties.

In short, "-cpu <avr core type>" is not enough to emulate accurately a givem program.

Regards,
Aleksandar

Quoted 775 lines · Michael Rolnik
Quoted 760 lines

Hi all.

When I decided to implement AVR 8 bit CPU support for QEMU I found this document which listed all AVR instructions.
After that I learned that there are several CPU flavours, I looked into this GCC file to figure out what are they as I could not find any official document explaining it. Then I downloaded several datasheets and created a list of instructions by CPU type (attached).It turned out that there are some variations e.g.
- AVTTINY - some have LDS, some don't
- AVR1, AVR25 - some have short SP, some don't
- AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 - some have RMW, some don't
- AVRXMEGA3 - some have RCALL, some don't

I decided to leave CPU flavour definition as suggested by GCC gcc/config/avr/avr-devices.c file and when a specific MCU is created it will set / reset CPU features relevant to it.

I hope this helps.

Best Regards,
Michael Rolnik

Quoted 734 lines · Aleksandar Markovic
Quoted 718 lines · Joaquin de Andres
Quoted 645 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
---
  target/avr/cpu.c | 601 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 601 insertions(+)
target/avr/cpu.c +591 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414,
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24,
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
+ * attiny841, at86rf401
+ */
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2, atmega16u2,
+ * atmega32u2, attiny167, attiny1634
+ */
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48, atmega48a,
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p,
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1,
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c,
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162,
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a,
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa,
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb,
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323,
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p,
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328,
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa,
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1,
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644,
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p,
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p,
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p,
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216,
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p,
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286,
+ * at90usb1287
+ */
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4, atxmega32c3,
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u,
+ * atxmega32c4, atxmega32e5
+ */
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416, attiny417, attiny814,
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214,
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609,
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1,
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3,
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u, atxmega128b1,
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3,
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega7
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a1, atxmega128a1u, atxmega128a4u
+ */
+static void avr_xmega7_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+typedef struct AVRCPUInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} AVRCPUInfo;
+
+
+static void avr_cpu_list_entry(gpointer data, gpointer user_data)
+{
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+
+    qemu_printf("%s\n", typename);
+}
+
+void avr_cpu_list(void)
+{
+    GSList *list;
+    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
+    g_slist_foreach(list, avr_cpu_list_entry, NULL);
+    g_slist_free(list);
+}
+
+#define DEFINE_AVR_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_AVR_CPU, \
+        .instance_init = initfn, \
+        .name = AVR_CPU_TYPE_NAME(model), \
+    }
+
+static const TypeInfo avr_cpu_type_info[] = {
+    {
+        .name = TYPE_AVR_CPU,
+        .parent = TYPE_CPU,
+        .instance_size = sizeof(AVRCPU),
+        .instance_init = avr_cpu_initfn,
+        .class_size = sizeof(AVRCPUClass),
+        .class_init = avr_cpu_class_init,
+        .abstract = true,
+    },
+    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
+    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
+    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
+    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
+    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
+    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
+    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
+    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
+    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
+    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
+    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
+    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
+};
+
+const char *avr_flags_to_cpu_type(uint32_t flags, const char *def_cpu_type)
+{
+    switch (flags & EF_AVR_MACH) {
+    case bfd_mach_avr1:
+        return AVR_CPU_TYPE_NAME("avr1");
+    case bfd_mach_avr2:
+        return AVR_CPU_TYPE_NAME("avr2");
+    case bfd_mach_avr25:
+        return AVR_CPU_TYPE_NAME("avr25");
+    case bfd_mach_avr3:
+        return AVR_CPU_TYPE_NAME("avr3");
+    case bfd_mach_avr31:
+        return AVR_CPU_TYPE_NAME("avr31");
+    case bfd_mach_avr35:
+        return AVR_CPU_TYPE_NAME("avr35");
+    case bfd_mach_avr4:
+        return AVR_CPU_TYPE_NAME("avr4");
+    case bfd_mach_avr5:
+        return AVR_CPU_TYPE_NAME("avr5");
+    case bfd_mach_avr51:
+        return AVR_CPU_TYPE_NAME("avr51");
+    case bfd_mach_avr6:
+        return AVR_CPU_TYPE_NAME("avr6");
+    case bfd_mach_avrtiny:
+        return AVR_CPU_TYPE_NAME("avrtiny");
+    case bfd_mach_avrxmega2:
+        return AVR_CPU_TYPE_NAME("xmega2");
+    case bfd_mach_avrxmega3:
+        return AVR_CPU_TYPE_NAME("xmega3");
+    case bfd_mach_avrxmega4:
+        return AVR_CPU_TYPE_NAME("xmega4");
+    case bfd_mach_avrxmega5:
+        return AVR_CPU_TYPE_NAME("xmega5");

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data) · line 818

Quoted 10 lines
target/avr/cpu.c +10 -0
+    case bfd_mach_avrxmega6:
+        return AVR_CPU_TYPE_NAME("xmega6");
+    case bfd_mach_avrxmega7:
+        return AVR_CPU_TYPE_NAME("xmega7");
+    default:
+        return def_cpu_type;
+    }
+}
+
+DEFINE_TYPES(avr_cpu_type_info)

Hi! me again. Following the RC2 discussion. I've being looking in the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL, AVR_MMCU_DEFAULT },
   /*
     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "1",   "avr1"  },
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"  },
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25" },
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"  },
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31" },
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35" },
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"  },
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"  },
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51" },
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"  },

   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100", "avrtiny"},
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102", "avrxmega2" },
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103", "avrxmega3" },
   { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0, "104", "avrxmega4" },
   { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0, "105", "avrxmega5" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0, "106", "avrxmega6" },
   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0, "107", "avrxmega7"  }

};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and microcontroller definition. Only looking at the family definition:

 AVR_MCU ("avr2",             ARCH_AVR2, AVR_ERRATA_SKIP, NULL,              0x0060, 0x0, 0x60000, 0)
 AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE, NULL,             0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE, NULL,             0x0060, 0x0, 0x6000, 0)
 AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP, NULL,             0x0060, 0x0, 0x20000, 0)
 AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE, NULL,             0x0100, 0x0, 0x4000, 0)
 AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE,  NULL,             0x0060, 0x0, 0x2000, 0)
 AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE, NULL,             0x0060, 0x0, 0x4000, 0)
 AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE, NULL,             0x0100, 0x0, 0x20000, 0)
 AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE, NULL,             0x0200, 0x0, 0x40000, 0)
 AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE, NULL,             0x2000, 0x0, 0x9000, 0)
 AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3, AVR_ISA_NONE,  NULL,             0x3f00, 0x0, 0x8000, 0)
 AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE, NULL,             0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL,             0x2000, 0x0, 0x11000, 0)
 AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE, NULL,                 0x2000, 0x0, 0x60000, 0)
 AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE, NULL,                 0x2000, 0x0, 0x22000, 0)
 AVR_MCU ("avrtiny",          ARCH_AVRTINY, AVR_ISA_NONE, NULL,             0x0040, 0x0, 0x400, 0)
 AVR_MCU ("avr1",             ARCH_AVR1, AVR_ISA_NONE, NULL,             0x0060, 0x0, 0x400, 0)
Quoted 2 lines

I don't really understand how do you get to the proposed family definition for qemu. Probably is my fault but if you can help me to understand will be grate!

Michal, can you really give us more details on how this mapping is done?

I alredy asked a similar question a while ago, and then you said you used wikipedia article + avr datasheets. Can you give us more detailed info of the whole process of creating ABRFeature list for a particular AVR core type, and how that compares with the corresponding content in gcc, as Joakin brought to our attention?

Thanks, Aleksandar

Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Regards,
--joa

--
Best Regards,
Michael Rolnik

--
Best Regards,
Michael Rolnik

#15 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Hi all.

I don't see how the fact that some MCUs have an instruction and some don't within same AVR family.
Think about gnu binutils (not GCC) these utils have no idea about MCUs all they are aware of AVR CPU only.
However, I don't mind removing -cpu flag.

Regards,
Michael Ronik

Quoted 909 lines · Aleksandar Markovic
Quoted 8 lines · Michael Rolnik

Hi all.

How is it going?

Regards,
Michael.

Michael,

I think we are very close to merging.

There is absolutely no need to support ALL AVR mcus or AVR core types in the first version that will be merged.

But this issue (recently discovered during Jaoquin's review) about the fact that an avr core type doesn't determine in a complete way the instruction set of a particular MCU is thorny.

Should we switch from "-cpu <avr core type>" to "-cpu <mcu>" (but keep the current avr core type organization for internal purpose)? Or something else?

This is a high-level AVR suppot design issue. Let's think about it without a rush.

The problem is that once one organization/meaning of that switch is upstreamed, it is very difficult to switch to other. There is a procedural rule that deprecation process lasts at least 8 months, plus there may be some technical obstacles and difficulties.

In short, "-cpu <avr core type>" is not enough to emulate accurately a givem program.

Regards,
Aleksandar

Quoted 1 line

On Mon, Feb 10, 2020 at 9:39 AM Michael Rolnik <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines

Hi all.

When I decided to implement AVR 8 bit CPU support for QEMU I found this

document which listed all AVR instructions.

Quoted 1 line
Quoted 1 line

After that I learned that there are several CPU flavours, I looked into

this GCC file to figure out what are they as I could not find any official document explaining it.

Quoted 1 line
Quoted 1 line

Then I downloaded several datasheets and created a list of instructions

by CPU type (attached).It turned out that there are some variations

Quoted 4 lines
Quoted 4 lines

e.g.
- AVTTINY - some have LDS, some don't
- AVR1, AVR25 - some have short SP, some don't
- AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 - some have

RMW, some don't

Quoted 3 lines
Quoted 3 lines

- AVRXMEGA3 - some have RCALL, some don't

I decided to leave CPU flavour definition as suggested by GCC

gcc/config/avr/avr-devices.c file and when a specific MCU is created it will set / reset CPU features relevant to it.

Quoted 13 lines
Quoted 13 lines

I hope this helps.

Best Regards,
Michael Rolnik

On Sat, Feb 8, 2020 at 9:35 AM Aleksandar Markovic <

Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Quoted 4 lines

On Sunday, February 2, 2020, Joaquin de Andres <[email protected]>

Quoted 34 lines · wrote:
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines · Aleksandar Markovic
Quoted 32 lines

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
---
  target/avr/cpu.c | 601

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass

Quoted 7 lines
  1 file changed, 601 insertions(+)
target/avr/cpu.c +0 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass

*oc, void *data)

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +18 -0
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,

at90s4414,

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
target/avr/cpu.c +16 -0
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a,

attiny24,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 268

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84,

attiny84a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 269

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461,

attiny461a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 270

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88,

attiny828,

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
target/avr/cpu.c +68 -0
+ * attiny841, at86rf401
+ */
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2,

atmega16u2,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
target/avr/cpu.c +19 -0
+ * atmega32u2, attiny167, attiny1634
+ */
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a,

atmega48, atmega48a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 374

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a,

atmega88p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 375

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva,

at90pwm1,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
target/avr/cpu.c +19 -0
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795,

ata5831, ata6613c,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 403

Quoted 1 line
target/avr/cpu.c +1 -0
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161,

atmega162,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 404

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165,

atmega165a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 405

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p,

atmega168pa,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 406

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa,

atmega16hvb,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 407

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32,

atmega323,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 408

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a,

atmega325p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 409

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa,

atmega328,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 410

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p,

atmega329pa,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 411

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1,

atmega32m1,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 412

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a,

atmega640, atmega644,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 413

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a,

atmega645p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 414

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a,

atmega649p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 415

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a,

atmega6490p,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 417

Quoted 2 lines
target/avr/cpu.c +2 -0
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64,

at90pwm161, at90pwm216,

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
target/avr/cpu.c +20 -0
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284,

atmega1284p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 446

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128,

at90usb1286,

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
target/avr/cpu.c +75 -0
+ * at90usb1287
+ */
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4,

atxmega32c3,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 530

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4,

atxmega32a4u,

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +21 -0
+ * atxmega32c4, atxmega32e5
+ */
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416,

attiny417, attiny814,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 560

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617,

attiny3214,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 561

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608,

atmega1609,

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +21 -0
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u,

atxmega64b1,

Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
target/avr/cpu.c +57 -0
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a1, atxmega64a1u
+ */
+static void avr_xmega5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPD);
+    set_avr_feature(env, AVR_FEATURE_RAMPX);
+    set_avr_feature(env, AVR_FEATURE_RAMPY);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass *oc, void *data)

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3,

atxmega256a3,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 656

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u,

atxmega128b1,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 657

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u,

atxmega192c3,

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
target/avr/cpu.c +62 -0
+ * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
+ */
+static void avr_xmega6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 8 lines
target/avr/cpu.c +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

object_class_get_name(OBJECT_CLASS(data));

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
target/avr/cpu.c +41 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 8 lines
target/avr/cpu.c +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*def_cpu_type)

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
target/avr/cpu.c +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 6 lines
target/avr/cpu.c +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Hi! me again. Following the RC2 discussion. I've being looking in the

GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL,

AVR_MMCU_DEFAULT },

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

/*

     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */

{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0, 32, "1", "avr1"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",   "avr2"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",  "avr25"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",   "avr3"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",  "avr31"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",  "avr35"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",   "avr4"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",   "avr5"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",  "avr51"

},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",   "avr6"

},

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100",

"avrtiny"},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102",

"avrxmega2" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0, "103",

"avrxmega3" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0, "104",

"avrxmega4" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0, "105",

"avrxmega5" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0, "106",

"avrxmega6" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0, "107",

"avrxmega7" }

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

};

And then you have features for the specific microcontrollers:

AVR_ISA_RMW
AVR_SHORT_SP
AVR_ERRATA_SKIP
AVR_ISA_LDS
AVR_ISA_RCALL

They are mixed in the file 'avr-mcus.def' for family and

microcontroller definition. Only looking at the family definition:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

AVR_MCU ("avr2", ARCH_AVR2, AVR_ERRATA_SKIP, NULL,

        0x0060, 0x0, 0x60000, 0)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

AVR_MCU ("avr25", ARCH_AVR25, AVR_ISA_NONE, NULL,

     0x0060, 0x0, 0x2000, 0)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

AVR_MCU ("avr3", ARCH_AVR3, AVR_ISA_NONE, NULL,

63 lines not shown · raw message

2 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#16 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Hi all.

are there any action items for me?

Regards,
Michael Rolnik

Quoted 931 lines · Michael Rolnik

Hi all.

I don't see how the fact that some MCUs have an instruction and some don't within same AVR family.
Think about gnu binutils (not GCC) these utils have no idea about MCUs all they are aware of AVR CPU only.
However, I don't mind removing -cpu flag.

Regards,
Michael Ronik

Quoted 882 lines · Aleksandar Markovic
Quoted 8 lines · Michael Rolnik

Hi all.

How is it going?

Regards,
Michael.

Michael,

I think we are very close to merging.

There is absolutely no need to support ALL AVR mcus or AVR core types in the first version that will be merged.

But this issue (recently discovered during Jaoquin's review) about the fact that an avr core type doesn't determine in a complete way the instruction set of a particular MCU is thorny.

Should we switch from "-cpu <avr core type>" to "-cpu <mcu>" (but keep the current avr core type organization for internal purpose)? Or something else?

This is a high-level AVR suppot design issue. Let's think about it without a rush.

The problem is that once one organization/meaning of that switch is upstreamed, it is very difficult to switch to other. There is a procedural rule that deprecation process lasts at least 8 months, plus there may be some technical obstacles and difficulties.

In short, "-cpu <avr core type>" is not enough to emulate accurately a givem program.

Regards,
Aleksandar

Quoted 1 line

On Mon, Feb 10, 2020 at 9:39 AM Michael Rolnik <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines

Hi all.

When I decided to implement AVR 8 bit CPU support for QEMU I found

this document which listed all AVR instructions.

Quoted 1 line
Quoted 1 line

After that I learned that there are several CPU flavours, I looked

into this GCC file to figure out what are they as I could not find any official document explaining it.

Quoted 1 line
Quoted 1 line

Then I downloaded several datasheets and created a list of

instructions by CPU type (attached).It turned out that there are some variations

Quoted 4 lines
Quoted 4 lines

e.g.
- AVTTINY - some have LDS, some don't
- AVR1, AVR25 - some have short SP, some don't
- AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 - some have

RMW, some don't

Quoted 3 lines
Quoted 3 lines

- AVRXMEGA3 - some have RCALL, some don't

I decided to leave CPU flavour definition as suggested by GCC

gcc/config/avr/avr-devices.c file and when a specific MCU is created it will set / reset CPU features relevant to it.

Quoted 13 lines
Quoted 13 lines

I hope this helps.

Best Regards,
Michael Rolnik

On Sat, Feb 8, 2020 at 9:35 AM Aleksandar Markovic <

Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Quoted 4 lines

On Sunday, February 2, 2020, Joaquin de Andres <

Quoted 34 lines · [email protected]> wrote:
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines · Aleksandar Markovic
Quoted 32 lines

From: Michael Rolnik <[email protected]>

AVR core types are:

- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7

Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).

AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.

[AM: Split a larger AVR introduction patch into logical units]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
---
  target/avr/cpu.c | 601

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass

Quoted 7 lines
  1 file changed, 601 insertions(+)
target/avr/cpu.c +0 -0
index f41a887..e0ae055 100644
@@ -215,3 +215,604 @@ static void avr_cpu_class_init(ObjectClass

*oc, void *data)

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +18 -0
      cc->gdb_num_core_regs = 35;
      cc->gdb_core_xml_file = "avr-cpu.xml";
  }
+
+/*
+ * Setting features of AVR core type avr1
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s1200, attiny11, attiny12, attiny15, attiny28
+ */
+static void avr_avr1_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 243

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,

at90s4414,

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
target/avr/cpu.c +16 -0
+ * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
+ */
+static void avr_avr2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 267

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr25
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5272, ata6616c, attiny13, attiny13a, attiny2313,

attiny2313a, attiny24,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 268

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny24a, attiny4313, attiny44, attiny44a, attiny441,

attiny84, attiny84a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 269

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461,

attiny461a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 270

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88,

attiny828,

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
target/avr/cpu.c +68 -0
+ * attiny841, at86rf401
+ */
+static void avr_avr25_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
+
+/*
+ * Setting features of AVR core type avr3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * at43usb355, at76c711
+ */
+static void avr_avr3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+/*
+ * Setting features of AVR core type avr31
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega103, at43usb320
+ */
+static void avr_avr31_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 346

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr35
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2,

atmega16u2,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
target/avr/cpu.c +19 -0
+ * atmega32u2, attiny167, attiny1634
+ */
+static void avr_avr35_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 373

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a,

atmega48, atmega48a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 374

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a,

atmega88p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 375

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva,

at90pwm1,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
target/avr/cpu.c +19 -0
+ * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
+ */
+static void avr_avr4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 402

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr5
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795,

ata5831, ata6613c,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 403

Quoted 1 line
target/avr/cpu.c +1 -0
+ * ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161,

atmega162,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 404

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega163, atmega164a, atmega164p, atmega164pa, atmega165,

atmega165a,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 405

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega165p, atmega165pa, atmega168, atmega168a, atmega168p,

atmega168pa,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 406

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa,

atmega16hvb,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 407

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32,

atmega323,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 408

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega324a, atmega324p, atmega324pa, atmega325, atmega325a,

atmega325p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 409

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega325pa, atmega3250, atmega3250a, atmega3250p,

atmega3250pa, atmega328,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 410

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega328p, atmega328pb, atmega329, atmega329a, atmega329p,

atmega329pa,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 411

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1,

atmega32m1,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 412

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega32u4, atmega32u6, atmega406, atmega64, atmega64a,

atmega640, atmega644,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 413

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega644a, atmega644p, atmega644pa, atmega645, atmega645a,

atmega645p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 414

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a,

atmega649p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 415

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega6490, atmega16hva, atmega16hva2, atmega32hvb,

atmega6490a, atmega6490p,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 417

Quoted 2 lines
target/avr/cpu.c +2 -0
+ * atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2,
+ * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64,

at90pwm161, at90pwm216,

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
target/avr/cpu.c +20 -0
+ * at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000
+ */
+static void avr_avr5_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 445

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type avr51
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega128, atmega128a, atmega1280, atmega1281, atmega1284,

atmega1284p,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 446

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128,

at90usb1286,

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
target/avr/cpu.c +75 -0
+ * at90usb1287
+ */
+static void avr_avr51_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avr6
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
+ */
+static void avr_avr6_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_RAMPZ);
+    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+}
+
+/*
+ * Setting features of AVR core type avrtiny
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
+ */
+static void avr_avrtiny_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 529

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega2
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4,

atxmega32c3,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 530

Quoted 1 line
target/avr/cpu.c +1 -0
+ * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4,

atxmega32a4u,

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +21 -0
+ * atxmega32c4, atxmega32e5
+ */
+static void avr_xmega2_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 559

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega3
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * attiny212, attiny214, attiny412, attiny414, attiny416,

attiny417, attiny814,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 560

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny816, attiny817, attiny1614, attiny1616, attiny1617,

attiny3214,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 561

Quoted 1 line
target/avr/cpu.c +1 -0
+ * attiny3216, attiny3217, atmega808, atmega809, atmega1608,

atmega1609,

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
target/avr/cpu.c +21 -0
+ * atmega3208, atmega3209, atmega4808, atmega4809
+ */
+static void avr_xmega3_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c static void avr_cpu_class_init(ObjectClass · line 590

Quoted 8 lines
target/avr/cpu.c +8 -0
+
+/*
+ * Setting features of AVR core type xmega4
+ * --------------------------------------
+ *
+ * This type of AVR core is present in the following AVR MCUs:
+ *
+ * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u,

atxmega64b1,

Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
target/avr/cpu.c +57 -0
+ * atxmega64b3, atxmega64c3, atxmega64d4
+ */
+static void avr_xmega4_initfn(Object *obj)
+{
+    AVRCPU *cpu = AVR_CPU(obj);
+    CPUAVRState *env = &cpu->env;
+
+    set_avr_feature(env, AVR_FEATURE_LPM);
+    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
+    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
+    set_avr_feature(env, AVR_FEATURE_SRAM);
+    set_avr_feature(env, AVR_FEATURE_BREAK);
+
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
+    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
+    set_avr_feature(env, AVR_FEATURE_ELPMX);
+    set_avr_feature(env, AVR_FEATURE_ELPM);
+    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
+    set_avr_feature(env, AVR_FEATURE_LPMX);
+    set_avr_feature(env, AVR_FEATURE_MOVW);
+    set_avr_feature(env, AVR_FEATURE_MUL);
+    set_avr_feature(env, AVR_FEATURE_RMW);
+}
+
+/*
+ * Setting features of AVR core type xmega5
+ * --------------------------------------
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 8 lines
target/avr/cpu.c +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

atxmega256a3,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c

Quoted 1 line
target/avr/cpu.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

atxmega128b1,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

target/avr/cpu.c

Quoted 1 line
target/avr/cpu.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

atxmega192c3,

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
target/avr/cpu.c +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 8 lines
target/avr/cpu.c +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

object_class_get_name(OBJECT_CLASS(data));

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
target/avr/cpu.c +41 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 8 lines
target/avr/cpu.c +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*def_cpu_type)

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
target/avr/cpu.c +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

target/avr/cpu.c

Quoted 6 lines
target/avr/cpu.c +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Hi! me again. Following the RC2 discussion. I've being looking in

the GCC definition of the architecture and as far as I can understand this definitions are the generic definitions of the arch families.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

avr_arch_types[] =

 {
   /* unknown device specified */
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, NULL,

AVR_MMCU_DEFAULT },

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

/*

     A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
     S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
     M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
              XW M  M  M  G  P  Y  a r     s e       e   h
                    X  P  A  D       t     h t       t   ID   */

{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0, 32, "1",

"avr1" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "2",

"avr2" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "25",

"avr25" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "3",

"avr3" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32, "31",

"avr31" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "35",

"avr35" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "4",

"avr4" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32, "5",

"avr5" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32, "51",

"avr51" },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32, "6",

"avr6" },

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0, "100",

"avrtiny"},

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
   { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0, "102",

64 lines not shown · raw message

Quoted 29 lines

28 lines not shown · raw message

3 lines not shown · raw message

2 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#17 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

Hi Michael,

Quoted 3 lines · Michael Rolnik

Hi all.

are there any action items for me?

I am not sure neither of the status of this. See below.

Quoted 37 lines

Regards,
Michael Rolnik

On Thu, Feb 27, 2020 at 10:38 AM Michael Rolnik <[email protected] <mailto:[email protected]>> wrote:

Hi all.

I don't see how the fact that some MCUs have an instruction and some don't within same AVR family.
Think about gnu binutils (not GCC) these utils have no idea about MCUs all they are aware of AVR CPU only.
However, I don't mind removing -cpu flag.

Regards,
Michael Ronik

On Fri, Feb 21, 2020 at 5:31 PM Aleksandar Markovic <[email protected] <mailto:[email protected]>> wrote:

On Fri, Feb 21, 2020 at 12:04 PM Michael Rolnik <[email protected] <mailto:[email protected]>> wrote:
>
> Hi all.
>
> How is it going?
>
> Regards,
> Michael.
>

Michael,

I think we are very close to merging.

Quoted 8 lines

There is absolutely no need to support ALL AVR mcus or AVR core types
in the first version that will be merged.

But this issue (recently discovered during Jaoquin's review) about the
fact that an avr core type doesn't determine in a complete way the instruction set of a particular MCU is thorny.

I addressed Joaquin comments in the fork we use
with the following commit:
https://gitlab.com/philmd/qemu/-/commit/c6b227f1a0b2a3

But this was more than 3 months ago, so I don't remember much.

Anyway this thread is in the rc4, rc5 is on the list, you should ping the rc5 thread instead.

Quoted 942 lines
        Should we switch from "-cpu <avr core type>" to "-cpu <mcu>"
        (but keep
        the current avr core type organization for internal purpose)? Or
        something else?

        This is a high-level AVR suppot design issue. Let's think about it
        without a rush.

        The problem is that once one organization/meaning of that switch is
        upstreamed, it is very difficult to switch to other. There is a
        procedural rule that deprecation process lasts at least 8
        months, plus
        there may be some technical obstacles and difficulties.

        In short, "-cpu <avr core type>" is not enough to emulate
        accurately a
        givem program.

        Regards,
        Aleksandar

        > On Mon, Feb 10, 2020 at 9:39 AM Michael Rolnik
        <[email protected] <mailto:[email protected]>> wrote:
        >>
        >> Hi all.
        >>
        >> When I decided to implement AVR 8 bit CPU support for QEMU I
        found this document which listed all AVR instructions.
        >> After that I learned that there are several CPU flavours, I
        looked into this GCC file to figure out what are they as I could
        not find any official document explaining it.
        >> Then I downloaded several datasheets and created a list of
        instructions by CPU type (attached).It turned out that there are
        some variations
        >> e.g.
        >> - AVTTINY - some have LDS, some don't
        >> - AVR1, AVR25 - some have short SP, some don't
        >> - AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 -
        some have RMW, some don't
        >> - AVRXMEGA3 - some have RCALL, some don't
        >>
        >> I decided to leave CPU flavour definition as suggested by GCC
        gcc/config/avr/avr-devices.c file and when a specific MCU is
        created it will set / reset CPU features relevant to it.
        >>
        >> I hope this helps.
        >>
        >> Best Regards,
        >> Michael Rolnik
        >>
        >>
        >>
        >>
        >>
        >>
        >>
        >> On Sat, Feb 8, 2020 at 9:35 AM Aleksandar Markovic
        <[email protected]
        <mailto:[email protected]>> wrote:
        >>>
        >>>
        >>>
        >>> On Sunday, February 2, 2020, Joaquin de Andres
        <[email protected] <mailto:[email protected]>> wrote:
        >>>>
        >>>> On 1/31/20 1:02 AM, Aleksandar Markovic wrote:
        >>>>>
        >>>>> From: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>>
        >>>>> AVR core types are:
        >>>>>
        >>>>>    - avr1
        >>>>>    - avr2
        >>>>>    - avr25
        >>>>>    - avr3
        >>>>>    - avr31
        >>>>>    - avr35
        >>>>>    - avr4
        >>>>>    - avr5
        >>>>>    - avr51
        >>>>>    - avr6
        >>>>>    - avrtiny
        >>>>>    - xmega2
        >>>>>    - xmega3
        >>>>>    - xmega4
        >>>>>    - xmega5
        >>>>>    - xmega6
        >>>>>    - xmega7
        >>>>>
        >>>>> Each core type covers multiple AVR MCUs, mentioned in the
        comments
        >>>>> before definition of particular AVR core type (part of
        this patch).
        >>>>>
        >>>>> AVR core type defines shared features that are valid for
        all AVR
        >>>>> MCUs belonging in that type.
        >>>>>
        >>>>> [AM: Split a larger AVR introduction patch into logical units]
        >>>>> Suggested-by: Aleksandar Markovic
        <[email protected] <mailto:[email protected]>>
        >>>>>
        >>>>> Co-developed-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Co-developed-by: Sarah Harris <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Sarah Harris <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Acked-by: Igor Mammedov <[email protected]
        <mailto:[email protected]>>
        >>>>> Tested-by: Philippe Mathieu-Daudé <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Richard Henderson
        <[email protected] <mailto:[email protected]>>
        >>>>> Signed-off-by: Aleksandar Markovic
        <[email protected] <mailto:[email protected]>>
        >>>>> ---
        >>>>>   target/avr/cpu.c | 601
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++
        >>>>>   1 file changed, 601 insertions(+)
        >>>>>
        >>>>> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
        >>>>> index f41a887..e0ae055 100644
        >>>>> --- a/target/avr/cpu.c
        >>>>> +++ b/target/avr/cpu.c
        >>>>> @@ -215,3 +215,604 @@ static void
        avr_cpu_class_init(ObjectClass *oc, void *data)
        >>>>>       cc->gdb_num_core_regs = 35;
        >>>>>       cc->gdb_core_xml_file = "avr-cpu.xml";
        >>>>>   }
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr1
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at90s1200, attiny11, attiny12, attiny15, attiny28
        >>>>> + */
        >>>>> +static void avr_avr1_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr2
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at90s2313, at90s2323, at90s2333, at90s2343, attiny22,
        attiny26, at90s4414,
        >>>>> + * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
        >>>>> + */
        >>>>> +static void avr_avr2_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr25
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5272, ata6616c, attiny13, attiny13a, attiny2313,
        attiny2313a, attiny24,
        >>>>> + * attiny24a, attiny4313, attiny44, attiny44a, attiny441,
        attiny84, attiny84a,
        >>>>> + * attiny25, attiny45, attiny85, attiny261, attiny261a,
        attiny461, attiny461a,
        >>>>> + * attiny861, attiny861a, attiny43u, attiny87, attiny48,
        attiny88, attiny828,
        >>>>> + * attiny841, at86rf401
        >>>>> + */
        >>>>> +static void avr_avr25_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr3
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at43usb355, at76c711
        >>>>> + */
        >>>>> +static void avr_avr3_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr31
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega103, at43usb320
        >>>>> + */
        >>>>> +static void avr_avr31_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr35
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5505, ata6617c, ata664251, at90usb82, at90usb162,
        atmega8u2, atmega16u2,
        >>>>> + * atmega32u2, attiny167, attiny1634
        >>>>> + */
        >>>>> +static void avr_avr35_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr4
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata6285, ata6286, ata6289, ata6612c, atmega8,
        atmega8a, atmega48, atmega48a,
        >>>>> + * atmega48p, atmega48pa, atmega48pb, atmega88,
        atmega88a, atmega88p,
        >>>>> + * atmega88pa, atmega88pb, atmega8515, atmega8535,
        atmega8hva, at90pwm1,
        >>>>> + * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
        >>>>> + */
        >>>>> +static void avr_avr4_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr5
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5702m322, ata5782, ata5790, ata5790n, ata5791,
        ata5795, ata5831, ata6613c,
        >>>>> + * ata6614q, ata8210, ata8510, atmega16, atmega16a,
        atmega161, atmega162,
        >>>>> + * atmega163, atmega164a, atmega164p, atmega164pa,
        atmega165, atmega165a,
        >>>>> + * atmega165p, atmega165pa, atmega168, atmega168a,
        atmega168p, atmega168pa,
        >>>>> + * atmega168pb, atmega169, atmega169a, atmega169p,
        atmega169pa, atmega16hvb,
        >>>>> + * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a,
        atmega32, atmega323,
        >>>>> + * atmega324a, atmega324p, atmega324pa, atmega325,
        atmega325a, atmega325p,
        >>>>> + * atmega325pa, atmega3250, atmega3250a, atmega3250p,
        atmega3250pa, atmega328,
        >>>>> + * atmega328p, atmega328pb, atmega329, atmega329a,
        atmega329p, atmega329pa,
        >>>>> + * atmega3290, atmega3290a, atmega3290p, atmega3290pa,
        atmega32c1, atmega32m1,
        >>>>> + * atmega32u4, atmega32u6, atmega406, atmega64,
        atmega64a, atmega640, atmega644,
        >>>>> + * atmega644a, atmega644p, atmega644pa, atmega645,
        atmega645a, atmega645p,
        >>>>> + * atmega6450, atmega6450a, atmega6450p, atmega649,
        atmega649a, atmega649p,
        >>>>> + * atmega6490, atmega16hva, atmega16hva2, atmega32hvb,
        atmega6490a, atmega6490p,
        >>>>> + * atmega64c1, atmega64m1, atmega64hve, atmega64hve2,
        atmega64rfr2,
        >>>>> + * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64,
        at90pwm161, at90pwm216,
        >>>>> + * at90pwm316, at90scr100, at90usb646, at90usb647, at94k,
        m3000
        >>>>> + */
        >>>>> +static void avr_avr5_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr51
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega128, atmega128a, atmega1280, atmega1281,
        atmega1284, atmega1284p,
        >>>>> + * atmega128rfa1, atmega128rfr2, atmega1284rfr2,
        at90can128, at90usb1286,
        >>>>> + * at90usb1287
        >>>>> + */
        >>>>> +static void avr_avr51_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr6
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
        >>>>> + */
        >>>>> +static void avr_avr6_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avrtiny
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
        >>>>> + */
        >>>>> +static void avr_avrtiny_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega2
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5,
        atxmega32a4, atxmega32c3,
        >>>>> + * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4,
        atxmega32a4u,
        >>>>> + * atxmega32c4, atxmega32e5
        >>>>> + */
        >>>>> +static void avr_xmega2_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega3
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * attiny212, attiny214, attiny412, attiny414, attiny416,
        attiny417, attiny814,
        >>>>> + * attiny816, attiny817, attiny1614, attiny1616,
        attiny1617, attiny3214,
        >>>>> + * attiny3216, attiny3217, atmega808, atmega809,
        atmega1608, atmega1609,
        >>>>> + * atmega3208, atmega3209, atmega4808, atmega4809
        >>>>> + */
        >>>>> +static void avr_xmega3_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega4
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u,
        atxmega64b1,
        >>>>> + * atxmega64b3, atxmega64c3, atxmega64d4
        >>>>> + */
        >>>>> +static void avr_xmega4_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega5
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega64a1, atxmega64a1u
        >>>>> + */
        >>>>> +static void avr_xmega5_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPD);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPY);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega6
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega128a3, atxmega128d3, atxmega192a3,
        atxmega192d3, atxmega256a3,
        >>>>> + * atxmega256a3b, atxmega256a3bu, atxmega256d3,
        atxmega128a3u, atxmega128b1,
        >>>>> + * atxmega128b3, atxmega128c3, atxmega128d4,
        atxmega192a3u, atxmega192c3,
        >>>>> + * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
        >>>>> + */
        >>>>> +static void avr_xmega6_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega7
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega128a1, atxmega128a1u, atxmega128a4u
        >>>>> + */
        >>>>> +static void avr_xmega7_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPD);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPY);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +typedef struct AVRCPUInfo {
        >>>>> +    const char *name;
        >>>>> +    void (*initfn)(Object *obj);
        >>>>> +} AVRCPUInfo;
        >>>>> +
        >>>>> +
        >>>>> +static void avr_cpu_list_entry(gpointer data, gpointer
        user_data)
        >>>>> +{
        >>>>> +    const char *typename =
        object_class_get_name(OBJECT_CLASS(data));
        >>>>> +
        >>>>> +    qemu_printf("%s\n", typename);
        >>>>> +}
        >>>>> +
        >>>>> +void avr_cpu_list(void)
        >>>>> +{
        >>>>> +    GSList *list;
        >>>>> +    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
        >>>>> +    g_slist_foreach(list, avr_cpu_list_entry, NULL);
        >>>>> +    g_slist_free(list);
        >>>>> +}
        >>>>> +
        >>>>> +#define DEFINE_AVR_CPU_TYPE(model, initfn) \
        >>>>> +    { \
        >>>>> +        .parent = TYPE_AVR_CPU, \
        >>>>> +        .instance_init = initfn, \
        >>>>> +        .name = AVR_CPU_TYPE_NAME(model), \
        >>>>> +    }
        >>>>> +
        >>>>> +static const TypeInfo avr_cpu_type_info[] = {
        >>>>> +    {
        >>>>> +        .name = TYPE_AVR_CPU,
        >>>>> +        .parent = TYPE_CPU,
        >>>>> +        .instance_size = sizeof(AVRCPU),
        >>>>> +        .instance_init = avr_cpu_initfn,
        >>>>> +        .class_size = sizeof(AVRCPUClass),
        >>>>> +        .class_init = avr_cpu_class_init,
        >>>>> +        .abstract = true,
        >>>>> +    },
        >>>>> +    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
        >>>>> +};
        >>>>> +
        >>>>> +const char *avr_flags_to_cpu_type(uint32_t flags, const
        char *def_cpu_type)
        >>>>> +{
        >>>>> +    switch (flags & EF_AVR_MACH) {
        >>>>> +    case bfd_mach_avr1:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr1");
        >>>>> +    case bfd_mach_avr2:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr2");
        >>>>> +    case bfd_mach_avr25:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr25");
        >>>>> +    case bfd_mach_avr3:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr3");
        >>>>> +    case bfd_mach_avr31:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr31");
        >>>>> +    case bfd_mach_avr35:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr35");
        >>>>> +    case bfd_mach_avr4:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr4");
        >>>>> +    case bfd_mach_avr5:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr5");
        >>>>> +    case bfd_mach_avr51:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr51");
        >>>>> +    case bfd_mach_avr6:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr6");
        >>>>> +    case bfd_mach_avrtiny:
        >>>>> +        return AVR_CPU_TYPE_NAME("avrtiny");
        >>>>> +    case bfd_mach_avrxmega2:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega2");
        >>>>> +    case bfd_mach_avrxmega3:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega3");
        >>>>> +    case bfd_mach_avrxmega4:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega4");
        >>>>> +    case bfd_mach_avrxmega5:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega5");
        >>>>> +    case bfd_mach_avrxmega6:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega6");
        >>>>> +    case bfd_mach_avrxmega7:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega7");
        >>>>> +    default:
        >>>>> +        return def_cpu_type;
        >>>>> +    }
        >>>>> +}
        >>>>> +
        >>>>> +DEFINE_TYPES(avr_cpu_type_info)
        >>>>>
        >>>>
        >>>> Hi! me again. Following the RC2 discussion. I've being
        looking in the GCC definition of the architecture and as far as
        I can understand this definitions are the generic definitions of
        the arch families.
        >>>>
        >>>>  avr_arch_types[] =
        >>>>  {
        >>>>    /* unknown device specified */
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        NULL, AVR_MMCU_DEFAULT },
        >>>>    /*
        >>>>      A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
        >>>>      S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
        >>>>      M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
        >>>>               XW M  M  M  G  P  Y  a r     s e       e   h
        >>>>                     X  P  A  D       t     h t       t 
         ID   */
        >>>>    { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "1",   "avr1"  },
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "2",   "avr2"  },
        >>>>    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "25",  "avr25" },
        >>>>    { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "3",   "avr3"  },
        >>>>    { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "31",  "avr31" },
        >>>>    { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "35",  "avr35" },
        >>>>    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "4",   "avr4"  },
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "5",   "avr5"  },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32,
        "51",  "avr51" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32,
        "6",   "avr6"  },
        >>>>
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0,
        "100", "avrtiny"},
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0,
        "102", "avrxmega2" },
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0,
        "103", "avrxmega3" },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0,
        "104", "avrxmega4" },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0,
        "105", "avrxmega5" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0,
        "106", "avrxmega6" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0,
        "107", "avrxmega7"  }
        >>>>  };
        >>>>
        >>>> And then you have features for the specific microcontrollers:
        >>>>
        >>>>  AVR_ISA_RMW
        >>>>  AVR_SHORT_SP
        >>>>  AVR_ERRATA_SKIP
        >>>>  AVR_ISA_LDS
        >>>>  AVR_ISA_RCALL
        >>>>
        >>>> They are mixed in the file 'avr-mcus.def' for family and
        microcontroller definition. Only looking at the family definition:
        >>>>
        >>>>  AVR_MCU ("avr2",             ARCH_AVR2, AVR_ERRATA_SKIP,
        NULL,              0x0060, 0x0, 0x60000, 0)
        >>>>  AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x2000, 0)
        >>>>  AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x6000, 0)
        >>>>  AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP,
        NULL,             0x0060, 0x0, 0x20000, 0)
        >>>>  AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE,
        NULL,             0x0100, 0x0, 0x4000, 0)
        >>>>  AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE, 
        NULL,             0x0060, 0x0, 0x2000, 0)
        >>>>  AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x4000, 0)
        >>>>  AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE,
        NULL,             0x0100, 0x0, 0x20000, 0)
        >>>>  AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE,
        NULL,             0x0200, 0x0, 0x40000, 0)
        >>>>  AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x9000, 0)
        >>>>  AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3,
        AVR_ISA_NONE,  NULL,             0x3f00, 0x0, 0x8000, 0)
        >>>>  AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x11000, 0)
        >>>>  AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x11000, 0)
        >>>>  AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE,
        NULL,                 0x2000, 0x0, 0x60000, 0)
        >>>>  AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE,
        NULL,                 0x2000, 0x0, 0x22000, 0)
        >>>>  AVR_MCU ("avrtiny",          ARCH_AVRTINY, AVR_ISA_NONE,
        NULL,             0x0040, 0x0, 0x400, 0)
        >>>>  AVR_MCU ("avr1",             ARCH_AVR1, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x400, 0)
        >>>>
        >>>> I don't really understand how do you get to the proposed
        family definition for qemu. Probably is my fault but if you can
        help me to understand will be grate!
        >>>>
        >>>
        >>> Michal, can you really give us more details on how this
        mapping is done?
        >>>
        >>> I alredy asked a similar question a while ago, and then you
        said you used wikipedia article + avr datasheets. Can you give
        us more detailed info of the whole process of creating
        ABRFeature list for a particular AVR core type, and how that
        compares with the corresponding content in gcc, as Joakin
        brought to our attention?
        >>>
        >>> Thanks, Aleksandar
        >>>
        >>>
        >>>
        >>>>
        >>>> Regards,
        >>>> --joa
        >>
        >>
        >>
        >> --
        >> Best Regards,
        >> Michael Rolnik
        >
        >
        >
        > --
        > Best Regards,
        > Michael Rolnik



    -- 
    Best Regards,
    Michael Rolnik
Signature · 2 lines
Best Regards,
Michael Rolnik
#18 lore raw

Re: [PATCH rc4 06/29] target/avr: Add defintions of AVR core types

In reply to Michael Rolnik

Hi Michael,

Quoted 3 lines · Michael Rolnik

Hi all.

are there any action items for me?

FYI QEMU 5.1 soft freeze is next Tuesday, so even if Aleksandar respin this week, it is very unlikely Richard and myself have time to review it again before next week.

TBH let face it, AVR won't be in the next release.

When QEMU 5.2 development windows opens, you should start pinging early and insist every week.

I'm sorry you have been waiting so long without any updates. If that can comfort you a bit, you are not the only one waiting for this to be merged. Now if the AVR users were more active in the QEMU community (simply by showing their presence, sharing how they would use it) this would raise the interest in this port.

Regards,

Phil.

Quoted 987 lines

Regards,
Michael Rolnik

On Thu, Feb 27, 2020 at 10:38 AM Michael Rolnik <[email protected] <mailto:[email protected]>> wrote:

    Hi all.

    I don't see how the fact that some MCUs have an instruction and some
    don't within same AVR family.
    Think about gnu binutils (not GCC) these utils have no idea about
    MCUs all they are aware of AVR CPU only.
    However, I don't mind removing -cpu flag.

    Regards,
    Michael Ronik

    On Fri, Feb 21, 2020 at 5:31 PM Aleksandar Markovic
    <[email protected] <mailto:[email protected]>>
    wrote:

        On Fri, Feb 21, 2020 at 12:04 PM Michael Rolnik
        <[email protected] <mailto:[email protected]>> wrote:
        >
        > Hi all.
        >
        > How is it going?
        >
        > Regards,
        > Michael.
        >

        Michael,

        I think we are very close to merging.

        There is absolutely no need to support ALL AVR mcus or AVR core
        types
        in the first version that will be merged.

        But this issue (recently discovered during Jaoquin's review)
        about the
        fact that an avr core type doesn't determine in a complete way the
        instruction set of a particular MCU is thorny.

        Should we switch from "-cpu <avr core type>" to "-cpu <mcu>"
        (but keep
        the current avr core type organization for internal purpose)? Or
        something else?

        This is a high-level AVR suppot design issue. Let's think about it
        without a rush.

        The problem is that once one organization/meaning of that switch is
        upstreamed, it is very difficult to switch to other. There is a
        procedural rule that deprecation process lasts at least 8
        months, plus
        there may be some technical obstacles and difficulties.

        In short, "-cpu <avr core type>" is not enough to emulate
        accurately a
        givem program.

        Regards,
        Aleksandar

        > On Mon, Feb 10, 2020 at 9:39 AM Michael Rolnik
        <[email protected] <mailto:[email protected]>> wrote:
        >>
        >> Hi all.
        >>
        >> When I decided to implement AVR 8 bit CPU support for QEMU I
        found this document which listed all AVR instructions.
        >> After that I learned that there are several CPU flavours, I
        looked into this GCC file to figure out what are they as I could
        not find any official document explaining it.
        >> Then I downloaded several datasheets and created a list of
        instructions by CPU type (attached).It turned out that there are
        some variations
        >> e.g.
        >> - AVTTINY - some have LDS, some don't
        >> - AVR1, AVR25 - some have short SP, some don't
        >> - AVRXMEGA2, AVRXMEGA4, AVRXMEGA5, AVRXMEGA6, AVRXMEGA7 -
        some have RMW, some don't
        >> - AVRXMEGA3 - some have RCALL, some don't
        >>
        >> I decided to leave CPU flavour definition as suggested by GCC
        gcc/config/avr/avr-devices.c file and when a specific MCU is
        created it will set / reset CPU features relevant to it.
        >>
        >> I hope this helps.
        >>
        >> Best Regards,
        >> Michael Rolnik
        >>
        >>
        >>
        >>
        >>
        >>
        >>
        >> On Sat, Feb 8, 2020 at 9:35 AM Aleksandar Markovic
        <[email protected]
        <mailto:[email protected]>> wrote:
        >>>
        >>>
        >>>
        >>> On Sunday, February 2, 2020, Joaquin de Andres
        <[email protected] <mailto:[email protected]>> wrote:
        >>>>
        >>>> On 1/31/20 1:02 AM, Aleksandar Markovic wrote:
        >>>>>
        >>>>> From: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>>
        >>>>> AVR core types are:
        >>>>>
        >>>>>    - avr1
        >>>>>    - avr2
        >>>>>    - avr25
        >>>>>    - avr3
        >>>>>    - avr31
        >>>>>    - avr35
        >>>>>    - avr4
        >>>>>    - avr5
        >>>>>    - avr51
        >>>>>    - avr6
        >>>>>    - avrtiny
        >>>>>    - xmega2
        >>>>>    - xmega3
        >>>>>    - xmega4
        >>>>>    - xmega5
        >>>>>    - xmega6
        >>>>>    - xmega7
        >>>>>
        >>>>> Each core type covers multiple AVR MCUs, mentioned in the
        comments
        >>>>> before definition of particular AVR core type (part of
        this patch).
        >>>>>
        >>>>> AVR core type defines shared features that are valid for
        all AVR
        >>>>> MCUs belonging in that type.
        >>>>>
        >>>>> [AM: Split a larger AVR introduction patch into logical units]
        >>>>> Suggested-by: Aleksandar Markovic
        <[email protected] <mailto:[email protected]>>
        >>>>>
        >>>>> Co-developed-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Co-developed-by: Sarah Harris <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Sarah Harris <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Michael Rolnik <[email protected]
        <mailto:[email protected]>>
        >>>>> Acked-by: Igor Mammedov <[email protected]
        <mailto:[email protected]>>
        >>>>> Tested-by: Philippe Mathieu-Daudé <[email protected]
        <mailto:[email protected]>>
        >>>>> Signed-off-by: Richard Henderson
        <[email protected] <mailto:[email protected]>>
        >>>>> Signed-off-by: Aleksandar Markovic
        <[email protected] <mailto:[email protected]>>
        >>>>> ---
        >>>>>   target/avr/cpu.c | 601
        +++++++++++++++++++++++++++++++++++++++++++++++++++++++
        >>>>>   1 file changed, 601 insertions(+)
        >>>>>
        >>>>> diff --git a/target/avr/cpu.c b/target/avr/cpu.c
        >>>>> index f41a887..e0ae055 100644
        >>>>> --- a/target/avr/cpu.c
        >>>>> +++ b/target/avr/cpu.c
        >>>>> @@ -215,3 +215,604 @@ static void
        avr_cpu_class_init(ObjectClass *oc, void *data)
        >>>>>       cc->gdb_num_core_regs = 35;
        >>>>>       cc->gdb_core_xml_file = "avr-cpu.xml";
        >>>>>   }
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr1
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at90s1200, attiny11, attiny12, attiny15, attiny28
        >>>>> + */
        >>>>> +static void avr_avr1_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr2
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at90s2313, at90s2323, at90s2333, at90s2343, attiny22,
        attiny26, at90s4414,
        >>>>> + * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
        >>>>> + */
        >>>>> +static void avr_avr2_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr25
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5272, ata6616c, attiny13, attiny13a, attiny2313,
        attiny2313a, attiny24,
        >>>>> + * attiny24a, attiny4313, attiny44, attiny44a, attiny441,
        attiny84, attiny84a,
        >>>>> + * attiny25, attiny45, attiny85, attiny261, attiny261a,
        attiny461, attiny461a,
        >>>>> + * attiny861, attiny861a, attiny43u, attiny87, attiny48,
        attiny88, attiny828,
        >>>>> + * attiny841, at86rf401
        >>>>> + */
        >>>>> +static void avr_avr25_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr3
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * at43usb355, at76c711
        >>>>> + */
        >>>>> +static void avr_avr3_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr31
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega103, at43usb320
        >>>>> + */
        >>>>> +static void avr_avr31_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr35
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5505, ata6617c, ata664251, at90usb82, at90usb162,
        atmega8u2, atmega16u2,
        >>>>> + * atmega32u2, attiny167, attiny1634
        >>>>> + */
        >>>>> +static void avr_avr35_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr4
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata6285, ata6286, ata6289, ata6612c, atmega8,
        atmega8a, atmega48, atmega48a,
        >>>>> + * atmega48p, atmega48pa, atmega48pb, atmega88,
        atmega88a, atmega88p,
        >>>>> + * atmega88pa, atmega88pb, atmega8515, atmega8535,
        atmega8hva, at90pwm1,
        >>>>> + * at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81
        >>>>> + */
        >>>>> +static void avr_avr4_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr5
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * ata5702m322, ata5782, ata5790, ata5790n, ata5791,
        ata5795, ata5831, ata6613c,
        >>>>> + * ata6614q, ata8210, ata8510, atmega16, atmega16a,
        atmega161, atmega162,
        >>>>> + * atmega163, atmega164a, atmega164p, atmega164pa,
        atmega165, atmega165a,
        >>>>> + * atmega165p, atmega165pa, atmega168, atmega168a,
        atmega168p, atmega168pa,
        >>>>> + * atmega168pb, atmega169, atmega169a, atmega169p,
        atmega169pa, atmega16hvb,
        >>>>> + * atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a,
        atmega32, atmega323,
        >>>>> + * atmega324a, atmega324p, atmega324pa, atmega325,
        atmega325a, atmega325p,
        >>>>> + * atmega325pa, atmega3250, atmega3250a, atmega3250p,
        atmega3250pa, atmega328,
        >>>>> + * atmega328p, atmega328pb, atmega329, atmega329a,
        atmega329p, atmega329pa,
        >>>>> + * atmega3290, atmega3290a, atmega3290p, atmega3290pa,
        atmega32c1, atmega32m1,
        >>>>> + * atmega32u4, atmega32u6, atmega406, atmega64,
        atmega64a, atmega640, atmega644,
        >>>>> + * atmega644a, atmega644p, atmega644pa, atmega645,
        atmega645a, atmega645p,
        >>>>> + * atmega6450, atmega6450a, atmega6450p, atmega649,
        atmega649a, atmega649p,
        >>>>> + * atmega6490, atmega16hva, atmega16hva2, atmega32hvb,
        atmega6490a, atmega6490p,
        >>>>> + * atmega64c1, atmega64m1, atmega64hve, atmega64hve2,
        atmega64rfr2,
        >>>>> + * atmega644rfr2, atmega32hvbrevb, at90can32, at90can64,
        at90pwm161, at90pwm216,
        >>>>> + * at90pwm316, at90scr100, at90usb646, at90usb647, at94k,
        m3000
        >>>>> + */
        >>>>> +static void avr_avr5_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr51
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega128, atmega128a, atmega1280, atmega1281,
        atmega1284, atmega1284p,
        >>>>> + * atmega128rfa1, atmega128rfr2, atmega1284rfr2,
        at90can128, at90usb1286,
        >>>>> + * at90usb1287
        >>>>> + */
        >>>>> +static void avr_avr51_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avr6
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2
        >>>>> + */
        >>>>> +static void avr_avr6_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type avrtiny
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
        >>>>> + */
        >>>>> +static void avr_avrtiny_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega2
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5,
        atxmega32a4, atxmega32c3,
        >>>>> + * atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4,
        atxmega32a4u,
        >>>>> + * atxmega32c4, atxmega32e5
        >>>>> + */
        >>>>> +static void avr_xmega2_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega3
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * attiny212, attiny214, attiny412, attiny414, attiny416,
        attiny417, attiny814,
        >>>>> + * attiny816, attiny817, attiny1614, attiny1616,
        attiny1617, attiny3214,
        >>>>> + * attiny3216, attiny3217, atmega808, atmega809,
        atmega1608, atmega1609,
        >>>>> + * atmega3208, atmega3209, atmega4808, atmega4809
        >>>>> + */
        >>>>> +static void avr_xmega3_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega4
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u,
        atxmega64b1,
        >>>>> + * atxmega64b3, atxmega64c3, atxmega64d4
        >>>>> + */
        >>>>> +static void avr_xmega4_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega5
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega64a1, atxmega64a1u
        >>>>> + */
        >>>>> +static void avr_xmega5_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPD);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPY);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega6
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega128a3, atxmega128d3, atxmega192a3,
        atxmega192d3, atxmega256a3,
        >>>>> + * atxmega256a3b, atxmega256a3bu, atxmega256d3,
        atxmega128a3u, atxmega128b1,
        >>>>> + * atxmega128b3, atxmega128c3, atxmega128d4,
        atxmega192a3u, atxmega192c3,
        >>>>> + * atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3
        >>>>> + */
        >>>>> +static void avr_xmega6_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +/*
        >>>>> + * Setting features of AVR core type xmega7
        >>>>> + * --------------------------------------
        >>>>> + *
        >>>>> + * This type of AVR core is present in the following AVR
        MCUs:
        >>>>> + *
        >>>>> + * atxmega128a1, atxmega128a1u, atxmega128a4u
        >>>>> + */
        >>>>> +static void avr_xmega7_initfn(Object *obj)
        >>>>> +{
        >>>>> +    AVRCPU *cpu = AVR_CPU(obj);
        >>>>> +    CPUAVRState *env = &cpu->env;
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_SRAM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_BREAK);
        >>>>> +
        >>>>> +    set_avr_feature(env, AVR_FEATURE_3_BYTE_PC);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPD);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPY);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RAMPZ);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_EIJMP_EICALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_ELPM);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_JMP_CALL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_LPMX);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MOVW);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_MUL);
        >>>>> +    set_avr_feature(env, AVR_FEATURE_RMW);
        >>>>> +}
        >>>>> +
        >>>>> +typedef struct AVRCPUInfo {
        >>>>> +    const char *name;
        >>>>> +    void (*initfn)(Object *obj);
        >>>>> +} AVRCPUInfo;
        >>>>> +
        >>>>> +
        >>>>> +static void avr_cpu_list_entry(gpointer data, gpointer
        user_data)
        >>>>> +{
        >>>>> +    const char *typename =
        object_class_get_name(OBJECT_CLASS(data));
        >>>>> +
        >>>>> +    qemu_printf("%s\n", typename);
        >>>>> +}
        >>>>> +
        >>>>> +void avr_cpu_list(void)
        >>>>> +{
        >>>>> +    GSList *list;
        >>>>> +    list = object_class_get_list_sorted(TYPE_AVR_CPU, false);
        >>>>> +    g_slist_foreach(list, avr_cpu_list_entry, NULL);
        >>>>> +    g_slist_free(list);
        >>>>> +}
        >>>>> +
        >>>>> +#define DEFINE_AVR_CPU_TYPE(model, initfn) \
        >>>>> +    { \
        >>>>> +        .parent = TYPE_AVR_CPU, \
        >>>>> +        .instance_init = initfn, \
        >>>>> +        .name = AVR_CPU_TYPE_NAME(model), \
        >>>>> +    }
        >>>>> +
        >>>>> +static const TypeInfo avr_cpu_type_info[] = {
        >>>>> +    {
        >>>>> +        .name = TYPE_AVR_CPU,
        >>>>> +        .parent = TYPE_CPU,
        >>>>> +        .instance_size = sizeof(AVRCPU),
        >>>>> +        .instance_init = avr_cpu_initfn,
        >>>>> +        .class_size = sizeof(AVRCPUClass),
        >>>>> +        .class_init = avr_cpu_class_init,
        >>>>> +        .abstract = true,
        >>>>> +    },
        >>>>> +    DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
        >>>>> +    DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),
        >>>>> +};
        >>>>> +
        >>>>> +const char *avr_flags_to_cpu_type(uint32_t flags, const
        char *def_cpu_type)
        >>>>> +{
        >>>>> +    switch (flags & EF_AVR_MACH) {
        >>>>> +    case bfd_mach_avr1:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr1");
        >>>>> +    case bfd_mach_avr2:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr2");
        >>>>> +    case bfd_mach_avr25:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr25");
        >>>>> +    case bfd_mach_avr3:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr3");
        >>>>> +    case bfd_mach_avr31:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr31");
        >>>>> +    case bfd_mach_avr35:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr35");
        >>>>> +    case bfd_mach_avr4:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr4");
        >>>>> +    case bfd_mach_avr5:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr5");
        >>>>> +    case bfd_mach_avr51:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr51");
        >>>>> +    case bfd_mach_avr6:
        >>>>> +        return AVR_CPU_TYPE_NAME("avr6");
        >>>>> +    case bfd_mach_avrtiny:
        >>>>> +        return AVR_CPU_TYPE_NAME("avrtiny");
        >>>>> +    case bfd_mach_avrxmega2:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega2");
        >>>>> +    case bfd_mach_avrxmega3:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega3");
        >>>>> +    case bfd_mach_avrxmega4:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega4");
        >>>>> +    case bfd_mach_avrxmega5:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega5");
        >>>>> +    case bfd_mach_avrxmega6:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega6");
        >>>>> +    case bfd_mach_avrxmega7:
        >>>>> +        return AVR_CPU_TYPE_NAME("xmega7");
        >>>>> +    default:
        >>>>> +        return def_cpu_type;
        >>>>> +    }
        >>>>> +}
        >>>>> +
        >>>>> +DEFINE_TYPES(avr_cpu_type_info)
        >>>>>
        >>>>
        >>>> Hi! me again. Following the RC2 discussion. I've being
        looking in the GCC definition of the architecture and as far as
        I can understand this definitions are the generic definitions of
        the arch families.
        >>>>
        >>>>  avr_arch_types[] =
        >>>>  {
        >>>>    /* unknown device specified */
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        NULL, AVR_MMCU_DEFAULT },
        >>>>    /*
        >>>>      A  M  J  LM E  E  E  X  R  T  d S     FPO     S O   A
        >>>>      S  U  M  PO L  L  I  M  A  I  a t     lMff    F ff  r
        >>>>      M  L  P  MV P  P  J  E  M  N  t a     a s     R s   c
        >>>>               XW M  M  M  G  P  Y  a r     s e       e   h
        >>>>                     X  P  A  D       t     h t       t 
         ID   */
        >>>>    { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "1",   "avr1"  },
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "2",   "avr2"  },
        >>>>    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "25",  "avr25" },
        >>>>    { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "3",   "avr3"  },
        >>>>    { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "31",  "avr31" },
        >>>>    { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "35",  "avr35" },
        >>>>    { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "4",   "avr4"  },
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 0,      32,
        "5",   "avr5"  },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 0,      32,
        "51",  "avr51" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 0,      32,
        "6",   "avr6"  },
        >>>>
        >>>>    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0x4000, 0,
        "100", "avrtiny"},
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0,      0,
        "102", "avrxmega2" },
        >>>>    { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0x8000, 0,
        "103", "avrxmega3" },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0,      0,
        "104", "avrxmega4" },
        >>>>    { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0,      0,
        "105", "avrxmega5" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0,      0,
        "106", "avrxmega6" },
        >>>>    { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0,      0,
        "107", "avrxmega7"  }
        >>>>  };
        >>>>
        >>>> And then you have features for the specific microcontrollers:
        >>>>
        >>>>  AVR_ISA_RMW
        >>>>  AVR_SHORT_SP
        >>>>  AVR_ERRATA_SKIP
        >>>>  AVR_ISA_LDS
        >>>>  AVR_ISA_RCALL
        >>>>
        >>>> They are mixed in the file 'avr-mcus.def' for family and
        microcontroller definition. Only looking at the family definition:
        >>>>
        >>>>  AVR_MCU ("avr2",             ARCH_AVR2, AVR_ERRATA_SKIP,
        NULL,              0x0060, 0x0, 0x60000, 0)
        >>>>  AVR_MCU ("avr25",            ARCH_AVR25, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x2000, 0)
        >>>>  AVR_MCU ("avr3",             ARCH_AVR3, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x6000, 0)
        >>>>  AVR_MCU ("avr31",            ARCH_AVR31, AVR_ERRATA_SKIP,
        NULL,             0x0060, 0x0, 0x20000, 0)
        >>>>  AVR_MCU ("avr35",            ARCH_AVR35, AVR_ISA_NONE,
        NULL,             0x0100, 0x0, 0x4000, 0)
        >>>>  AVR_MCU ("avr4",             ARCH_AVR4, AVR_ISA_NONE, 
        NULL,             0x0060, 0x0, 0x2000, 0)
        >>>>  AVR_MCU ("avr5",             ARCH_AVR5, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x4000, 0)
        >>>>  AVR_MCU ("avr51",            ARCH_AVR51, AVR_ISA_NONE,
        NULL,             0x0100, 0x0, 0x20000, 0)
        >>>>  AVR_MCU ("avr6",             ARCH_AVR6, AVR_ISA_NONE,
        NULL,             0x0200, 0x0, 0x40000, 0)
        >>>>  AVR_MCU ("avrxmega2",        ARCH_AVRXMEGA2, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x9000, 0)
        >>>>  AVR_MCU ("avrxmega3",        ARCH_AVRXMEGA3,
        AVR_ISA_NONE,  NULL,             0x3f00, 0x0, 0x8000, 0)
        >>>>  AVR_MCU ("avrxmega4",        ARCH_AVRXMEGA4, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x11000, 0)
        >>>>  AVR_MCU ("avrxmega5",        ARCH_AVRXMEGA5, AVR_ISA_NONE,
        NULL,             0x2000, 0x0, 0x11000, 0)
        >>>>  AVR_MCU ("avrxmega6",        ARCH_AVRXMEGA6, AVR_ISA_NONE,
        NULL,                 0x2000, 0x0, 0x60000, 0)
        >>>>  AVR_MCU ("avrxmega7",        ARCH_AVRXMEGA7, AVR_ISA_NONE,
        NULL,                 0x2000, 0x0, 0x22000, 0)
        >>>>  AVR_MCU ("avrtiny",          ARCH_AVRTINY, AVR_ISA_NONE,
        NULL,             0x0040, 0x0, 0x400, 0)
        >>>>  AVR_MCU ("avr1",             ARCH_AVR1, AVR_ISA_NONE,
        NULL,             0x0060, 0x0, 0x400, 0)
        >>>>
        >>>> I don't really understand how do you get to the proposed
        family definition for qemu. Probably is my fault but if you can
        help me to understand will be grate!
        >>>>
        >>>
        >>> Michal, can you really give us more details on how this
        mapping is done?
        >>>
        >>> I alredy asked a similar question a while ago, and then you
        said you used wikipedia article + avr datasheets. Can you give
        us more detailed info of the whole process of creating
        ABRFeature list for a particular AVR core type, and how that
        compares with the corresponding content in gcc, as Joakin
        brought to our attention?
        >>>
        >>> Thanks, Aleksandar
        >>>
        >>>
        >>>
        >>>>
        >>>> Regards,
        >>>> --joa
        >>
        >>
        >>
        >> --
        >> Best Regards,
        >> Michael Rolnik
        >
        >
        >
        > --
        > Best Regards,
        > Michael Rolnik



    -- 
    Best Regards,
    Michael Rolnik
Signature · 2 lines
Best Regards,
Michael Rolnik
#19 lore raw

PATCH 7/29 target/avr: Add instruction helpers

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add helpers for instructions that need to interact with QEMU. Also, add stubs for unimplemented instructions. Instructions SPM and WDR are left unimplemented because they require emulation of complex peripherals. The implementation of instruction SLEEP is very limited due to the lack of peripherals to generate wake interrupts. Memory access instructions are implemented here because some address ranges actually refer to CPU registers.

---
 target/avr/helper.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 target/avr/helper.h |  29 ++++++++
 2 files changed, 232 insertions(+)
 create mode 100644 target/avr/helper.h
target/avr/helper.c +203 -0
index 354def2..c582312 100644
@@ -137,3 +137,206 @@ bool avr_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
 
     return true;
 }
+
+/*
+ *  helpers
+ */
+
+void helper_sleep(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_HLT;
+    cpu_loop_exit(cs);
+}
+
+void helper_unsupported(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    /*
+     *  I count not find what happens on the real platform, so
+     *  it's EXCP_DEBUG for meanwhile
+     */
+    cs->exception_index = EXCP_DEBUG;
+    if (qemu_loglevel_mask(LOG_UNIMP)) {
+        qemu_log("UNSUPPORTED\n");
+        cpu_dump_state(cs, stderr, 0);
+    }
+    cpu_loop_exit(cs);
+}
+
+void helper_debug(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+void helper_break(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+void helper_wdr(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    /* WD is not implemented yet, placeholder */
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+/*
+ * This function implements IN instruction
+ *
+ * It does the following
+ * a.  if an IO register belongs to CPU, its value is read and returned
+ * b.  otherwise io address is translated to mem address and physical memory
+ *     is read.
+ * c.  it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
+ *
+ */
+target_ulong helper_inb(CPUAVRState *env, uint32_t port)
+{
+    target_ulong data = 0;
+
+    switch (port) {
+    case 0x38: /* RAMPD */
+        data = 0xff & (env->rampD >> 16);
+        break;
+    case 0x39: /* RAMPX */
+        data = 0xff & (env->rampX >> 16);
+        break;
+    case 0x3a: /* RAMPY */
+        data = 0xff & (env->rampY >> 16);
+        break;
+    case 0x3b: /* RAMPZ */
+        data = 0xff & (env->rampZ >> 16);
+        break;
+    case 0x3c: /* EIND */
+        data = 0xff & (env->eind >> 16);
+        break;
+    case 0x3d: /* SPL */
+        data = env->sp & 0x00ff;
+        break;
+    case 0x3e: /* SPH */
+        data = env->sp >> 8;
+        break;
+    case 0x3f: /* SREG */
+        data = cpu_get_sreg(env);
+        break;
+    default:
+        /* not a special register, pass to normal memory access */
+        cpu_physical_memory_read(OFFSET_IO_REGISTERS + port, &data, 1);
+    }
+
+    return data;
+}
+
+/*
+ *  This function implements OUT instruction
+ *
+ *  It does the following
+ *  a.  if an IO register belongs to CPU, its value is written into the register
+ *  b.  otherwise io address is translated to mem address and physical memory
+ *      is written.
+ *  c.  it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
+ *
+ */
+void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)
+{
+    data &= 0x000000ff;
+
+    switch (port) {
+    case 0x38: /* RAMPD */
+        if (avr_feature(env, AVR_FEATURE_RAMPD)) {
+            env->rampD = (data & 0xff) << 16;
+        }
+        break;
+    case 0x39: /* RAMPX */
+        if (avr_feature(env, AVR_FEATURE_RAMPX)) {
+            env->rampX = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3a: /* RAMPY */
+        if (avr_feature(env, AVR_FEATURE_RAMPY)) {
+            env->rampY = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3b: /* RAMPZ */
+        if (avr_feature(env, AVR_FEATURE_RAMPZ)) {
+            env->rampZ = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3c: /* EIDN */
+        env->eind = (data & 0xff) << 16;
+        break;
+    case 0x3d: /* SPL */
+        env->sp = (env->sp & 0xff00) | (data);
+        break;
+    case 0x3e: /* SPH */
+        if (avr_feature(env, AVR_FEATURE_2_BYTE_SP)) {
+            env->sp = (env->sp & 0x00ff) | (data << 8);
+        }
+        break;
+    case 0x3f: /* SREG */
+        cpu_set_sreg(env, data);
+        break;
+    default:
+        /* not a special register, pass to normal memory access */
+        cpu_physical_memory_write(OFFSET_IO_REGISTERS + port, &data, 1);
+    }
+}
+
+/*
+ *  this function implements LD instruction when there is a posibility to read
+ *  from a CPU register
+ */
+target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr)
+{
+    uint8_t data;
+
+    env->fullacc = false;
+
+    if (addr < NUMBER_OF_CPU_REGISTERS) {
+        /* CPU registers */
+        data = env->r[addr];
+    } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
+        /* IO registers */
+        data = helper_inb(env, addr - NUMBER_OF_CPU_REGISTERS);
+    } else {
+        /* memory */
+        cpu_physical_memory_read(OFFSET_DATA + addr, &data, 1);
+    }
+    return data;
+}
+
+/*
+ *  this function implements ST instruction when there is a posibility to write
+ *  into a CPU register
+ */
+void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr)
+{
+    env->fullacc = false;
+
+    /* Following logic assumes this: */
+    assert(OFFSET_CPU_REGISTERS == OFFSET_DATA);
+    assert(OFFSET_IO_REGISTERS == OFFSET_CPU_REGISTERS +
+            NUMBER_OF_CPU_REGISTERS);
+
+    if (addr < NUMBER_OF_CPU_REGISTERS) {
+        /* CPU registers */
+        env->r[addr] = data;
+    } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
+        /* IO registers */
+        helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data);
+    } else {
+        /* memory */
+        cpu_physical_memory_write(OFFSET_DATA + addr, &data, 1);
+    }
+}
target/avr/helper.h new file +29 -0
new file mode 100644
index 0000000..bf08750
@@ -0,0 +1,29 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+DEF_HELPER_1(wdr, void, env)
+DEF_HELPER_1(debug, void, env)
+DEF_HELPER_1(break, void, env)
+DEF_HELPER_1(sleep, void, env)
+DEF_HELPER_1(unsupported, void, env)
+DEF_HELPER_3(outb, void, env, i32, i32)
+DEF_HELPER_2(inb, tl, env, i32)
+DEF_HELPER_3(fullwr, void, env, i32, i32)
+DEF_HELPER_2(fullrd, tl, env, i32)
Signature · 1 line
2.7.4
Reviewed-by on v1 7/29
#20 lore raw

Re: [PATCH rc4 07/29] target/avr: Add instruction helpers

Quoted 10 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add helpers for instructions that need to interact with QEMU. Also, add stubs for unimplemented instructions. Instructions SPM and WDR are left unimplemented because they require emulation of complex peripherals. The implementation of instruction SLEEP is very limited due to the lack of peripherals to generate wake interrupts. Memory access instructions are implemented here because some address ranges actually refer to CPU registers.

Quoted 5 lines

---

Hello, Michael.

Regarding this and patches 8-14, I did not find any functional inaccuracies. "avrtiny" issues (lack of support for cores with fewer registers) are agreed to be addressed later on, some time after the merge, as not critical for the rest of series.

I had, and still have some concerns about missing comments and code readibility in general (details can be seen in my previuos reviews). I have some concerns about lack of usage of enum AVRFeature in some functions (instead of int). I have some concerns abuot functions organization too.

But, all of these concerns are not related to the final functionality. In my view, it is even too risky to address them at this stage of the series. They can be easily addressed after the series merge.

Therefore:

For patches 7-14:

Quoted 264 lines
 target/avr/helper.c | 203 ++++++++++++++++++++++++++++++
++++++++++++++++++++++
 target/avr/helper.h |  29 ++++++++
 2 files changed, 232 insertions(+)
 create mode 100644 target/avr/helper.h
target/avr/helper.c +60 -0
index 354def2..c582312 100644
@@ -137,3 +137,206 @@ bool avr_cpu_tlb_fill(CPUState *cs, vaddr address,
 int size,
 
     return true;
 }
+
+/*
+ *  helpers
+ */
+
+void helper_sleep(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_HLT;
+    cpu_loop_exit(cs);
+}
+
+void helper_unsupported(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    /*
+     *  I count not find what happens on the real platform, so
+     *  it's EXCP_DEBUG for meanwhile
+     */
+    cs->exception_index = EXCP_DEBUG;
+    if (qemu_loglevel_mask(LOG_UNIMP)) {
+        qemu_log("UNSUPPORTED\n");
+        cpu_dump_state(cs, stderr, 0);
+    }
+    cpu_loop_exit(cs);
+}
+
+void helper_debug(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+void helper_break(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+void helper_wdr(CPUAVRState *env)
+{
+    CPUState *cs = env_cpu(env);
+
+    /* WD is not implemented yet, placeholder */
+    cs->exception_index = EXCP_DEBUG;
+    cpu_loop_exit(cs);
+}
+
+/*
+ * This function implements IN instruction
+ *
+ * It does the following
+ * a.  if an IO register belongs to CPU, its value is read and returned
+ * b.  otherwise io address is translated to mem address and physical

memory
+ * is read.
+ * c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
+ *
+ */

target/avr/helper.c +42 -0
+target_ulong helper_inb(CPUAVRState *env, uint32_t port)
+{
+    target_ulong data = 0;
+
+    switch (port) {
+    case 0x38: /* RAMPD */
+        data = 0xff & (env->rampD >> 16);
+        break;
+    case 0x39: /* RAMPX */
+        data = 0xff & (env->rampX >> 16);
+        break;
+    case 0x3a: /* RAMPY */
+        data = 0xff & (env->rampY >> 16);
+        break;
+    case 0x3b: /* RAMPZ */
+        data = 0xff & (env->rampZ >> 16);
+        break;
+    case 0x3c: /* EIND */
+        data = 0xff & (env->eind >> 16);
+        break;
+    case 0x3d: /* SPL */
+        data = env->sp & 0x00ff;
+        break;
+    case 0x3e: /* SPH */
+        data = env->sp >> 8;
+        break;
+    case 0x3f: /* SREG */
+        data = cpu_get_sreg(env);
+        break;
+    default:
+        /* not a special register, pass to normal memory access */
+        cpu_physical_memory_read(OFFSET_IO_REGISTERS + port, &data, 1);
+    }
+
+    return data;
+}
+
+/*
+ *  This function implements OUT instruction
+ *
+ *  It does the following
+ *  a.  if an IO register belongs to CPU, its value is written into the

register
+ * b. otherwise io address is translated to mem address and physical memory
+ * is written.
+ * c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation
+ *
+ */

target/avr/helper.c +47 -0
+void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)
+{
+    data &= 0x000000ff;
+
+    switch (port) {
+    case 0x38: /* RAMPD */
+        if (avr_feature(env, AVR_FEATURE_RAMPD)) {
+            env->rampD = (data & 0xff) << 16;
+        }
+        break;
+    case 0x39: /* RAMPX */
+        if (avr_feature(env, AVR_FEATURE_RAMPX)) {
+            env->rampX = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3a: /* RAMPY */
+        if (avr_feature(env, AVR_FEATURE_RAMPY)) {
+            env->rampY = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3b: /* RAMPZ */
+        if (avr_feature(env, AVR_FEATURE_RAMPZ)) {
+            env->rampZ = (data & 0xff) << 16;
+        }
+        break;
+    case 0x3c: /* EIDN */
+        env->eind = (data & 0xff) << 16;
+        break;
+    case 0x3d: /* SPL */
+        env->sp = (env->sp & 0xff00) | (data);
+        break;
+    case 0x3e: /* SPH */
+        if (avr_feature(env, AVR_FEATURE_2_BYTE_SP)) {
+            env->sp = (env->sp & 0x00ff) | (data << 8);
+        }
+        break;
+    case 0x3f: /* SREG */
+        cpu_set_sreg(env, data);
+        break;
+    default:
+        /* not a special register, pass to normal memory access */
+        cpu_physical_memory_write(OFFSET_IO_REGISTERS + port, &data, 1);
+    }
+}
+
+/*
+ *  this function implements LD instruction when there is a posibility to

read
+ * from a CPU register
+ */

target/avr/helper.c +21 -0
+target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr)
+{
+    uint8_t data;
+
+    env->fullacc = false;
+
+    if (addr < NUMBER_OF_CPU_REGISTERS) {
+        /* CPU registers */
+        data = env->r[addr];
+    } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
+        /* IO registers */
+        data = helper_inb(env, addr - NUMBER_OF_CPU_REGISTERS);
+    } else {
+        /* memory */
+        cpu_physical_memory_read(OFFSET_DATA + addr, &data, 1);
+    }
+    return data;
+}
+
+/*
+ *  this function implements ST instruction when there is a posibility to

write
+ * into a CPU register
+ */

target/avr/helper.c +20 -0
+void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr)
+{
+    env->fullacc = false;
+
+    /* Following logic assumes this: */
+    assert(OFFSET_CPU_REGISTERS == OFFSET_DATA);
+    assert(OFFSET_IO_REGISTERS == OFFSET_CPU_REGISTERS +
+            NUMBER_OF_CPU_REGISTERS);
+
+    if (addr < NUMBER_OF_CPU_REGISTERS) {
+        /* CPU registers */
+        env->r[addr] = data;
+    } else if (addr < NUMBER_OF_CPU_REGISTERS + NUMBER_OF_IO_REGISTERS) {
+        /* IO registers */
+        helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data);
+    } else {
+        /* memory */
+        cpu_physical_memory_write(OFFSET_DATA + addr, &data, 1);
+    }
+}
target/avr/helper.h new file +29 -1
new file mode 100644
index 0000000..bf08750
@@ -0,0 +1,29 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+DEF_HELPER_1(wdr, void, env)
+DEF_HELPER_1(debug, void, env)
+DEF_HELPER_1(break, void, env)
+DEF_HELPER_1(sleep, void, env)
+DEF_HELPER_1(unsupported, void, env)
+DEF_HELPER_3(outb, void, env, i32, i32)
+DEF_HELPER_2(inb, tl, env, i32)
+DEF_HELPER_3(fullwr, void, env, i32, i32)
+DEF_HELPER_2(fullrd, tl, env, i32)
--

2.7.4

#21 lore raw

PATCH 8/29 target/avr: Add instruction translation - Register definitions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Start implementation of instructions by adding register definitions.

---
 target/avr/translate.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 171 insertions(+)
 create mode 100644 target/avr/translate.c
target/avr/translate.c new file +171 -0
new file mode 100644
index 0000000..535f666
@@ -0,0 +1,171 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/qemu-print.h"
+#include "tcg/tcg.h"
+#include "cpu.h"
+#include "exec/exec-all.h"
+#include "tcg/tcg-op.h"
+#include "exec/cpu_ldst.h"
+#include "exec/helper-proto.h"
+#include "exec/helper-gen.h"
+#include "exec/log.h"
+#include "exec/translator.h"
+#include "exec/gen-icount.h"
+
+/*
+ *  Define if you want a BREAK instruction translated to a breakpoint
+ *  Active debugging connection is assumed
+ *  This is for
+ *  https://github.com/seharris/qemu-avr-tests/tree/master/instruction-tests
+ *  tests
+ */
+#undef BREAKPOINT_ON_BREAK
+
+static TCGv cpu_pc;
+
+static TCGv cpu_Cf;
+static TCGv cpu_Zf;
+static TCGv cpu_Nf;
+static TCGv cpu_Vf;
+static TCGv cpu_Sf;
+static TCGv cpu_Hf;
+static TCGv cpu_Tf;
+static TCGv cpu_If;
+
+static TCGv cpu_rampD;
+static TCGv cpu_rampX;
+static TCGv cpu_rampY;
+static TCGv cpu_rampZ;
+
+static TCGv cpu_r[NUMBER_OF_CPU_REGISTERS];
+static TCGv cpu_eind;
+static TCGv cpu_sp;
+
+static TCGv cpu_skip;
+
+static const char reg_names[NUMBER_OF_CPU_REGISTERS][8] = {
+    "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
+    "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
+    "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
+    "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
+};
+#define REG(x) (cpu_r[x])
+
+enum {
+    DISAS_EXIT   = DISAS_TARGET_0,  /* We want return to the cpu main loop.  */
+    DISAS_LOOKUP = DISAS_TARGET_1,  /* We have a variable condition exit.  */
+    DISAS_CHAIN  = DISAS_TARGET_2,  /* We have a single condition exit.  */
+};
+
+typedef struct DisasContext DisasContext;
+
+/* This is the state at translation time. */
+struct DisasContext {
+    TranslationBlock *tb;
+
+    CPUAVRState *env;
+    CPUState *cs;
+
+    target_long npc;
+    uint32_t opcode;
+
+    /* Routine used to access memory */
+    int memidx;
+    int bstate;
+    int singlestep;
+
+    /*
+     * some AVR instructions can make the following instruction to be skipped
+     * Let's name those instructions
+     *     A   - instruction that can skip the next one
+     *     B   - instruction that can be skipped. this depends on execution of A
+     * there are two scenarios
+     * 1. A and B belong to the same translation block
+     * 2. A is the last instruction in the translation block and B is the last
+     *
+     * following variables are used to simplify the skipping logic, they are
+     * used in the following manner (sketch)
+     *
+     * TCGLabel *skip_label = NULL;
+     * if (ctx.skip_cond != TCG_COND_NEVER) {
+     *     skip_label = gen_new_label();
+     *     tcg_gen_brcond_tl(skip_cond, skip_var0, skip_var1, skip_label);
+     * }
+     *
+     * if (free_skip_var0) {
+     *     tcg_temp_free(skip_var0);
+     *     free_skip_var0 = false;
+     * }
+     *
+     * translate(&ctx);
+     *
+     * if (skip_label) {
+     *     gen_set_label(skip_label);
+     * }
+     */
+    TCGv skip_var0;
+    TCGv skip_var1;
+    TCGCond skip_cond;
+    bool free_skip_var0;
+};
+
+static int to_regs_16_31_by_one(DisasContext *ctx, int indx)
+{
+    return 16 + (indx % 16);
+}
+
+static int to_regs_16_23_by_one(DisasContext *ctx, int indx)
+{
+    return 16 + (indx % 8);
+}
+static int to_regs_24_30_by_two(DisasContext *ctx, int indx)
+{
+    return 24 + (indx % 4) * 2;
+}
+static int to_regs_00_30_by_two(DisasContext *ctx, int indx)
+{
+    return (indx % 16) * 2;
+}
+
+static uint16_t next_word(DisasContext *ctx)
+{
+    return cpu_lduw_code(ctx->env, ctx->npc++ * 2);
+}
+
+static int append_16(DisasContext *ctx, int x)
+{
+    return x << 16 | next_word(ctx);
+}
+
+
+static bool avr_have_feature(DisasContext *ctx, int feature)
+{
+    if (!avr_feature(ctx->env, feature)) {
+        gen_helper_unsupported(cpu_env);
+        ctx->bstate = DISAS_NORETURN;
+        return false;
+    }
+    return true;
+}
+
+static bool decode_insn(DisasContext *ctx, uint16_t insn);
+#include "decode_insn.inc.c"
Signature · 1 line
2.7.4
#22 lore raw

PATCH 9/29 target/avr: Add instruction translation - Arithmetic and Logic Instructions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes:
- ADD, ADC, ADIW
- SBIW, SUB, SUBI, SBC, SBCI
- AND, ANDI
- OR, ORI, EOR
- COM, NEG
- INC, DEC
- MUL, MULS, MULSU
- FMUL, FMULS, FMULSU
- DES

---
 target/avr/insn.decode |  93 ++++++
 target/avr/translate.c | 752 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 845 insertions(+)
 create mode 100644 target/avr/insn.decode
target/avr/insn.decode new file +93 -0
new file mode 100644
index 0000000..9c71ed6
@@ -0,0 +1,93 @@
+#
+# AVR instruction decode definitions.
+#
+# Copyright (c) 2019 Michael Rolnik <[email protected]>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, see <http://www.gnu.org/licenses/>.
+#
+
+#
+#   regs_16_31_by_one = [16 .. 31]
+#   regs_16_23_by_one = [16 .. 23]
+#   regs_24_30_by_two = [24, 26, 28, 30]
+#   regs_00_30_by_two = [0, 2, 4, 6, 8, .. 30]
+
+%rd             4:5
+%rr             9:1 0:4
+
+%rd_a           4:4                         !function=to_regs_16_31_by_one
+%rd_b           4:3                         !function=to_regs_16_23_by_one
+%rd_c           4:2                         !function=to_regs_24_30_by_two
+%rd_d           4:4                         !function=to_regs_00_30_by_two
+%rr_a           0:4                         !function=to_regs_16_31_by_one
+%rr_b           0:3                         !function=to_regs_16_23_by_one
+%rr_d           0:4                         !function=to_regs_00_30_by_two
+
+%imm6           6:2 0:4
+%imm8           8:4 0:4
+
+%io_imm         9:2 0:4
+%ldst_d_imm     13:1 10:2 0:3
+
+# The 22-bit immediate is partially in the opcode word,
+# and partially in the next.  Use append_16 to build the
+# complete 22-bit value.
+%imm_call       4:5 0:1                     !function=append_16
+
+
+&rd_rr          rd rr
+&rd_imm         rd imm
+
+@op_rd_rr       .... .. . ..... ....        &rd_rr      rd=%rd rr=%rr
+@op_rd_imm6     .... .... .. .. ....        &rd_imm     rd=%rd_c imm=%imm6
+@op_rd_imm8     .... .... .... ....         &rd_imm     rd=%rd_a imm=%imm8
+@op_bit         .... .... . bit:3 ....
+@op_bit_imm     .... .. imm:s7 bit:3
+@fmul           .... .... . ... . ...       &rd_rr      rd=%rd_b rr=%rr_b
+@io_rd_imm      .... . .. ..... ....        &rd_imm     rd=%rd imm=%io_imm
+@ldst_d         .. . . .. . rd:5  . ...     &rd_imm     imm=%ldst_d_imm
+
+# The 16-bit immediate is completely in the next word.
+# Fields cannot be defined with no bits, so we cannot play
+# the same trick and append to a zero-bit value.
+# Defer reading the immediate until trans_{LDS,STS}.
+@ldst_s         .... ... rd:5 ....          imm=0
+
+#
+# Arithmetic Instructions
+#
+ADD             0000 11 . ..... ....        @op_rd_rr
+ADC             0001 11 . ..... ....        @op_rd_rr
+ADIW            1001 0110 .. .. ....        @op_rd_imm6
+SUB             0001 10 . ..... ....        @op_rd_rr
+SUBI            0101 .... .... ....         @op_rd_imm8
+SBC             0000 10 . ..... ....        @op_rd_rr
+SBCI            0100 .... .... ....         @op_rd_imm8
+SBIW            1001 0111 .. .. ....        @op_rd_imm6
+AND             0010 00 . ..... ....        @op_rd_rr
+ANDI            0111 .... .... ....         @op_rd_imm8
+OR              0010 10 . ..... ....        @op_rd_rr
+ORI             0110 .... .... ....         @op_rd_imm8
+EOR             0010 01 . ..... ....        @op_rd_rr
+COM             1001 010 rd:5 0000
+NEG             1001 010 rd:5 0001
+INC             1001 010 rd:5 0011
+DEC             1001 010 rd:5 1010
+MUL             1001 11 . ..... ....        @op_rd_rr
+MULS            0000 0010 .... ....         &rd_rr      rd=%rd_a rr=%rr_a
+MULSU           0000 0011 0 ... 0 ...       @fmul
+FMUL            0000 0011 0 ... 1 ...       @fmul
+FMULS           0000 0011 1 ... 0 ...       @fmul
+FMULSU          0000 0011 1 ... 1 ...       @fmul
+DES             1001 0100 imm:4 1011
target/avr/translate.c +752 -0

755 lines not on this page · raw message

Signature · 1 line
2.7.4
#23 lore raw

PATCH 10/29 target/avr: Add instruction translation - Branch Instructions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes:
- RJMP, IJMP, EIJMP, JMP
- RCALL, ICALL, EICALL, CALL
- RET, RETI
- CPSE, CP, CPC, CPI
- SBRC, SBRS, SBIC, SBIS
- BRBC, BRBS

---
 target/avr/insn.decode |  24 +++
 target/avr/translate.c | 532 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 556 insertions(+)
target/avr/insn.decode +24 -0
index 9c71ed6..32034c1 100644
@@ -91,3 +91,27 @@ FMUL            0000 0011 0 ... 1 ...       @fmul
 FMULS           0000 0011 1 ... 0 ...       @fmul
 FMULSU          0000 0011 1 ... 1 ...       @fmul
 DES             1001 0100 imm:4 1011
+
+#
+# Branch Instructions
+#
+RJMP            1100 imm:s12
+IJMP            1001 0100 0000 1001
+EIJMP           1001 0100 0001 1001
+JMP             1001 010 ..... 110 .        imm=%imm_call
+RCALL           1101 imm:s12
+ICALL           1001 0101 0000 1001
+EICALL          1001 0101 0001 1001
+CALL            1001 010 ..... 111 .        imm=%imm_call
+RET             1001 0101 0000 1000
+RETI            1001 0101 0001 1000
+CPSE            0001 00 . ..... ....        @op_rd_rr
+CP              0001 01 . ..... ....        @op_rd_rr
+CPC             0000 01 . ..... ....        @op_rd_rr
+CPI             0011 .... .... ....         @op_rd_imm8
+SBRC            1111 110 rr:5 0 bit:3
+SBRS            1111 111 rr:5 0 bit:3
+SBIC            1001 1001 reg:5 bit:3
+SBIS            1001 1011 reg:5 bit:3
+BRBS            1111 00 ....... ...         @op_bit_imm
+BRBC            1111 01 ....... ...         @op_bit_imm
target/avr/translate.c +532 -0

535 lines not on this page · raw message

Signature · 1 line
2.7.4
#24 lore raw

PATCH 11/29 target/avr: Add instruction translation - Data Transfer Instructions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes:
- MOV, MOVW
- LDI, LDS LDX LDY LDZ
- LDDY, LDDZ
- STS, STX STY STZ
- STDY, STDZ
- LPM, LPMX
- ELPM, ELPMX
- SPM, SPMX
- IN, OUT
- PUSH, POP
- XCH
- LAS, LAC LAT

---
 target/avr/insn.decode |  43 +++
 target/avr/translate.c | 987 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1030 insertions(+)
target/avr/insn.decode +43 -0
index 32034c1..3f9304f 100644
@@ -115,3 +115,46 @@ SBIC            1001 1001 reg:5 bit:3
 SBIS            1001 1011 reg:5 bit:3
 BRBS            1111 00 ....... ...         @op_bit_imm
 BRBC            1111 01 ....... ...         @op_bit_imm
+
+#
+# Data Transfer Instructions
+#
+MOV             0010 11 . ..... ....        @op_rd_rr
+MOVW            0000 0001 .... ....         &rd_rr      rd=%rd_d rr=%rr_d
+LDI             1110 .... .... ....         @op_rd_imm8
+LDS             1001 000 ..... 0000         @ldst_s
+LDX1            1001 000 rd:5 1100
+LDX2            1001 000 rd:5 1101
+LDX3            1001 000 rd:5 1110
+LDY2            1001 000 rd:5 1001
+LDY3            1001 000 rd:5 1010
+LDZ2            1001 000 rd:5 0001
+LDZ3            1001 000 rd:5 0010
+LDDY            10 . 0 .. 0 ..... 1 ...     @ldst_d
+LDDZ            10 . 0 .. 0 ..... 0 ...     @ldst_d
+STS             1001 001 ..... 0000         @ldst_s
+STX1            1001 001 rr:5 1100
+STX2            1001 001 rr:5 1101
+STX3            1001 001 rr:5 1110
+STY2            1001 001 rd:5 1001
+STY3            1001 001 rd:5 1010
+STZ2            1001 001 rd:5 0001
+STZ3            1001 001 rd:5 0010
+STDY            10 . 0 .. 1 ..... 1 ...     @ldst_d
+STDZ            10 . 0 .. 1 ..... 0 ...     @ldst_d
+LPM1            1001 0101 1100 1000
+LPM2            1001 000 rd:5 0100
+LPMX            1001 000 rd:5 0101
+ELPM1           1001 0101 1101 1000
+ELPM2           1001 000 rd:5 0110
+ELPMX           1001 000 rd:5 0111
+SPM             1001 0101 1110 1000
+SPMX            1001 0101 1111 1000
+IN              1011 0 .. ..... ....        @io_rd_imm
+OUT             1011 1 .. ..... ....        @io_rd_imm
+PUSH            1001 001 rd:5 1111
+POP             1001 000 rd:5 1111
+XCH             1001 001 rd:5 0100
+LAC             1001 001 rd:5 0110
+LAS             1001 001 rd:5 0101
+LAT             1001 001 rd:5 0111
target/avr/translate.c +987 -0

990 lines not on this page · raw message

Signature · 1 line
2.7.4
#25 lore raw

PATCH 12/29 target/avr: Add instruction translation - Bit and Bit-test Instructions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes:
- LSR, ROR
- ASR
- SWAP
- SBI, CBI
- BST, BLD
- BSET, BCLR

---
 target/avr/insn.decode |  14 +++
 target/avr/translate.c | 241 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 255 insertions(+)
target/avr/insn.decode +14 -0
index 3f9304f..4ee5586 100644
@@ -158,3 +158,17 @@ XCH             1001 001 rd:5 0100
 LAC             1001 001 rd:5 0110
 LAS             1001 001 rd:5 0101
 LAT             1001 001 rd:5 0111
+
+#
+# Bit and Bit-test Instructions
+#
+LSR             1001 010 rd:5 0110
+ROR             1001 010 rd:5 0111
+ASR             1001 010 rd:5 0101
+SWAP            1001 010 rd:5 0010
+SBI             1001 1010 reg:5 bit:3
+CBI             1001 1000 reg:5 bit:3
+BST             1111 101 rd:5 0 bit:3
+BLD             1111 100 rd:5 0 bit:3
+BSET            1001 0100 0 bit:3 1000
+BCLR            1001 0100 1 bit:3 1000
target/avr/translate.c +241 -0

244 lines not on this page · raw message

Signature · 1 line
2.7.4
#26 lore raw

PATCH 13/29 target/avr: Add instruction translation - MCU Control Instructions

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This includes:
- BREAK
- NOP
- SLEEP
- WDR

---
 target/avr/insn.decode |  8 ++++++
 target/avr/translate.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
target/avr/insn.decode +8 -0
index 4ee5586..f8d32f2 100644
@@ -172,3 +172,11 @@ BST             1111 101 rd:5 0 bit:3
 BLD             1111 100 rd:5 0 bit:3
 BSET            1001 0100 0 bit:3 1000
 BCLR            1001 0100 1 bit:3 1000
+
+#
+# MCU Control Instructions
+#
+BREAK           1001 0101 1001 1000
+NOP             0000 0000 0000 0000
+SLEEP           1001 0101 1000 1000
+WDR             1001 0101 1010 1000
target/avr/translate.c +68 -0

71 lines not on this page · raw message

Signature · 1 line
2.7.4
#27 lore raw

PATCH 14/29 target/avr: Add instruction translation - CPU main translation function

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

---
 target/avr/translate.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 234 insertions(+)
target/avr/translate.c +234 -0
index 4c68007..af88bb2 100644
@@ -2749,3 +2749,237 @@ static bool trans_WDR(DisasContext *ctx, arg_WDR *a)
 
     return true;
 }
+
+
+void avr_cpu_tcg_init(void)
+{
+    int i;
+
+#define AVR_REG_OFFS(x) offsetof(CPUAVRState, x)
+    cpu_pc = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(pc_w), "pc");
+    cpu_Cf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregC), "Cf");
+    cpu_Zf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregZ), "Zf");
+    cpu_Nf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregN), "Nf");
+    cpu_Vf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregV), "Vf");
+    cpu_Sf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregS), "Sf");
+    cpu_Hf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregH), "Hf");
+    cpu_Tf = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregT), "Tf");
+    cpu_If = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sregI), "If");
+    cpu_rampD = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampD), "rampD");
+    cpu_rampX = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampX), "rampX");
+    cpu_rampY = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampY), "rampY");
+    cpu_rampZ = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(rampZ), "rampZ");
+    cpu_eind = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(eind), "eind");
+    cpu_sp = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(sp), "sp");
+    cpu_skip = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(skip), "skip");
+
+    for (i = 0; i < NUMBER_OF_CPU_REGISTERS; i++) {
+        cpu_r[i] = tcg_global_mem_new_i32(cpu_env, AVR_REG_OFFS(r[i]),
+                                          reg_names[i]);
+    }
+#undef AVR_REG_OFFS
+}
+
+static void translate(DisasContext *ctx)
+{
+    uint32_t opcode = next_word(ctx);
+
+    if (!decode_insn(ctx, opcode)) {
+        gen_helper_unsupported(cpu_env);
+        ctx->bstate = DISAS_NORETURN;
+    }
+}
+
+/* Standardize the cpu_skip condition to NE.  */
+static bool canonicalize_skip(DisasContext *ctx)
+{
+    switch (ctx->skip_cond) {
+    case TCG_COND_NEVER:
+        /* Normal case: cpu_skip is known to be false.  */
+        return false;
+
+    case TCG_COND_ALWAYS:
+        /*
+         * Breakpoint case: cpu_skip is known to be true, via TB_FLAGS_SKIP.
+         * The breakpoint is on the instruction being skipped, at the start
+         * of the TranslationBlock.  No need to update.
+         */
+        return false;
+
+    case TCG_COND_NE:
+        if (ctx->skip_var1 == NULL) {
+            tcg_gen_mov_tl(cpu_skip, ctx->skip_var0);
+        } else {
+            tcg_gen_xor_tl(cpu_skip, ctx->skip_var0, ctx->skip_var1);
+            ctx->skip_var1 = NULL;
+        }
+        break;
+
+    default:
+        /* Convert to a NE condition vs 0. */
+        if (ctx->skip_var1 == NULL) {
+            tcg_gen_setcondi_tl(ctx->skip_cond, cpu_skip, ctx->skip_var0, 0);
+        } else {
+            tcg_gen_setcond_tl(ctx->skip_cond, cpu_skip,
+                               ctx->skip_var0, ctx->skip_var1);
+            ctx->skip_var1 = NULL;
+        }
+        ctx->skip_cond = TCG_COND_NE;
+        break;
+    }
+    if (ctx->free_skip_var0) {
+        tcg_temp_free(ctx->skip_var0);
+        ctx->free_skip_var0 = false;
+    }
+    ctx->skip_var0 = cpu_skip;
+    return true;
+}
+
+void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
+{
+    CPUAVRState *env = cs->env_ptr;
+    DisasContext ctx = {
+        .tb = tb,
+        .cs = cs,
+        .env = env,
+        .memidx = 0,
+        .bstate = DISAS_NEXT,
+        .skip_cond = TCG_COND_NEVER,
+        .singlestep = cs->singlestep_enabled,
+    };
+    target_ulong pc_start = tb->pc / 2;
+    int num_insns = 0;
+
+    if (tb->flags & TB_FLAGS_FULL_ACCESS) {
+        /*
+         * This flag is set by ST/LD instruction we will regenerate it ONLY
+         * with mem/cpu memory access instead of mem access
+         */
+        max_insns = 1;
+    }
+    if (ctx.singlestep) {
+        max_insns = 1;
+    }
+
+    gen_tb_start(tb);
+
+    ctx.npc = pc_start;
+    if (tb->flags & TB_FLAGS_SKIP) {
+        ctx.skip_cond = TCG_COND_ALWAYS;
+        ctx.skip_var0 = cpu_skip;
+    }
+
+    do {
+        TCGLabel *skip_label = NULL;
+
+        /* translate current instruction */
+        tcg_gen_insn_start(ctx.npc);
+        num_insns++;
+
+        /*
+         * this is due to some strange GDB behavior
+         * let's assume main has address 0x100
+         * b main   - sets breakpoint at address 0x00000100 (code)
+         * b *0x100 - sets breakpoint at address 0x00800100 (data)
+         */
+        if (unlikely(!ctx.singlestep &&
+                (cpu_breakpoint_test(cs, OFFSET_CODE + ctx.npc * 2, BP_ANY) ||
+                 cpu_breakpoint_test(cs, OFFSET_DATA + ctx.npc * 2, BP_ANY)))) {
+            canonicalize_skip(&ctx);
+            tcg_gen_movi_tl(cpu_pc, ctx.npc);
+            gen_helper_debug(cpu_env);
+            goto done_generating;
+        }
+
+        /* Conditionally skip the next instruction, if indicated.  */
+        if (ctx.skip_cond != TCG_COND_NEVER) {
+            skip_label = gen_new_label();
+            if (ctx.skip_var0 == cpu_skip) {
+                /*
+                 * Copy cpu_skip so that we may zero it before the branch.
+                 * This ensures that cpu_skip is non-zero after the label
+                 * if and only if the skipped insn itself sets a skip.
+                 */
+                ctx.free_skip_var0 = true;
+                ctx.skip_var0 = tcg_temp_new();
+                tcg_gen_mov_tl(ctx.skip_var0, cpu_skip);
+                tcg_gen_movi_tl(cpu_skip, 0);
+            }
+            if (ctx.skip_var1 == NULL) {
+                tcg_gen_brcondi_tl(ctx.skip_cond, ctx.skip_var0, 0, skip_label);
+            } else {
+                tcg_gen_brcond_tl(ctx.skip_cond, ctx.skip_var0,
+                                  ctx.skip_var1, skip_label);
+                ctx.skip_var1 = NULL;
+            }
+            if (ctx.free_skip_var0) {
+                tcg_temp_free(ctx.skip_var0);
+                ctx.free_skip_var0 = false;
+            }
+            ctx.skip_cond = TCG_COND_NEVER;
+            ctx.skip_var0 = NULL;
+        }
+
+        translate(&ctx);
+
+        if (skip_label) {
+            canonicalize_skip(&ctx);
+            gen_set_label(skip_label);
+            if (ctx.bstate == DISAS_NORETURN) {
+                ctx.bstate = DISAS_CHAIN;
+            }
+        }
+    } while (ctx.bstate == DISAS_NEXT
+             && num_insns < max_insns
+             && (ctx.npc - pc_start) * 2 < TARGET_PAGE_SIZE - 4
+             && !tcg_op_buf_full());
+
+    if (tb->cflags & CF_LAST_IO) {
+        gen_io_end();
+    }
+
+    bool nonconst_skip = canonicalize_skip(&ctx);
+
+    switch (ctx.bstate) {
+    case DISAS_NORETURN:
+        assert(!nonconst_skip);
+        break;
+    case DISAS_NEXT:
+    case DISAS_TOO_MANY:
+    case DISAS_CHAIN:
+        if (!nonconst_skip) {
+            /* Note gen_goto_tb checks singlestep.  */
+            gen_goto_tb(&ctx, 1, ctx.npc);
+            break;
+        }
+        tcg_gen_movi_tl(cpu_pc, ctx.npc);
+        /* fall through */
+    case DISAS_LOOKUP:
+        if (!ctx.singlestep) {
+            tcg_gen_lookup_and_goto_ptr();
+            break;
+        }
+        /* fall through */
+    case DISAS_EXIT:
+        if (ctx.singlestep) {
+            gen_helper_debug(cpu_env);
+        } else {
+            tcg_gen_exit_tb(NULL, 0);
+        }
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+done_generating:
+    gen_tb_end(tb, num_insns);
+
+    tb->size = (ctx.npc - pc_start) * 2;
+    tb->icount = num_insns;
+}
+
+void restore_state_to_opc(CPUAVRState *env, TranslationBlock *tb,
+                            target_ulong *data)
+{
+    env->pc_w = data[0];
+}
Signature · 1 line
2.7.4
#28 lore raw

PATCH 15/29 target/avr: Add instruction disassembly function

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Provide function disassembles executed instruction when -d in_asm is provided

Example:
./avr-softmmu/qemu-system-avr -bios free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf -d in_asm will produce something like the following

```
    ...
    IN:
    0x0000014a:  CALL      0x3808

    IN: main
    0x00003808:  CALL      0x4b4

    IN: vParTestInitialise
    0x000004b4:  LDI       r24, 255
    0x000004b6:  STS       r24, 0
    0x000004b8:  MULS      r16, r20
    0x000004ba:  OUT       $1, r24
    0x000004bc:  LDS       r24, 0
    0x000004be:  MULS      r16, r20
    0x000004c0:  OUT       $2, r24
    0x000004c2:  RET
    ...
```
---
 target/avr/cpu.c       |   2 +-
 target/avr/cpu.h       |   1 +
 target/avr/disas.c     | 246 +++++++++++++++++++++++++++++++++++++++++++++++++
 target/avr/translate.c |  12 +++
 4 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 target/avr/disas.c
target/avr/cpu.c +1 -1
index e0ae055..930dd10 100644
@@ -84,7 +84,7 @@ static void avr_cpu_reset(CPUState *cs)
 static void avr_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 {
     info->mach = bfd_arch_avr;
-    info->print_insn = NULL;
+    info->print_insn = avr_print_insn;
 }
 
 static void avr_cpu_realizefn(DeviceState *dev, Error **errp)
target/avr/cpu.h +1 -0
index e94dab3..4169add 100644
@@ -162,6 +162,7 @@ bool avr_cpu_exec_interrupt(CPUState *cpu, int int_req);
 hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 int avr_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
 int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
+int avr_print_insn(bfd_vma addr, disassemble_info *info);
 
 static inline int avr_feature(CPUAVRState *env, AVRFeature feature)
 {
target/avr/disas.c new file +246 -0

246 lines not on this page · raw message

target/avr/translate.c +12 -0
index af88bb2..064eee0 100644
@@ -2976,6 +2976,18 @@ done_generating:
 
     tb->size = (ctx.npc - pc_start) * 2;
     tb->icount = num_insns;
+
+#ifdef DEBUG_DISAS
+    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
+        && qemu_log_in_addr_range(tb->pc)) {
+        FILE *fd;
+        fd = qemu_log_lock();
+        qemu_log("IN: %s\n", lookup_symbol(tb->pc));
+        log_target_disas(cs, tb->pc, tb->size);
+        qemu_log("\n");
+        qemu_log_unlock(fd);
+    }
+#endif
 }
 
 void restore_state_to_opc(CPUAVRState *env, TranslationBlock *tb,
Signature · 1 line
2.7.4
#29 lore raw

PATCH 16/29 hw/char: Add limited support for AVR USART peripheral

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

These were designed to facilitate testing but should provide enough function to be useful in other contexts. Only a subset of the functions of each peripheral is implemented, mainly due to the lack of a standard way to handle electrical connections (like GPIO pins).

[AM: Remove word 'Atmel' from filenames and all elements of code]
[rth: Squash I/O size fix and file rename from f4bug]
---
 hw/char/Kconfig             |   3 +
 hw/char/Makefile.objs       |   1 +
 hw/char/avr_usart.c         | 320 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/char/avr_usart.h |  93 +++++++++++++
 4 files changed, 417 insertions(+)
 create mode 100644 hw/char/avr_usart.c
 create mode 100644 include/hw/char/avr_usart.h
hw/char/Kconfig +3 -0
index 40e7a8b..331b209 100644
@@ -46,3 +46,6 @@ config SCLPCONSOLE
 
 config TERMINAL3270
     bool
+
+config AVR_USART
+    bool
hw/char/Makefile.objs +1 -0
index 02d8a66..f05c1f5 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
 obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
 obj-$(CONFIG_RASPI) += bcm2835_aux.o
+common-obj-$(CONFIG_AVR_USART) += avr_usart.o
 
 common-obj-$(CONFIG_CMSDK_APB_UART) += cmsdk-apb-uart.o
 common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
hw/char/avr_usart.c new file +320 -0

320 lines not on this page · raw message

include/hw/char/avr_usart.h new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
#30 lore raw

PATCH 17/29 hw/timer: Add limited support for AVR 16-bit timer peripheral

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

These were designed to facilitate testing but should provide enough function to be useful in other contexts. Only a subset of the functions of each peripheral is implemented, mainly due to the lack of a standard way to handle electrical connections (like GPIO pins).

[AM: Remove word 'Atmel' from filenames and all elements of code]
[rth: Squash info mtree fixes and a file rename from f4bug]
[PMD: Use qemu_log_mask(LOG_UNIMP), replace goto by return]
---
 hw/timer/Kconfig               |   3 +
 hw/timer/Makefile.objs         |   2 +
 hw/timer/avr_timer16.c         | 604 +++++++++++++++++++++++++++++++++++++++++
 include/hw/timer/avr_timer16.h |  94 +++++++
 4 files changed, 703 insertions(+)
 create mode 100644 hw/timer/avr_timer16.c
 create mode 100644 include/hw/timer/avr_timer16.h
hw/timer/Kconfig +3 -0
index 59b3f44..2521056 100644
@@ -35,3 +35,6 @@ config CMSDK_APB_TIMER
 config CMSDK_APB_DUALTIMER
     bool
     select PTIMER
+
+config AVR_TIMER16
+    bool
hw/timer/Makefile.objs +2 -0
index dece235..af0913c 100644
@@ -35,3 +35,5 @@ common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
 common-obj-$(CONFIG_CMSDK_APB_DUALTIMER) += cmsdk-apb-dualtimer.o
 common-obj-$(CONFIG_MSF2) += mss-timer.o
 common-obj-$(CONFIG_RASPI) += bcm2835_systmr.o
+
+obj-$(CONFIG_AVR_TIMER16) += avr_timer16.o
hw/timer/avr_timer16.c new file +604 -0

604 lines not on this page · raw message

include/hw/timer/avr_timer16.h new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.7.4
#31 lore raw

PATCH 18/29 hw/misc: Add limited support for AVR power device

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

This is a simple device of just one register, and whenever this register is written to it calls qemu_set_irq function for each of 8 bits/IRQs. It is used to implement AVR Power Reduction.

[AM: Remove word 'Atmel' from filenames and all elements of code]
[rth: Squash include fix and file rename from f4bug]
---
 hw/misc/Kconfig             |   3 ++
 hw/misc/Makefile.objs       |   2 +
 hw/misc/avr_power.c         | 112 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/misc/avr_power.h |  46 ++++++++++++++++++
 4 files changed, 163 insertions(+)
 create mode 100644 hw/misc/avr_power.c
 create mode 100644 include/hw/misc/avr_power.h
hw/misc/Kconfig +3 -0
index bdd77d8..92c397c 100644
@@ -131,4 +131,7 @@ config MAC_VIA
     select MOS6522
     select ADB
 
+config AVR_POWER
+    bool
+
 source macio/Kconfig
hw/misc/Makefile.objs +2 -0
index da993f4..df8e457 100644
@@ -85,3 +85,5 @@ common-obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
 obj-$(CONFIG_MAC_VIA) += mac_via.o
 
 common-obj-$(CONFIG_GRLIB) += grlib_ahb_apb_pnp.o
+
+obj-$(CONFIG_AVR_POWER) += avr_power.o
hw/misc/avr_power.c new file +112 -0

112 lines not on this page · raw message

include/hw/misc/avr_power.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.7.4
#32 lore raw
In reply to Aleksandar Markovic

Michael, Philippe,

Can you guys do a quick checkup of this rc4? rc4, rc3,and rc2 should be functionally 100% equivalent.

Thank you,
Aleksandar

Quoted 158 lines · Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This is the AVR port from Michael, release (merge) candidate 4.

The series can be found also in this repository:

https://github.com/AMarkovic/qemu-avr-merger-rc4

History:

Since v3:

- Removed a patch on load_elf() modification, since it has been merged
- Removed references to CONFIG_USER_ONLY and provided a guard against building lunux user mode for AVR
- Removed all references to 'Atmel' (including file renames)
- Rebased the code (there was common interface change regarding 'props')
- Various corrections of commit messages
- A bit field for AVRFeatures is nor 64 bit long
- Other minor fixes

Since v2:

- First patch is split into six smaller logical units (net result remains the same)
- Patch "hw/core/loader: Let load_elf populate the processor-specific flags" was redone to reflect the original intent that was lost in transalation between multiple autors
- Patch "hw/avr: Add helper to load raw/ELF firmware binaries" was corrected only in one line to rectify type of "e_flags"
- Patch "target/avr: Add section about AVR into QEMU documentation"
- Spurious <message-Id:> elements were removed
- The series was rebased to the latest code

Since v1:

- Addressed Thomas comments
- Fixed a non-critical bug in ATmega (incorrect SRAM base address)
- Added ELF parsing requested by Aleksandar
- Dropped default machine (as with the ARM port)

Michael Rolnik (25):
target/avr: Add basic parameters for new AVR platform target/avr: Introduce AVR CPU class object
target/avr: Add migration support
target/avr: Add GDB support
target/avr: Introduce enumeration AVRFeature
target/avr: Add defintions of AVR core types
target/avr: Add instruction helpers
target/avr: Add instruction translation - Register definitions target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Data Transfer Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function
hw/char: Add limited support for AVR USART peripheral hw/timer: Add limited support for AVR 16-bit timer peripheral hw/misc: Add limited support for AVR power device target/avr: Add section about AVR into QEMU documentation target/avr: Register AVR support with the rest of QEMU target/avr: Add machine none test
target/avr: Update MAINTAINERS file
target/avr: Update build system
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board

Philippe Mathieu-Daudé (4):
hw/avr: Add helper to load raw/ELF firmware binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add some Arduino boards .travis.yml: Run the AVR acceptance tests

 .travis.yml                      |    2 +-
 MAINTAINERS                      |   31 +
 arch_init.c                      |    2 +
 configure                        |    7 +
 default-configs/avr-softmmu.mak  |    5 +
 gdb-xml/avr-cpu.xml              |   49 +
 hw/avr/Kconfig                   |    9 +
 hw/avr/Makefile.objs             |    3 +
 hw/avr/arduino.c                 |  151 ++
 hw/avr/atmega.c                  |  470 ++++++
 hw/avr/atmega.h                  |   48 +
 hw/avr/boot.c                    |   74 +
 hw/avr/boot.h                    |   33 +
 hw/char/Kconfig                  |    3 +
 hw/char/Makefile.objs            |    1 +
 hw/char/avr_usart.c              |  320 ++++
 hw/misc/Kconfig                  |    3 +
 hw/misc/Makefile.objs            |    2 +
 hw/misc/avr_power.c              |  112 ++
 hw/timer/Kconfig                 |    3 +
 hw/timer/Makefile.objs           |    2 +
 hw/timer/avr_timer16.c           |  604 ++++++++
 include/disas/dis-asm.h          |   19 +
 include/elf.h                    |    2 +
 include/hw/char/avr_usart.h      |   93 ++
 include/hw/misc/avr_power.h      |   46 +
 include/hw/timer/avr_timer16.h   |   94 ++
 include/sysemu/arch_init.h       |    1 +
 qapi/machine.json                |    3 +-
 qemu-doc.texi                    |   51 +
 target/avr/Makefile.objs         |   34 +
 target/avr/cpu-param.h           |   37 +
 target/avr/cpu-qom.h             |   54 +
 target/avr/cpu.c                 |  818 +++++++++++
 target/avr/cpu.h                 |  259 ++++
 target/avr/disas.c               |  246 ++++
 target/avr/gdbstub.c             |   84 ++
 target/avr/helper.c              |  342 +++++
 target/avr/helper.h              |   29 +
 target/avr/insn.decode           |  182 +++
 target/avr/machine.c             |  121 ++
 target/avr/translate.c           | 2997 ++++++++++++++++++++++++++++++++++++++
 tests/acceptance/machine_avr6.py |   50 +
 tests/qtest/Makefile.include     |    2 +
 tests/qtest/boot-serial-test.c   |   11 +
 tests/qtest/machine-none-test.c  |    1 +
 46 files changed, 7508 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 gdb-xml/avr-cpu.xml
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/Makefile.objs
 create mode 100644 hw/avr/arduino.c
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
 create mode 100644 hw/avr/boot.c
 create mode 100644 hw/avr/boot.h
 create mode 100644 hw/char/avr_usart.c
 create mode 100644 hw/misc/avr_power.c
 create mode 100644 hw/timer/avr_timer16.c
 create mode 100644 include/hw/char/avr_usart.h
 create mode 100644 include/hw/misc/avr_power.h
 create mode 100644 include/hw/timer/avr_timer16.h
 create mode 100644 target/avr/Makefile.objs
 create mode 100644 target/avr/cpu-param.h
 create mode 100644 target/avr/cpu-qom.h
 create mode 100644 target/avr/cpu.c
 create mode 100644 target/avr/cpu.h
 create mode 100644 target/avr/disas.c
 create mode 100644 target/avr/gdbstub.c
 create mode 100644 target/avr/helper.c
 create mode 100644 target/avr/helper.h
 create mode 100644 target/avr/insn.decode
 create mode 100644 target/avr/machine.c
 create mode 100644 target/avr/translate.c
 create mode 100644 tests/acceptance/machine_avr6.py

--
2.7.4

#33 lore raw
Quoted 4 lines · Aleksandar Markovic

Michael, Philippe,

Can you guys do a quick checkup of this rc4? rc4, rc3,and rc2 should be functionally 100% equivalent.

Tested OK.

git-backport-diff with rc2:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/31:[down] 'target/avr: Add basic parameters for new AVR platform' 002/31:[down] 'target/avr: Introduce AVR CPU class object'
003/31:[down] 'target/avr: Add migration support'
004/31:[down] 'target/avr: Add GDB support'
005/31:[down] 'target/avr: Introduce enumeration AVRFeature'
006/31:[down] 'target/avr: Add defintions of AVR core types'
007/31:[0148] [FC] 'target/avr: Add instruction helpers'
008/31:[down] 'target/avr: Add instruction translation - Register definitions' 009/31:[----] [--] 'target/avr: Add instruction translation - Arithmetic and Logic Instructions' 010/31:[----] [--] 'target/avr: Add instruction translation - Branch Instructions' 011/31:[----] [--] 'target/avr: Add instruction translation - Data Transfer Instructions' 012/31:[----] [--] 'target/avr: Add instruction translation - Bit and Bit-test Instructions' 013/31:[----] [--] 'target/avr: Add instruction translation - MCU Control Instructions' 014/31:[----] [--] 'target/avr: Add instruction translation - CPU main translation function' 015/31:[----] [--] 'target/avr: Add instruction disassembly function' 016/31:[down] 'hw/char: Add limited support for AVR USART peripheral' 017/31:[down] 'hw/timer: Add limited support for AVR 16-bit timer peripheral' 018/31:[down] 'hw/misc: Add limited support for AVR power device'
019/31:[0012] [FC] 'target/avr: Add section about AVR into QEMU documentation' 020/31:[0002] [FC] 'target/avr: Register AVR support with the rest of QEMU' 021/31:[----] [--] 'target/avr: Add machine none test'
022/31:[0014] [FC] 'target/avr: Update MAINTAINERS file'
023/31:[0002] [FC] 'hw/avr: Add helper to load raw/ELF firmware binaries' 024/31:[0026] [FC] 'hw/avr: Add some ATmega microcontrollers'
025/31:[0009] [FC] 'hw/avr: Add some Arduino boards'
026/31:[----] [--] 'target/avr: Update build system'
027/31:[----] [--] 'tests/boot-serial-test: Test some Arduino boards (AVR based)' 028/31:[----] [--] 'tests/acceptance: Test the Arduino MEGA2560 board' 029/31:[----] [--] '.travis.yml: Run the AVR acceptance tests'
030/31:[down] '!fixup "hw/misc: Add limited support for AVR power device"' 031/31:[down] '!fixup "hw/timer: Add limited support for AVR 16-bit timer peripheral"'

One thing that annoys me is we ignored the review comments from Joaquin, but I think it might now be easier to address them as new patches, once this series is merged.

I made 2 comments (definitions in incorrect patch, and definition misplaced in elf.h), and sent 2 patches converting the PRINTF() to trace-events. Thanks for preparing the rc4, hopefully we are done!

Quoted 165 lines

Thank you,
Aleksandar

Quoted 158 lines · Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This is the AVR port from Michael, release (merge) candidate 4.

The series can be found also in this repository:

https://github.com/AMarkovic/qemu-avr-merger-rc4

History:

Since v3:

- Removed a patch on load_elf() modification, since it has been merged
- Removed references to CONFIG_USER_ONLY and provided a guard against building lunux user mode for AVR
- Removed all references to 'Atmel' (including file renames)
- Rebased the code (there was common interface change regarding 'props')
- Various corrections of commit messages
- A bit field for AVRFeatures is nor 64 bit long
- Other minor fixes

Since v2:

- First patch is split into six smaller logical units (net result remains the same)
- Patch "hw/core/loader: Let load_elf populate the processor-specific flags" was redone to reflect the original intent that was lost in transalation between multiple autors
- Patch "hw/avr: Add helper to load raw/ELF firmware binaries" was corrected only in one line to rectify type of "e_flags"
- Patch "target/avr: Add section about AVR into QEMU documentation"
- Spurious <message-Id:> elements were removed
- The series was rebased to the latest code

Since v1:

- Addressed Thomas comments
- Fixed a non-critical bug in ATmega (incorrect SRAM base address)
- Added ELF parsing requested by Aleksandar
- Dropped default machine (as with the ARM port)

Michael Rolnik (25):
target/avr: Add basic parameters for new AVR platform target/avr: Introduce AVR CPU class object
target/avr: Add migration support
target/avr: Add GDB support
target/avr: Introduce enumeration AVRFeature
target/avr: Add defintions of AVR core types
target/avr: Add instruction helpers
target/avr: Add instruction translation - Register definitions target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Data Transfer Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function
hw/char: Add limited support for AVR USART peripheral hw/timer: Add limited support for AVR 16-bit timer peripheral hw/misc: Add limited support for AVR power device target/avr: Add section about AVR into QEMU documentation target/avr: Register AVR support with the rest of QEMU target/avr: Add machine none test
target/avr: Update MAINTAINERS file
target/avr: Update build system
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board

Philippe Mathieu-Daudé (4):
hw/avr: Add helper to load raw/ELF firmware binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add some Arduino boards .travis.yml: Run the AVR acceptance tests

  .travis.yml                      |    2 +-
  MAINTAINERS                      |   31 +
  arch_init.c                      |    2 +
  configure                        |    7 +
  default-configs/avr-softmmu.mak  |    5 +
  gdb-xml/avr-cpu.xml              |   49 +
  hw/avr/Kconfig                   |    9 +
  hw/avr/Makefile.objs             |    3 +
  hw/avr/arduino.c                 |  151 ++
  hw/avr/atmega.c                  |  470 ++++++
  hw/avr/atmega.h                  |   48 +
  hw/avr/boot.c                    |   74 +
  hw/avr/boot.h                    |   33 +
  hw/char/Kconfig                  |    3 +
  hw/char/Makefile.objs            |    1 +
  hw/char/avr_usart.c              |  320 ++++
  hw/misc/Kconfig                  |    3 +
  hw/misc/Makefile.objs            |    2 +
  hw/misc/avr_power.c              |  112 ++
  hw/timer/Kconfig                 |    3 +
  hw/timer/Makefile.objs           |    2 +
  hw/timer/avr_timer16.c           |  604 ++++++++
  include/disas/dis-asm.h          |   19 +
  include/elf.h                    |    2 +
  include/hw/char/avr_usart.h      |   93 ++
  include/hw/misc/avr_power.h      |   46 +
  include/hw/timer/avr_timer16.h   |   94 ++
  include/sysemu/arch_init.h       |    1 +
  qapi/machine.json                |    3 +-
  qemu-doc.texi                    |   51 +
  target/avr/Makefile.objs         |   34 +
  target/avr/cpu-param.h           |   37 +
  target/avr/cpu-qom.h             |   54 +
  target/avr/cpu.c                 |  818 +++++++++++
  target/avr/cpu.h                 |  259 ++++
  target/avr/disas.c               |  246 ++++
  target/avr/gdbstub.c             |   84 ++
  target/avr/helper.c              |  342 +++++
  target/avr/helper.h              |   29 +
  target/avr/insn.decode           |  182 +++
  target/avr/machine.c             |  121 ++
  target/avr/translate.c           | 2997 ++++++++++++++++++++++++++++++++++++++
  tests/acceptance/machine_avr6.py |   50 +
  tests/qtest/Makefile.include     |    2 +
  tests/qtest/boot-serial-test.c   |   11 +
  tests/qtest/machine-none-test.c  |    1 +
  46 files changed, 7508 insertions(+), 2 deletions(-)

create mode 100644 default-configs/avr-softmmu.mak create mode 100644 gdb-xml/avr-cpu.xml create mode 100644 hw/avr/Kconfig
create mode 100644 hw/avr/Makefile.objs create mode 100644 hw/avr/arduino.c
create mode 100644 hw/avr/atmega.c
create mode 100644 hw/avr/atmega.h
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h
create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_power.c create mode 100644 hw/timer/avr_timer16.c create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_power.h create mode 100644 include/hw/timer/avr_timer16.h create mode 100644 target/avr/Makefile.objs create mode 100644 target/avr/cpu-param.h create mode 100644 target/avr/cpu-qom.h create mode 100644 target/avr/cpu.c
create mode 100644 target/avr/cpu.h
create mode 100644 target/avr/disas.c create mode 100644 target/avr/gdbstub.c create mode 100644 target/avr/helper.c create mode 100644 target/avr/helper.h create mode 100644 target/avr/insn.decode create mode 100644 target/avr/machine.c create mode 100644 target/avr/translate.c create mode 100644 tests/acceptance/machine_avr6.py

--
2.7.4

#34 lore raw

Looks good. Thanks

Quoted 236 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Aleksandar Markovic

Michael, Philippe,

Can you guys do a quick checkup of this rc4? rc4, rc3,and rc2 should be functionally 100% equivalent.

Tested OK.

git-backport-diff with rc2:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/31:[down] 'target/avr: Add basic parameters for new AVR platform' 002/31:[down] 'target/avr: Introduce AVR CPU class object' 003/31:[down] 'target/avr: Add migration support'
004/31:[down] 'target/avr: Add GDB support'
005/31:[down] 'target/avr: Introduce enumeration AVRFeature' 006/31:[down] 'target/avr: Add defintions of AVR core types' 007/31:[0148] [FC] 'target/avr: Add instruction helpers' 008/31:[down] 'target/avr: Add instruction translation - Register definitions'
009/31:[----] [--] 'target/avr: Add instruction translation - Arithmetic and Logic Instructions'
010/31:[----] [--] 'target/avr: Add instruction translation - Branch Instructions'
011/31:[----] [--] 'target/avr: Add instruction translation - Data Transfer Instructions'
012/31:[----] [--] 'target/avr: Add instruction translation - Bit and Bit-test Instructions'
013/31:[----] [--] 'target/avr: Add instruction translation - MCU Control Instructions'
014/31:[----] [--] 'target/avr: Add instruction translation - CPU main translation function'
015/31:[----] [--] 'target/avr: Add instruction disassembly function' 016/31:[down] 'hw/char: Add limited support for AVR USART peripheral' 017/31:[down] 'hw/timer: Add limited support for AVR 16-bit timer peripheral'
018/31:[down] 'hw/misc: Add limited support for AVR power device' 019/31:[0012] [FC] 'target/avr: Add section about AVR into QEMU documentation'
020/31:[0002] [FC] 'target/avr: Register AVR support with the rest of QEMU' 021/31:[----] [--] 'target/avr: Add machine none test' 022/31:[0014] [FC] 'target/avr: Update MAINTAINERS file' 023/31:[0002] [FC] 'hw/avr: Add helper to load raw/ELF firmware binaries' 024/31:[0026] [FC] 'hw/avr: Add some ATmega microcontrollers' 025/31:[0009] [FC] 'hw/avr: Add some Arduino boards' 026/31:[----] [--] 'target/avr: Update build system' 027/31:[----] [--] 'tests/boot-serial-test: Test some Arduino boards (AVR based)'
028/31:[----] [--] 'tests/acceptance: Test the Arduino MEGA2560 board' 029/31:[----] [--] '.travis.yml: Run the AVR acceptance tests' 030/31:[down] '!fixup "hw/misc: Add limited support for AVR power device"' 031/31:[down] '!fixup "hw/timer: Add limited support for AVR 16-bit timer peripheral"'

One thing that annoys me is we ignored the review comments from Joaquin, but I think it might now be easier to address them as new patches, once this series is merged.

I made 2 comments (definitions in incorrect patch, and definition misplaced in elf.h), and sent 2 patches converting the PRINTF() to trace-events. Thanks for preparing the rc4, hopefully we are done!

Quoted 126 lines

Thank you,
Aleksandar

Quoted 120 lines · Aleksandar Markovic

From: Aleksandar Markovic <[email protected]>

This is the AVR port from Michael, release (merge) candidate 4.

The series can be found also in this repository:

https://github.com/AMarkovic/qemu-avr-merger-rc4

History:

Since v3:

- Removed a patch on load_elf() modification, since it has been merged
- Removed references to CONFIG_USER_ONLY and provided a guard against building lunux user mode for AVR
- Removed all references to 'Atmel' (including file renames)
- Rebased the code (there was common interface change regarding 'props')
- Various corrections of commit messages
- A bit field for AVRFeatures is nor 64 bit long
- Other minor fixes

Since v2:

- First patch is split into six smaller logical units (net result remains the same)
- Patch "hw/core/loader: Let load_elf populate the processor-specific flags" was redone to reflect the original intent that was lost in transalation between multiple autors
- Patch "hw/avr: Add helper to load raw/ELF firmware binaries" was corrected only in one line to rectify type of "e_flags"
- Patch "target/avr: Add section about AVR into QEMU documentation"
- Spurious <message-Id:> elements were removed
- The series was rebased to the latest code

Since v1:

- Addressed Thomas comments
- Fixed a non-critical bug in ATmega (incorrect SRAM base address)
- Added ELF parsing requested by Aleksandar
- Dropped default machine (as with the ARM port)

Michael Rolnik (25):
target/avr: Add basic parameters for new AVR platform target/avr: Introduce AVR CPU class object
target/avr: Add migration support
target/avr: Add GDB support
target/avr: Introduce enumeration AVRFeature
target/avr: Add defintions of AVR core types
target/avr: Add instruction helpers
target/avr: Add instruction translation - Register definitions target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Data Transfer Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function
hw/char: Add limited support for AVR USART peripheral hw/timer: Add limited support for AVR 16-bit timer peripheral hw/misc: Add limited support for AVR power device target/avr: Add section about AVR into QEMU documentation target/avr: Register AVR support with the rest of QEMU target/avr: Add machine none test
target/avr: Update MAINTAINERS file
target/avr: Update build system
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board

Philippe Mathieu-Daudé (4):
hw/avr: Add helper to load raw/ELF firmware binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add some Arduino boards .travis.yml: Run the AVR acceptance tests

  .travis.yml                      |    2 +-
  MAINTAINERS                      |   31 +
  arch_init.c                      |    2 +
  configure                        |    7 +
  default-configs/avr-softmmu.mak  |    5 +
  gdb-xml/avr-cpu.xml              |   49 +
  hw/avr/Kconfig                   |    9 +
  hw/avr/Makefile.objs             |    3 +
  hw/avr/arduino.c                 |  151 ++
  hw/avr/atmega.c                  |  470 ++++++
  hw/avr/atmega.h                  |   48 +
  hw/avr/boot.c                    |   74 +
  hw/avr/boot.h                    |   33 +
  hw/char/Kconfig                  |    3 +
  hw/char/Makefile.objs            |    1 +
  hw/char/avr_usart.c              |  320 ++++
  hw/misc/Kconfig                  |    3 +
  hw/misc/Makefile.objs            |    2 +
  hw/misc/avr_power.c              |  112 ++
  hw/timer/Kconfig                 |    3 +
  hw/timer/Makefile.objs           |    2 +
  hw/timer/avr_timer16.c           |  604 ++++++++
  include/disas/dis-asm.h          |   19 +
  include/elf.h                    |    2 +
  include/hw/char/avr_usart.h      |   93 ++
  include/hw/misc/avr_power.h      |   46 +
  include/hw/timer/avr_timer16.h   |   94 ++
  include/sysemu/arch_init.h       |    1 +
  qapi/machine.json                |    3 +-
  qemu-doc.texi                    |   51 +
  target/avr/Makefile.objs         |   34 +
  target/avr/cpu-param.h           |   37 +
  target/avr/cpu-qom.h             |   54 +
  target/avr/cpu.c                 |  818 +++++++++++
  target/avr/cpu.h                 |  259 ++++
  target/avr/disas.c               |  246 ++++
  target/avr/gdbstub.c             |   84 ++
  target/avr/helper.c              |  342 +++++
  target/avr/helper.h              |   29 +
  target/avr/insn.decode           |  182 +++
  target/avr/machine.c             |  121 ++
  target/avr/translate.c           | 2997

++++++++++++++++++++++++++++++++++++++

Quoted 39 lines
Quoted 38 lines
  tests/acceptance/machine_avr6.py |   50 +
  tests/qtest/Makefile.include     |    2 +
  tests/qtest/boot-serial-test.c   |   11 +
  tests/qtest/machine-none-test.c  |    1 +
  46 files changed, 7508 insertions(+), 2 deletions(-)

create mode 100644 default-configs/avr-softmmu.mak create mode 100644 gdb-xml/avr-cpu.xml create mode 100644 hw/avr/Kconfig
create mode 100644 hw/avr/Makefile.objs create mode 100644 hw/avr/arduino.c
create mode 100644 hw/avr/atmega.c
create mode 100644 hw/avr/atmega.h
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h
create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_power.c create mode 100644 hw/timer/avr_timer16.c create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_power.h create mode 100644 include/hw/timer/avr_timer16.h create mode 100644 target/avr/Makefile.objs create mode 100644 target/avr/cpu-param.h create mode 100644 target/avr/cpu-qom.h create mode 100644 target/avr/cpu.c
create mode 100644 target/avr/cpu.h
create mode 100644 target/avr/disas.c create mode 100644 target/avr/gdbstub.c create mode 100644 target/avr/helper.c create mode 100644 target/avr/helper.h create mode 100644 target/avr/insn.decode create mode 100644 target/avr/machine.c create mode 100644 target/avr/translate.c create mode 100644 tests/acceptance/machine_avr6.py

--
2.7.4

Signature · 2 lines
Best Regards,
Michael Rolnik
#35 lore raw

PATCH 19/29 target/avr: Add section about AVR into QEMU documentation

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Explains basic ways of using AVR target in QEMU.

Message-Id: <[email protected]>

---
 qemu-doc.texi | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
qemu-doc.texi +51 -0
index 2328e7e..aaf4e54 100644
@@ -1723,6 +1723,7 @@ differences are mentioned in the following sections.
 * Microblaze System emulator::
 * SH4 System emulator::
 * Xtensa System emulator::
+* AVR System emulator::
 @end menu
 
 @node PowerPC System emulator
@@ -2496,6 +2497,56 @@ so should only be used with trusted guest OS.
 
 @c man end
 
+@node AVR System emulator
+@section AVR System emulator
+@cindex system emulation (AVR)
+
+Use the executable @file{qemu-system-avr} to emulates a AVR 8 bit based machine
+having one for the following cores: avr1, avr2, avr25, avr3, avr31, avr35, avr4,
+avr5, avr51, avr6, avrtiny, xmega2, xmega3, xmega4, xmega5, xmega6 and xmega7.
+
+As for now it supports few Arduino boards for educational and testing purposes.
+These boards use a ATmega controller, which model is limited to USART & 16 bit
+timer devices, enought to run FreeRTOS based applications (like this @url{https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf,,demo})
+
+Following are examples of possible usages, assuming demo.elf is compiled for
+AVR cpu
+@itemize
+
+@item Continuous non interrupted execution
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf
+@end example
+
+@item Continuous non interrupted execution with serial output into telnet window
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -serial tcp::5678,server,nowait -nographic
+@end example
+and then in another shell
+@example
+telnet localhost 5678
+@end example
+
+@item Debugging wit GDB debugger
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -s -S
+@end example
+and then in another shell
+@example
+avr-gdb demo.elf
+@end example
+and then within GDB shell
+@example
+target remote :1234
+@end example
+
+@item Print out executed instructions
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm
+@end example
+
+@end itemize
+
 @node QEMU User space emulator
 @chapter QEMU User space emulator
 
Signature · 1 line
2.7.4
Reviewed-by on v1 19/29
#36 lore raw

Re: [PATCH rc4 19/29] target/avr: Add section about AVR into QEMU documentation

Quoted 5 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Explains basic ways of using AVR target in QEMU.

Quoted 10 lines

Message-Id: <[email protected]>

---
 qemu-doc.texi | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
Quoted 83 lines
qemu-doc.texi +6 -0
index 2328e7e..aaf4e54 100644
@@ -1723,6 +1723,7 @@ differences are mentioned in the following sections.
 * Microblaze System emulator::
 * SH4 System emulator::
 * Xtensa System emulator::
+* AVR System emulator::
 @end menu
 
 @node PowerPC System emulator
@@ -2496,6 +2497,56 @@ so should only be used with trusted guest OS.
 
 @c man end
 
+@node AVR System emulator
+@section AVR System emulator
+@cindex system emulation (AVR)
+
+Use the executable @file{qemu-system-avr} to emulates a AVR 8 bit based

machine
+having one for the following cores: avr1, avr2, avr25, avr3, avr31, avr35, avr4,
+avr5, avr51, avr6, avrtiny, xmega2, xmega3, xmega4, xmega5, xmega6 and xmega7.

qemu-doc.texi +2 -0
+
+As for now it supports few Arduino boards for educational and testing

purposes.
+These boards use a ATmega controller, which model is limited to USART & 16 bit
+timer devices, enought to run FreeRTOS based applications (like this @url{
https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_
ATMega2560_GCC/demo.elf,,demo})

qemu-doc.texi +2 -0
+
+Following are examples of possible usages, assuming demo.elf is compiled

for

qemu-doc.texi +9 -0
+AVR cpu
+@itemize
+
+@item Continuous non interrupted execution
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf
+@end example
+
+@item Continuous non interrupted execution with serial output into telnet

window
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -serial tcp::5678,server,nowait -nographic
+@end example

qemu-doc.texi +25 -1
+and then in another shell
+@example
+telnet localhost 5678
+@end example
+
+@item Debugging wit GDB debugger
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -s -S
+@end example
+and then in another shell
+@example
+avr-gdb demo.elf
+@end example
+and then within GDB shell
+@example
+target remote :1234
+@end example
+
+@item Print out executed instructions
+@example
+qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm
+@end example
+
+@end itemize
+
 @node QEMU User space emulator
 @chapter QEMU User space emulator
 
--

2.7.4

#37 lore raw

PATCH 20/29 target/avr: Register AVR support with the rest of QEMU

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add AVR related definitions into QEMU.

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 arch_init.c                |  2 ++
 include/disas/dis-asm.h    | 19 +++++++++++++++++++
 include/sysemu/arch_init.h |  1 +
 qapi/machine.json          |  3 ++-
 4 files changed, 24 insertions(+), 1 deletion(-)
arch_init.c +2 -0
index 705d0b9..6a74116 100644
@@ -89,6 +89,8 @@ int graphic_depth = 32;
 #define QEMU_ARCH QEMU_ARCH_UNICORE32
 #elif defined(TARGET_XTENSA)
 #define QEMU_ARCH QEMU_ARCH_XTENSA
+#elif defined(TARGET_AVR)
+#define QEMU_ARCH QEMU_ARCH_AVR
 #endif
 
 const uint32_t arch_type = QEMU_ARCH;
include/disas/dis-asm.h +19 -0
index f87f468..a36e658 100644
@@ -211,6 +211,25 @@ enum bfd_architecture
 #define bfd_mach_m32r          0  /* backwards compatibility */
   bfd_arch_mn10200,    /* Matsushita MN10200 */
   bfd_arch_mn10300,    /* Matsushita MN10300 */
+  bfd_arch_avr,        /* AVR microcontrollers */
+#define bfd_mach_avr1       1
+#define bfd_mach_avr2       2
+#define bfd_mach_avr25      25
+#define bfd_mach_avr3       3
+#define bfd_mach_avr31      31
+#define bfd_mach_avr35      35
+#define bfd_mach_avr4       4
+#define bfd_mach_avr5       5
+#define bfd_mach_avr51      51
+#define bfd_mach_avr6       6
+#define bfd_mach_avrtiny    100
+#define bfd_mach_avrxmega1  101
+#define bfd_mach_avrxmega2  102
+#define bfd_mach_avrxmega3  103
+#define bfd_mach_avrxmega4  104
+#define bfd_mach_avrxmega5  105
+#define bfd_mach_avrxmega6  106
+#define bfd_mach_avrxmega7  107
   bfd_arch_cris,       /* Axis CRIS */
 #define bfd_mach_cris_v0_v10   255
 #define bfd_mach_cris_v32      32
include/sysemu/arch_init.h +1 -0
index 62c6fe4..893df26 100644
@@ -24,6 +24,7 @@ enum {
     QEMU_ARCH_NIOS2 = (1 << 17),
     QEMU_ARCH_HPPA = (1 << 18),
     QEMU_ARCH_RISCV = (1 << 19),
+    QEMU_ARCH_AVR = (1 << 20),
 };
 
 extern const uint32_t arch_type;
qapi/machine.json +2 -1
index b3d30bc..f2dc385 100644
@@ -21,11 +21,12 @@
 #        is true even for "qemu-system-x86_64".
 #
 # ppcemb: dropped in 3.1
+# avr: since 5.0
 #
 # Since: 3.0
 ##
 { 'enum' : 'SysEmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32',
+  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'cris', 'hppa', 'i386', 'lm32',
              'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64',
              'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc',
              'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
Signature · 1 line
2.7.4
#38 lore raw

Re: [PATCH rc4 20/29] target/avr: Register AVR support with the rest of QEMU

Quoted 49 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add AVR related definitions into QEMU.

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
  arch_init.c                |  2 ++
  include/disas/dis-asm.h    | 19 +++++++++++++++++++
  include/sysemu/arch_init.h |  1 +
  qapi/machine.json          |  3 ++-
  4 files changed, 24 insertions(+), 1 deletion(-)
arch_init.c +2 -0
index 705d0b9..6a74116 100644
@@ -89,6 +89,8 @@ int graphic_depth = 32;
  #define QEMU_ARCH QEMU_ARCH_UNICORE32
  #elif defined(TARGET_XTENSA)
  #define QEMU_ARCH QEMU_ARCH_XTENSA
+#elif defined(TARGET_AVR)
+#define QEMU_ARCH QEMU_ARCH_AVR
  #endif
 
  const uint32_t arch_type = QEMU_ARCH;
include/disas/dis-asm.h +9 -0
index f87f468..a36e658 100644
@@ -211,6 +211,25 @@ enum bfd_architecture
  #define bfd_mach_m32r          0  /* backwards compatibility */
    bfd_arch_mn10200,    /* Matsushita MN10200 */
    bfd_arch_mn10300,    /* Matsushita MN10300 */
+  bfd_arch_avr,        /* AVR microcontrollers */
+#define bfd_mach_avr1       1
+#define bfd_mach_avr2       2
+#define bfd_mach_avr25      25
+#define bfd_mach_avr3       3
+#define bfd_mach_avr31      31
+#define bfd_mach_avr35      35
+#define bfd_mach_avr4       4
+#define bfd_mach_avr5       5

include/disas/dis-asm.h enum bfd_architecture · line 232

Quoted 10 lines
include/disas/dis-asm.h +10 -0
+#define bfd_mach_avr51      51
+#define bfd_mach_avr6       6
+#define bfd_mach_avrtiny    100
+#define bfd_mach_avrxmega1  101
+#define bfd_mach_avrxmega2  102
+#define bfd_mach_avrxmega3  103
+#define bfd_mach_avrxmega4  104
+#define bfd_mach_avrxmega5  105
+#define bfd_mach_avrxmega6  106
+#define bfd_mach_avrxmega7  107

I think the changes in include/disas/dis-asm.h should go in patch #6 "target/avr: Add defintions of AVR core types" where the definitions are used:

const char *avr_flags_to_cpu_type(uint32_t flags, const char
*def_cpu_type)

  {
      switch (flags & EF_AVR_MACH) {
      case bfd_mach_avr1:
          return AVR_CPU_TYPE_NAME("avr1");
Quoted 34 lines
include/disas/dis-asm.h +0 -0
    bfd_arch_cris,       /* Axis CRIS */
  #define bfd_mach_cris_v0_v10   255
  #define bfd_mach_cris_v32      32
include/sysemu/arch_init.h +1 -0
index 62c6fe4..893df26 100644
@@ -24,6 +24,7 @@ enum {
      QEMU_ARCH_NIOS2 = (1 << 17),
      QEMU_ARCH_HPPA = (1 << 18),
      QEMU_ARCH_RISCV = (1 << 19),
+    QEMU_ARCH_AVR = (1 << 20),
  };
 
  extern const uint32_t arch_type;
qapi/machine.json +2 -1
index b3d30bc..f2dc385 100644
@@ -21,11 +21,12 @@
  #        is true even for "qemu-system-x86_64".
  #
  # ppcemb: dropped in 3.1
+# avr: since 5.0
  #
  # Since: 3.0
  ##
  { 'enum' : 'SysEmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32',
+  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'cris', 'hppa', 'i386', 'lm32',
               'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64',
               'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc',
               'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
#39 lore raw

Re: [PATCH rc4 20/29] target/avr: Register AVR support with the rest of QEMU

Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 49 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add AVR related definitions into QEMU.

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
  arch_init.c                |  2 ++
  include/disas/dis-asm.h    | 19 +++++++++++++++++++
  include/sysemu/arch_init.h |  1 +
  qapi/machine.json          |  3 ++-
  4 files changed, 24 insertions(+), 1 deletion(-)
arch_init.c +2 -0
index 705d0b9..6a74116 100644
@@ -89,6 +89,8 @@ int graphic_depth = 32;
  #define QEMU_ARCH QEMU_ARCH_UNICORE32
  #elif defined(TARGET_XTENSA)
  #define QEMU_ARCH QEMU_ARCH_XTENSA
+#elif defined(TARGET_AVR)
+#define QEMU_ARCH QEMU_ARCH_AVR
  #endif
 
  const uint32_t arch_type = QEMU_ARCH;
include/disas/dis-asm.h +9 -0
index f87f468..a36e658 100644
@@ -211,6 +211,25 @@ enum bfd_architecture
  #define bfd_mach_m32r          0  /* backwards compatibility */
    bfd_arch_mn10200,    /* Matsushita MN10200 */
    bfd_arch_mn10300,    /* Matsushita MN10300 */
+  bfd_arch_avr,        /* AVR microcontrollers */
+#define bfd_mach_avr1       1
+#define bfd_mach_avr2       2
+#define bfd_mach_avr25      25
+#define bfd_mach_avr3       3
+#define bfd_mach_avr31      31
+#define bfd_mach_avr35      35
+#define bfd_mach_avr4       4
+#define bfd_mach_avr5       5

include/disas/dis-asm.h enum bfd_architecture · line 232

Quoted 10 lines
include/disas/dis-asm.h +10 -0
+#define bfd_mach_avr51      51
+#define bfd_mach_avr6       6
+#define bfd_mach_avrtiny    100
+#define bfd_mach_avrxmega1  101
+#define bfd_mach_avrxmega2  102
+#define bfd_mach_avrxmega3  103
+#define bfd_mach_avrxmega4  104
+#define bfd_mach_avrxmega5  105
+#define bfd_mach_avrxmega6  106
+#define bfd_mach_avrxmega7  107

I think the changes in include/disas/dis-asm.h should go in patch #6 "target/avr: Add defintions of AVR core types" where the definitions are used:

Quoted 7 lines

const char *avr_flags_to_cpu_type(uint32_t flags, const char
*def_cpu_type)

   {
       switch (flags & EF_AVR_MACH) {
       case bfd_mach_avr1:
           return AVR_CPU_TYPE_NAME("avr1");

I agree.

Quoted 35 lines
Quoted 34 lines
include/disas/dis-asm.h +0 -0
    bfd_arch_cris,       /* Axis CRIS */
  #define bfd_mach_cris_v0_v10   255
  #define bfd_mach_cris_v32      32
include/sysemu/arch_init.h +1 -0
index 62c6fe4..893df26 100644
@@ -24,6 +24,7 @@ enum {
      QEMU_ARCH_NIOS2 = (1 << 17),
      QEMU_ARCH_HPPA = (1 << 18),
      QEMU_ARCH_RISCV = (1 << 19),
+    QEMU_ARCH_AVR = (1 << 20),
  };
 
  extern const uint32_t arch_type;
qapi/machine.json +2 -1
index b3d30bc..f2dc385 100644
@@ -21,11 +21,12 @@
  #        is true even for "qemu-system-x86_64".
  #
  # ppcemb: dropped in 3.1
+# avr: since 5.0
  #
  # Since: 3.0
  ##
  { 'enum' : 'SysEmuTarget',
-  'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32',
+  'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'cris', 'hppa', 'i386', 'lm32',
               'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64',
               'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc',
               'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
#40 lore raw

PATCH 21/29 target/avr: Add machine none test

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Add a single code line that will automatically provide 'machine none' test.

---
 tests/qtest/machine-none-test.c | 1 +
 1 file changed, 1 insertion(+)
tests/qtest/machine-none-test.c +1 -0
index 5953d31..3e5c74e 100644
@@ -27,6 +27,7 @@ static struct arch2cpu cpus_map[] = {
     /* tested targets list */
     { "arm", "cortex-a15" },
     { "aarch64", "cortex-a57" },
+    { "avr", "avr6-avr-cpu" },
     { "x86_64", "qemu64,apic-id=0" },
     { "i386", "qemu32,apic-id=0" },
     { "alpha", "ev67" },
Signature · 1 line
2.7.4
#41 lore raw

PATCH 22/29 target/avr: Update MAINTAINERS file

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Include AVR maintaners in MAINTAINERS file

---
 MAINTAINERS | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
MAINTAINERS +24 -0
index c45e886..d0a114b 100644
@@ -163,6 +163,14 @@ S: Maintained
 F: hw/arm/smmu*
 F: include/hw/arm/smmu*
 
+AVR TCG CPUs
+M: Michael Rolnik <[email protected]>
+R: Sarah Harris <[email protected]>
+S: Maintained
+F: target/avr/
+F: default-configs/avr-softmmu.mak
+F: gdb-xml/avr-cpu.xml
+
 CRIS TCG CPUs
 M: Edgar E. Iglesias <[email protected]>
 S: Maintained
@@ -882,6 +890,22 @@ F: include/hw/*/nrf51*.h
 F: include/hw/*/microbit*.h
 F: tests/qtest/microbit-test.c
 
+AVR Machines
+-------------
+
+AVR MCUs
+M: Michael Rolnik <[email protected]>
+R: Sarah Harris <[email protected]>
+S: Maintained
+F: hw/avr/
+F: hw/char/avr_usart.c
+F: include/hw/char/avr_usart.h
+F: hw/timer/avr_timer16.c
+F: include/hw/timer/avr_timer16.h
+F: hw/misc/avr_power.c
+F: include/hw/misc/avr_power.h
+F: tests/acceptance/machine_avr6.py
+
 CRIS Machines
 -------------
 Axis Dev88
Signature · 1 line
2.7.4
#42 lore raw

PATCH 23/29 hw/avr: Add helper to load raw/ELF firmware binaries

In reply to Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add avr_load_firmware() function to load firmware in ELF or raw binary format.

[AM: Corrected the type of the variable containing e_flags]

---
 hw/avr/Makefile.objs |  1 +
 hw/avr/boot.c        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/boot.h        | 33 +++++++++++++++++++++++
 include/elf.h        |  2 ++
 4 files changed, 110 insertions(+)
 create mode 100644 hw/avr/Makefile.objs
 create mode 100644 hw/avr/boot.c
 create mode 100644 hw/avr/boot.h
hw/avr/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..123f174
@@ -0,0 +1 @@
+obj-y += boot.o
hw/avr/boot.c new file +74 -0

74 lines not on this page · raw message

hw/avr/boot.h new file +33 -0
new file mode 100644
index 0000000..62bc10c
@@ -0,0 +1,33 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_BOOT_H
+#define HW_AVR_BOOT_H
+
+#include "hw/boards.h"
+#include "cpu.h"
+
+/**
+ * avr_load_firmware:   load an image into a memory region
+ *
+ * @cpu:        Handle a AVR CPU object
+ * @ms:         A MachineState
+ * @mr:         Memory Region to load into
+ * @firmware:   Path to the firmware file (raw binary or ELF format)
+ *
+ * Load a firmware supplied by the machine or by the user  with the
+ * '-bios' command line option, and put it in target memory.
+ *
+ * Returns: true on success, false on error.
+ */
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware);
+
+#endif
include/elf.h +2 -0
index 8fbfe60..3f08f68 100644
@@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 {
 #define EM_MOXIE           223     /* Moxie processor family */
 #define EM_MOXIE_OLD       0xFEED
 
+#define EM_AVR 83 /* AVR 8-bit microcontroller */
+
 /* This is the info that is needed to parse the dynamic section of the file */
 #define DT_NULL		0
 #define DT_NEEDED	1
Signature · 1 line
2.7.4
#43 lore raw

Re: [PATCH rc4 23/29] hw/avr: Add helper to load raw/ELF firmware binaries

Quoted 151 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add avr_load_firmware() function to load firmware in ELF or raw binary format.

[AM: Corrected the type of the variable containing e_flags]

---
  hw/avr/Makefile.objs |  1 +
  hw/avr/boot.c        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/avr/boot.h        | 33 +++++++++++++++++++++++
  include/elf.h        |  2 ++
  4 files changed, 110 insertions(+)

create mode 100644 hw/avr/Makefile.objs
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h

hw/avr/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..123f174
@@ -0,0 +1 @@
+obj-y += boot.o
hw/avr/boot.c new file +74 -0
new file mode 100644
index 0000000..9ac2c88
@@ -0,0 +1,74 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/loader.h"
+#include "elf.h"
+#include "boot.h"
+#include "qemu/error-report.h"
+
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware)
+{
+    const char *filename;
+    int bytes_loaded;
+    uint64_t entry;
+    uint32_t e_flags;
+
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+    if (filename == NULL) {
+        error_report("Unable to find %s", firmware);
+        return false;
+    }
+
+    bytes_loaded = load_elf_ram_sym(filename,
+                                    NULL, NULL, NULL,
+                                    &entry, NULL, NULL,
+                                    &e_flags, 0, EM_AVR, 0, 0,
+                                    NULL, true, NULL);
+    if (bytes_loaded >= 0) {
+        /* If ELF file is provided, determine CPU type reading ELF e_flags. */
+        const char *elf_cpu = avr_flags_to_cpu_type(e_flags, NULL);
+        const char *mcu_cpu_type = object_get_typename(OBJECT(cpu));
+        int cpu_len = strlen(mcu_cpu_type) - strlen(AVR_CPU_TYPE_SUFFIX);
+
+        if (entry) {
+            error_report("BIOS entry_point must be 0x0000 "
+                         "(ELF image '%s' has entry_point 0x%04" PRIx64 ")",
+                         firmware, entry);
+            return false;
+        }
+        if (!elf_cpu) {
+            warn_report("Could not determine CPU type for ELF image '%s', "
+                        "assuming '%.*s' CPU",
+                         firmware, cpu_len, mcu_cpu_type);
+            return true;
+        }
+        if (strcmp(elf_cpu, mcu_cpu_type)) {
+            error_report("Current machine: %s with '%.*s' CPU",
+                         MACHINE_GET_CLASS(ms)->desc, cpu_len, mcu_cpu_type);
+            error_report("ELF image '%s' is for '%.*s' CPU",
+                         firmware,
+                         (int)(strlen(elf_cpu) - strlen(AVR_CPU_TYPE_SUFFIX)),
+                         elf_cpu);
+            return false;
+        }
+    } else {
+        bytes_loaded = load_image_targphys(filename, OFFSET_CODE,
+                                           memory_region_size(mr));
+    }
+    if (bytes_loaded < 0) {
+        error_report("Unable to load firmware image %s as ELF or raw binary",
+                     firmware);
+        return false;
+    }
+    return true;
+}
hw/avr/boot.h new file +33 -0
new file mode 100644
index 0000000..62bc10c
@@ -0,0 +1,33 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_BOOT_H
+#define HW_AVR_BOOT_H
+
+#include "hw/boards.h"
+#include "cpu.h"
+
+/**
+ * avr_load_firmware:   load an image into a memory region
+ *
+ * @cpu:        Handle a AVR CPU object
+ * @ms:         A MachineState
+ * @mr:         Memory Region to load into
+ * @firmware:   Path to the firmware file (raw binary or ELF format)
+ *
+ * Load a firmware supplied by the machine or by the user  with the
+ * '-bios' command line option, and put it in target memory.
+ *
+ * Returns: true on success, false on error.
+ */
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware);
+
+#endif
include/elf.h +0 -0
index 8fbfe60..3f08f68 100644

include/elf.h typedef struct mips_elf_abiflags_v0 { · line 205

Quoted 4 lines
include/elf.h +1 -0
@@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 {
  #define EM_MOXIE           223     /* Moxie processor family */
  #define EM_MOXIE_OLD       0xFEED
 
+#define EM_AVR 83 /* AVR 8-bit microcontroller */

IIRC from previous version you suggested to move this, I suppose between:

#define EM_CRIS 76

#define EM_V850 87

Quoted 5 lines
include/elf.h +1 -0
+
  /* This is the info that is needed to parse the dynamic section of the file */
  #define DT_NULL		0
  #define DT_NEEDED	1
#44 lore raw

Re: [PATCH rc4 23/29] hw/avr: Add helper to load raw/ELF firmware binaries

Quoted 156 lines · Philippe Mathieu-Daudé
Quoted 154 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add avr_load_firmware() function to load firmware in ELF or raw binary format.

[AM: Corrected the type of the variable containing e_flags]

---
  hw/avr/Makefile.objs |  1 +
  hw/avr/boot.c        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/avr/boot.h        | 33 +++++++++++++++++++++++
  include/elf.h        |  2 ++
  4 files changed, 110 insertions(+)

create mode 100644 hw/avr/Makefile.objs
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h

hw/avr/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..123f174
@@ -0,0 +1 @@
+obj-y += boot.o
hw/avr/boot.c new file +74 -0
new file mode 100644
index 0000000..9ac2c88
@@ -0,0 +1,74 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/loader.h"
+#include "elf.h"
+#include "boot.h"
+#include "qemu/error-report.h"
+
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware)
+{
+    const char *filename;
+    int bytes_loaded;
+    uint64_t entry;
+    uint32_t e_flags;
+
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+    if (filename == NULL) {
+        error_report("Unable to find %s", firmware);
+        return false;
+    }
+
+    bytes_loaded = load_elf_ram_sym(filename,
+                                    NULL, NULL, NULL,
+                                    &entry, NULL, NULL,
+                                    &e_flags, 0, EM_AVR, 0, 0,
+                                    NULL, true, NULL);
+    if (bytes_loaded >= 0) {
+        /* If ELF file is provided, determine CPU type reading ELF e_flags. */
+        const char *elf_cpu = avr_flags_to_cpu_type(e_flags, NULL);
+        const char *mcu_cpu_type = object_get_typename(OBJECT(cpu));
+        int cpu_len = strlen(mcu_cpu_type) - strlen(AVR_CPU_TYPE_SUFFIX);
+
+        if (entry) {
+            error_report("BIOS entry_point must be 0x0000 "
+                         "(ELF image '%s' has entry_point 0x%04" PRIx64 ")",
+                         firmware, entry);
+            return false;
+        }
+        if (!elf_cpu) {
+            warn_report("Could not determine CPU type for ELF image '%s', "
+                        "assuming '%.*s' CPU",
+                         firmware, cpu_len, mcu_cpu_type);
+            return true;
+        }
+        if (strcmp(elf_cpu, mcu_cpu_type)) {
+            error_report("Current machine: %s with '%.*s' CPU",
+                         MACHINE_GET_CLASS(ms)->desc, cpu_len, mcu_cpu_type);
+            error_report("ELF image '%s' is for '%.*s' CPU",
+                         firmware,
+                         (int)(strlen(elf_cpu) - strlen(AVR_CPU_TYPE_SUFFIX)),
+                         elf_cpu);
+            return false;
+        }
+    } else {
+        bytes_loaded = load_image_targphys(filename, OFFSET_CODE,
+                                           memory_region_size(mr));
+    }
+    if (bytes_loaded < 0) {
+        error_report("Unable to load firmware image %s as ELF or raw binary",
+                     firmware);
+        return false;
+    }
+    return true;
+}
hw/avr/boot.h new file +33 -0
new file mode 100644
index 0000000..62bc10c
@@ -0,0 +1,33 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_BOOT_H
+#define HW_AVR_BOOT_H
+
+#include "hw/boards.h"
+#include "cpu.h"
+
+/**
+ * avr_load_firmware:   load an image into a memory region
+ *
+ * @cpu:        Handle a AVR CPU object
+ * @ms:         A MachineState
+ * @mr:         Memory Region to load into
+ * @firmware:   Path to the firmware file (raw binary or ELF format)
+ *
+ * Load a firmware supplied by the machine or by the user  with the
+ * '-bios' command line option, and put it in target memory.
+ *
+ * Returns: true on success, false on error.
+ */
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware);
+
+#endif
include/elf.h +0 -0
index 8fbfe60..3f08f68 100644
@@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 {
  #define EM_MOXIE           223     /* Moxie processor family */
  #define EM_MOXIE_OLD       0xFEED
 
Quoted 8 lines

include/elf.h typedef struct mips_elf_abiflags_v0 { · line 205

Quoted 1 line
include/elf.h +1 -0
+#define EM_AVR 83 /* AVR 8-bit microcontroller */

IIRC from previous version you suggested to move this, I suppose between:

#define EM_CRIS 76

#define EM_V850 87

I forgot about that, thinking about other larger changes.

Quoted 6 lines
Quoted 5 lines
include/elf.h +1 -0
+
  /* This is the info that is needed to parse the dynamic section of the file */
  #define DT_NULL             0
  #define DT_NEEDED   1
#45 lore raw

Re: [PATCH rc4 23/29] hw/avr: Add helper to load raw/ELF firmware binaries

Quoted 162 lines · Aleksandar Markovic
Quoted 160 lines · Philippe Mathieu-Daudé
Quoted 151 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add avr_load_firmware() function to load firmware in ELF or raw binary format.

[AM: Corrected the type of the variable containing e_flags]

---
   hw/avr/Makefile.objs |  1 +
   hw/avr/boot.c        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
   hw/avr/boot.h        | 33 +++++++++++++++++++++++
   include/elf.h        |  2 ++
   4 files changed, 110 insertions(+)

create mode 100644 hw/avr/Makefile.objs
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h

hw/avr/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..123f174
@@ -0,0 +1 @@
+obj-y += boot.o
hw/avr/boot.c new file +74 -0
new file mode 100644
index 0000000..9ac2c88
@@ -0,0 +1,74 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/loader.h"
+#include "elf.h"
+#include "boot.h"
+#include "qemu/error-report.h"
+
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware)
+{
+    const char *filename;
+    int bytes_loaded;
+    uint64_t entry;
+    uint32_t e_flags;
+
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+    if (filename == NULL) {
+        error_report("Unable to find %s", firmware);
+        return false;
+    }
+
+    bytes_loaded = load_elf_ram_sym(filename,
+                                    NULL, NULL, NULL,
+                                    &entry, NULL, NULL,
+                                    &e_flags, 0, EM_AVR, 0, 0,
+                                    NULL, true, NULL);
+    if (bytes_loaded >= 0) {
+        /* If ELF file is provided, determine CPU type reading ELF e_flags. */
+        const char *elf_cpu = avr_flags_to_cpu_type(e_flags, NULL);
+        const char *mcu_cpu_type = object_get_typename(OBJECT(cpu));
+        int cpu_len = strlen(mcu_cpu_type) - strlen(AVR_CPU_TYPE_SUFFIX);
+
+        if (entry) {
+            error_report("BIOS entry_point must be 0x0000 "
+                         "(ELF image '%s' has entry_point 0x%04" PRIx64 ")",
+                         firmware, entry);
+            return false;
+        }
+        if (!elf_cpu) {
+            warn_report("Could not determine CPU type for ELF image '%s', "
+                        "assuming '%.*s' CPU",
+                         firmware, cpu_len, mcu_cpu_type);
+            return true;
+        }
+        if (strcmp(elf_cpu, mcu_cpu_type)) {
+            error_report("Current machine: %s with '%.*s' CPU",
+                         MACHINE_GET_CLASS(ms)->desc, cpu_len, mcu_cpu_type);
+            error_report("ELF image '%s' is for '%.*s' CPU",
+                         firmware,
+                         (int)(strlen(elf_cpu) - strlen(AVR_CPU_TYPE_SUFFIX)),
+                         elf_cpu);
+            return false;
+        }
+    } else {
+        bytes_loaded = load_image_targphys(filename, OFFSET_CODE,
+                                           memory_region_size(mr));
+    }
+    if (bytes_loaded < 0) {
+        error_report("Unable to load firmware image %s as ELF or raw binary",
+                     firmware);
+        return false;
+    }
+    return true;
+}
hw/avr/boot.h new file +33 -0
new file mode 100644
index 0000000..62bc10c
@@ -0,0 +1,33 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_BOOT_H
+#define HW_AVR_BOOT_H
+
+#include "hw/boards.h"
+#include "cpu.h"
+
+/**
+ * avr_load_firmware:   load an image into a memory region
+ *
+ * @cpu:        Handle a AVR CPU object
+ * @ms:         A MachineState
+ * @mr:         Memory Region to load into
+ * @firmware:   Path to the firmware file (raw binary or ELF format)
+ *
+ * Load a firmware supplied by the machine or by the user  with the
+ * '-bios' command line option, and put it in target memory.
+ *
+ * Returns: true on success, false on error.
+ */
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware);
+
+#endif
include/elf.h +0 -0
index 8fbfe60..3f08f68 100644

include/elf.h typedef struct mips_elf_abiflags_v0 { · line 205

Quoted 4 lines
include/elf.h +1 -0
@@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 {
   #define EM_MOXIE           223     /* Moxie processor family */
   #define EM_MOXIE_OLD       0xFEED
 
+#define EM_AVR 83 /* AVR 8-bit microcontroller */

IIRC from previous version you suggested to move this, I suppose between:

Quoted 6 lines
Quoted 4 lines

#define EM_CRIS 76

#define EM_V850 87

I forgot about that, thinking about other larger changes.

Anyway looking closer, the definitions are not ordered correctly, so I think we don't care much. Your call :)

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
include/elf.h +1 -0
+
   /* This is the info that is needed to parse the dynamic section of the file */
   #define DT_NULL             0
   #define DT_NEEDED   1
#46 lore raw

Re: [PATCH rc4 23/29] hw/avr: Add helper to load raw/ELF firmware binaries

Quoted 166 lines · Philippe Mathieu-Daudé
Quoted 164 lines · Aleksandar Markovic
Quoted 162 lines · Philippe Mathieu-Daudé
Quoted 151 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add avr_load_firmware() function to load firmware in ELF or raw binary format.

[AM: Corrected the type of the variable containing e_flags]

---
   hw/avr/Makefile.objs |  1 +
   hw/avr/boot.c        | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
   hw/avr/boot.h        | 33 +++++++++++++++++++++++
   include/elf.h        |  2 ++
   4 files changed, 110 insertions(+)

create mode 100644 hw/avr/Makefile.objs
create mode 100644 hw/avr/boot.c
create mode 100644 hw/avr/boot.h

hw/avr/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..123f174
@@ -0,0 +1 @@
+obj-y += boot.o
hw/avr/boot.c new file +74 -0
new file mode 100644
index 0000000..9ac2c88
@@ -0,0 +1,74 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/loader.h"
+#include "elf.h"
+#include "boot.h"
+#include "qemu/error-report.h"
+
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware)
+{
+    const char *filename;
+    int bytes_loaded;
+    uint64_t entry;
+    uint32_t e_flags;
+
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+    if (filename == NULL) {
+        error_report("Unable to find %s", firmware);
+        return false;
+    }
+
+    bytes_loaded = load_elf_ram_sym(filename,
+                                    NULL, NULL, NULL,
+                                    &entry, NULL, NULL,
+                                    &e_flags, 0, EM_AVR, 0, 0,
+                                    NULL, true, NULL);
+    if (bytes_loaded >= 0) {
+        /* If ELF file is provided, determine CPU type reading ELF e_flags. */
+        const char *elf_cpu = avr_flags_to_cpu_type(e_flags, NULL);
+        const char *mcu_cpu_type = object_get_typename(OBJECT(cpu));
+        int cpu_len = strlen(mcu_cpu_type) - strlen(AVR_CPU_TYPE_SUFFIX);
+
+        if (entry) {
+            error_report("BIOS entry_point must be 0x0000 "
+                         "(ELF image '%s' has entry_point 0x%04" PRIx64 ")",
+                         firmware, entry);
+            return false;
+        }
+        if (!elf_cpu) {
+            warn_report("Could not determine CPU type for ELF image '%s', "
+                        "assuming '%.*s' CPU",
+                         firmware, cpu_len, mcu_cpu_type);
+            return true;
+        }
+        if (strcmp(elf_cpu, mcu_cpu_type)) {
+            error_report("Current machine: %s with '%.*s' CPU",
+                         MACHINE_GET_CLASS(ms)->desc, cpu_len, mcu_cpu_type);
+            error_report("ELF image '%s' is for '%.*s' CPU",
+                         firmware,
+                         (int)(strlen(elf_cpu) - strlen(AVR_CPU_TYPE_SUFFIX)),
+                         elf_cpu);
+            return false;
+        }
+    } else {
+        bytes_loaded = load_image_targphys(filename, OFFSET_CODE,
+                                           memory_region_size(mr));
+    }
+    if (bytes_loaded < 0) {
+        error_report("Unable to load firmware image %s as ELF or raw binary",
+                     firmware);
+        return false;
+    }
+    return true;
+}
hw/avr/boot.h new file +33 -0
new file mode 100644
index 0000000..62bc10c
@@ -0,0 +1,33 @@
+/*
+ * AVR loader helpers
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_BOOT_H
+#define HW_AVR_BOOT_H
+
+#include "hw/boards.h"
+#include "cpu.h"
+
+/**
+ * avr_load_firmware:   load an image into a memory region
+ *
+ * @cpu:        Handle a AVR CPU object
+ * @ms:         A MachineState
+ * @mr:         Memory Region to load into
+ * @firmware:   Path to the firmware file (raw binary or ELF format)
+ *
+ * Load a firmware supplied by the machine or by the user  with the
+ * '-bios' command line option, and put it in target memory.
+ *
+ * Returns: true on success, false on error.
+ */
+bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
+                       MemoryRegion *mr, const char *firmware);
+
+#endif
include/elf.h +0 -0
index 8fbfe60..3f08f68 100644

include/elf.h typedef struct mips_elf_abiflags_v0 { · line 205

Quoted 4 lines
include/elf.h +1 -0
@@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 {
   #define EM_MOXIE           223     /* Moxie processor family */
   #define EM_MOXIE_OLD       0xFEED
 
+#define EM_AVR 83 /* AVR 8-bit microcontroller */

IIRC from previous version you suggested to move this, I suppose between:

#define EM_CRIS 76

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

#define EM_V850 87

I forgot about that, thinking about other larger changes.

Anyway looking closer, the definitions are not ordered correctly, so I think we don't care much. Your call :)

Let's not add more mess to the mess. :)

Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
include/elf.h +1 -0
+
   /* This is the info that is needed to parse the dynamic section of the file */
   #define DT_NULL             0
   #define DT_NEEDED   1
#47 lore raw

PATCH 24/29 hw/avr: Add some ATmega microcontrollers

In reply to Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +470 -0

470 lines not on this page · raw message

hw/avr/atmega.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.7.4
#48 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

Thanks,
Aleksandar

Quoted 518 lines
hw/avr/atmega.c new file +461 -0
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
+#include "sysemu/sysemu.h"
+#include "hw/qdev-properties.h"
+#include "hw/sysbus.h"
+#include "hw/boards.h" /* FIXME memory_region_allocate_system_memory for sram */
+#include "hw/misc/unimp.h"
+#include "atmega.h"
+
+enum AtmegaPeripheral {
+    POWER0, POWER1,
+    GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF,
+    GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK, GPIOL,
+    USART0, USART1, USART2, USART3,
+    TIMER0, TIMER1, TIMER2, TIMER3, TIMER4, TIMER5,
+    PERIFMAX
+};
+
+#define GPIO(n)     (n + GPIOA)
+#define USART(n)    (n + USART0)
+#define TIMER(n)    (n + TIMER0)
+#define POWER(n)    (n + POWER0)
+
+typedef struct {
+    uint16_t addr;
+    enum AtmegaPeripheral power_index;
+    uint8_t power_bit;
+    /* timer specific */
+    uint16_t intmask_addr;
+    uint16_t intflag_addr;
+    bool is_timer16;
+} peripheral_cfg;
+
+typedef struct AtmegaMcuClass {
+    /*< private >*/
+    SysBusDeviceClass parent_class;
+    /*< public >*/
+    const char *uc_name;
+    const char *cpu_type;
+    size_t flash_size;
+    size_t eeprom_size;
+    size_t sram_size;
+    size_t io_size;
+    size_t gpio_count;
+    size_t adc_count;
+    const uint8_t *irq;
+    const peripheral_cfg *dev;
+} AtmegaMcuClass;
+
+#define ATMEGA_MCU_CLASS(klass) \
+    OBJECT_CLASS_CHECK(AtmegaMcuClass, (klass), TYPE_ATMEGA_MCU)
+#define ATMEGA_MCU_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(AtmegaMcuClass, (obj), TYPE_ATMEGA_MCU)
+
+static const peripheral_cfg dev168_328[PERIFMAX] = {
+    [USART0]        = {  0xc0, POWER0, 1 },
+    [TIMER2]        = {  0xb0, POWER0, 6, 0x70, 0x37, false },
+    [TIMER1]        = {  0x80, POWER0, 3, 0x6f, 0x36, true },
+    [POWER0]        = {  0x64 },
+    [TIMER0]        = {  0x44, POWER0, 5, 0x6e, 0x35, false },
+    [GPIOD]         = {  0x29 },
+    [GPIOC]         = {  0x26 },
+    [GPIOB]         = {  0x23 },
+}, dev1280_2560[PERIFMAX] = {
+    [USART3]        = { 0x130, POWER1, 2 },
+    [TIMER5]        = { 0x120, POWER1, 5, 0x73, 0x3a, true },
+    [GPIOL]         = { 0x109 },
+    [GPIOK]         = { 0x106 },
+    [GPIOJ]         = { 0x103 },
+    [GPIOH]         = { 0x100 },
+    [USART2]        = {  0xd0, POWER1, 1 },
+    [USART1]        = {  0xc8, POWER1, 0 },
+    [USART0]        = {  0xc0, POWER0, 1 },
+    [TIMER2]        = {  0xb0, POWER0, 6, 0x70, 0x37, false }, /* TODO async */
+    [TIMER4]        = {  0xa0, POWER1, 4, 0x72, 0x39, true },
+    [TIMER3]        = {  0x90, POWER1, 3, 0x71, 0x38, true },
+    [TIMER1]        = {  0x80, POWER0, 3, 0x6f, 0x36, true },
+    [POWER1]        = {  0x65 },
+    [POWER0]        = {  0x64 },
+    [TIMER0]        = {  0x44, POWER0, 5, 0x6e, 0x35, false },
+    [GPIOG]         = {  0x32 },
+    [GPIOF]         = {  0x2f },
+    [GPIOE]         = {  0x2c },
+    [GPIOD]         = {  0x29 },
+    [GPIOC]         = {  0x26 },
+    [GPIOB]         = {  0x23 },
+    [GPIOA]         = {  0x20 },
+};
+
+enum AtmegaIrq {
+    USART0_RXC_IRQ, USART0_DRE_IRQ, USART0_TXC_IRQ,
+    USART1_RXC_IRQ, USART1_DRE_IRQ, USART1_TXC_IRQ,
+    USART2_RXC_IRQ, USART2_DRE_IRQ, USART2_TXC_IRQ,
+    USART3_RXC_IRQ, USART3_DRE_IRQ, USART3_TXC_IRQ,
+    TIMER0_CAPT_IRQ, TIMER0_COMPA_IRQ, TIMER0_COMPB_IRQ,
+        TIMER0_COMPC_IRQ, TIMER0_OVF_IRQ,
+    TIMER1_CAPT_IRQ, TIMER1_COMPA_IRQ, TIMER1_COMPB_IRQ,
+        TIMER1_COMPC_IRQ, TIMER1_OVF_IRQ,
+    TIMER2_CAPT_IRQ, TIMER2_COMPA_IRQ, TIMER2_COMPB_IRQ,
+        TIMER2_COMPC_IRQ, TIMER2_OVF_IRQ,
+    TIMER3_CAPT_IRQ, TIMER3_COMPA_IRQ, TIMER3_COMPB_IRQ,
+        TIMER3_COMPC_IRQ, TIMER3_OVF_IRQ,
+    TIMER4_CAPT_IRQ, TIMER4_COMPA_IRQ, TIMER4_COMPB_IRQ,
+        TIMER4_COMPC_IRQ, TIMER4_OVF_IRQ,
+    TIMER5_CAPT_IRQ, TIMER5_COMPA_IRQ, TIMER5_COMPB_IRQ,
+        TIMER5_COMPC_IRQ, TIMER5_OVF_IRQ,
+    IRQ_COUNT
+};
+
+#define USART_IRQ_COUNT     3
+#define USART_RXC_IRQ(n)    (n * USART_IRQ_COUNT + USART0_RXC_IRQ)
+#define USART_DRE_IRQ(n)    (n * USART_IRQ_COUNT + USART0_DRE_IRQ)
+#define USART_TXC_IRQ(n)    (n * USART_IRQ_COUNT + USART0_TXC_IRQ)
+#define TIMER_IRQ_COUNT     5
+#define TIMER_CAPT_IRQ(n)   (n * TIMER_IRQ_COUNT + TIMER0_CAPT_IRQ)
+#define TIMER_COMPA_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPA_IRQ)
+#define TIMER_COMPB_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPB_IRQ)
+#define TIMER_COMPC_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPC_IRQ)
+#define TIMER_OVF_IRQ(n)    (n * TIMER_IRQ_COUNT + TIMER0_OVF_IRQ)
+
+static const uint8_t irq168_328[IRQ_COUNT] = {
+    [TIMER2_COMPA_IRQ]      = 8,
+    [TIMER2_COMPB_IRQ]      = 9,
+    [TIMER2_OVF_IRQ]        = 10,
+    [TIMER1_CAPT_IRQ]       = 11,
+    [TIMER1_COMPA_IRQ]      = 12,
+    [TIMER1_COMPB_IRQ]      = 13,
+    [TIMER1_OVF_IRQ]        = 14,
+    [TIMER0_COMPA_IRQ]      = 15,
+    [TIMER0_COMPB_IRQ]      = 16,
+    [TIMER0_OVF_IRQ]        = 17,
+    [USART0_RXC_IRQ]        = 19,
+    [USART0_DRE_IRQ]        = 20,
+    [USART0_TXC_IRQ]        = 21,
+}, irq1280_2560[IRQ_COUNT] = {
+    [TIMER2_COMPA_IRQ]      = 14,
+    [TIMER2_COMPB_IRQ]      = 15,
+    [TIMER2_OVF_IRQ]        = 16,
+    [TIMER1_CAPT_IRQ]       = 17,
+    [TIMER1_COMPA_IRQ]      = 18,
+    [TIMER1_COMPB_IRQ]      = 19,
+    [TIMER1_COMPC_IRQ]      = 20,
+    [TIMER1_OVF_IRQ]        = 21,
+    [TIMER0_COMPA_IRQ]      = 22,
+    [TIMER0_COMPB_IRQ]      = 23,
+    [TIMER0_OVF_IRQ]        = 24,
+    [USART0_RXC_IRQ]        = 26,
+    [USART0_DRE_IRQ]        = 27,
+    [USART0_TXC_IRQ]        = 28,
+    [TIMER3_CAPT_IRQ]       = 32,
+    [TIMER3_COMPA_IRQ]      = 33,
+    [TIMER3_COMPB_IRQ]      = 34,
+    [TIMER3_COMPC_IRQ]      = 35,
+    [TIMER3_OVF_IRQ]        = 36,
+    [USART1_RXC_IRQ]        = 37,
+    [USART1_DRE_IRQ]        = 38,
+    [USART1_TXC_IRQ]        = 39,
+    [TIMER4_CAPT_IRQ]       = 42,
+    [TIMER4_COMPA_IRQ]      = 43,
+    [TIMER4_COMPB_IRQ]      = 44,
+    [TIMER4_COMPC_IRQ]      = 45,
+    [TIMER4_OVF_IRQ]        = 46,
+    [TIMER5_CAPT_IRQ]       = 47,
+    [TIMER5_COMPA_IRQ]      = 48,
+    [TIMER5_COMPB_IRQ]      = 49,
+    [TIMER5_COMPC_IRQ]      = 50,
+    [TIMER5_OVF_IRQ]        = 51,
+    [USART2_RXC_IRQ]        = 52,
+    [USART2_DRE_IRQ]        = 53,
+    [USART2_TXC_IRQ]        = 54,
+    [USART3_RXC_IRQ]        = 55,
+    [USART3_DRE_IRQ]        = 56,
+    [USART3_TXC_IRQ]        = 57,
+};
+
+static void connect_peripheral_irq(const AtmegaMcuClass *mc,
+                                   SysBusDevice *sbd,
+                                   DeviceState *dev, int n,
+                                   unsigned peripheral_irq)
+{
+    int irq = mc->irq[peripheral_irq];
+
+    if (!irq) {
+        return;
+    }
+    /* FIXME move that to avr_cpu_set_int() once 'sample' board is removed */
+    assert(irq >= 2);
+    irq -= 2;
+
+    sysbus_connect_irq(sbd, n, qdev_get_gpio_in(dev, irq));
+}
+
+static void connect_power_reduction_gpio(AtmegaMcuState *s,
+                                         const AtmegaMcuClass *mc,
+                                         DeviceState *dev,
+                                         int peripheral_index)
+{
+    unsigned power_index = mc->dev[peripheral_index].power_index;
+    assert(mc->dev[power_index].addr);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pwr[power_index - POWER0]),
+                       mc->dev[peripheral_index].power_bit,
+                       qdev_get_gpio_in(dev, 0));
+}
+
+static void atmega_realize(DeviceState *dev, Error **errp)
+{
+    AtmegaMcuState *s = ATMEGA_MCU(dev);
+    const AtmegaMcuClass *mc = ATMEGA_MCU_GET_CLASS(dev);
+    DeviceState *cpudev;
+    SysBusDevice *sbd;
+    Error *err = NULL;
+    char *devname;
+    size_t i;
+
+    assert(mc->io_size <= 0x200);
+
+    if (!s->xtal_freq_hz) {
+        error_setg(errp, "\"xtal-frequency-hz\" property must be provided.");
+        return;
+    }
+
+    /* CPU */
+    object_initialize_child(OBJECT(dev), "cpu", &s->cpu, sizeof(s->cpu),
+                            mc->cpu_type, &err, NULL);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &error_abort);
+    cpudev = DEVICE(&s->cpu);
+
+    /* SRAM */
+    memory_region_init_ram(&s->sram, OBJECT(dev), "sram", mc->sram_size,
+                           &error_abort);
+    memory_region_add_subregion(get_system_memory(),
+                                OFFSET_DATA + mc->io_size, &s->sram);
+
+    /* Flash */
+    memory_region_init_rom(&s->flash, OBJECT(dev),
+                           "flash", mc->flash_size, &error_fatal);
+    memory_region_add_subregion(get_system_memory(), OFFSET_CODE, &s->flash);
+
+    /*
+     * I/O
+     *
+     * 0x00 - 0x1f: Registers
+     * 0x20 - 0x5f: I/O memory
+     * 0x60 - 0xff: Extended I/O
+     */
+    s->io = qdev_create(NULL, TYPE_UNIMPLEMENTED_DEVICE);
+    qdev_prop_set_string(s->io, "name", "I/O");
+    qdev_prop_set_uint64(s->io, "size", mc->io_size);
+    qdev_init_nofail(s->io);
+    sysbus_mmio_map_overlap(SYS_BUS_DEVICE(s->io), 0, OFFSET_DATA, -1234);
+
+    /* Power Reduction */
+    for (i = 0; i < POWER_MAX; i++) {
+        int idx = POWER(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("power%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->pwr[i], sizeof(s->pwr[i]),
+                                TYPE_AVR_MASK, &error_abort, NULL);
+        object_property_set_bool(OBJECT(&s->pwr[i]), true, "realized",
+                                 &error_abort);
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->pwr[i]), 0,
+                        OFFSET_DATA + mc->dev[idx].addr);
+        g_free(devname);
+    }
+
+    /* GPIO */
+    for (i = 0; i < GPIO_MAX; i++) {
+        int idx = GPIO(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("avr-gpio-%c", 'a' + (char)i);
+        create_unimplemented_device(devname,
+                                    OFFSET_DATA + mc->dev[idx].addr, 3);
+        g_free(devname);
+    }
+
+    /* USART */
+    for (i = 0; i < USART_MAX; i++) {
+        int idx = USART(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("usart%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->usart[i], sizeof(s->usart[i]),
+                                TYPE_AVR_USART, &error_abort, NULL);
+        qdev_prop_set_chr(DEVICE(&s->usart[i]), "chardev", serial_hd(i));
+        object_property_set_bool(OBJECT(&s->usart[i]), true, "realized",
+                                 &error_abort);
+        sbd = SYS_BUS_DEVICE(&s->usart[i]);
+        sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[USART(i)].addr);
+        connect_peripheral_irq(mc, sbd, cpudev, 0, USART_RXC_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 1, USART_DRE_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 2, USART_TXC_IRQ(i));
+        connect_power_reduction_gpio(s, mc, DEVICE(&s->usart[i]), idx);
+        g_free(devname);
+    }
+
+    /* Timer */
+    for (i = 0; i < TIMER_MAX; i++) {
+        int idx = TIMER(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        if (!mc->dev[idx].is_timer16) {
+            create_unimplemented_device("avr-timer8",
+                                        OFFSET_DATA + mc->dev[idx].addr, 5);
+            create_unimplemented_device("avr-timer8-intmask",
+                                        OFFSET_DATA
+                                        + mc->dev[idx].intmask_addr, 1);
+            create_unimplemented_device("avr-timer8-intflag",
+                                        OFFSET_DATA
+                                        + mc->dev[idx].intflag_addr, 1);
+            continue;
+        }
+        devname = g_strdup_printf("timer%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->timer[i], sizeof(s->timer[i]),
+                                TYPE_AVR_TIMER16, &error_abort, NULL);
+        object_property_set_uint(OBJECT(&s->timer[i]), s->xtal_freq_hz,
+                                 "cpu-frequency-hz", &error_abort);
+        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized",
+                                 &error_abort);
+        sbd = SYS_BUS_DEVICE(&s->timer[i]);
+        sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[idx].addr);
+        sysbus_mmio_map(sbd, 1, OFFSET_DATA + mc->dev[idx].intmask_addr);
+        sysbus_mmio_map(sbd, 2, OFFSET_DATA + mc->dev[idx].intflag_addr);
+        connect_peripheral_irq(mc, sbd, cpudev, 0, TIMER_CAPT_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 1, TIMER_COMPA_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 2, TIMER_COMPB_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 3, TIMER_COMPC_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 4, TIMER_OVF_IRQ(i));
+        connect_power_reduction_gpio(s, mc, DEVICE(&s->timer[i]), idx);
+        g_free(devname);
+    }
+
+    create_unimplemented_device("avr-twi",          OFFSET_DATA + 0x0b8, 6);
+    create_unimplemented_device("avr-adc",          OFFSET_DATA + 0x078, 8);
+    create_unimplemented_device("avr-ext-mem-ctrl", OFFSET_DATA + 0x074, 2);
+    create_unimplemented_device("avr-watchdog",     OFFSET_DATA + 0x060, 1);
+    create_unimplemented_device("avr-spi",          OFFSET_DATA + 0x04c, 3);
+    create_unimplemented_device("avr-eeprom",       OFFSET_DATA + 0x03f, 3);
+}
+
+static Property atmega_props[] = {
+    DEFINE_PROP_UINT64("xtal-frequency-hz", AtmegaMcuState,
+                       xtal_freq_hz, 0),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void atmega_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = atmega_realize;
+    device_class_set_props(dc, atmega_props);
+    /* Reason: Mapped at fixed location on the system bus */
+    dc->user_creatable = false;
+}
+
+static void atmega168_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr5");
+    amc->flash_size = 16 * KiB;
+    amc->eeprom_size = 512;
+    amc->sram_size = 1 * KiB;
+    amc->io_size = 256;
+    amc->gpio_count = 23;
+    amc->adc_count = 6;
+    amc->irq = irq168_328;
+    amc->dev = dev168_328;
+};
+
+static void atmega328_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr5");
+    amc->flash_size = 32 * KiB;
+    amc->eeprom_size = 1 * KiB;
+    amc->sram_size = 2 * KiB;
+    amc->io_size = 256;
+    amc->gpio_count = 23;
+    amc->adc_count = 6;
+    amc->irq = irq168_328;
+    amc->dev = dev168_328;
+};
+
+static void atmega1280_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr6");
+    amc->flash_size = 128 * KiB;
+    amc->eeprom_size = 4 * KiB;
+    amc->sram_size = 8 * KiB;
+    amc->io_size = 512;
+    amc->gpio_count = 86;
+    amc->adc_count = 16;
+    amc->irq = irq1280_2560;
+    amc->dev = dev1280_2560;
+};
+
+static void atmega2560_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr6");
+    amc->flash_size = 256 * KiB;
+    amc->eeprom_size = 4 * KiB;
+    amc->sram_size = 8 * KiB;
+    amc->io_size = 512;
+    amc->gpio_count = 54;
+    amc->adc_count = 16;
+    amc->irq = irq1280_2560;
+    amc->dev = dev1280_2560;
+};
+
+static const TypeInfo atmega_mcu_types[] = {
+    {
+        .name           = TYPE_ATMEGA168_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega168_class_init,
+    }, {
+        .name           = TYPE_ATMEGA328_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega328_class_init,
+    }, {
+        .name           = TYPE_ATMEGA1280_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega1280_class_init,
+    }, {
+        .name           = TYPE_ATMEGA2560_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega2560_class_init,
+    }, {
+        .name           = TYPE_ATMEGA_MCU,
+        .parent         = TYPE_SYS_BUS_DEVICE,
+        .instance_size  = sizeof(AtmegaMcuState),
+        .class_size     = sizeof(AtmegaMcuClass),
+        .class_init     = atmega_class_init,
+        .abstract       = true,
+    }
+};
+
+DEFINE_TYPES(atmega_mcu_types)
hw/avr/atmega.h new file +48 -1
new file mode 100644
index 0000000..1cfbb6b
@@ -0,0 +1,48 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_AVR_ATMEGA_H
+#define HW_AVR_ATMEGA_H
+
+#include "hw/char/avr_usart.h"
+#include "hw/timer/avr_timer16.h"
+#include "hw/misc/avr_power.h"
+#include "target/avr/cpu.h"
+
+#define TYPE_ATMEGA_MCU     "ATmega"
+#define TYPE_ATMEGA168_MCU  "ATmega168"
+#define TYPE_ATMEGA328_MCU  "ATmega328"
+#define TYPE_ATMEGA1280_MCU "ATmega1280"
+#define TYPE_ATMEGA2560_MCU "ATmega2560"
+
+#define ATMEGA_MCU(obj) OBJECT_CHECK(AtmegaMcuState, (obj), TYPE_ATMEGA_MCU)
+
+#define POWER_MAX 2
+#define USART_MAX 4
+#define TIMER_MAX 6
+#define GPIO_MAX 12
+
+typedef struct AtmegaMcuState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
+    AVRCPU cpu;
+    MemoryRegion flash;
+    MemoryRegion eeprom;
+    MemoryRegion sram;
+    DeviceState *io;
+    AVRMaskState pwr[POWER_MAX];
+    AVRUsartState usart[USART_MAX];
+    AVRTimer16State timer[TIMER_MAX];
+    uint64_t xtal_freq_hz;
+} AtmegaMcuState;
+
+#endif /* HW_AVR_ATMEGA_H */
--

2.7.4

#49 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Quoted 3 lines

Thanks,
Aleksandar

#50 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 87 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

Aleksandar

Quoted 3 lines
Quoted 3 lines

Thanks,
Aleksandar

#51 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 115 lines · Aleksandar Markovic
Quoted 87 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Quoted 9 lines

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

I didn't mean to scare you, I am just a developer like you, and I want to avoid thinking about licenses, and think of our real work, so, I gather, in my layman terms, it is better to have the same license for the new platform in its entirety, if possible, that is all. :)

Quoted 5 lines

Aleksandar

Quoted 3 lines
Quoted 3 lines

Thanks,
Aleksandar

#52 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 127 lines · Aleksandar Markovic
Quoted 115 lines · Aleksandar Markovic
Quoted 87 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Quoted 9 lines

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

Quoted 4 lines

I didn't mean to scare you, I am just a developer like you, and I want to avoid thinking about licenses, and think of our real work, so, I gather, in my layman terms, it is better to have the same license for the new platform in its entirety, if possible, that is all. :)

This is all part of QEMU, and QEMU is licensed under the GPLv2. If someone wants to use a less strict license for their own code that is still compatible with the GPLv2, like the LGPLv2.1, that's fine. But I think if Philippe does not like to release his code under the LGPL, and wants to use GPL instead, you can not force him to use LGPL here. It's the decision of Philippe what he wants to use for his code.

Thomas

#53 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 134 lines · Thomas Huth
Quoted 127 lines · Aleksandar Markovic
Quoted 115 lines · Aleksandar Markovic
Quoted 87 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Quoted 9 lines

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

Quoted 4 lines

I didn't mean to scare you, I am just a developer like you, and I want to avoid thinking about licenses, and think of our real work, so, I gather, in my layman terms, it is better to have the same license for the new platform in its entirety, if possible, that is all. :)

Quoted 7 lines

This is all part of QEMU, and QEMU is licensed under the GPLv2. If someone wants to use a less strict license for their own code that is still compatible with the GPLv2, like the LGPLv2.1, that's fine. But I think if Philippe does not like to release his code under the LGPL, and wants to use GPL instead, you can not force him to use LGPL here. It's the decision of Philippe what he wants to use for his code.

It is his decision, but it can be reasonable or not so reasonable. I think it is logical that he follows the license model of the module he contributes to, isn't it?

Aleksandar

Quoted 2 lines

Thomas

#54 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 84 lines · Aleksandar Markovic
Quoted 83 lines · Thomas Huth
Quoted 82 lines · Aleksandar Markovic
Quoted 80 lines · Aleksandar Markovic
Quoted 78 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

Note I'm not worried about my authorship but than other contributors being able to reuse and modify this code.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 4 lines

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

I don't use QEMU as a library, it is my main application. I tried to make this file clean/easy to read so it can be reused by other archs when implementing boards able to use multiple SoCs, this is not AVR-only.

I see LGPLv2.1 is deprecated for version 3, why use 2.1?

https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html

```
You can use it too, but we suggest you first think carefully about
whether this license or the ordinary General Public License is the
better strategy to use in any particular case, based on the
explanations below.
...
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
```

Personally I don't care about non-free programs using QEMU as a library, and I don't think a such program would use the default QEMU config anyway.

You can build the AVR (tcg) cpus without GPLv2+ hardware with this patch:

---

default-configs/avr-softmmu.mak +1 -1
@@ -2,4 +2,4 @@
 
 # Boards:
 #
-CONFIG_ARDUINO=y
+CONFIG_ARDUINO=n

---

But I doubt you can build QEMU without GPLv2+ components.

See also:
https://www.gnu.org/licenses/why-not-lgpl.html

```
Which license is best for a given library is a matter of strategy ...
Using the ordinary GPL for a library gives free software developers an
advantage over proprietary developers: a library that they can use,
while proprietary developers cannot use it ... When a free library's
features are readily available for proprietary software through other
alternative libraries ... the library cannot give free software any
particular advantage, so it is better to use the Lesser GPL for that
library.
```
Quoted 21 lines
Quoted 5 lines
Quoted 4 lines

I didn't mean to scare you, I am just a developer like you, and I want to avoid thinking about licenses, and think of our real work, so, I gather, in my layman terms, it is better to have the same license for the new platform in its entirety, if possible, that is all. :)

Quoted 7 lines

This is all part of QEMU, and QEMU is licensed under the GPLv2. If someone wants to use a less strict license for their own code that is still compatible with the GPLv2, like the LGPLv2.1, that's fine. But I think if Philippe does not like to release his code under the LGPL, and wants to use GPL instead, you can not force him to use LGPL here. It's the decision of Philippe what he wants to use for his code.

It is his decision, but it can be reasonable or not so reasonable. I think it is logical that he follows the license model of the module he contributes to, isn't it?

Aleksandar

Quoted 2 lines

Thomas

#55 lore raw

Re: [PATCH rc4 24/29] hw/avr: Add some ATmega microcontrollers

Quoted 180 lines · Philippe Mathieu-Daudé
Quoted 84 lines · Aleksandar Markovic
Quoted 83 lines · Thomas Huth
Quoted 82 lines · Aleksandar Markovic
Quoted 80 lines · Aleksandar Markovic
Quoted 78 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Cc'ing Thomas & Daniel who are not lawyers but tried to explain me few times how licensing works.

Quoted 70 lines · Aleksandar Markovic
Quoted 56 lines · Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Add some AVR microcontrollers from the ATmega family:

- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560

For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560

Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 hw/avr/Kconfig       |   5 +
 hw/avr/Makefile.objs |   1 +
 hw/avr/atmega.c      | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/avr/atmega.h      |  48 ++++++
 4 files changed, 524 insertions(+)
 create mode 100644 hw/avr/Kconfig
 create mode 100644 hw/avr/atmega.c
 create mode 100644 hw/avr/atmega.h
hw/avr/Kconfig new file +5 -0
new file mode 100644
index 0000000..9e6527e
@@ -0,0 +1,5 @@
+config AVR_ATMEGA_MCU
+    bool
+    select AVR_TIMER16
+    select AVR_USART
+    select AVR_POWER
hw/avr/Makefile.objs +1 -0
index 123f174..af0fdde 100644
@@ -1 +1,2 @@
 obj-y += boot.o
+obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
hw/avr/atmega.c new file +0 -0
new file mode 100644
index 0000000..8cdf28b

hw/avr/atmega.c line 9

Quoted 9 lines
hw/avr/atmega.c new file +9 -0
@@ -0,0 +1,470 @@
+/*
+ * QEMU ATmega MCU
+ *
+ * Copyright (c) 2019 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */

Philippe,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Michael and I already agreed at some moment that the whole target AVR should have harmonized licenses, and Sarrah agreed to change her license to achieve this. Do you agree to harmonize your licenses with the rest of the project? (This would mean changing the preable, but of course you remain copyright carrier as is now.)

Note I'm not worried about my authorship but than other contributors being able to reuse and modify this code.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 4 lines

What license do you want to use? I always use "GPLv2 or later" with QEMU, mostly following what the others do.

Quoted 8 lines

Per https://wiki.qemu.org/License:

Source files with no licensing information are released under the
GNU General Public License, version 2 or (at your option) any later version.

Reading about licensing is not fun :(

Philippe, here is the deal: All new files for AVR platform has the following preamble, that Michael chose from the outset:

+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Now, it is preferable that licenses are harmonized within a module, and I ask you to change the preamble to be the same as the rest of the module, that is all. This practically means LGPL2.1+later instead LGPL2.0+later. I think it is reasonable that we want to simplify out license stuff, not complicate it with different licenses within a module. There are examples of complications in cases of different license within the same module, so it would be ideal if we avoid such situations.

I don't use QEMU as a library, it is my main application. I tried to make this file clean/easy to read so it can be reused by other archs when implementing boards able to use multiple SoCs, this is not AVR-only.

I see LGPLv2.1 is deprecated for version 3, why use 2.1?

https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html

```
You can use it too, but we suggest you first think carefully about
whether this license or the ordinary General Public License is the
better strategy to use in any particular case, based on the
explanations below.
...
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
```

Personally I don't care about non-free programs using QEMU as a library, and I don't think a such program would use the default QEMU config anyway.

You can build the AVR (tcg) cpus without GPLv2+ hardware with this patch:

---

default-configs/avr-softmmu.mak +1 -2
@@ -2,4 +2,4 @@
 
 # Boards:
 #
-CONFIG_ARDUINO=y
+CONFIG_ARDUINO=n
---

But I doubt you can build QEMU without GPLv2+ components.

See also:
https://www.gnu.org/licenses/why-not-lgpl.html

Quoted 11 lines
```
Which license is best for a given library is a matter of strategy ...
Using the ordinary GPL for a library gives free software developers an
advantage over proprietary developers: a library that they can use,
while proprietary developers cannot use it ... When a free library's
features are readily available for proprietary software through other
alternative libraries ... the library cannot give free software any
particular advantage, so it is better to use the Lesser GPL for that
library.
```

Philippe,

You are just overly complicating the license stuff.

The original and main AVR contributor chose LGPL2.1+later, which is compatible with QEMU. For that reason alone, I think anyone contributing to this target in a substantial way should respect that and continue using that license. I am just politely asking you, for the sake of simplicity and common sense, to harmonize your contributions. That is all.

Thanks,
Aleksandar

Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 4 lines

I didn't mean to scare you, I am just a developer like you, and I want to avoid thinking about licenses, and think of our real work, so, I gather, in my layman terms, it is better to have the same license for the new platform in its entirety, if possible, that is all. :)

Quoted 7 lines

This is all part of QEMU, and QEMU is licensed under the GPLv2. If someone wants to use a less strict license for their own code that is still compatible with the GPLv2, like the LGPLv2.1, that's fine. But I think if Philippe does not like to release his code under the LGPL, and wants to use GPL instead, you can not force him to use LGPL here. It's the decision of Philippe what he wants to use for his code.

It is his decision, but it can be reasonable or not so reasonable. I think it is logical that he follows the license model of the module he contributes to, isn't it?

Aleksandar

Quoted 2 lines

Thomas

#56 lore raw

PATCH 25/29 hw/avr: Add some Arduino boards

In reply to Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

Arduino boards are build with AVR chipsets.
Add some of the popular boards:

- Arduino Duemilanove
- Arduino Uno
- Arduino Mega

For more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popular

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 MAINTAINERS          |   7 +++
 hw/avr/Kconfig       |   4 ++
 hw/avr/Makefile.objs |   1 +
 hw/avr/arduino.c     | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 163 insertions(+)
 create mode 100644 hw/avr/arduino.c
MAINTAINERS +7 -0
index d0a114b..97c8ef7 100644
@@ -905,6 +905,13 @@ F: include/hw/timer/avr_timer16.h
 F: hw/misc/avr_power.c
 F: include/hw/misc/avr_power.h
 F: tests/acceptance/machine_avr6.py
+F: hw/avr/atmega.*
+
+Arduino
+M: Philippe Mathieu-Daudé <[email protected]>
+R: Sarah Harris <[email protected]>
+S: Maintained
+F: hw/avr/arduino.c
 
 CRIS Machines
 -------------
hw/avr/Kconfig +4 -0
index 9e6527e..d31298c 100644
@@ -3,3 +3,7 @@ config AVR_ATMEGA_MCU
     select AVR_TIMER16
     select AVR_USART
     select AVR_POWER
+
+config ARDUINO
+    select AVR_ATMEGA_MCU
+    select UNIMP
hw/avr/Makefile.objs +1 -0
index af0fdde..4dca064 100644
@@ -1,2 +1,3 @@
 obj-y += boot.o
 obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
+obj-$(CONFIG_ARDUINO) += arduino.o
hw/avr/arduino.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
2.7.4
#57 lore raw

PATCH 26/29 target/avr: Update build system

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Make AVR support buildable.

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 configure                       |  7 +++++++
 default-configs/avr-softmmu.mak |  5 +++++
 target/avr/Makefile.objs        | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 target/avr/Makefile.objs
configure +7 -0
index a72a5de..51f0b9e 100755
@@ -7640,6 +7640,10 @@ case "$target_name" in
     mttcg="yes"
     gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
   ;;
+  avr)
+    gdb_xml_files="avr-cpu.xml"
+    target_compiler=$cross_cc_avr
+  ;;
   cris)
   ;;
   hppa)
@@ -7859,6 +7863,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
       disas_config "ARM_A64"
     fi
   ;;
+  avr)
+    disas_config "AVR"
+  ;;
   cris)
     disas_config "CRIS"
   ;;
default-configs/avr-softmmu.mak new file +5 -0
new file mode 100644
index 0000000..80218ad
@@ -0,0 +1,5 @@
+# Default configuration for avr-softmmu
+
+# Boards:
+#
+CONFIG_ARDUINO=y
target/avr/Makefile.objs new file +34 -0
new file mode 100644
index 0000000..7523e0c
@@ -0,0 +1,34 @@
+#
+#  QEMU AVR CPU
+#
+#  Copyright (c) 2019 Michael Rolnik
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, see
+#  <http://www.gnu.org/licenses/lgpl-2.1.html>
+#
+
+DECODETREE = $(SRC_PATH)/scripts/decodetree.py
+decode-y = $(SRC_PATH)/target/avr/insn.decode
+
+target/avr/decode_insn.inc.c: $(decode-y) $(DECODETREE)
+	$(call quiet-command, \
+	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn --insnwidth 16 $<, \
+	  "GEN", $(TARGET_DIR)$@)
+
+target/avr/translate.o: target/avr/decode_insn.inc.c
+
+obj-y += translate.o cpu.o helper.o
+obj-y += gdbstub.o
+obj-y += disas.o
+obj-$(CONFIG_SOFTMMU) += machine.o
Signature · 1 line
2.7.4
#58 lore raw

Re: [PATCH rc4 26/29] target/avr: Update build system

Quoted 91 lines · Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Make AVR support buildable.

[AM: Remove word 'Atmel' from filenames and all elements of code]
---
 configure                       |  7 +++++++
 default-configs/avr-softmmu.mak |  5 +++++
 target/avr/Makefile.objs        | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 target/avr/Makefile.objs
configure +0 -0
index a72a5de..51f0b9e 100755
@@ -7640,6 +7640,10 @@ case "$target_name" in
     mttcg="yes"
     gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml

arm-vfp.xml arm-vfp3.xml arm-neon.xml"
;;

configure +7 -0
+  avr)
+    gdb_xml_files="avr-cpu.xml"
+    target_compiler=$cross_cc_avr
+  ;;
   cris)
   ;;
   hppa)
@@ -7859,6 +7863,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
       disas_config "ARM_A64"
     fi
   ;;
+  avr)
+    disas_config "AVR"
+  ;;
   cris)
     disas_config "CRIS"
   ;;
default-configs/avr-softmmu.mak new file +5 -0
new file mode 100644
index 0000000..80218ad
@@ -0,0 +1,5 @@
+# Default configuration for avr-softmmu
+
+# Boards:
+#
+CONFIG_ARDUINO=y
target/avr/Makefile.objs new file +26 -0
new file mode 100644
index 0000000..7523e0c
@@ -0,0 +1,34 @@
+#
+#  QEMU AVR CPU
+#
+#  Copyright (c) 2019 Michael Rolnik
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, see
+#  <http://www.gnu.org/licenses/lgpl-2.1.html>
+#
+
+DECODETREE = $(SRC_PATH)/scripts/decodetree.py
+decode-y = $(SRC_PATH)/target/avr/insn.decode
+
+target/avr/decode_insn.inc.c: $(decode-y) $(DECODETREE)
+       $(call quiet-command, \
+         $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn --insnwidth

16 $<, \

target/avr/Makefile.objs line 34

Quoted 8 lines
target/avr/Makefile.objs new file +8 -0
+         "GEN", $(TARGET_DIR)$@)
+
+target/avr/translate.o: target/avr/decode_insn.inc.c
+
+obj-y += translate.o cpu.o helper.o
+obj-y += gdbstub.o
+obj-y += disas.o
+obj-$(CONFIG_SOFTMMU) += machine.o

The last line should not contain "-$(CONFIG_SOFTMMU)", since there is only softmmu case for avr. I will remove it in rc5, unless somebody tell me not to do so.

Aleksandar

Quoted 4 lines

--
2.7.4

#59 lore raw

PATCH 27/29 tests/boot-serial-test: Test some Arduino boards (AVR based)

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

Print out 'T' through serial port

The Arduino Duemilanove is based on a AVR5 CPU, while the Arduino MEGA2560 on a AVR6 CPU.

---
 tests/qtest/Makefile.include   |  2 ++
 tests/qtest/boot-serial-test.c | 11 +++++++++++
 2 files changed, 13 insertions(+)
tests/qtest/Makefile.include +2 -0
index e6bb4ab..4817b63 100644
@@ -65,6 +65,8 @@ check-qtest-i386-y += numa-test
 
 check-qtest-x86_64-y += $(check-qtest-i386-y)
 
+check-qtest-avr-y += boot-serial-test
+
 check-qtest-alpha-y += boot-serial-test
 check-qtest-alpha-$(CONFIG_VGA) += display-vga-test
 
tests/qtest/boot-serial-test.c +11 -0
index 8e8c5b0..55a37a4 100644
@@ -16,6 +16,15 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 
+static const uint8_t bios_avr[] = {
+    0x88, 0xe0,             /* ldi r24, 0x08   */
+    0x80, 0x93, 0xc1, 0x00, /* sts 0x00C1, r24 ; Enable tx */
+    0x86, 0xe0,             /* ldi r24, 0x06   */
+    0x80, 0x93, 0xc2, 0x00, /* sts 0x00C2, r24 ; Set the data bits to 8 */
+    0x84, 0xe5,             /* ldi r24, 0x54   */
+    0x80, 0x93, 0xc6, 0x00, /* sts 0x00C6, r24 ; Output 'T' */
+};
+
 static const uint8_t kernel_mcf5208[] = {
     0x41, 0xf9, 0xfc, 0x06, 0x00, 0x00,     /* lea 0xfc060000,%a0 */
     0x10, 0x3c, 0x00, 0x54,                 /* move.b #'T',%d0 */
@@ -103,6 +112,8 @@ typedef struct testdef {
 
 static testdef_t tests[] = {
     { "alpha", "clipper", "", "PCI:" },
+    { "avr", "arduino-duemilanove", "", "T", sizeof(bios_avr), NULL, bios_avr },
+    { "avr", "arduino-mega-2560-v3", "", "T", sizeof(bios_avr), NULL, bios_avr},
     { "ppc", "ppce500", "", "U-Boot" },
     { "ppc", "40p", "-vga none -boot d", "Trying cd:," },
     { "ppc", "g3beige", "", "PowerPC,750" },
Signature · 1 line
2.7.4
#60 lore raw

PATCH 28/29 tests/acceptance: Test the Arduino MEGA2560 board

In reply to Aleksandar Markovic

From: Michael Rolnik <[email protected]>

The test is based on
https://github.com/seharris/qemu-avr-tests/tree/master/free-rtos/Demo
demo which. If working correctly, prints 'ABCDEFGHIJKLMNOPQRSTUVWX' out. it also demostrates that timer and IRQ are working

As the path name demonstrates, the FreeRTOS tests target a board based on a ATMega2560 MCU. We have one, the Arduino MEGA2560.

Complementary documentation:

https://feilipu.me/2012/01/15/ethermega-arduino-mega-2560-and-freertos/
https://feilipu.me/2015/11/24/arduino_freertos/ (see 'Compatibility')

---
 tests/acceptance/machine_avr6.py | 50 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 tests/acceptance/machine_avr6.py
tests/acceptance/machine_avr6.py new file +50 -0
new file mode 100644
index 0000000..b644d2a
@@ -0,0 +1,50 @@
+#
+# QEMU AVR
+#
+# Copyright (c) 2019 Michael Rolnik <[email protected]>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import time
+
+from avocado_qemu import Test
+
+class AVR6Machine(Test):
+    timeout = 5
+
+    def test_freertos(self):
+        """
+        :avocado: tags=arch:avr
+        :avocado: tags=machine:arduino-mega-2560-v3
+        """
+        """
+        https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf
+        constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX'
+        """
+        rom_url = ('https://github.com/seharris/qemu-avr-tests'
+                   '/raw/36c3e67b8755dcf/free-rtos/Demo'
+                   '/AVR_ATMega2560_GCC/demo.elf')
+        rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4'
+        rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
+
+        self.vm.add_args('-bios', rom_path)
+        self.vm.add_args('-nographic')
+        self.vm.launch()
+
+        time.sleep(2)
+        self.vm.shutdown()
+
+        self.assertIn('ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX',
+                self.vm.get_log())
Signature · 1 line
2.7.4
#61 lore raw

PATCH 29/29 .travis.yml: Run the AVR acceptance tests

In reply to Aleksandar Markovic

From: Philippe Mathieu-Daudé <[email protected]>

We have one test so far, and it is very fast:

  $ avocado --show=app run -t arch:avr tests/acceptance/
  (1/1) tests/acceptance/machine_avr6.py:AVR6Machine.test_freertos: PASS (2.13 s)
  RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 2.30 s
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
index 1ae645e..71390e2 100644
@@ -268,7 +268,7 @@ matrix:
 
     # Acceptance (Functional) tests
     - env:
-        - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc-softmmu,ppc64-softmmu,m68k-softmmu,sparc-softmmu"
+        - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc-softmmu,ppc64-softmmu,m68k-softmmu,sparc-softmmu,avr-softmmu"
         - TEST_CMD="make check-acceptance"
       after_script:
         - python3 -c 'import json; r = json.load(open("tests/results/latest/results.json")); [print(t["logfile"]) for t in r["tests"] if t["status"] not in ("PASS", "SKIP")]' | xargs cat
Signature · 1 line
2.7.4
#62 lore raw

cover !fixup target/avr merger-rc4

In reply to Aleksandar Markovic

Aleksandar, I addressed Alex Bennée comment as fixup, so you can squash directly. See:
https://www.mail-archive.com/[email protected]/msg673846.html

- convert DB_PRINT() to trace-events
- fix style/indentation

Based-on: <[email protected]>

Philippe Mathieu-Daudé (2):
!fixup "hw/misc: Add limited support for AVR power device" !fixup "hw/timer: Add limited support for AVR 16-bit timer peripheral"

 hw/misc/avr_power.c    | 17 +++++++++--------
 hw/timer/avr_timer16.c | 25 +++++++++++++++----------
 hw/misc/trace-events   |  4 ++++
 hw/timer/trace-events  | 12 ++++++++++++
 4 files changed, 40 insertions(+), 18 deletions(-)
Signature · 1 line
2.21.1