AVR port
Possible false-positives from checkpatch:
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
The following changes since commit 7623b5ba017f61de5d7c2bba12c6feb3d55091b1:
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.1-pull-=
request' into staging (2020-07-06 11:40:10 +0100)
are available in the Git repository at:
https://gitlab.com/philmd/qemu.git tags/avr-port-20200707
for you to fetch changes up to 0cdaf2f343491f60dbf7dd2a912cd88b5f9f899c:
target/avr/disas: Fix store instructions display order (2020-07-07 20:14:15=
+0200)
----------------------------------------------------------------
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=C3=A9 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=3Dapp 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 | CANC= EL 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/163985815
. https://travis-ci.org/github/philmd/qemu/builds/705817933
. https://app.shippable.com/github/philmd/qemu/runs/822/summary/console
----------------------------------------------------------------
Michael Rolnik (25):
target/avr: Add basic parameters of the new platform target/avr: Introduce basic CPU class object
target/avr: CPU class: Add interrupt handling support target/avr: CPU class: Add memory menagement support target/avr: CPU class: Add migration support
target/avr: CPU class: Add GDB support
target/avr: Introduce enumeration AVRFeature
target/avr: Add definitions 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: Initialize TCG register variables
target/avr: Add support for disassembling via option '-d in_asm' target/avr: Register AVR support with the rest of QEMU tests/machine-none: Add AVR support
hw/char: avr: Add limited support for USART peripheral hw/timer: avr: Add limited support for 16-bit timer peripheral hw/misc: avr: Add limited support for power reduction device tests/boot-serial: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board
Philippe Mathieu-Daud=C3=A9 (6):
hw/avr: Add support for loading ELF/raw binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add limited support for some Arduino boards target/avr/cpu: Drop tlb_flush() in avr_cpu_reset() target/avr/cpu: Fix $PC displayed address target/avr/disas: Fix store instructions display order
Thomas Huth (1):
target/avr: Add section into QEMU documentation
docs/system/target-avr.rst | 37 + docs/system/targets.rst | 1 + configure | 7 + default-configs/avr-softmmu.mak | 5 + qapi/machine.json | 3 +- hw/avr/atmega.h | 48 + hw/avr/boot.h | 33 + include/disas/dis-asm.h | 19 + include/elf.h | 4 + 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 + target/avr/cpu-param.h | 36 + target/avr/cpu-qom.h | 54 + target/avr/cpu.h | 256 +++ target/avr/helper.h | 29 + target/avr/insn.decode | 187 ++ arch_init.c | 2 + hw/avr/arduino.c | 149 ++ hw/avr/atmega.c | 458 +++++ hw/avr/boot.c | 115 ++ hw/char/avr_usart.c | 320 ++++ hw/misc/avr_power.c | 113 ++ hw/timer/avr_timer16.c | 621 ++++++ target/avr/cpu.c | 367 ++++ target/avr/disas.c | 246 +++ target/avr/gdbstub.c | 84 + target/avr/helper.c | 342 ++++ target/avr/machine.c | 121 ++ target/avr/translate.c | 3061 ++++++++++++++++++++++++++++++ tests/qtest/boot-serial-test.c | 11 + tests/qtest/machine-none-test.c | 1 + MAINTAINERS | 30 + gdb-xml/avr-cpu.xml | 49 + hw/Kconfig | 1 + hw/avr/Kconfig | 9 + hw/avr/Makefile.objs | 3 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/misc/trace-events | 4 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + hw/timer/trace-events | 12 + target/avr/Makefile.objs | 34 + tests/acceptance/machine_avr6.py | 50 + tests/qtest/Makefile.include | 2 + 49 files changed, 7171 insertions(+), 1 deletion(-) create mode 100644 docs/system/target-avr.rst create mode 100644 default-configs/avr-softmmu.mak create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/boot.h 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/cpu-param.h create mode 100644 target/avr/cpu-qom.h create mode 100644 target/avr/cpu.h create mode 100644 target/avr/helper.h create mode 100644 target/avr/insn.decode create mode 100644 hw/avr/arduino.c create mode 100644 hw/avr/atmega.c create mode 100644 hw/avr/boot.c 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 target/avr/cpu.c 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/machine.c create mode 100644 target/avr/translate.c create mode 100644 gdb-xml/avr-cpu.xml create mode 100644 hw/avr/Kconfig create mode 100644 hw/avr/Makefile.objs create mode 100644 target/avr/Makefile.objs create mode 100644 tests/acceptance/machine_avr6.py
--=20
2.21.3
[PULL 01/32] target/avr: Add basic parameters of the new platform
From: Michael Rolnik <[email protected]>
This includes definitions of various basic parameters needed for integration of a new platform into QEMU.
Message-Id: <[email protected]>
--- target/avr/cpu-param.h | 36 +++++++++++++++++++++++ target/avr/cpu.h | 66 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++++ 3 files changed, 108 insertions(+) create mode 100644 target/avr/cpu-param.h create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016-2020 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 +66 -0
66 lines not on this page · raw message
MAINTAINERS +6 -0
@@ -167,6 +167,12 @@ 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/ + CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained
Signature · 1 line
2.21.3
[PULL 02/32] target/avr: Introduce basic CPU class object
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This patch introduces AVR CPU class object and its basic elements and functions.
Message-Id: <[email protected]>
--- target/avr/cpu-qom.h | 54 +++++++++++ target/avr/cpu.h | 139 +++++++++++++++++++++++++++++ target/avr/cpu.c | 207 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 400 insertions(+) create mode 100644 target/avr/cpu-qom.h create mode 100644 target/avr/cpu.c
target/avr/cpu-qom.h new file +54 -0
@@ -0,0 +1,54 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016-2020 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; +DeviceReset parent_reset; +}AVRCPUClass ; + +typedef struct AVRCPU AVRCPU ; + + +#endif /* !defined (QEMU_AVR_CPU_QOM_H) */
target/avr/cpu.h +139 -0
151 lines not on this page · raw message
target/avr/cpu.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 05/32] target/avr: CPU class: Add migration support
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Add migration-related functions of AVR CPU class object.
Message-Id: <[email protected]>
--- target/avr/cpu.h | 2 + target/avr/cpu.c | 1 + target/avr/machine.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 target/avr/machine.c
target/avr/cpu.h +2 -0
@@ -118,6 +118,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/cpu.c +1 -0
@@ -206,6 +206,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->memory_rw_debug = avr_cpu_memory_rw_debug; cc->get_phys_page_debug = avr_cpu_get_phys_page_debug; cc->tlb_fill = avr_cpu_tlb_fill; + cc->vmsd = &vms_avr_cpu; cc->disas_set_info = avr_cpu_disas_set_info; cc->tcg_initialize = avr_cpu_tcg_init; cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
target/avr/machine.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 04/32] target/avr: CPU class: Add memory menagement support
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This patch introduces three memory-management-related functions that will become part of AVR CPU class object.
Message-Id: <[email protected]>
--- target/avr/cpu.c | 3 +++ target/avr/helper.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
target/avr/cpu.c +3 -0
@@ -203,6 +203,9 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->cpu_exec_interrupt = avr_cpu_exec_interrupt; cc->dump_state = avr_cpu_dump_state; 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->tlb_fill = avr_cpu_tlb_fill; cc->disas_set_info = avr_cpu_disas_set_info; cc->tcg_initialize = avr_cpu_tcg_init; cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
target/avr/helper.c +50 -0
53 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 06/32] target/avr: CPU class: Add GDB support
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This includes GDB hooks for reading from wnd wrtiting to AVR registers, and xml register definition file as well.
Message-Id: <[email protected]>
--- target/avr/cpu.h | 2 ++ target/avr/cpu.c | 4 +++ target/avr/gdbstub.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + gdb-xml/avr-cpu.xml | 49 ++++++++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 target/avr/gdbstub.c create mode 100644 gdb-xml/avr-cpu.xml
target/avr/cpu.h +2 -0
@@ -123,6 +123,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,GByteArray *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/cpu.c +4 -0
@@ -210,4 +210,8 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->disas_set_info = avr_cpu_disas_set_info; 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/gdbstub.c new file +84 -0
84 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -171,6 +171,7 @@ AVR TCG CPUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: gdb-xml/avr-cpu.xml F: target/avr/ CRIS TCG CPUs
gdb-xml/avr-cpu.xml new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 03/32] target/avr: CPU class: Add interrupt handling support
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This patch introduces functions avr_cpu_do_interrupt() and avr_cpu_exec_interrupt() that are part of AVR CPU class object.
Message-Id: <[email protected]>
--- target/avr/cpu.c | 2 + target/avr/helper.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 target/avr/helper.c
target/avr/cpu.c +2 -0
@@ -199,6 +199,8 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->class_by_name = avr_cpu_class_by_name; cc->has_work = avr_cpu_has_work; + cc->do_interrupt = avr_cpu_do_interrupt; + cc->cpu_exec_interrupt = avr_cpu_exec_interrupt; cc->dump_state = avr_cpu_dump_state; cc->set_pc = avr_cpu_set_pc; cc->disas_set_info = avr_cpu_disas_set_info;
target/avr/helper.c new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 12/32] target/avr: Add instruction translation - Branch Instructions
In reply to Philippe Mathieu-Daudé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
Message-Id: <[email protected]>
--- target/avr/insn.decode | 33 +++ target/avr/translate.c | 543 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 576 insertions(+)
target/avr/insn.decode +33 -0
@@ -74,3 +74,36 @@ 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 +# + +# 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 + +@op_bit .... .... . bit:3 .... +@op_bit_imm .... .. imm:s7 bit:3 + +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 +543 -0
552 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 08/32] target/avr: Add definitions of AVR core types
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
AVR core types are:
- avr5
- avr51
- avr6
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.
Message-Id: <[email protected]>
--- target/avr/cpu.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
target/avr/cpu.c +152 -0
@@ -215,3 +215,155 @@ 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 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 ); +} + +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 ("avr5" , avr_avr5_initfn), +DEFINE_AVR_CPU_TYPE ("avr51" , avr_avr51_initfn), +DEFINE_AVR_CPU_TYPE ("avr6" , avr_avr6_initfn), +}; + + +DEFINE_TYPES (avr_cpu_type_info)
Signature · 1 line
2.21.3
[PULL 07/32] target/avr: Introduce enumeration AVRFeature
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This patch introduces enumeration "AVRFeature" that will be used for defining various AVR core types.
Message-Id: <[email protected]>
--- target/avr/cpu.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
target/avr/cpu.h +46 -0
@@ -72,6 +72,42 @@*/ #define OFFSET_IO_REGISTERS (OFFSET_DATA + NUMBER_OF_CPU_REGISTERS) +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 {
@@ -126,6 +162,16 @@ hwaddr avr_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);int avr_cpu_gdb_read_register (CPUState *cpu,GByteArray *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.21.3
[PULL 17/32] target/avr: Initialize TCG register variables
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Initialize TCG register variables.
Message-Id: <[email protected]>
--- target/avr/translate.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
target/avr/translate.c +29 -0
@@ -128,6 +128,35 @@ struct DisasContext {bool free_skip_var0; }; +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 int to_regs_16_31_by_one (DisasContext *ctx,int indx) {return 16 + (indx %16 );
Signature · 1 line
2.21.3
[PULL 10/32] target/avr: Add instruction translation - Register definitions
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Start implementation of instructions by adding register definitions.
Message-Id: <[email protected]>
--- target/avr/translate.c | 142 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 target/avr/translate.c
target/avr/translate.c new file +142 -0
@@ -0,0 +1,142 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019-2020 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 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.21.3
[PULL 09/32] target/avr: Add instruction helpers
In reply to Philippe Mathieu-Daudé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.
Message-Id: <[email protected]>
--- target/avr/helper.h | 29 +++++++ target/avr/helper.c | 203 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 target/avr/helper.h
target/avr/helper.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* QEMU AVR CPU helpers +* +* Copyright (c) 2016-2020 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)
target/avr/helper.c +203 -0
206 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 16/32] target/avr: Add instruction translation - CPU main translation function
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Add the core of translation mechanism.
Message-Id: <[email protected]>
--- target/avr/translate.c | 213 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+)
target/avr/translate.c +213 -0
@@ -2805,3 +2805,216 @@ static bool trans_WDR(DisasContext *ctx, arg_WDR *a)return true; } + +/* +* Core translation mechanism functions: +* +* - translate() +* - canonicalize_skip() +* - gen_intermediate_code() +* - restore_state_to_opc() +* +*/ +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.21.3
[PULL 20/32] tests/machine-none: Add AVR support
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Add a single code line that will automatically provide 'machine none' test.
Message-Id: <[email protected]>
--- tests/qtest/machine-none-test.c | 1 + 1 file changed, 1 insertion(+)
tests/qtest/machine-none-test.c +1 -0
@@ -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.21.3
[PULL 14/32] target/avr: Add instruction translation - Bit and Bit-test Instructions
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This includes:
- LSR, ROR
- ASR
- SWAP
- SBI, CBI
- BST, BLD
- BSET, BCLR
Message-Id: <[email protected]>
--- target/avr/insn.decode | 14 +++ target/avr/translate.c | 247 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+)
target/avr/insn.decode +14 -0
@@ -163,3 +163,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 +247 -0
250 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 11/32] target/avr: Add instruction translation - Arithmetic and Logic Instructions
In reply to Philippe Mathieu-Daudé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
Message-Id: <[email protected]>
--- target/avr/insn.decode | 76 ++++ target/avr/translate.c | 820 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 896 insertions(+) create mode 100644 target/avr/insn.decode
target/avr/insn.decode new file +76 -0
@@ -0,0 +1,76 @@ +# +# AVR instruction decode definitions. +# +# Copyright (c) 2019-2020 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 +%rr_a 0:4 !function=to_regs_16_31_by_one +%rr_b 0:3 !function=to_regs_16_23_by_one + +%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 + + +&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 +@fmul .... .... . ... . ... &rd_rr rd=%rd_b rr=%rr_b + +# +# 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 +820 -0
829 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 18/32] target/avr: Add support for disassembling via option '-d in_asm'
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Provide function disassembles executed instruction when '-d in_asm' is provided.
Example:
$ qemu-system-avr -bios free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf -d in_asm
...
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
...Message-Id: <[email protected]>
--- target/avr/cpu.h | 1 + target/avr/cpu.c | 2 +- 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.h +1 -0
@@ -161,6 +161,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,GByteArray *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/cpu.c +1 -1
@@ -85,7 +85,7 @@ static void avr_cpu_reset(DeviceState *ds)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/disas.c new file +246 -0
246 lines not on this page · raw message
target/avr/translate.c +12 -0
@@ -3040,6 +3040,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.21.3
[PULL 28/32] tests/acceptance: Test the Arduino MEGA2560 board
In reply to Philippe Mathieu-Daudé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')
--- MAINTAINERS | 1 + tests/acceptance/machine_avr6.py | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/acceptance/machine_avr6.py
MAINTAINERS +1 -0
@@ -173,6 +173,7 @@ R: Sarah Harris <[email protected]> S: Maintained F: gdb-xml/avr-cpu.xml F: target/avr/ +F: tests/acceptance/machine_avr6.py CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
tests/acceptance/machine_avr6.py new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 22/32] hw/timer: avr: Add limited support for 16-bit timer peripheral
In reply to Philippe Mathieu-Daudé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).
Message-Id: <[email protected]>
--- include/hw/timer/avr_timer16.h | 94 +++++ hw/timer/avr_timer16.c | 621 +++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + hw/timer/trace-events | 12 + 6 files changed, 734 insertions(+) create mode 100644 include/hw/timer/avr_timer16.h create mode 100644 hw/timer/avr_timer16.c
include/hw/timer/avr_timer16.h new file +94 -0
@@ -0,0 +1,94 @@ +/* +* AVR 16-bit timer +* +* Copyright (c) 2018 University of Kent +* Author: Ed Robbins +* +* 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> +*/ + +/* +* Driver for 16 bit timers on 8 bit AVR devices. +* Note: +* On ATmega640/V-1280/V-1281/V-2560/V-2561/V timers 1, 3, 4 and 5 are 16 bit +*/ + +#ifndef HW_TIMER_AVR_TIMER16_H +#define HW_TIMER_AVR_TIMER16_H + +#include "hw/sysbus.h" +#include "qemu/timer.h" +#include "hw/hw.h" + +enum NextInterrupt { +OVERFLOW , +COMPA , +COMPB , +COMPC , +CAPT +}; + +#define TYPE_AVR_TIMER16 "avr-timer16" +#define AVR_TIMER16 (obj) \ + OBJECT_CHECK(AVRTimer16State, (obj), TYPE_AVR_TIMER16) + +typedef struct AVRTimer16State { +/* <private> */ +SysBusDevice parent_obj; + +/* <public> */ +MemoryRegion iomem; +MemoryRegion imsk_iomem; +MemoryRegion ifr_iomem; +QEMUTimer *timer; +qemu_irq capt_irq; +qemu_irq compa_irq; +qemu_irq compb_irq; +qemu_irq compc_irq; +qemu_irq ovf_irq; + +bool enabled; + +/* registers */ +uint8_t cra; +uint8_t crb; +uint8_t crc; +uint8_t cntl; +uint8_t cnth; +uint8_t icrl; +uint8_t icrh; +uint8_t ocral; +uint8_t ocrah; +uint8_t ocrbl; +uint8_t ocrbh; +uint8_t ocrcl; +uint8_t ocrch; +/* +* Reads and writes to CNT and ICR utilise a bizarre temporary +* register, which we emulate +*/ +uint8_t rtmp; +uint8_t imsk; +uint8_t ifr; + +uint8_t id; +uint64_t cpu_freq_hz; +uint64_t freq_hz; +uint64_t period_ns; +uint64_t reset_time_ns; +enum NextInterrupt next_interrupt; +}AVRTimer16State ; + +#endif /* HW_TIMER_AVR_TIMER16_H */
hw/timer/avr_timer16.c new file +621 -0
621 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -985,6 +985,8 @@ S: Maintained F: default-configs/avr-softmmu.mak F: include/hw/char/avr_usart.h F: hw/char/avr_usart.c +F: include/hw/timer/avr_timer16.h +F: hw/timer/avr_timer16.c CRIS Machines -------------
hw/timer/Kconfig +3 -0
@@ -41,3 +41,6 @@ config RENESAS_TMR config RENESAS_CMT bool + +config AVR_TIMER16 + bool
hw/timer/Makefile.objs +2 -0
@@ -37,3 +37,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/trace-events +12 -0
@@ -75,3 +75,15 @@ nrf51_timer_set_count(uint8_t timer_id, uint8_t counter_id, uint32_t value) "tim bcm2835_systmr_irq(bool enable) "timer irq state %u" bcm2835_systmr_read(uint64_t offset, uint64_t data) "timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 bcm2835_systmr_write(uint64_t offset, uint64_t data) "timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 + +# avr_timer16.c +avr_timer16_read(uint8_t addr, uint8_t value) "timer16 read addr:%u value:%u" +avr_timer16_read_ifr(uint8_t value) "timer16 read addr:ifr value:%u" +avr_timer16_read_imsk(uint8_t value) "timer16 read addr:imsk value:%u" +avr_timer16_write(uint8_t addr, uint8_t value) "timer16 write addr:%u value:%u" +avr_timer16_write_ifr(uint8_t value) "timer16 write addr:ifr value:%u" +avr_timer16_write_imsk(uint8_t value) "timer16 write addr:imsk value:%u" +avr_timer16_interrupt_count(uint8_t cnt) "count: %u" +avr_timer16_interrupt_overflow(const char *reason) "overflow: %s" +avr_timer16_next_alarm(uint64_t delay_ns) "next alarm: %" PRIu64 " ns from now" +avr_timer16_clksrc_update(uint64_t freq_hz, uint64_t period_ns, uint64_t delay_s) "timer frequency: %" PRIu64 " Hz, period: %" PRIu64 " ns (%" PRId64 " us)"
Signature · 1 line
2.21.3
[PULL 19/32] target/avr: Register AVR support with the rest of QEMU
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
Add AVR related definitions into QEMU, make AVR support buildable.
Message-Id: <[email protected]>
--- configure | 7 +++++++ default-configs/avr-softmmu.mak | 1 + qapi/machine.json | 3 ++- include/disas/dis-asm.h | 19 ++++++++++++++++++ include/sysemu/arch_init.h | 1 + arch_init.c | 2 ++ MAINTAINERS | 9 +++++++++ target/avr/Makefile.objs | 34 +++++++++++++++++++++++++++++++++ 8 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 target/avr/Makefile.objs
configure +7 -0
@@ -8115,6 +8115,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 arm-m-profile.xml" ;; + avr) + gdb_xml_files="avr-cpu.xml" + target_compiler=$cross_cc_avr + ;; cris) ;; hppa)
@@ -8359,6 +8363,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 +1 -0
@@ -0,0 +1 @@ +# Default configuration for avr-softmmu
qapi/machine.json +2 -1
@@ -17,6 +17,7 @@ # being. # # @rx: since 5.0 +# @avr: since 5.1 # # Notes: The resulting QMP strings can be appended to the "qemu-system-" # prefix to produce the corresponding QEMU executable name. This
@@ -25,7 +26,7 @@ # 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', 'rx', 's390x', 'sh4',
include/disas/dis-asm.h +19 -0
@@ -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
@@ -25,6 +25,7 @@ enum {QEMU_ARCH_HPPA = (1 <<18 ),QEMU_ARCH_RISCV = (1 <<19 ),QEMU_ARCH_RX = (1 <<20 ), +QEMU_ARCH_AVR = (1 <<21 ), QEMU_ARCH_NONE = (1 << 31), };
arch_init.c +2 -0
@@ -90,6 +90,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 ;
MAINTAINERS +9 -0
@@ -975,6 +975,15 @@ 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: default-configs/avr-softmmu.mak + CRIS Machines ------------- Axis Dev88
target/avr/Makefile.objs new file +34 -0
@@ -0,0 +1,34 @@ +# +# QEMU AVR +# +# Copyright (c) 2016-2020 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.21.3
[PULL 13/32] target/avr: Add instruction translation - Data Transfer Instructions
In reply to Philippe Mathieu-Daudé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
Message-Id: <[email protected]>
--- target/avr/insn.decode | 56 +++ target/avr/translate.c | 990 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1046 insertions(+)
target/avr/insn.decode +56 -0
@@ -107,3 +107,59 @@ 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 +# + +%rd_d 4:4 !function=to_regs_00_30_by_two +%rr_d 0:4 !function=to_regs_00_30_by_two + +@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 + +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 +990 -0
999 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 26/32] hw/avr: Add limited support for some Arduino boards
In reply to Philippe Mathieu-DaudéArduino boards are build with AVR chipsets. Add some of these 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
Message-Id: <[email protected]>
--- default-configs/avr-softmmu.mak | 4 + hw/avr/arduino.c | 149 ++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/Kconfig | 1 + hw/avr/Kconfig | 4 + hw/avr/Makefile.objs | 1 + 6 files changed, 165 insertions(+) create mode 100644 hw/avr/arduino.c
default-configs/avr-softmmu.mak +4 -0
@@ -1 +1,5 @@ # Default configuration for avr-softmmu + +# Boards: +# +CONFIG_ARDUINO=y
hw/avr/arduino.c new file +149 -0
149 lines not on this page · raw message
MAINTAINERS +6 -0
@@ -991,6 +991,12 @@ F: hw/timer/avr_timer16.c F: include/hw/misc/avr_power.h F: hw/misc/avr_power.c +Arduino +M: Philippe Mathieu-Daudé <[email protected]> +R: Sarah Harris <[email protected]> +S: Maintained +F: hw/avr/arduino.c + CRIS Machines ------------- Axis Dev88
hw/Kconfig +1 -0
@@ -43,6 +43,7 @@ source watchdog/Kconfig # arch Kconfig source arm/Kconfig source alpha/Kconfig +source avr/Kconfig source cris/Kconfig source hppa/Kconfig source i386/Kconfig
hw/avr/Kconfig +4 -0
@@ -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
@@ -1,2 +1,3 @@ obj-y += boot.o obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o +obj-$(CONFIG_ARDUINO) += arduino.o
Signature · 1 line
2.21.3
[PULL 24/32] hw/avr: Add support for loading ELF/raw binaries
In reply to Philippe Mathieu-DaudéAdd avr_load_firmware() function to load firmware in ELF or raw binary format.
Message-Id: <[email protected]>
--- hw/avr/boot.h | 33 +++++++++++++ include/elf.h | 4 ++ hw/avr/boot.c | 115 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/avr/Makefile.objs | 1 + 5 files changed, 154 insertions(+) create mode 100644 hw/avr/boot.h create mode 100644 hw/avr/boot.c create mode 100644 hw/avr/Makefile.objs
hw/avr/boot.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* AVR loader helpers +* +* Copyright (c) 2019-2020 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 +4 -0
@@ -160,6 +160,8 @@ typedef struct mips_elf_abiflags_v0 {#define EM_CRIS 76/* Axis Communications 32-bit embedded processor */ +#define EM_AVR 83/* AVR 8-bit microcontroller */ +#define EM_V850 87/* NEC v850 */ #define EM_H8_300H 47/* Hitachi H8/300H */
@@ -202,6 +204,8 @@ typedef struct mips_elf_abiflags_v0 {#define EM_MOXIE 223/* Moxie processor family */ #define EM_MOXIE_OLD 0xFEED +#define EF_AVR_MACH 0x7F/* Mask for AVR e_flags to get core type */ +/* This is the info that is needed to parse the dynamic section of the file */ #define DT_NULL 0#define DT_NEEDED 1
hw/avr/boot.c new file +115 -0
115 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -983,6 +983,7 @@ M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained F: default-configs/avr-softmmu.mak +F: hw/avr/ F: include/hw/char/avr_usart.h F: hw/char/avr_usart.c F: include/hw/timer/avr_timer16.h
hw/avr/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +obj-y += boot.o
Signature · 1 line
2.21.3
Re: [PULL 24/32] hw/avr: Add support for loading ELF/raw binaries
Quoted 3 lines · Philippe Mathieu-Daudé
Add
avr_load_firmware()function to load firmware in ELF or raw binary format.
Hi; Coverity points out a memory leak (CID 1430449) in this function:
hw/avr/boot.c line 68
Quoted 9 lines
hw/avr/boot.c new file +9
-0+bool avr_load_firmware (AVRCPU *cpu,MachineState *ms, +MemoryRegion *program_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);
qemu_find_file() allocates and returns memory, but we don't pass this to any function that takes ownership of it, and none of the exit paths from the function (either error-exit or success-exit cases) call g_free() on it.
thanks
-- PMM
Re: [PULL 24/32] hw/avr: Add support for loading ELF/raw binaries
Quoted 7 lines · Peter Maydell
Quoted 3 lines · Philippe Mathieu-Daudé
Add
avr_load_firmware()function to load firmware in ELF or raw binary format.Hi; Coverity points out a memory leak (CID 1430449) in this function:
Quoted 14 lines
hw/avr/boot.c line 68
Quoted 9 lines
hw/avr/boot.c new file +9
-0+bool avr_load_firmware (AVRCPU *cpu,MachineState *ms, +MemoryRegion *program_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);
qemu_find_file()allocates and returns memory, but we don't pass this to any function that takes ownership of it, and none of the exit paths from the function (either error-exit or success-exit cases) callg_free()on it.
Ah I didn't know it was allocated, I looked at the declaration in the header then quickly if there was a comment in the source, but didn't read the implementation (now I see the obvious g_strdup() call... Neither have I looked at the other callers.
I'll send a patch.
Thanks for following the Coverity reports,
Phil.
Quoted 4 lines
thanks
-- PMM
[PULL 15/32] target/avr: Add instruction translation - MCU Control Instructions
In reply to Philippe Mathieu-DaudéFrom: Michael Rolnik <[email protected]>
This includes:
- BREAK
- NOP
- SLEEP
- WDR
Message-Id: <[email protected]>
--- target/avr/insn.decode | 8 ++++++ target/avr/translate.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
target/avr/insn.decode +8 -0
@@ -177,3 +177,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 +65 -0
68 lines not on this page · raw message
Signature · 1 line
2.21.3
[PULL 25/32] hw/avr: Add some ATmega microcontrollers
In reply to Philippe Mathieu-Daudé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
Message-Id: <[email protected]>
--- hw/avr/atmega.h | 48 +++++ hw/avr/atmega.c | 458 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Kconfig | 5 + hw/avr/Makefile.objs | 1 + 4 files changed, 512 insertions(+) create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/atmega.c create mode 100644 hw/avr/Kconfig
hw/avr/atmega.h new file +48 -0
@@ -0,0 +1,48 @@ +/* +* QEMU ATmega MCU +* +* Copyright (c) 2019-2020 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 */
hw/avr/atmega.c new file +458 -0
458 lines not on this page · raw message
hw/avr/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +config AVR_ATMEGA_MCU + bool + select AVR_TIMER16 + select AVR_USART + select AVR_POWER
hw/avr/Makefile.objs +1 -0
@@ -1 +1,2 @@ obj-y += boot.o +obj-$(CONFIG_AVR_ATMEGA_MCU) += atmega.o
Signature · 1 line
2.21.3
[PULL 21/32] hw/char: avr: Add limited support for USART peripheral
In reply to Philippe Mathieu-Daudé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).
Message-Id: <[email protected]>
--- include/hw/char/avr_usart.h | 93 +++++++++++ hw/char/avr_usart.c | 320 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + 5 files changed, 419 insertions(+) create mode 100644 include/hw/char/avr_usart.h create mode 100644 hw/char/avr_usart.c
include/hw/char/avr_usart.h new file +93 -0
@@ -0,0 +1,93 @@ +/* +* AVR USART +* +* Copyright (c) 2018 University of Kent +* Author: Sarah Harris +* +* 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 HW_CHAR_AVR_USART_H +#define HW_CHAR_AVR_USART_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" +#include "hw/hw.h" + +/* Offsets of registers. */ +#define USART_DR 0x06 +#define USART_CSRA 0x00 +#define USART_CSRB 0x01 +#define USART_CSRC 0x02 +#define USART_BRRH 0x05 +#define USART_BRRL 0x04 + +/* Relevant bits in regiters. */ +#define USART_CSRA_RXC (1 << 7) +#define USART_CSRA_TXC (1 << 6) +#define USART_CSRA_DRE (1 << 5) +#define USART_CSRA_MPCM (1 << 0) + +#define USART_CSRB_RXCIE (1 << 7) +#define USART_CSRB_TXCIE (1 << 6) +#define USART_CSRB_DREIE (1 << 5) +#define USART_CSRB_RXEN (1 << 4) +#define USART_CSRB_TXEN (1 << 3) +#define USART_CSRB_CSZ2 (1 << 2) +#define USART_CSRB_RXB8 (1 << 1) +#define USART_CSRB_TXB8 (1 << 0) + +#define USART_CSRC_MSEL1 (1 << 7) +#define USART_CSRC_MSEL0 (1 << 6) +#define USART_CSRC_PM1 (1 << 5) +#define USART_CSRC_PM0 (1 << 4) +#define USART_CSRC_CSZ1 (1 << 2) +#define USART_CSRC_CSZ0 (1 << 1) + +#define TYPE_AVR_USART "avr-usart" +#define AVR_USART (obj) \ + OBJECT_CHECK(AVRUsartState, (obj), TYPE_AVR_USART) + +typedef struct { +/* <private> */ +SysBusDevice parent_obj; + +/* <public> */ +MemoryRegion mmio; + +CharBackend chr; + +bool enabled; + +uint8_t data; +bool data_valid; +uint8_t char_mask; +/* Control and Status Registers */ +uint8_t csra; +uint8_t csrb; +uint8_t csrc; +/* Baud Rate Registers (low/high byte) */ +uint8_t brrh; +uint8_t brrl; + +/* Receive Complete */ +qemu_irq rxc_irq; +/* Transmit Complete */ +qemu_irq txc_irq; +/* Data Register Empty */ +qemu_irq dre_irq; +}AVRUsartState ; + +#endif /* HW_CHAR_AVR_USART_H */
hw/char/avr_usart.c new file +320 -0
320 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -983,6 +983,8 @@ M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained F: default-configs/avr-softmmu.mak +F: include/hw/char/avr_usart.h +F: hw/char/avr_usart.c CRIS Machines -------------
hw/char/Kconfig +3 -0
@@ -49,3 +49,6 @@ config TERMINAL3270 config RENESAS_SCI bool + +config AVR_USART + bool
hw/char/Makefile.objs +1 -0
@@ -22,6 +22,7 @@ common-obj-$(CONFIG_DIGIC) += digic-uart.o common-obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o common-obj-$(CONFIG_RASPI) += bcm2835_aux.o common-obj-$(CONFIG_RENESAS_SCI) += renesas_sci.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
Signature · 1 line
2.21.3
[PULL 32/32] target/avr/disas: Fix store instructions display order
In reply to Philippe Mathieu-DaudéWhile LOAD instructions use the target register as first argument, STORE instructions use it as second argument:
LD Rd, X // Rd <- (X)
ST Y, Rd // (Y) <- Rr
Message-Id: <[email protected]>
--- target/avr/disas.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/avr/disas.c +10 -10
@@ -196,16 +196,16 @@ INSN(LDZ2, "r%d, Z+", a->rd) INSN(LDZ3, "r%d, -Z", a->rd) INSN(LDDY, "r%d, Y+%d", a->rd, a->imm) INSN(LDDZ, "r%d, Z+%d", a->rd, a->imm) -INSN(STS, "r%d, %d", a->rd, a->imm) -INSN(STX1, "r%d, X", a->rr) -INSN(STX2, "r%d, X+", a->rr) -INSN(STX3, "r%d, -X", a->rr) -INSN(STY2, "r%d, Y+", a->rd) -INSN(STY3, "r%d, -Y", a->rd) -INSN(STZ2, "r%d, Z+", a->rd) -INSN(STZ3, "r%d, -Z", a->rd) -INSN(STDY, "r%d, Y+%d", a->rd, a->imm) -INSN(STDZ, "r%d, Z+%d", a->rd, a->imm) +INSN(STS, "%d, r%d", a->imm, a->rd) +INSN(STX1, "X, r%d", a->rr) +INSN(STX2, "X+, r%d", a->rr) +INSN(STX3, "-X, r%d", a->rr) +INSN(STY2, "Y+, r%d", a->rd) +INSN(STY3, "-Y, r%d", a->rd) +INSN(STZ2, "Z+, r%d", a->rd) +INSN(STZ3, "-Z, r%d", a->rd) +INSN(STDY, "Y+%d, r%d", a->imm, a->rd) +INSN(STDZ, "Z+%d, r%d", a->imm, a->rd) INSN(LPM1, "") INSN(LPM2, "r%d, Z", a->rd)INSN (LPMX ,"r%d, Z+" , a->rd)
Signature · 1 line
2.21.3
[PULL 27/32] tests/boot-serial: Test some Arduino boards (AVR based)
In reply to Philippe Mathieu-Daudé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.
Message-Id: <[email protected]>
--- tests/qtest/boot-serial-test.c | 11 +++++++++++ tests/qtest/Makefile.include | 2 ++ 2 files changed, 13 insertions(+)
tests/qtest/boot-serial-test.c +11 -0
@@ -17,6 +17,15 @@#include "libqtest.h" #include "libqos/libqos-spapr.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 */
@@ -104,6 +113,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" },
tests/qtest/Makefile.include +2 -0
@@ -66,6 +66,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
Signature · 1 line
2.21.3
[PULL 23/32] hw/misc: avr: Add limited support for power reduction device
In reply to Philippe Mathieu-Daudé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.
Message-Id: <[email protected]>
--- include/hw/misc/avr_power.h | 46 +++++++++++++++ hw/misc/avr_power.c | 113 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/misc/trace-events | 4 ++ 6 files changed, 170 insertions(+) create mode 100644 include/hw/misc/avr_power.h create mode 100644 hw/misc/avr_power.c
include/hw/misc/avr_power.h new file +46 -0
@@ -0,0 +1,46 @@ +/* +* AVR Power Reduction Management +* +* Copyright (c) 2019-2020 Michael Rolnik +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef HW_MISC_AVR_POWER_H +#define HW_MISC_AVR_POWER_H + +#include "hw/sysbus.h" +#include "hw/hw.h" + + +#define TYPE_AVR_MASK "avr-power" +#define AVR_MASK (obj) OBJECT_CHECK(AVRMaskState, (obj), TYPE_AVR_MASK) + +typedef struct { +/* <private> */ +SysBusDevice parent_obj; + +/* <public> */ +MemoryRegion iomem; + +uint8_t val; +qemu_irq irq[8 ]; +}AVRMaskState ; + +#endif /* HW_MISC_AVR_POWER_H */
hw/misc/avr_power.c new file +113 -0
113 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -987,6 +987,8 @@ F: include/hw/char/avr_usart.h F: hw/char/avr_usart.c F: include/hw/timer/avr_timer16.h F: hw/timer/avr_timer16.c +F: include/hw/misc/avr_power.h +F: hw/misc/avr_power.c CRIS Machines -------------
hw/misc/Kconfig +3 -0
@@ -131,4 +131,7 @@ config MAC_VIA select MOS6522 select ADB +config AVR_POWER + bool + source macio/Kconfig
hw/misc/Makefile.objs +2 -0
@@ -91,3 +91,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/trace-events +4 -0
@@ -19,6 +19,10 @@ allwinner_h3_dramphy_write(uint64_t offset, uint64_t data, unsigned size) "write allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 +# avr_power.c +avr_power_read(uint8_t value) "power_reduc read value:%u" +avr_power_write(uint8_t value) "power_reduc write value:%u" + # eccmemctl.c ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x" ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
Signature · 1 line
2.21.3
[PULL 30/32] target/avr/cpu: Drop tlb_flush() in avr_cpu_reset()
In reply to Philippe Mathieu-DaudéSince commit 1f5c00cfdb tlb_flush() is called from cpu_common_reset().
Message-Id: <[email protected]>
--- target/avr/cpu.c | 2 -- 1 file changed, 2 deletions(-)
target/avr/cpu.c +0 -2
@@ -78,8 +78,6 @@ static void avr_cpu_reset(DeviceState *ds) env->skip =0 ;memset (env->r,0 ,sizeof (env->r)); - -tlb_flush (cs); }static void avr_cpu_disas_set_info (CPUState *cpu,disassemble_info *info)
Signature · 1 line
2.21.3
[PULL 29/32] target/avr: Add section into QEMU documentation
In reply to Philippe Mathieu-DaudéFrom: Thomas Huth <[email protected]>
The new section explains basic ways of using AVR target in QEMU.
Message-Id: <[email protected]>
--- docs/system/target-avr.rst | 37 +++++++++++++++++++++++++++++++++++++ docs/system/targets.rst | 1 + 2 files changed, 38 insertions(+) create mode 100644 docs/system/target-avr.rst
docs/system/target-avr.rst new file +37 -0
@@ -0,0 +1,37 @@ +.. _AVR-System-emulator: + +AVR System emulator +------------------- + +Use the executable ``qemu-system-avr`` to emulate a AVR 8 bit based machine. +These can have one of 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 +https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf +). + +Following are examples of possible usages, assuming demo.elf is compiled for +AVR cpu + + - Continuous non interrupted execution: + ``qemu-system-avr -machine mega2560 -bios demo.elf`` + + - Continuous non interrupted execution with serial output into telnet window: + ``qemu-system-avr -machine mega2560 -bios demo.elf -serial + tcp::5678,server,nowait -nographic`` + and then in another shell + ``telnet localhost 5678`` + + - Debugging wit GDB debugger: + ``qemu-system-avr -machine mega2560 -bios demo.elf -s -S`` + and then in another shell + ``avr-gdb demo.elf`` + and then within GDB shell + ``target remote :1234`` + + - Print out executed instructions: + ``qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm``
docs/system/targets.rst +1 -0
@@ -19,3 +19,4 @@ Contents: target-xtensa target-s390x target-rx + target-avr
Signature · 1 line
2.21.3
[PULL 31/32] target/avr/cpu: Fix $PC displayed address
In reply to Philippe Mathieu-Daudé$PC is 16-bit wide. Other registers display addresses on a byte granularity.
To have a coherent ouput, display $PC using byte granularity too.
Message-Id: <[email protected]>
--- target/avr/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/cpu.c +1 -1
@@ -151,7 +151,7 @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)int i;qemu_fprintf (f,"\n" ); -qemu_fprintf (f,"PC: %06x\n" , env->pc_w); +qemu_fprintf (f,"PC: %06x\n" , env->pc_w *2 );/* PC points to words */ qemu_fprintf (f,"SP: %04x\n" , env->sp);qemu_fprintf (f,"rampD: %02x\n" , env->rampD >>16 );qemu_fprintf (f,"rampX: %02x\n" , env->rampX >>16 );
Signature · 1 line
2.21.3
Quoted 16 lines · Philippe Mathieu-Daudé
Possible false-positives from checkpatch:
WARNING: added, moved or deleted file(s), does
MAINTAINERSneed updating?The following changes since commit
7623b5ba017f61de5d7c2bba12c6feb3d55091b1:Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.1-pull-=
request' into staging (2020-07-06 11:40:10 +0100)are available in the Git repository at:
https://gitlab.com/philmd/qemu.git tags/avr-port-20200707
for you to fetch changes up to
0cdaf2f343491f60dbf7dd2a912cd88b5f9f899c:
Quoted 8 lines
target/avr/disas: Fix store instructions display order (2020-07-07 20:14:15=
+0200)----------------------------------------------------------------
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.
Hi; I'm afraid this fails "make check" on big-endian hosts (s390x, ppc64):
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=avr-softmmu/qemu-system-avr QTEST_QEMU_IMG=qemu-img tests/qtest/boot-serial-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl --test-name="boot-serial-test"
qemu-system-avr: execution left flash memory
** (tests/qtest/boot-serial-test:24048): ERROR **: 11:00:46.466:
Failed to find expected string. Please check '/tmp/qtest-boot-serial-sVGEXHI'
ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sVGEXHI'
thanks
-- PMM
Quoted 34 lines · Peter Maydell
Quoted 16 lines · Philippe Mathieu-Daudé
Possible false-positives from checkpatch:
WARNING: added, moved or deleted file(s), does
MAINTAINERSneed updating?The following changes since commit
7623b5ba017f61de5d7c2bba12c6feb3d55091b1:Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.1-pull-=
request' into staging (2020-07-06 11:40:10 +0100)are available in the Git repository at:
https://gitlab.com/philmd/qemu.git tags/avr-port-20200707
for you to fetch changes up to
0cdaf2f343491f60dbf7dd2a912cd88b5f9f899c:Quoted 8 lines
target/avr/disas: Fix store instructions display order (2020-07-07 20:14:15=
+0200)----------------------------------------------------------------
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.
Hi; I'm afraid this fails "make check" on big-endian hosts (s390x, ppc64):
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=avr-softmmu/qemu-system-avr QTEST_QEMU_IMG=qemu-img tests/qtest/boot-serial-test -m=quick -k --tap <
/dev/null|./scripts/tap-driver.pl--test-name="boot-serial-test"
qemu-system-avr: execution left flash memory
Quoted 5 lines
** (tests/qtest/boot-serial-test:24048): ERROR **: 11:00:46.466:
Failed to find expected string. Please check '/tmp/qtest-boot-serial-sVGEXHI'
ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sVGEXHI'
Endianess bug ... this should fix it:
target/avr/helper.c +0 -0
@@ -337,6 +337,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data,
uint32_t addr)
helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data);
} else {
/* memory */
- cpu_physical_memory_write(OFFSET_DATA + addr, &data, 1);
+ uint8_t data8 = data;
+ cpu_physical_memory_write(OFFSET_DATA + addr, &data8, 1);
}}
Thomas
Quoted 6 lines · Thomas Huth
Endianess bug ... this should fix it:
target/avr/helper.c void helper_fullwr(CPUAVRState *env, uint32_t data, · line 343
Quoted 8 lines
target/avr/helper.c +2
-1@@ -337,6 +337,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data); }else {/* memory */ -cpu_physical_memory_write (OFFSET_DATA + addr, &data,1 ); +uint8_t data8 = data; +cpu_physical_memory_write (OFFSET_DATA + addr, &data8,1 ); }
Or equivalently
address_space_stb(&address_space_memory, data, MEMTXATTRS_UNSPECIFIED, NULL);
(better choices of address space may be available, but this is the exact-same-behaviour one).
Quoted 1 line
}
thanks
-- PMM
Quoted 19 lines · Peter Maydell
Quoted 6 lines · Thomas Huth
Endianess bug ... this should fix it:
target/avr/helper.c void helper_fullwr(CPUAVRState *env, uint32_t data, · line 343
Quoted 8 lines
target/avr/helper.c +2
-1@@ -337,6 +337,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data); }else {/* memory */ -cpu_physical_memory_write (OFFSET_DATA + addr, &data,1 ); +uint8_t data8 = data; +cpu_physical_memory_write (OFFSET_DATA + addr, &data8,1 ); }Or equivalently
address_space_stb(&address_space_memory, data, MEMTXATTRS_UNSPECIFIED, NULL);
Quoted 2 lines
(better choices of address space may be available, but this is the exact-same-behaviour one).
Ah, this is my stashed fix:
-- >8 --
@@ -320,8 +320,10 @@ target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr)
* 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) +void helper_fullwr(CPUAVRState *env, uint32_t data32, uint32_t addr)
{
+ uint8_t data = data32;
+ assert(data == data32);
+
env->fullacc = false;
---
3 ways to do the same :) The assert is probably superfluous.
I don't like the fact that env->r[addr] (which is u8) is silently casted from u32.
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Peter Maydell
Quoted 6 lines · Thomas Huth
Endianess bug ... this should fix it:
target/avr/helper.c void helper_fullwr(CPUAVRState *env, uint32_t data, · line 343
Quoted 8 lines
target/avr/helper.c +2
-1@@ -337,6 +337,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data); }else {/* memory */ -cpu_physical_memory_write (OFFSET_DATA + addr, &data,1 ); +uint8_t data8 = data; +cpu_physical_memory_write (OFFSET_DATA + addr, &data8,1 ); }Or equivalently
address_space_stb(&address_space_memory, data, MEMTXATTRS_UNSPECIFIED, NULL);Quoted 2 lines
(better choices of address space may be available, but this is the exact-same-behaviour one).
Ah, this is my stashed fix:
-- >8 --
(quoted diff) +0
-0@@ -320,8 +320,10 @@ target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr) * this function implements ST instruction when there is a posibilityto write
* into a CPU register
*/(quoted diff) +4
-2-void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) +void helper_fullwr(CPUAVRState *env, uint32_t data32, uint32_t addr) { + uint8_t data = data32; + assert(data == data32); + env->fullacc = false; ---
Quoted 4 lines
3 ways to do the same :) The assert is probably superfluous.
I don't like the fact that env->r[addr] (which is u8) is silently casted from u32.
I'll squash Peter suggested fix:
-- >8 --
target/avr/helper.c +3 -1
@@ -232,7 +232,9 @@ target_ulong helper_inb(CPUAVRState *env, uint32_t port)break ;default :/* not a special register, pass to normal memory access */ -cpu_physical_memory_read (OFFSET_IO_REGISTERS + port, &data,1 ); + data =address_space_ldub (&address_space_memory, +OFFSET_IO_REGISTERS + port, +MEMTXATTRS_UNSPECIFIED ,NULL ); }return data;
@@ -289,7 +291,8 @@ void helper_outb(CPUAVRState *env, uint32_t port,
uint32_t data)
break;
default:
/* not a special register, pass to normal memory access */
- cpu_physical_memory_write(OFFSET_IO_REGISTERS + port, &data, 1);
+ address_space_stb(&address_space_memory, OFFSET_IO_REGISTERS +
port,
+ data, MEMTXATTRS_UNSPECIFIED, NULL);
}}
@@ -305,13 +308,14 @@ target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr)
if (addr < NUMBER_OF_CPU_REGISTERS) {
/* CPU registers */
- data = env->r[addr];
+ data = cpu_to_le32(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);
+ data = address_space_ldub(&address_space_memory, OFFSET_DATA +
addr,
+ MEMTXATTRS_UNSPECIFIED, NULL);
}
return data;
}
@@ -337,6 +341,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data,
uint32_t addr)
helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data);
} else {
/* memory */
- cpu_physical_memory_write(OFFSET_DATA + addr, &data, 1);
+ address_space_stb(&address_space_memory, OFFSET_DATA + addr, data,
+ MEMTXATTRS_UNSPECIFIED, NULL);
} }
---
Quoted 49 lines · Philippe Mathieu-Daudé
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Peter Maydell
Quoted 6 lines · Thomas Huth
Endianess bug ... this should fix it:
target/avr/helper.c void helper_fullwr(CPUAVRState *env, uint32_t data, · line 343
Quoted 8 lines
target/avr/helper.c +2
-1@@ -337,6 +337,7 @@ void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) helper_outb(env, addr - NUMBER_OF_CPU_REGISTERS, data); }else {/* memory */ -cpu_physical_memory_write (OFFSET_DATA + addr, &data,1 ); +uint8_t data8 = data; +cpu_physical_memory_write (OFFSET_DATA + addr, &data8,1 ); }Or equivalently
address_space_stb(&address_space_memory, data, MEMTXATTRS_UNSPECIFIED, NULL);Quoted 2 lines
(better choices of address space may be available, but this is the exact-same-behaviour one).
Ah, this is my stashed fix:
-- >8 --
(quoted diff) +0
-0@@ -320,8 +320,10 @@ target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr) * this function implements ST instruction when there is a posibilityto write
* into a CPU register
*/(quoted diff) +4
-2-void helper_fullwr(CPUAVRState *env, uint32_t data, uint32_t addr) +void helper_fullwr(CPUAVRState *env, uint32_t data32, uint32_t addr) { + uint8_t data = data32; + assert(data == data32); + env->fullacc = false; ---Quoted 4 lines
3 ways to do the same :) The assert is probably superfluous.
I don't like the fact that env->r[addr] (which is u8) is silently casted from u32.
I'll squash Peter suggested fix:
[...]
Review target_ulong helper_fullrd(CPUAVRState *env, · line 312
Quoted 7 lines
(quoted diff) +1
-1@@ -305,13 +308,14 @@ target_ulong helper_fullrd(CPUAVRState *env, uint32_t addr) if (addr < NUMBER_OF_CPU_REGISTERS) { /* CPU registers */ - data = env->r[addr]; + data = cpu_to_le32(env->r[addr]);
That part looks wrong?
Thomas
Review
Quoted 4 lines · Philippe Mathieu-Daudé
if (addr < NUMBER_OF_CPU_REGISTERS) { /* CPU registers */(quoted diff) +1
-1- data = env->r[addr]; + data = cpu_to_le32(env->r[addr]);
This doesn't look right. Why?
r~
Quoted 7 lines · Richard Henderson
Review
Quoted 4 lines · Philippe Mathieu-Daudé
if (addr < NUMBER_OF_CPU_REGISTERS) { /* CPU registers */(quoted diff) +1
-1- data = env->r[addr]; + data = cpu_to_le32(env->r[addr]);This doesn't look right. Why?
Sorry guys, false alarm, leftover from previous test but this is definitively not in the pull request :D