Skip to content

Commit d344983

Browse files
committed
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/avr-port-20200711' into staging
8bit AVR port from Michael Rolnik. Michael started to work on the AVR port few years ago [*] and kept improving the code over various series. List of people who help him (in chronological order): - Richard Henderson - Sarah Harris and Edward Robbins - Philippe Mathieu-Daudé and Aleksandar Markovic - Pavel Dovgalyuk - Thomas Huth [*] The oldest contribution I could find on the list is from 2016: https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg02985.html Tests included: $ avocado --show=app run -t arch:avr tests/acceptance/ Fetching asset from tests/acceptance/machine_avr6.py:AVR6Machine.test_freertos (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.35 s $ make check-qtest-avr TEST check-qtest-avr: tests/qtest/boot-serial-test TEST check-qtest-avr: tests/qtest/cdrom-test TEST check-qtest-avr: tests/qtest/device-introspect-test TEST check-qtest-avr: tests/qtest/machine-none-test TEST check-qtest-avr: tests/qtest/qmp-test TEST check-qtest-avr: tests/qtest/qmp-cmd-test TEST check-qtest-avr: tests/qtest/qom-test TEST check-qtest-avr: tests/qtest/test-hmp TEST check-qtest-avr: tests/qtest/qos-test CI results: . https://cirrus-ci.com/build/5697049146425344 . https://gitlab.com/philmd/qemu/-/pipelines/165328058 . https://travis-ci.org/github/philmd/qemu/builds/705817933 . https://app.shippable.com/github/philmd/qemu/runs/822/summary/console # gpg: Signature made Sat 11 Jul 2020 10:03:11 BST # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <[email protected]>" [full] # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * remotes/philmd-gitlab/tags/avr-port-20200711: (32 commits) target/avr/disas: Fix store instructions display order target/avr/cpu: Fix $PC displayed address target/avr/cpu: Drop tlb_flush() in avr_cpu_reset() target/avr: Add section into QEMU documentation tests/acceptance: Test the Arduino MEGA2560 board tests/boot-serial: Test some Arduino boards (AVR based) hw/avr: Add limited support for some Arduino boards hw/avr: Add some ATmega microcontrollers hw/avr: Add support for loading ELF/raw binaries hw/misc: avr: Add limited support for power reduction device hw/timer: avr: Add limited support for 16-bit timer peripheral hw/char: avr: Add limited support for USART peripheral tests/machine-none: Add AVR support target/avr: Register AVR support with the rest of QEMU target/avr: Add support for disassembling via option '-d in_asm' target/avr: Initialize TCG register variables target/avr: Add instruction translation - CPU main translation function target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - Bit and Bit-test Instructions target/avr: Add instruction translation - Data Transfer Instructions ... Signed-off-by: Peter Maydell <[email protected]>
2 parents 2033cc6 + 19b2934 commit d344983

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7172
-1
lines changed

MAINTAINERS

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ S: Maintained
167167
F: hw/arm/smmu*
168168
F: include/hw/arm/smmu*
169169

170+
AVR TCG CPUs
171+
M: Michael Rolnik <[email protected]>
172+
R: Sarah Harris <[email protected]>
173+
S: Maintained
174+
F: gdb-xml/avr-cpu.xml
175+
F: target/avr/
176+
F: tests/acceptance/machine_avr6.py
177+
170178
CRIS TCG CPUs
171179
M: Edgar E. Iglesias <[email protected]>
172180
S: Maintained
@@ -982,6 +990,28 @@ F: include/hw/*/nrf51*.h
982990
F: include/hw/*/microbit*.h
983991
F: tests/qtest/microbit-test.c
984992

993+
AVR Machines
994+
-------------
995+
996+
AVR MCUs
997+
M: Michael Rolnik <[email protected]>
998+
R: Sarah Harris <[email protected]>
999+
S: Maintained
1000+
F: default-configs/avr-softmmu.mak
1001+
F: hw/avr/
1002+
F: include/hw/char/avr_usart.h
1003+
F: hw/char/avr_usart.c
1004+
F: include/hw/timer/avr_timer16.h
1005+
F: hw/timer/avr_timer16.c
1006+
F: include/hw/misc/avr_power.h
1007+
F: hw/misc/avr_power.c
1008+
1009+
Arduino
1010+
M: Philippe Mathieu-Daudé <[email protected]>
1011+
R: Sarah Harris <[email protected]>
1012+
S: Maintained
1013+
F: hw/avr/arduino.c
1014+
9851015
CRIS Machines
9861016
-------------
9871017
Axis Dev88

configure

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8143,6 +8143,10 @@ case "$target_name" in
81438143
mttcg="yes"
81448144
gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml arm-m-profile.xml"
81458145
;;
8146+
avr)
8147+
gdb_xml_files="avr-cpu.xml"
8148+
target_compiler=$cross_cc_avr
8149+
;;
81468150
cris)
81478151
;;
81488152
hppa)
@@ -8387,6 +8391,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
83878391
disas_config "ARM_A64"
83888392
fi
83898393
;;
8394+
avr)
8395+
disas_config "AVR"
8396+
;;
83908397
cris)
83918398
disas_config "CRIS"
83928399
;;

default-configs/avr-softmmu.mak

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Default configuration for avr-softmmu
2+
3+
# Boards:
4+
#
5+
CONFIG_ARDUINO=y

docs/system/target-avr.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _AVR-System-emulator:
2+
3+
AVR System emulator
4+
-------------------
5+
6+
Use the executable ``qemu-system-avr`` to emulate a AVR 8 bit based machine.
7+
These can have one of the following cores: avr1, avr2, avr25, avr3, avr31,
8+
avr35, avr4, avr5, avr51, avr6, avrtiny, xmega2, xmega3, xmega4, xmega5,
9+
xmega6 and xmega7.
10+
11+
As for now it supports few Arduino boards for educational and testing purposes.
12+
These boards use a ATmega controller, which model is limited to USART & 16-bit
13+
timer devices, enought to run FreeRTOS based applications (like
14+
https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf
15+
).
16+
17+
Following are examples of possible usages, assuming demo.elf is compiled for
18+
AVR cpu
19+
20+
- Continuous non interrupted execution:
21+
``qemu-system-avr -machine mega2560 -bios demo.elf``
22+
23+
- Continuous non interrupted execution with serial output into telnet window:
24+
``qemu-system-avr -machine mega2560 -bios demo.elf -serial
25+
tcp::5678,server,nowait -nographic``
26+
and then in another shell
27+
``telnet localhost 5678``
28+
29+
- Debugging wit GDB debugger:
30+
``qemu-system-avr -machine mega2560 -bios demo.elf -s -S``
31+
and then in another shell
32+
``avr-gdb demo.elf``
33+
and then within GDB shell
34+
``target remote :1234``
35+
36+
- Print out executed instructions:
37+
``qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm``

docs/system/targets.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Contents:
1919
target-xtensa
2020
target-s390x
2121
target-rx
22+
target-avr

gdb-xml/avr-cpu.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2018-2019 Free Software Foundation, Inc.
3+
4+
Copying and distribution of this file, with or without modification,
5+
are permitted in any medium without royalty provided the copyright
6+
notice and this notice are preserved. -->
7+
8+
<!-- Register numbers are hard-coded in order to maintain backward
9+
compatibility with older versions of tools that didn't use xml
10+
register descriptions. -->
11+
12+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
13+
<feature name="org.gnu.gdb.riscv.cpu">
14+
<reg name="r0" bitsize="8" type="int" regnum="0"/>
15+
<reg name="r1" bitsize="8" type="int"/>
16+
<reg name="r2" bitsize="8" type="int"/>
17+
<reg name="r3" bitsize="8" type="int"/>
18+
<reg name="r4" bitsize="8" type="int"/>
19+
<reg name="r5" bitsize="8" type="int"/>
20+
<reg name="r6" bitsize="8" type="int"/>
21+
<reg name="r7" bitsize="8" type="int"/>
22+
<reg name="r8" bitsize="8" type="int"/>
23+
<reg name="r9" bitsize="8" type="int"/>
24+
<reg name="r10" bitsize="8" type="int"/>
25+
<reg name="r11" bitsize="8" type="int"/>
26+
<reg name="r12" bitsize="8" type="int"/>
27+
<reg name="r13" bitsize="8" type="int"/>
28+
<reg name="r14" bitsize="8" type="int"/>
29+
<reg name="r15" bitsize="8" type="int"/>
30+
<reg name="r16" bitsize="8" type="int"/>
31+
<reg name="r17" bitsize="8" type="int"/>
32+
<reg name="r18" bitsize="8" type="int"/>
33+
<reg name="r19" bitsize="8" type="int"/>
34+
<reg name="r20" bitsize="8" type="int"/>
35+
<reg name="r21" bitsize="8" type="int"/>
36+
<reg name="r22" bitsize="8" type="int"/>
37+
<reg name="r23" bitsize="8" type="int"/>
38+
<reg name="r24" bitsize="8" type="int"/>
39+
<reg name="r25" bitsize="8" type="int"/>
40+
<reg name="r26" bitsize="8" type="int"/>
41+
<reg name="r27" bitsize="8" type="int"/>
42+
<reg name="r28" bitsize="8" type="int"/>
43+
<reg name="r29" bitsize="8" type="int"/>
44+
<reg name="r30" bitsize="8" type="int"/>
45+
<reg name="r31" bitsize="8" type="int"/>
46+
<reg name="sreg" bitsize="8" type="int"/>
47+
<reg name="sp" bitsize="8" type="int"/>
48+
<reg name="pc" bitsize="8" type="int"/>
49+
</feature>

hw/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ source watchdog/Kconfig
4343
# arch Kconfig
4444
source arm/Kconfig
4545
source alpha/Kconfig
46+
source avr/Kconfig
4647
source cris/Kconfig
4748
source hppa/Kconfig
4849
source i386/Kconfig

hw/avr/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
config AVR_ATMEGA_MCU
2+
bool
3+
select AVR_TIMER16
4+
select AVR_USART
5+
select AVR_POWER
6+
7+
config ARDUINO
8+
select AVR_ATMEGA_MCU
9+
select UNIMP

hw/avr/Makefile.objs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
obj-y += boot.o
2+
obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
3+
obj-$(CONFIG_ARDUINO) += arduino.o

hw/avr/arduino.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* QEMU Arduino boards
3+
*
4+
* Copyright (c) 2019-2020 Philippe Mathieu-Daudé
5+
*
6+
* This work is licensed under the terms of the GNU GPLv2 or later.
7+
* See the COPYING file in the top-level directory.
8+
* SPDX-License-Identifier: GPL-2.0-or-later
9+
*/
10+
11+
/* TODO: Implement the use of EXTRAM */
12+
13+
#include "qemu/osdep.h"
14+
#include "qapi/error.h"
15+
#include "hw/boards.h"
16+
#include "atmega.h"
17+
#include "boot.h"
18+
19+
typedef struct ArduinoMachineState {
20+
/*< private >*/
21+
MachineState parent_obj;
22+
/*< public >*/
23+
AtmegaMcuState mcu;
24+
} ArduinoMachineState;
25+
26+
typedef struct ArduinoMachineClass {
27+
/*< private >*/
28+
MachineClass parent_class;
29+
/*< public >*/
30+
const char *mcu_type;
31+
uint64_t xtal_hz;
32+
} ArduinoMachineClass;
33+
34+
#define TYPE_ARDUINO_MACHINE \
35+
MACHINE_TYPE_NAME("arduino")
36+
#define ARDUINO_MACHINE(obj) \
37+
OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE)
38+
#define ARDUINO_MACHINE_CLASS(klass) \
39+
OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE)
40+
#define ARDUINO_MACHINE_GET_CLASS(obj) \
41+
OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE)
42+
43+
static void arduino_machine_init(MachineState *machine)
44+
{
45+
ArduinoMachineClass *amc = ARDUINO_MACHINE_GET_CLASS(machine);
46+
ArduinoMachineState *ams = ARDUINO_MACHINE(machine);
47+
48+
object_initialize_child(OBJECT(machine), "mcu", &ams->mcu, amc->mcu_type);
49+
object_property_set_uint(OBJECT(&ams->mcu), "xtal-frequency-hz",
50+
amc->xtal_hz, &error_abort);
51+
sysbus_realize(SYS_BUS_DEVICE(&ams->mcu), &error_abort);
52+
53+
if (machine->firmware) {
54+
if (!avr_load_firmware(&ams->mcu.cpu, machine,
55+
&ams->mcu.flash, machine->firmware)) {
56+
exit(1);
57+
}
58+
}
59+
}
60+
61+
static void arduino_machine_class_init(ObjectClass *oc, void *data)
62+
{
63+
MachineClass *mc = MACHINE_CLASS(oc);
64+
65+
mc->init = arduino_machine_init;
66+
mc->default_cpus = 1;
67+
mc->min_cpus = mc->default_cpus;
68+
mc->max_cpus = mc->default_cpus;
69+
mc->no_floppy = 1;
70+
mc->no_cdrom = 1;
71+
mc->no_parallel = 1;
72+
}
73+
74+
static void arduino_duemilanove_class_init(ObjectClass *oc, void *data)
75+
{
76+
MachineClass *mc = MACHINE_CLASS(oc);
77+
ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
78+
79+
/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */
80+
mc->desc = "Arduino Duemilanove (ATmega168)",
81+
mc->alias = "2009";
82+
amc->mcu_type = TYPE_ATMEGA168_MCU;
83+
amc->xtal_hz = 16 * 1000 * 1000;
84+
};
85+
86+
static void arduino_uno_class_init(ObjectClass *oc, void *data)
87+
{
88+
MachineClass *mc = MACHINE_CLASS(oc);
89+
ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
90+
91+
/* https://store.arduino.cc/arduino-uno-rev3 */
92+
mc->desc = "Arduino UNO (ATmega328P)";
93+
mc->alias = "uno";
94+
amc->mcu_type = TYPE_ATMEGA328_MCU;
95+
amc->xtal_hz = 16 * 1000 * 1000;
96+
};
97+
98+
static void arduino_mega_class_init(ObjectClass *oc, void *data)
99+
{
100+
MachineClass *mc = MACHINE_CLASS(oc);
101+
ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
102+
103+
/* https://www.arduino.cc/en/Main/ArduinoBoardMega */
104+
mc->desc = "Arduino Mega (ATmega1280)";
105+
mc->alias = "mega";
106+
amc->mcu_type = TYPE_ATMEGA1280_MCU;
107+
amc->xtal_hz = 16 * 1000 * 1000;
108+
};
109+
110+
static void arduino_mega2560_class_init(ObjectClass *oc, void *data)
111+
{
112+
MachineClass *mc = MACHINE_CLASS(oc);
113+
ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
114+
115+
/* https://store.arduino.cc/arduino-mega-2560-rev3 */
116+
mc->desc = "Arduino Mega 2560 (ATmega2560)";
117+
mc->alias = "mega2560";
118+
amc->mcu_type = TYPE_ATMEGA2560_MCU;
119+
amc->xtal_hz = 16 * 1000 * 1000; /* CSTCE16M0V53-R0 */
120+
};
121+
122+
static const TypeInfo arduino_machine_types[] = {
123+
{
124+
.name = MACHINE_TYPE_NAME("arduino-duemilanove"),
125+
.parent = TYPE_ARDUINO_MACHINE,
126+
.class_init = arduino_duemilanove_class_init,
127+
}, {
128+
.name = MACHINE_TYPE_NAME("arduino-uno"),
129+
.parent = TYPE_ARDUINO_MACHINE,
130+
.class_init = arduino_uno_class_init,
131+
}, {
132+
.name = MACHINE_TYPE_NAME("arduino-mega"),
133+
.parent = TYPE_ARDUINO_MACHINE,
134+
.class_init = arduino_mega_class_init,
135+
}, {
136+
.name = MACHINE_TYPE_NAME("arduino-mega-2560-v3"),
137+
.parent = TYPE_ARDUINO_MACHINE,
138+
.class_init = arduino_mega2560_class_init,
139+
}, {
140+
.name = TYPE_ARDUINO_MACHINE,
141+
.parent = TYPE_MACHINE,
142+
.instance_size = sizeof(ArduinoMachineState),
143+
.class_size = sizeof(ArduinoMachineClass),
144+
.class_init = arduino_machine_class_init,
145+
.abstract = true,
146+
}
147+
};
148+
149+
DEFINE_TYPES(arduino_machine_types)

0 commit comments

Comments
 (0)