target/avr merger
cover target/avr merger
From: Aleksandar Markovic <[email protected]>
This is the AVR port from Michael, release (merge) candidate 5.
The series can be found also in this repository:
https://github.com/AMarkovic/qemu-avr-merger-rc5
History:
Since v4:
- Alex tracing improvements (the only functional difference from v4)
- Moving code between patches, and sometimes between files
- Several new patches were extracted from more complex ones
- Improved commit messages
- Other minor improvements
- I added my 8 "R-b:"s that I explained in rc4, plus some more
- Series now has 0 errors and 0 warnings (checkpatch)
Since v3:
- Removed a patch on load_elf() modification, since it has been merged
- Removed references to CONFIG_USER_ONLY and provided a guard against building lunux user mode for AVR
- Removed all references to 'Atmel' (including file renames)
- Rebased the code (there was common interface change regarding 'props')
- Various corrections of commit messages
- A bit field for AVRFeatures is nor 64 bit long
- Other minor fixes
Since v2:
- First patch is split into six smaller logical units (net result remains the same)
- Patch "hw/core/loader: Let load_elf populate the processor-specific flags" was redone to reflect the original intent that was lost in transalation between multiple autors
- Patch "hw/avr: Add helper to load raw/ELF firmware binaries" was corrected only in one line to rectify type of "e_flags"
- Patch "target/avr: Add section about AVR into QEMU documentation"
- Spurious <message-Id:> elements were removed
- The series was rebased to the latest code
Since v1:
- Addressed Thomas comments
- Fixed a non-critical bug in ATmega (incorrect SRAM base address)
- Added ELF parsing requested by Aleksandar
- Dropped default machine (as with the ARM port)
Michael Rolnik (28):
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 defintions of AVR core types
target/avr: Add instruction helpers
target/avr: Add instruction translation - Register definitions target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Data Transfer Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Initialize TCG register variables
target/avr: Add support for disassembling via option '-d in_asm' 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 target/avr: Register AVR support with the rest of QEMU target/avr: Update build system
tests/machine-none: Add AVR support
tests/boot-serial: Test some Arduino boards (AVR based) tests/acceptance: Test the Arduino MEGA2560 board target/avr: Simplify sections in MAINTAINERS file target/avr: Add section into QEMU documentation
Philippe Mathieu-Daudé (4):
hw/avr: Add support for loading ELF/raw binaries hw/avr: Add some ATmega microcontrollers hw/avr: Add limited support for some Arduino boards .travis.yml: Run the AVR acceptance tests
qemu-doc.texi | 51 + 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 | 37 + 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 | 151 ++ hw/avr/atmega.c | 470 ++++++ hw/avr/boot.c | 116 ++ hw/char/avr_usart.c | 320 ++++ hw/misc/avr_power.c | 113 ++ hw/timer/avr_timer16.c | 609 ++++++++ target/avr/cpu.c | 777 ++++++++++ target/avr/disas.c | 246 +++ target/avr/gdbstub.c | 84 ++ target/avr/helper.c | 342 +++++ target/avr/machine.c | 121 ++ target/avr/translate.c | 3073 ++++++++++++++++++++++++++++++++++++++ tests/qtest/boot-serial-test.c | 11 + tests/qtest/machine-none-test.c | 1 + .travis.yml | 2 +- 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, 7611 insertions(+), 2 deletions(-) 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
Signature · 1 line
2.7.4
PATCH 1/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.
--- target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++++ target/avr/cpu.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 7 ++++++ 3 files changed, 110 insertions(+) create mode 100644 target/avr/cpu-param.h create mode 100644 target/avr/cpu.h
target/avr/cpu-param.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#ifndef AVR_CPU_PARAM_H +#define AVR_CPU_PARAM_H + +#define TARGET_LONG_BITS 32 +/* +* TARGET_PAGE_BITS cannot be more than 8 bits because +* 1. all IO registers occupy [0x0000 .. 0x00ff] address range, and they +* should be implemented as a device and not memory +* 2. SRAM starts at the address 0x0100 +*/ +#define TARGET_PAGE_BITS 8 +#define TARGET_PHYS_ADDR_SPACE_BITS 24 +#define TARGET_VIRT_ADDR_SPACE_BITS 24 +#define NB_MMU_MODES 2 + + +#endif
target/avr/cpu.h new file +66 -0
66 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -163,6 +163,13 @@ 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/cpu-param.h +F: target/avr/cpu.h + CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained
Signature · 1 line
2.7.4
Re: [PATCH rc5 01/32] target/avr: Add basic parameters of the new platform
Quoted 161 lines · Aleksandar Markovic
From: Michael Rolnik <[email protected]>
This includes definitions of various basic parameters needed for integration of a new platform into QEMU.
[AM: Split a larger AVR introduction patch into logical units]Suggested-by Aleksandar Markovic <[email protected]>Co-developed-by Michael Rolnik <[email protected]>Co-developed-by Sarah Harris <[email protected]>Signed-off-by Michael Rolnik <[email protected]>Signed-off-by Sarah Harris <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Aleksandar Markovic <[email protected]>Acked-by Igor Mammedov <[email protected]>--- target/avr/cpu-param.h | 37 ++++++++++++++++++++++++++++ target/avr/cpu.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 7 ++++++ 3 files changed, 110 insertions(+) create mode 100644 target/avr/cpu-param.h create mode 100644 target/avr/cpu.htarget/avr/cpu-param.h new file +37
-0@@ -0,0 +1,37 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#ifndef AVR_CPU_PARAM_H +#define AVR_CPU_PARAM_H + +#define TARGET_LONG_BITS 32 +/* +* TARGET_PAGE_BITS cannot be more than 8 bits because +* 1. all IO registers occupy [0x0000 .. 0x00ff] address range, and they +* should be implemented as a device and not memory +* 2. SRAM starts at the address 0x0100 +*/ +#define TARGET_PAGE_BITS 8 +#define TARGET_PHYS_ADDR_SPACE_BITS 24 +#define TARGET_VIRT_ADDR_SPACE_BITS 24 +#define NB_MMU_MODES 2 + + +#endif target/avr/cpu.h new file +66
-0@@ -0,0 +1,66 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#ifndef QEMU_AVR_CPU_H +#define QEMU_AVR_CPU_H + +#include "exec/cpu-defs.h" + +#define TCG_GUEST_DEFAULT_MO 0 + +/* +* AVR has two memory spaces, data & code. +* e.g. both have 0 address +* ST/LD instructions access data space +* LPM/SPM and instruction fetching access code memory space +*/ +#define MMU_CODE_IDX 0 +#define MMU_DATA_IDX 1 + +#define EXCP_RESET 1 +#define EXCP_INT (n) (EXCP_RESET + (n) + 1) + +/* Number of CPU registers */ +#define NUMBER_OF_CPU_REGISTERS 32 +/* Number of IO registers accessible by ld/st/in/out */ +#define NUMBER_OF_IO_REGISTERS 64 + +/* +* Offsets of AVR memory regions in host memory space. +* +* This is needed because the AVR has separate code and data address +* spaces that both have start from zero but have to go somewhere in +* host memory. +* +* It's also useful to know where some things are, like the IO registers. +*/ +/* Flash program memory */ +#define OFFSET_CODE 0x00000000 +/* CPU registers, IO registers, and SRAM */ +#define OFFSET_DATA 0x00800000 +/* CPU registers specifically, these are mapped at the start of data */ +#define OFFSET_CPU_REGISTERS OFFSET_DATA +/* +* IO registers, including status register, stack pointer, and memory +* mapped peripherals, mapped just after CPU registers +*/ +#define OFFSET_IO_REGISTERS (OFFSET_DATA + NUMBER_OF_CPU_REGISTERS) + +#endif /* !defined (QEMU_AVR_CPU_H) */ MAINTAINERS +7
-1@@ -163,6 +163,13 @@ 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/cpu-param.h +F: target/avr/cpu.h + CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.7.4
Signature · 2 lines
Best Regards, Michael Rolnik
PATCH 2/32 target/avr: Introduce basic CPU class object
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This patch introduces AVR CPU class object and its basic elements and functions.
--- target/avr/cpu-qom.h | 54 ++++++++++++++ target/avr/cpu.h | 139 ++++++++++++++++++++++++++++++++++ target/avr/cpu.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + 4 files changed, 402 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) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#ifndef QEMU_AVR_QOM_H +#define QEMU_AVR_QOM_H + +#include "hw/core/cpu.h" + +#define TYPE_AVR_CPU "avr-cpu" + +#define AVR_CPU_CLASS (klass) \ + OBJECT_CLASS_CHECK(AVRCPUClass, (klass), TYPE_AVR_CPU) +#define AVR_CPU (obj) \ + OBJECT_CHECK(AVRCPU, (obj), TYPE_AVR_CPU) +#define AVR_CPU_GET_CLASS (obj) \ + OBJECT_GET_CLASS(AVRCPUClass, (obj), TYPE_AVR_CPU) + +/** +* AVRCPUClass: +* @parent_realize: The parent class' realize handler. +* @parent_reset: The parent class' reset handler. +* @vr: Version Register value. +* +* A AVR CPU model. +*/ +typedef struct AVRCPUClass { +/*< private >*/ +CPUClass parent_class; +/*< public >*/ +DeviceRealize parent_realize; +void (*parent_reset)(CPUState *cpu); +}AVRCPUClass ; + +typedef struct AVRCPU AVRCPU ; + + +#endif /* !defined (QEMU_AVR_CPU_QOM_H) */
target/avr/cpu.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
MAINTAINERS +2 -0
@@ -168,7 +168,9 @@ M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained F: target/avr/cpu-param.h +F: target/avr/cpu-qom.h F: target/avr/cpu.h +F: target/avr/cpu.c CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
Signature · 1 line
2.7.4
PATCH 3/32 target/avr: CPU class: Add interrupt handling support
In reply to Aleksandar MarkovicFrom: 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.
--- target/avr/cpu.c | 2 ++ target/avr/helper.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 92 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
MAINTAINERS +1 -0
@@ -171,6 +171,7 @@ F: target/avr/cpu-param.h F: target/avr/cpu-qom.h F: target/avr/cpu.h F: target/avr/cpu.c +F: target/avr/helper.c CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
Signature · 1 line
2.7.4
PATCH 4/32 target/avr: CPU class: Add memory menagement support
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This patch introduces three memory-management-related functions that will become part of AVR CPU class object.
--- 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.7.4
PATCH 5/32 target/avr: CPU class: Add migration support
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Add migration-related functions of AVR CPU class object.
--- target/avr/cpu.h | 2 + target/avr/cpu.c | 1 + target/avr/machine.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 4 files changed, 125 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
MAINTAINERS +1 -0
@@ -172,6 +172,7 @@ F: target/avr/cpu-qom.h F: target/avr/cpu.h F: target/avr/cpu.c F: target/avr/helper.c +F: target/avr/machine.c CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
Signature · 1 line
2.7.4
PATCH 6/32 target/avr: CPU class: Add GDB support
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes GDB hooks for reading from wnd wrtiting to AVR registers, and xml register definition file as well.
--- target/avr/cpu.h | 2 ++ target/avr/cpu.c | 4 +++ target/avr/gdbstub.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 ++ gdb-xml/avr-cpu.xml | 49 ++++++++++++++++++++++++++++++ 5 files changed, 141 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,uint8_t *buf,int reg); +int avr_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);#define cpu_list avr_cpu_list#define cpu_signal_handler cpu_avr_signal_handler
target/avr/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 +2 -0
@@ -167,11 +167,13 @@ AVR TCG CPUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: gdb-xml/avr-cpu.xml F: target/avr/cpu-param.h F: target/avr/cpu-qom.h F: target/avr/cpu.h F: target/avr/cpu.c F: target/avr/helper.c +F: target/avr/gdbstub.c F: target/avr/machine.c CRIS TCG CPUs
gdb-xml/avr-cpu.xml new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 7/32 target/avr: Introduce enumeration AVRFeature
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This patch introduces enumeration "AVRFeature" that will be used for defining various AVR core types.
--- 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,uint8_t *buf,int reg);int avr_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); +static inline int avr_feature (CPUAVRState *env,AVRFeature feature) +{ +return (env->features & (1U << feature)) !=0 ; +} + +static inline void set_avr_feature (CPUAVRState *env,int feature) +{ + env->features |= (1U << feature); +} +#define cpu_list avr_cpu_list#define cpu_signal_handler cpu_avr_signal_handler#define cpu_mmu_index avr_cpu_mmu_index
Signature · 1 line
2.7.4
PATCH 8/32 target/avr: Add defintions of AVR core types
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
AVR core types are:
- avr1
- avr2
- avr25
- avr3
- avr31
- avr35
- avr4
- avr5
- avr51
- avr6
- avrtiny
- xmega2
- xmega3
- xmega4
- xmega5
- xmega6
- xmega7
Each core type covers multiple AVR MCUs, mentioned in the comments before definition of particular AVR core type (part of this patch).
AVR core type defines shared features that are valid for all AVR MCUs belonging in that type.
--- target/avr/cpu.c | 560 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 560 insertions(+)
target/avr/cpu.c +560 -0
@@ -215,3 +215,563 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_num_core_regs =35 ; cc->gdb_core_xml_file ="avr-cpu.xml" ; } + +/* +* Setting features of AVR core type avr1 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* at90s1200, attiny11, attiny12, attiny15, attiny28 +*/ +static void avr_avr1_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +} + +/* +* Setting features of AVR core type avr2 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414, +* at90s4433, at90s4434, at90s8515, at90c8534, at90s8535 +*/ +static void avr_avr2_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +} + +/* +* Setting features of AVR core type avr25 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, +* attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a, +* attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a, +* attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828, +* attiny841, at86rf401 +*/ +static void avr_avr25_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +} + +/* +* Setting features of AVR core type avr3 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* at43usb355, at76c711 +*/ +static void avr_avr3_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +} + +/* +* Setting features of AVR core type avr31 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atmega103, at43usb320 +*/ +static void avr_avr31_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +} + +/* +* Setting features of AVR core type avr35 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* ata5505, ata6617c, ata664251, at90usb82, at90usb162, atmega8u2, atmega16u2, +* atmega32u2, attiny167, attiny1634 +*/ +static void avr_avr35_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +} + +/* +* Setting features of AVR core type avr4 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* ata6285, ata6286, ata6289, ata6612c, atmega8, atmega8a, atmega48, atmega48a, +* atmega48p, atmega48pa, atmega48pb, atmega88, atmega88a, atmega88p, +* atmega88pa, atmega88pb, atmega8515, atmega8535, atmega8hva, at90pwm1, +* at90pwm2, at90pwm2b, at90pwm3, at90pwm3b, at90pwm81 +*/ +static void avr_avr4_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +} + +/* +* Setting features of AVR core type avr5 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* ata5702m322, ata5782, ata5790, ata5790n, ata5791, ata5795, ata5831, ata6613c, +* ata6614q, ata8210, ata8510, atmega16, atmega16a, atmega161, atmega162, +* atmega163, atmega164a, atmega164p, atmega164pa, atmega165, atmega165a, +* atmega165p, atmega165pa, atmega168, atmega168a, atmega168p, atmega168pa, +* atmega168pb, atmega169, atmega169a, atmega169p, atmega169pa, atmega16hvb, +* atmega16hvbrevb, atmega16m1, atmega16u4, atmega32a, atmega32, atmega323, +* atmega324a, atmega324p, atmega324pa, atmega325, atmega325a, atmega325p, +* atmega325pa, atmega3250, atmega3250a, atmega3250p, atmega3250pa, atmega328, +* atmega328p, atmega328pb, atmega329, atmega329a, atmega329p, atmega329pa, +* atmega3290, atmega3290a, atmega3290p, atmega3290pa, atmega32c1, atmega32m1, +* atmega32u4, atmega32u6, atmega406, atmega64, atmega64a, atmega640, atmega644, +* atmega644a, atmega644p, atmega644pa, atmega645, atmega645a, atmega645p, +* atmega6450, atmega6450a, atmega6450p, atmega649, atmega649a, atmega649p, +* atmega6490, atmega16hva, atmega16hva2, atmega32hvb, atmega6490a, atmega6490p, +* atmega64c1, atmega64m1, atmega64hve, atmega64hve2, atmega64rfr2, +* atmega644rfr2, atmega32hvbrevb, at90can32, at90can64, at90pwm161, at90pwm216, +* at90pwm316, at90scr100, at90usb646, at90usb647, at94k, m3000 +*/ +static void avr_avr5_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +} + +/* +* Setting features of AVR core type avr51 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atmega128, atmega128a, atmega1280, atmega1281, atmega1284, atmega1284p, +* atmega128rfa1, atmega128rfr2, atmega1284rfr2, at90can128, at90usb1286, +* at90usb1287 +*/ +static void avr_avr51_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +} + +/* +* Setting features of AVR core type avr6 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atmega2560, atmega2561, atmega256rfr2, atmega2564rfr2 +*/ +static void avr_avr6_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_3_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_EIJMP_EICALL ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +} + +/* +* Setting features of AVR core type avrtiny +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* attiny4, attiny5, attiny9, attiny10, attiny20, attiny40 +*/ +static void avr_avrtiny_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_1_BYTE_SP ); +} + +/* +* Setting features of AVR core type xmega2 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atxmega8e5, atxmega16a4, atxmega16d4, atxmega16e5, atxmega32a4, atxmega32c3, +* atxmega32d3, atxmega32d4, atxmega16a4u, atxmega16c4, atxmega32a4u, +* atxmega32c4, atxmega32e5 +*/ +static void avr_xmega2_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +/* +* Setting features of AVR core type xmega3 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* attiny212, attiny214, attiny412, attiny414, attiny416, attiny417, attiny814, +* attiny816, attiny817, attiny1614, attiny1616, attiny1617, attiny3214, +* attiny3216, attiny3217, atmega808, atmega809, atmega1608, atmega1609, +* atmega3208, atmega3209, atmega4808, atmega4809 +*/ +static void avr_xmega3_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +/* +* Setting features of AVR core type xmega4 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atxmega64a3, atxmega64d3, atxmega64a3u, atxmega64a4u, atxmega64b1, +* atxmega64b3, atxmega64c3, atxmega64d4 +*/ +static void avr_xmega4_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +/* +* Setting features of AVR core type xmega5 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atxmega64a1, atxmega64a1u +*/ +static void avr_xmega5_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPD ); +set_avr_feature (env,AVR_FEATURE_RAMPX ); +set_avr_feature (env,AVR_FEATURE_RAMPY ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +/* +* Setting features of AVR core type xmega6 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atxmega128a3, atxmega128d3, atxmega192a3, atxmega192d3, atxmega256a3, +* atxmega256a3b, atxmega256a3bu, atxmega256d3, atxmega128a3u, atxmega128b1, +* atxmega128b3, atxmega128c3, atxmega128d4, atxmega192a3u, atxmega192c3, +* atxmega256a3u, atxmega256c3, atxmega384c3, atxmega384d3 +*/ +static void avr_xmega6_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_3_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_EIJMP_EICALL ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +/* +* Setting features of AVR core type xmega7 +* -------------------------------------- +* +* This type of AVR core is present in the following AVR MCUs: +* +* atxmega128a1, atxmega128a1u, atxmega128a4u +*/ +static void avr_xmega7_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +set_avr_feature (env,AVR_FEATURE_LPM ); +set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); +set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); +set_avr_feature (env,AVR_FEATURE_SRAM ); +set_avr_feature (env,AVR_FEATURE_BREAK ); + +set_avr_feature (env,AVR_FEATURE_3_BYTE_PC ); +set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); +set_avr_feature (env,AVR_FEATURE_RAMPD ); +set_avr_feature (env,AVR_FEATURE_RAMPX ); +set_avr_feature (env,AVR_FEATURE_RAMPY ); +set_avr_feature (env,AVR_FEATURE_RAMPZ ); +set_avr_feature (env,AVR_FEATURE_EIJMP_EICALL ); +set_avr_feature (env,AVR_FEATURE_ELPMX ); +set_avr_feature (env,AVR_FEATURE_ELPM ); +set_avr_feature (env,AVR_FEATURE_JMP_CALL ); +set_avr_feature (env,AVR_FEATURE_LPMX ); +set_avr_feature (env,AVR_FEATURE_MOVW ); +set_avr_feature (env,AVR_FEATURE_MUL ); +set_avr_feature (env,AVR_FEATURE_RMW ); +} + +typedef struct AVRCPUInfo { +const char *name; +void (*initfn)(Object *obj); +}AVRCPUInfo ; + + +static void avr_cpu_list_entry (gpointer data,gpointer user_data) +{ +const char *typename =object_class_get_name (OBJECT_CLASS (data)); + +qemu_printf ("%s\n" , typename); +} + +void avr_cpu_list (void ) +{ +GSList *list; + list =object_class_get_list_sorted (TYPE_AVR_CPU , false); +g_slist_foreach (list, avr_cpu_list_entry,NULL ); +g_slist_free (list); +} + +#define DEFINE_AVR_CPU_TYPE (model, initfn) \ + { \ + .parent = TYPE_AVR_CPU, \ + .instance_init = initfn, \ + .name = AVR_CPU_TYPE_NAME(model), \ + } + +static const TypeInfo avr_cpu_type_info[] = { + { + .name =TYPE_AVR_CPU , + .parent =TYPE_CPU , + .instance_size =sizeof (AVRCPU ), + .instance_init = avr_cpu_initfn, + .class_size =sizeof (AVRCPUClass), + .class_init = avr_cpu_class_init, + .abstract = true, + }, +DEFINE_AVR_CPU_TYPE ("avrtiny" , avr_avrtiny_initfn), +DEFINE_AVR_CPU_TYPE ("avr1" , avr_avr1_initfn), +DEFINE_AVR_CPU_TYPE ("avr2" , avr_avr2_initfn), +DEFINE_AVR_CPU_TYPE ("avr25" , avr_avr25_initfn), +DEFINE_AVR_CPU_TYPE ("avr3" , avr_avr3_initfn), +DEFINE_AVR_CPU_TYPE ("avr31" , avr_avr31_initfn), +DEFINE_AVR_CPU_TYPE ("avr35" , avr_avr35_initfn), +DEFINE_AVR_CPU_TYPE ("avr4" , avr_avr4_initfn), +DEFINE_AVR_CPU_TYPE ("avr5" , avr_avr5_initfn), +DEFINE_AVR_CPU_TYPE ("avr51" , avr_avr51_initfn), +DEFINE_AVR_CPU_TYPE ("avr6" , avr_avr6_initfn), +DEFINE_AVR_CPU_TYPE ("xmega2" , avr_xmega2_initfn), +DEFINE_AVR_CPU_TYPE ("xmega3" , avr_xmega3_initfn), +DEFINE_AVR_CPU_TYPE ("xmega4" , avr_xmega4_initfn), +DEFINE_AVR_CPU_TYPE ("xmega5" , avr_xmega5_initfn), +DEFINE_AVR_CPU_TYPE ("xmega6" , avr_xmega6_initfn), +DEFINE_AVR_CPU_TYPE ("xmega7" , avr_xmega7_initfn), +}; + + +DEFINE_TYPES (avr_cpu_type_info)
Signature · 1 line
2.7.4
PATCH 1/1 !fixup "target/avr: Add defintions of AVR core types"
These cores have unresolved review comment:
https://www.mail-archive.com/[email protected]/msg674105.html
https://www.mail-archive.com/[email protected]/msg674259.html
and:
https://www.mail-archive.com/[email protected]/msg676046.html
As we don't want a bad start with this architecture, remove them.
---
Based-on: <[email protected]>
Side note: typo in the subject "definitions"
--- target/avr/cpu.c | 96 ------------------------------------------------ 1 file changed, 96 deletions(-)
target/avr/cpu.c +0 -96
@@ -216,77 +216,6 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_core_xml_file ="avr-cpu.xml" ; } -/* -* Setting features of AVR core type avr1 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* at90s1200, attiny11, attiny12, attiny15, attiny28 -*/ -static void avr_avr1_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -} - -/* -* Setting features of AVR core type avr2 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414, -* at90s4433, at90s4434, at90s8515, at90c8534, at90s8535 -*/ -static void avr_avr2_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); -set_avr_feature (env,AVR_FEATURE_SRAM ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -} - -/* -* Setting features of AVR core type avr25 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, -* attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a, -* attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a, -* attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828, -* attiny841, at86rf401 -*/ -static void avr_avr25_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); -set_avr_feature (env,AVR_FEATURE_SRAM ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -set_avr_feature (env,AVR_FEATURE_LPMX ); -set_avr_feature (env,AVR_FEATURE_MOVW ); -} -/* * Setting features of AVR core type avr3 * --------------------------------------
@@ -499,27 +428,6 @@ static void avr_avr6_initfn(Object *obj)set_avr_feature (env,AVR_FEATURE_MUL ); } -/* -* Setting features of AVR core type avrtiny -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* attiny4, attiny5, attiny9, attiny10, attiny20, attiny40 -*/ -static void avr_avrtiny_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_1_BYTE_SP ); -} -/* * Setting features of AVR core type xmega2 * --------------------------------------
@@ -754,10 +662,6 @@ static const TypeInfo avr_cpu_type_info[] = { .class_init = avr_cpu_class_init, .abstract = true, }, -DEFINE_AVR_CPU_TYPE ("avrtiny" , avr_avrtiny_initfn), -DEFINE_AVR_CPU_TYPE ("avr1" , avr_avr1_initfn), -DEFINE_AVR_CPU_TYPE ("avr2" , avr_avr2_initfn), -DEFINE_AVR_CPU_TYPE ("avr25" , avr_avr25_initfn),DEFINE_AVR_CPU_TYPE ("avr3" , avr_avr3_initfn),DEFINE_AVR_CPU_TYPE ("avr31" , avr_avr31_initfn), DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
Signature · 1 line
2.21.1
Re: [PATCH] !fixup "target/avr: Add defintions of AVR core types"
Quoted 9 lines · Philippe Mathieu-Daudé
These cores have unresolved review comment:
https://www.mail-archive.com/[email protected]/msg674105.html
https://www.mail-archive.com/[email protected]/msg674259.html
and:
https://www.mail-archive.com/[email protected]/msg676046.htmlAs we don't want a bad start with this architecture, remove them.
I agree with underlying motivation of your fixup.
Still, the division of AVR cores into avr1, avr2, ... , xmega7 is here to stay. The reason is that because such coding is a part of ELF header, and this means they will stay forever (as they are approved by some kind of ELF comitee, and are meant not to be ever changed in future).
Rather than deleting definitions and references of core types we know we don't support (or, at least, don't fully support), let's think of some less intrusive way - for example, checking core type of executable given via CLI, and refusing to emulate, if we know we still have some issues with the core type in question.
For example, "avrtiny" type is missing handling the fact that it has 16 register instead of 32 registers, like otger AVR core types. But, other AVRFeatures of "avrtiny" are correctly identified, and it would be a shame to delete them now and force someone in future to reinvent the wheel. Just refusing to emulate "avrtiny" seems a better approach to me.
Aleksandar
Quoted 140 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Based-on: <[email protected]>Side note: typo in the subject "definitions"
--- target/avr/cpu.c | 96 ------------------------------------------------ 1 file changed, 96 deletions(-)target/avr/cpu.c +0
-50@@ -216,77 +216,6 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_core_xml_file ="avr-cpu.xml" ; } -/* -* Setting features of AVR core type avr1 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* at90s1200, attiny11, attiny12, attiny15, attiny28 -*/ -static void avr_avr1_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -} - -/* -* Setting features of AVR core type avr2 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at90s4414, -* at90s4433, at90s4434, at90s8515, at90c8534, at90s8535 -*/ -static void avr_avr2_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); -set_avr_feature (env,AVR_FEATURE_SRAM ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -} - -/* -* Setting features of AVR core type avr25 -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, -* attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84, attiny84a,
- * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461, attiny461a,
- * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88, attiny828,
- * attiny841, at86rf401
- */target/avr/cpu.c +0
-43-static void avr_avr25_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_ADIW_SBIW ); -set_avr_feature (env,AVR_FEATURE_SRAM ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_2_BYTE_SP ); -set_avr_feature (env,AVR_FEATURE_LPMX ); -set_avr_feature (env,AVR_FEATURE_MOVW ); -} -/* * Setting features of AVR core type avr3 * -------------------------------------- @@ -499,27 +428,6 @@ static void avr_avr6_initfn(Object *obj)set_avr_feature (env,AVR_FEATURE_MUL ); } -/* -* Setting features of AVR core type avrtiny -* -------------------------------------- -* -* This type of AVR core is present in the following AVR MCUs: -* -* attiny4, attiny5, attiny9, attiny10, attiny20, attiny40 -*/ -static void avr_avrtiny_initfn (Object *obj) -{ -AVRCPU *cpu =AVR_CPU (obj); -CPUAVRState *env = &cpu->env; - -set_avr_feature (env,AVR_FEATURE_LPM ); -set_avr_feature (env,AVR_FEATURE_IJMP_ICALL ); -set_avr_feature (env,AVR_FEATURE_BREAK ); - -set_avr_feature (env,AVR_FEATURE_2_BYTE_PC ); -set_avr_feature (env,AVR_FEATURE_1_BYTE_SP ); -} -/* * Setting features of AVR core type xmega2 * -------------------------------------- @@ -754,10 +662,6 @@ static const TypeInfo avr_cpu_type_info[] = { .class_init = avr_cpu_class_init, .abstract = true, }, -DEFINE_AVR_CPU_TYPE ("avrtiny" , avr_avrtiny_initfn), -DEFINE_AVR_CPU_TYPE ("avr1" , avr_avr1_initfn), -DEFINE_AVR_CPU_TYPE ("avr2" , avr_avr2_initfn), -DEFINE_AVR_CPU_TYPE ("avr25" , avr_avr25_initfn),DEFINE_AVR_CPU_TYPE ("avr3" , avr_avr3_initfn),DEFINE_AVR_CPU_TYPE ("avr31" , avr_avr31_initfn), DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn), --2.21.1
Re: [PATCH] !fixup "target/avr: Add defintions of AVR core types"
Hi Aleksandar,
Quoted 15 lines · Aleksandar Markovic
On Friday, February 7, 2020, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
These cores have unresolved review comment: https://www.mail-archive.com/[email protected]/msg674105.html <https://www.mail-archive.com/[email protected]/msg674105.html> https://www.mail-archive.com/[email protected]/msg674259.html <https://www.mail-archive.com/[email protected]/msg674259.html> and: https://www.mail-archive.com/[email protected]/msg676046.html <https://www.mail-archive.com/[email protected]/msg676046.html> As we don't want a bad start with this architecture, remove them.
Quoted 6 lines
I agree with underlying motivation of your fixup.
Still, the division of AVR cores into avr1, avr2, ... , xmega7 is here to stay. The reason is that because such coding is a part of ELF header, and this means they will stay forever (as they are approved by some kind of ELF comitee, and are meant not to be ever changed in future).
I am not removing anything ELF related. We don't have any machine using CPU avrtiny/avr1/avr2/avr25 so AFAIK I'm simply removing unreviewed dead code.
Quoted 11 lines
Rather than deleting definitions and references of core types we know we don't support (or, at least, don't fully support), let's think of some less intrusive way - for example, checking core type of executable given via CLI, and refusing to emulate, if we know we still have some issues with the core type in question.
For example, "avrtiny" type is missing handling the fact that it has 16 register instead of 32 registers, like otger AVR core types. But, other AVRFeatures of "avrtiny" are correctly identified, and it would be a shame to delete them now and force someone in future to reinvent the wheel. Just refusing to emulate "avrtiny" seems a better approach to me.
It is hard to follow you, this port is contributed by hobbyist and you appeared lately in the review process and asked to raised the quality to a professional level. Now professionals are taking extra care to review little details as the CPU features implemented by each core, and you are saying we shouldn't delete incorrect code?
I am not saying we will never accept these cores, I'm proposing to start with reviewed cores, so we don't delay the merge if this port. There are already a lot of cores to use:
DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
DEFINE_AVR_CPU_TYPE("avr4", avr_avr4_initfn),
DEFINE_AVR_CPU_TYPE("avr5", avr_avr5_initfn),
DEFINE_AVR_CPU_TYPE("avr51", avr_avr51_initfn),
DEFINE_AVR_CPU_TYPE("avr6", avr_avr6_initfn),
DEFINE_AVR_CPU_TYPE("xmega2", avr_xmega2_initfn),
DEFINE_AVR_CPU_TYPE("xmega3", avr_xmega3_initfn),
DEFINE_AVR_CPU_TYPE("xmega4", avr_xmega4_initfn),
DEFINE_AVR_CPU_TYPE("xmega5", avr_xmega5_initfn),
DEFINE_AVR_CPU_TYPE("xmega6", avr_xmega6_initfn),
DEFINE_AVR_CPU_TYPE("xmega7", avr_xmega7_initfn),Then it will be less stressful to correct/review/add the avr1/2/tiny cores. This seems simpler than keep respining 30 patches during the next 6 months. I don't want the community to get tired and loose interest in this port, we already spent a fair amount of time to get it merged.
Regards,
Phil.
Quoted 143 lines
Signed-off-by: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>
---
Based-on:
<[email protected]
<mailto:[email protected]>>
Side note: typo in the subject "definitions"
---
target/avr/cpu.c | 96 ------------------------------------------------
1 file changed, 96 deletions(-)
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 8a084c750f..b3d661142d 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -216,77 +216,6 @@ static void avr_cpu_class_init(ObjectClass *oc,
void *data)
cc->gdb_core_xml_file = "avr-cpu.xml";
}
-/*
- * Setting features of AVR core type avr1
- * --------------------------------------
- *
- * This type of AVR core is present in the following AVR MCUs:
- *
- * at90s1200, attiny11, attiny12, attiny15, attiny28
- */
-static void avr_avr1_initfn(Object *obj)
-{
- AVRCPU *cpu = AVR_CPU(obj);
- CPUAVRState *env = &cpu->env;
-
- set_avr_feature(env, AVR_FEATURE_LPM);
- set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
- set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
-}
-
-/*
- * Setting features of AVR core type avr2
- * --------------------------------------
- *
- * This type of AVR core is present in the following AVR MCUs:
- *
- * at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26,
at90s4414,
- * at90s4433, at90s4434, at90s8515, at90c8534, at90s8535
- */
-static void avr_avr2_initfn(Object *obj)
-{
- AVRCPU *cpu = AVR_CPU(obj);
- CPUAVRState *env = &cpu->env;
-
- set_avr_feature(env, AVR_FEATURE_LPM);
- set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
- set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
- set_avr_feature(env, AVR_FEATURE_SRAM);
- set_avr_feature(env, AVR_FEATURE_BREAK);
-
- set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
- set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
-}
-
-/*
- * Setting features of AVR core type avr25
- * --------------------------------------
- *
- * This type of AVR core is present in the following AVR MCUs:
- *
- * ata5272, ata6616c, attiny13, attiny13a, attiny2313, attiny2313a,
attiny24,
- * attiny24a, attiny4313, attiny44, attiny44a, attiny441, attiny84,
attiny84a,
- * attiny25, attiny45, attiny85, attiny261, attiny261a, attiny461,
attiny461a,
- * attiny861, attiny861a, attiny43u, attiny87, attiny48, attiny88,
attiny828,
- * attiny841, at86rf401
- */
-static void avr_avr25_initfn(Object *obj)
-{
- AVRCPU *cpu = AVR_CPU(obj);
- CPUAVRState *env = &cpu->env;
-
- set_avr_feature(env, AVR_FEATURE_LPM);
- set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
- set_avr_feature(env, AVR_FEATURE_ADIW_SBIW);
- set_avr_feature(env, AVR_FEATURE_SRAM);
- set_avr_feature(env, AVR_FEATURE_BREAK);
-
- set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
- set_avr_feature(env, AVR_FEATURE_2_BYTE_SP);
- set_avr_feature(env, AVR_FEATURE_LPMX);
- set_avr_feature(env, AVR_FEATURE_MOVW);
-}
-
/*
* Setting features of AVR core type avr3
* --------------------------------------
@@ -499,27 +428,6 @@ static void avr_avr6_initfn(Object *obj)
set_avr_feature(env, AVR_FEATURE_MUL);
}
-/*
- * Setting features of AVR core type avrtiny
- * --------------------------------------
- *
- * This type of AVR core is present in the following AVR MCUs:
- *
- * attiny4, attiny5, attiny9, attiny10, attiny20, attiny40
- */
-static void avr_avrtiny_initfn(Object *obj)
-{
- AVRCPU *cpu = AVR_CPU(obj);
- CPUAVRState *env = &cpu->env;
-
- set_avr_feature(env, AVR_FEATURE_LPM);
- set_avr_feature(env, AVR_FEATURE_IJMP_ICALL);
- set_avr_feature(env, AVR_FEATURE_BREAK);
-
- set_avr_feature(env, AVR_FEATURE_2_BYTE_PC);
- set_avr_feature(env, AVR_FEATURE_1_BYTE_SP);
-}
-
/*
* Setting features of AVR core type xmega2
* --------------------------------------
@@ -754,10 +662,6 @@ static const TypeInfo avr_cpu_type_info[] = {
.class_init = avr_cpu_class_init,
.abstract = true,
},
- DEFINE_AVR_CPU_TYPE("avrtiny", avr_avrtiny_initfn),
- DEFINE_AVR_CPU_TYPE("avr1", avr_avr1_initfn),
- DEFINE_AVR_CPU_TYPE("avr2", avr_avr2_initfn),
- DEFINE_AVR_CPU_TYPE("avr25", avr_avr25_initfn),
DEFINE_AVR_CPU_TYPE("avr3", avr_avr3_initfn),
DEFINE_AVR_CPU_TYPE("avr31", avr_avr31_initfn),
DEFINE_AVR_CPU_TYPE("avr35", avr_avr35_initfn),
--
2.21.1Re: [PATCH] !fixup "target/avr: Add defintions of AVR core types"
Quoted 21 lines · Philippe Mathieu-Daudé
Hi Aleksandar,
Quoted 17 lines · Aleksandar Markovic
On Friday, February 7, 2020, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
These cores have unresolved review comment: https://www.mail-archive.com/[email protected]/msg674105.html <https://www.mail-archive.com/[email protected]/msg674105.html> https://www.mail-archive.com/[email protected]/msg674259.html <https://www.mail-archive.com/[email protected]/msg674259.html> and: https://www.mail-archive.com/[email protected]/msg676046.html <https://www.mail-archive.com/[email protected]/msg676046.html> As we don't want a bad start with this architecture, remove them.I agree with underlying motivation of your fixup.
Quoted 9 lines
Quoted 4 lines
Still, the division of AVR cores into avr1, avr2, ... , xmega7 is here to stay. The reason is that because such coding is a part of ELF header, and this means they will stay forever (as they are approved by some kind of ELF comitee, and are meant not to be ever changed in future).
I am not removing anything ELF related. We don't have any machine using CPU avrtiny/avr1/avr2/avr25 so AFAIK I'm simply removing unreviewed dead code.
The portion of the code that classifies AVR cores is and should remain as independent as possible of the machine-related code. In other words, my point is that your fixup is inadequate. We should not touch the portion of the code that enumarates AVR core types, except to add some TODO notes as noted during review. If one wants to remove "dead" code as defined by you, one should leave just two AVR core types and also eliminate at least half of "AVRFeatures", which is absurd.
There is much less intrusive solution to this, that will also provide guarantee that we never emulate the code that we know has some issues, or support for it is not completed yet.
You should read more carefully previous reviews, and you'll see that Michael and I agreed that support for "avrtiny" cores will be provided in some point in future, but this doesn't mean we should delete that AVR type from the current code.
I hope I am clear enough to you now. :)
Regards,
Aleksandar
PATCH 9/32 target/avr: Add instruction helpers
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Add helpers for instructions that need to interact with QEMU. Also, add stubs for unimplemented instructions. Instructions SPM and WDR are left unimplemented because they require emulation of complex peripherals. The implementation of instruction SLEEP is very limited due to the lack of peripherals to generate wake interrupts. Memory access instructions are implemented here because some address ranges actually refer to CPU registers.
--- target/avr/helper.h | 29 ++++++++ target/avr/helper.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 233 insertions(+) create mode 100644 target/avr/helper.h
target/avr/helper.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +DEF_HELPER_1(wdr, void, env) +DEF_HELPER_1(debug, void, env) +DEF_HELPER_1(break, void, env) +DEF_HELPER_1(sleep, void, env) +DEF_HELPER_1(unsupported, void, env) +DEF_HELPER_3(outb, void, env, i32, i32) +DEF_HELPER_2(inb, tl, env, i32) +DEF_HELPER_3(fullwr, void, env, i32, i32) +DEF_HELPER_2 (fullrd, tl, env, i32)
target/avr/helper.c +203 -0
206 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -172,6 +172,7 @@ F: target/avr/cpu-param.h F: target/avr/cpu-qom.h F: target/avr/cpu.h F: target/avr/cpu.c +F: target/avr/helper.h F: target/avr/helper.c F: target/avr/gdbstub.c F: target/avr/machine.c
Signature · 1 line
2.7.4
PATCH 10/32 target/avr: Add instruction translation - Register definitions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Start implementation of instructions by adding register definitions.
--- target/avr/translate.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 144 insertions(+) create mode 100644 target/avr/translate.c
target/avr/translate.c new file +143 -0
@@ -0,0 +1,143 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2019 Michael Rolnik +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#include "qemu/osdep.h" +#include "qemu/qemu-print.h" +#include "tcg/tcg.h" +#include "cpu.h" +#include "exec/exec-all.h" +#include "tcg/tcg-op.h" +#include "exec/cpu_ldst.h" +#include "exec/helper-proto.h" +#include "exec/helper-gen.h" +#include "exec/log.h" +#include "exec/translator.h" +#include "exec/gen-icount.h" + +/* +* Define if you want a BREAK instruction translated to a breakpoint +* Active debugging connection is assumed +* This is for +* https://github.com/seharris/qemu-avr-tests/tree/master/instruction-tests +* tests +*/ +#undef BREAKPOINT_ON_BREAK + +static TCGv cpu_pc; + +static TCGv cpu_Cf; +static TCGv cpu_Zf; +static TCGv cpu_Nf; +static TCGv cpu_Vf; +static TCGv cpu_Sf; +static TCGv cpu_Hf; +static TCGv cpu_Tf; +static TCGv cpu_If; + +static TCGv cpu_rampD; +static TCGv cpu_rampX; +static TCGv cpu_rampY; +static TCGv cpu_rampZ; + +static TCGv cpu_r[NUMBER_OF_CPU_REGISTERS ]; +static TCGv cpu_eind; +static TCGv cpu_sp; + +static TCGv cpu_skip; + +static const char reg_names[NUMBER_OF_CPU_REGISTERS ][8 ] = { +"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" , +"r8" ,"r9" ,"r10" ,"r11" ,"r12" ,"r13" ,"r14" ,"r15" , +"r16" ,"r17" ,"r18" ,"r19" ,"r20" ,"r21" ,"r22" ,"r23" , +"r24" ,"r25" ,"r26" ,"r27" ,"r28" ,"r29" ,"r30" ,"r31" , +}; +#define REG (x) (cpu_r[x]) + +enum { +DISAS_EXIT =DISAS_TARGET_0 ,/* We want return to the cpu main loop. */ +DISAS_LOOKUP =DISAS_TARGET_1 ,/* We have a variable condition exit. */ +DISAS_CHAIN =DISAS_TARGET_2 ,/* We have a single condition exit. */ +}; + +typedef struct DisasContext DisasContext ; + +/* This is the state at translation time. */ +struct DisasContext { +TranslationBlock *tb; + +CPUAVRState *env; +CPUState *cs; + +target_long npc; +uint32_t opcode; + +/* Routine used to access memory */ +int memidx; +int bstate; +int singlestep; + +/* +* some AVR instructions can make the following instruction to be skipped +* Let's name those instructions +* A - instruction that can skip the next one +* B - instruction that can be skipped. this depends on execution of A +* there are two scenarios +* 1. A and B belong to the same translation block +* 2. A is the last instruction in the translation block and B is the last +* +* following variables are used to simplify the skipping logic, they are +* used in the following manner (sketch) +* +* TCGLabel *skip_label = NULL; +* if (ctx.skip_cond != TCG_COND_NEVER) { +* skip_label = gen_new_label(); +* tcg_gen_brcond_tl(skip_cond, skip_var0, skip_var1, skip_label); +* } +* +* if (free_skip_var0) { +* tcg_temp_free(skip_var0); +* free_skip_var0 = false; +* } +* +* translate(&ctx); +* +* if (skip_label) { +* gen_set_label(skip_label); +* } +*/ +TCGv skip_var0; +TCGv skip_var1; +TCGCond skip_cond; +bool free_skip_var0; +}; + + +static 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"
MAINTAINERS +1 -0
@@ -176,6 +176,7 @@ F: target/avr/helper.h F: target/avr/helper.c F: target/avr/gdbstub.c F: target/avr/machine.c +F: target/avr/translate.c CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
Signature · 1 line
2.7.4
PATCH 11/32 target/avr: Add instruction translation - Arithmetic and Logic Instructions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes:
- ADD, ADC, ADIW
- SBIW, SUB, SUBI, SBC, SBCI
- AND, ANDI
- OR, ORI, EOR
- COM, NEG
- INC, DEC
- MUL, MULS, MULSU
- FMUL, FMULS, FMULSU
- DES
--- target/avr/insn.decode | 76 +++++ target/avr/translate.c | 823 +++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 900 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 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 +823 -0
832 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -177,6 +177,7 @@ F: target/avr/helper.c F: target/avr/gdbstub.c F: target/avr/machine.c F: target/avr/translate.c +F: target/avr/insn.decode CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]>
Signature · 1 line
2.7.4
PATCH 12/32 target/avr: Add instruction translation - Branch Instructions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes:
- RJMP, IJMP, EIJMP, JMP
- RCALL, ICALL, EICALL, CALL
- RET, RETI
- CPSE, CP, CPC, CPI
- SBRC, SBRS, SBIC, SBIS
- BRBC, BRBS
--- target/avr/insn.decode | 33 +++ target/avr/translate.c | 544 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 577 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 +544 -0
553 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 13/32 target/avr: Add instruction translation - Data Transfer Instructions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes:
- MOV, MOVW
- LDI, LDS LDX LDY LDZ
- LDDY, LDDZ
- STS, STX STY STZ
- STDY, STDZ
- LPM, LPMX
- ELPM, ELPMX
- SPM, SPMX
- IN, OUT
- PUSH, POP
- XCH
- LAS, LAC LAT
--- target/avr/insn.decode | 56 +++ target/avr/translate.c | 992 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1048 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 +992 -0
1,001 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 14/32 target/avr: Add instruction translation - Bit and Bit-test Instructions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes:
- LSR, ROR
- ASR
- SWAP
- SBI, CBI
- BST, BLD
- BSET, BCLR
--- target/avr/insn.decode | 14 +++ target/avr/translate.c | 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.7.4
PATCH 15/32 target/avr: Add instruction translation - MCU Control Instructions
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
This includes:
- BREAK
- NOP
- SLEEP
- WDR
--- target/avr/insn.decode | 8 ++++++ target/avr/translate.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
target/avr/insn.decode +8 -0
@@ -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 +68 -0
71 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 16/32 target/avr: Add instruction translation - CPU main translation function
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Add the core of translation mechanism.
--- target/avr/translate.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+)
target/avr/translate.c +214 -0
@@ -2815,3 +2815,217 @@ 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.7.4
PATCH 17/32 target/avr: Initialize TCG register variables
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Initialize TCG register variables.
--- target/avr/translate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
target/avr/translate.c +30 -0
@@ -129,6 +129,36 @@ struct DisasContext { }; +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.7.4
PATCH 18/32 target/avr: Add support for disassembling via option '-d in_asm'
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Provide function disassembles executed instruction when -d in_asm is provided
Example:./avr-softmmu/qemu-system-avr -bios free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf -d in_asm will produce something like the following
```
...
IN:
0x0000014a: CALL 0x3808
IN: main
0x00003808: CALL 0x4b4
IN: vParTestInitialise
0x000004b4: LDI r24, 255
0x000004b6: STS r24, 0
0x000004b8: MULS r16, r20
0x000004ba: OUT $1, r24
0x000004bc: LDS r24, 0
0x000004be: MULS r16, r20
0x000004c0: OUT $2, r24
0x000004c2: RET
...
```--- target/avr/cpu.h | 1 + target/avr/cpu.c | 2 +- target/avr/disas.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++++ target/avr/translate.c | 12 +++ MAINTAINERS | 1 + 5 files changed, 261 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,uint8_t *buf,int reg);int avr_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); +int avr_print_insn (bfd_vma addr,disassemble_info *info);static inline int avr_feature (CPUAVRState *env,AVRFeature feature) {
target/avr/cpu.c +1 -1
@@ -84,7 +84,7 @@ static void avr_cpu_reset(CPUState *cs)static void avr_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) { info->mach = bfd_arch_avr; - info->print_insn =NULL ; + info->print_insn = avr_print_insn; }static void avr_cpu_realizefn (DeviceState *dev,Error **errp)
target/avr/disas.c new file +246 -0
246 lines not on this page · raw message
target/avr/translate.c +12 -0
@@ -3052,6 +3052,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,
MAINTAINERS +1 -0
@@ -172,6 +172,7 @@ F: target/avr/cpu-param.h F: target/avr/cpu-qom.h F: target/avr/cpu.h F: target/avr/cpu.c +F: target/avr/disas.c F: target/avr/helper.h F: target/avr/helper.c F: target/avr/gdbstub.c
Signature · 1 line
2.7.4
PATCH 19/32 hw/char: avr: Add limited support for USART peripheral
In reply to Aleksandar MarkovicFrom: 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).
--- include/hw/char/avr_usart.h | 93 +++++++++++++ hw/char/avr_usart.c | 320 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 10 ++ hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + 5 files changed, 427 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 +10 -0
@@ -905,6 +905,16 @@ 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: include/hw/char/avr_usart.h +F: hw/char/avr_usart.c + CRIS Machines ------------- Axis Dev88
hw/char/Kconfig +3 -0
@@ -46,3 +46,6 @@ config SCLPCONSOLE config TERMINAL3270 bool + +config AVR_USART + bool
hw/char/Makefile.objs +1 -0
@@ -20,6 +20,7 @@ common-obj-$(CONFIG_SH4) += sh_serial.o 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_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.7.4
PATCH 20/32 hw/timer: avr: Add limited support for 16-bit timer peripheral
In reply to Aleksandar MarkovicFrom: 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).
--- include/hw/timer/avr_timer16.h | 94 +++++++ hw/timer/avr_timer16.c | 609 +++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + hw/timer/trace-events | 12 + 6 files changed, 722 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 +609 -0
609 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -914,6 +914,8 @@ R: Sarah Harris <[email protected]> S: Maintained 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
@@ -35,3 +35,6 @@ config CMSDK_APB_TIMER config CMSDK_APB_DUALTIMER bool select PTIMER + +config AVR_TIMER16 + bool
hw/timer/Makefile.objs +2 -0
@@ -35,3 +35,5 @@ common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o common-obj-$(CONFIG_CMSDK_APB_DUALTIMER) += cmsdk-apb-dualtimer.o common-obj-$(CONFIG_MSF2) += mss-timer.o common-obj-$(CONFIG_RASPI) += bcm2835_systmr.o + +obj-$(CONFIG_AVR_TIMER16) += avr_timer16.o
hw/timer/trace-events +12 -0
@@ -74,3 +74,15 @@ nrf51_timer_write(uint64_t addr, uint32_t value, unsigned size) "write addr 0x%" 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.7.4
PATCH 21/32 hw/misc: avr: Add limited support for power reduction device
In reply to Aleksandar MarkovicFrom: 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.
--- 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 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
@@ -916,6 +916,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
@@ -85,3 +85,5 @@ common-obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o obj-$(CONFIG_MAC_VIA) += mac_via.o common-obj-$(CONFIG_GRLIB) += grlib_ahb_apb_pnp.o + +obj-$(CONFIG_AVR_POWER) += avr_power.o
hw/misc/trace-events +4 -0
@@ -179,3 +179,7 @@ via1_rtc_cmd_pram_read(int addr, int value) "addr=%u value=0x%02x" via1_rtc_cmd_pram_write(int addr, int value) "addr=%u value=0x%02x" via1_rtc_cmd_pram_sect_read(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=%d value=0x%02x" via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value) "sector=%u offset=%u addr=%d value=0x%02x" + +# 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"
Signature · 1 line
2.7.4
PATCH 22/32 target/avr: Register AVR support with the rest of QEMU
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Add AVR related definitions into QEMU.
--- qapi/machine.json | 3 ++- include/disas/dis-asm.h | 19 +++++++++++++++++++ include/sysemu/arch_init.h | 1 + arch_init.c | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-)
qapi/machine.json +2 -1
@@ -21,11 +21,12 @@ # is true even for "qemu-system-x86_64". # # ppcemb: dropped in 3.1 +# avr: since 5.0 # # Since: 3.0 ## { 'enum' : 'SysEmuTarget', - 'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32', + 'data' : [ 'aarch64', 'alpha', 'arm', 'avr', 'cris', 'hppa', 'i386', 'lm32', 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc', 'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
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
@@ -24,6 +24,7 @@ enum {QEMU_ARCH_NIOS2 = (1 <<17 ),QEMU_ARCH_HPPA = (1 <<18 ),QEMU_ARCH_RISCV = (1 <<19 ), + QEMU_ARCH_AVR = (1 << 20), };extern const uint32_t arch_type;
arch_init.c +2 -0
@@ -89,6 +89,8 @@ int graphic_depth = 32;#define QEMU_ARCH QEMU_ARCH_UNICORE32#elif defined(TARGET_XTENSA )#define QEMU_ARCH QEMU_ARCH_XTENSA +#elif defined(TARGET_AVR ) +#define QEMU_ARCH QEMU_ARCH_AVR#endif const uint32_t arch_type =QEMU_ARCH ;
Signature · 1 line
2.7.4
PATCH 23/32 hw/avr: Add support for loading ELF/raw binaries
In reply to Aleksandar MarkovicFrom: Philippe Mathieu-Daudé <[email protected]>
Add avr_load_firmware() function to load firmware in ELF or raw binary format.
--- hw/avr/boot.h | 33 +++++++++++++++ include/elf.h | 4 ++ hw/avr/boot.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 3 ++ hw/avr/Makefile.objs | 1 + 5 files changed, 157 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 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 +116 -0
116 lines not on this page · raw message
MAINTAINERS +3 -0
@@ -912,6 +912,9 @@ AVR MCUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: hw/avr/Makefile.objs +F: hw/avr/boot.h +F: hw/avr/boot.c 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.7.4
PATCH 24/32 hw/avr: Add some ATmega microcontrollers
In reply to Aleksandar MarkovicFrom: Philippe Mathieu-Daudé <[email protected]>
Add some AVR microcontrollers from the ATmega family:
- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560
For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560
Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf
--- hw/avr/atmega.h | 48 ++++++ hw/avr/atmega.c | 470 +++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 3 + hw/avr/Kconfig | 5 + hw/avr/Makefile.objs | 1 + 5 files changed, 527 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 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 +470 -0
470 lines not on this page · raw message
MAINTAINERS +3 -0
@@ -912,9 +912,12 @@ AVR MCUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: hw/avr/Kconfig F: hw/avr/Makefile.objs F: hw/avr/boot.h F: hw/avr/boot.c +F: hw/avr/atmega.h +F: hw/avr/atmega.c F: include/hw/char/avr_usart.h F: hw/char/avr_usart.c F: include/hw/timer/avr_timer16.h
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.7.4
PATCH 25/32 hw/avr: Add limited support for some Arduino boards
In reply to Aleksandar MarkovicFrom: Philippe Mathieu-Daudé <[email protected]>
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
--- hw/avr/arduino.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/Kconfig | 1 + hw/avr/Kconfig | 4 ++ hw/avr/Makefile.objs | 1 + 5 files changed, 163 insertions(+) create mode 100644 hw/avr/arduino.c
hw/avr/arduino.c new file +151 -0
@@ -0,0 +1,151 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "atmega.h" +#include "boot.h" + +typedef struct ArduinoMachineState { +/*< private >*/ +MachineState parent_obj; +/*< public >*/ +AtmegaMcuState mcu; +}ArduinoMachineState ; + +typedef struct ArduinoMachineClass { +/*< private >*/ +MachineClass parent_class; +/*< public >*/ +const char *mcu_type; +uint64_t xtal_hz; +}ArduinoMachineClass ; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +if (!avr_load_firmware (&ams->mcu.cpu, machine, + &ams->mcu.flash, machine->firmware)) { +exit (1 ); + } + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)
MAINTAINERS +6 -0
@@ -925,6 +925,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.7.4
PATCH 26/32 target/avr: Update build system
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Make AVR support buildable.
--- configure | 7 +++++++ default-configs/avr-softmmu.mak | 5 +++++ MAINTAINERS | 2 ++ target/avr/Makefile.objs | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 target/avr/Makefile.objs
configure +7 -0
@@ -7667,6 +7667,10 @@ case "$target_name" in mttcg="yes" gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml" ;; + avr) + gdb_xml_files="avr-cpu.xml" + target_compiler=$cross_cc_avr + ;; cris) ;; hppa)
@@ -7886,6 +7890,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do disas_config "ARM_A64" fi ;; + avr) + disas_config "AVR" + ;; cris) disas_config "CRIS" ;;
default-configs/avr-softmmu.mak new file +5 -0
@@ -0,0 +1,5 @@ +# Default configuration for avr-softmmu + +# Boards: +# +CONFIG_ARDUINO=y
MAINTAINERS +2 -0
@@ -168,6 +168,7 @@ M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained F: gdb-xml/avr-cpu.xml +F: target/avr/Makefile.objs F: target/avr/cpu-param.h F: target/avr/cpu-qom.h F: target/avr/cpu.h
@@ -912,6 +913,7 @@ AVR MCUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: default-configs/avr-softmmu.mak F: hw/avr/Kconfig F: hw/avr/Makefile.objs F: hw/avr/boot.h
target/avr/Makefile.objs new file +34 -0
@@ -0,0 +1,34 @@ +# +# QEMU AVR CPU +# +# Copyright (c) 2019 Michael Rolnik +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see +# <http://www.gnu.org/licenses/lgpl-2.1.html> +# + +DECODETREE = $(SRC_PATH)/scripts/decodetree.py +decode-y = $(SRC_PATH)/target/avr/insn.decode + +target/avr/decode_insn.inc.c: $(decode-y) $(DECODETREE) + $(call quiet-command, \ + $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn --insnwidth 16 $<, \ + "GEN", $(TARGET_DIR)$@) + +target/avr/translate.o: target/avr/decode_insn.inc.c + +obj-y += translate.o cpu.o helper.o +obj-y += gdbstub.o +obj-y += disas.o +obj-$(CONFIG_SOFTMMU) += machine.o
Signature · 1 line
2.7.4
PATCH 27/32 tests/machine-none: Add AVR support
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Add a single code line that will automatically provide 'machine none' test.
--- tests/qtest/machine-none-test.c | 1 + 1 file changed, 1 insertion(+)
tests/qtest/machine-none-test.c +1 -0
@@ -27,6 +27,7 @@ static struct arch2cpu cpus_map[] = {/* tested targets list */ { "arm", "cortex-a15" }, { "aarch64", "cortex-a57" }, + { "avr", "avr6-avr-cpu" }, { "x86_64", "qemu64,apic-id=0" }, { "i386", "qemu32,apic-id=0" }, { "alpha", "ev67" },
Signature · 1 line
2.7.4
PATCH 28/32 tests/boot-serial: Test some Arduino boards (AVR based)
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Print out 'T' through serial port.
The Arduino Duemilanove is based on a AVR5 CPU, while the Arduino MEGA2560 on a AVR6 CPU.
--- tests/qtest/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
@@ -65,6 +65,8 @@ check-qtest-i386-y += numa-test check-qtest-x86_64-y += $(check-qtest-i386-y) +check-qtest-avr-y += boot-serial-test + check-qtest-alpha-y += boot-serial-test check-qtest-alpha-$(CONFIG_VGA) += display-vga-test
Signature · 1 line
2.7.4
PATCH 29/32 tests/acceptance: Test the Arduino MEGA2560 board
In reply to Aleksandar MarkovicFrom: 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
@@ -180,6 +180,7 @@ F: target/avr/gdbstub.c F: target/avr/machine.c F: target/avr/translate.c F: target/avr/insn.decode +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.7.4
PATCH 30/32 .travis.yml: Run the AVR acceptance tests
In reply to Aleksandar MarkovicFrom: Philippe Mathieu-Daudé <[email protected]>
We have one test so far, and it is very fast:
$ avocado --show=app run -t arch:avr tests/acceptance/ (1/1) tests/acceptance/machine_avr6.py:AVR6Machine.test_freertos: PASS (2.13 s) RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0 JOB TIME : 2.30 s
--- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
.travis.yml +1 -1
@@ -313,7 +313,7 @@ matrix: # Acceptance (Functional) tests - name: "GCC check-acceptance" env: - - CONFIG="--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc-softmmu,ppc64-softmmu,m68k-softmmu,sparc-softmmu" + - CONFIG="--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc-softmmu,ppc64-softmmu,m68k-softmmu,sparc-softmmu,avr-softmmu" - TEST_CMD="make check-acceptance" after_script: - python3 -c 'import json; r = json.load(open("tests/results/latest/results.json")); [print(t["logfile"]) for t in r["tests"] if t["status"] not in ("PASS", "SKIP")]' | xargs cat
Signature · 1 line
2.7.4
PATCH 31/32 target/avr: Simplify sections in MAINTAINERS file
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
Simplify sections for AVR maintanenance in MAINTAINERS file.
--- MAINTAINERS | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
MAINTAINERS +3 -19
@@ -167,19 +167,9 @@ AVR TCG CPUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained +F: target/avr/ +F: default-configs/avr-softmmu.mak F: gdb-xml/avr-cpu.xml -F: target/avr/Makefile.objs -F: target/avr/cpu-param.h -F: target/avr/cpu-qom.h -F: target/avr/cpu.h -F: target/avr/cpu.c -F: target/avr/disas.c -F: target/avr/helper.h -F: target/avr/helper.c -F: target/avr/gdbstub.c -F: target/avr/machine.c -F: target/avr/translate.c -F: target/avr/insn.decode F: tests/acceptance/machine_avr6.py CRIS TCG CPUs
@@ -914,13 +904,7 @@ AVR MCUs M: Michael Rolnik <[email protected]> R: Sarah Harris <[email protected]> S: Maintained -F: default-configs/avr-softmmu.mak -F: hw/avr/Kconfig -F: hw/avr/Makefile.objs -F: hw/avr/boot.h -F: hw/avr/boot.c -F: hw/avr/atmega.h -F: hw/avr/atmega.c +F: hw/avr/ F: include/hw/char/avr_usart.h F: hw/char/avr_usart.c F: include/hw/timer/avr_timer16.h
Signature · 1 line
2.7.4
PATCH 32/32 target/avr: Add section into QEMU documentation
In reply to Aleksandar MarkovicFrom: Michael Rolnik <[email protected]>
The new section explains basic ways of using AVR target in QEMU.
--- qemu-doc.texi | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
qemu-doc.texi +51 -0
@@ -1719,6 +1719,7 @@ differences are mentioned in the following sections. * Microblaze System emulator:: * SH4 System emulator:: * Xtensa System emulator:: +* AVR System emulator:: @end menu @node PowerPC System emulator
@@ -2487,6 +2488,56 @@ so should only be used with trusted guest OS. @c man end +@node AVR System emulator +@section AVR System emulator +@cindex system emulation (AVR) + +Use the executable @file{qemu-system-avr} to emulates a AVR 8 bit based machine +having one for the following cores: avr1, avr2, avr25, avr3, avr31, avr35, avr4, +avr5, avr51, avr6, avrtiny, xmega2, xmega3, xmega4, xmega5, xmega6 and xmega7. + +As for now it supports few Arduino boards for educational and testing purposes. +These boards use a ATmega controller, which model is limited to USART & 16 bit +timer devices, enought to run FreeRTOS based applications (like this @url{https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf,,demo}) + +Following are examples of possible usages, assuming demo.elf is compiled for +AVR cpu +@itemize + +@item Continuous non interrupted execution +@example +qemu-system-avr -machine mega2560 -bios demo.elf +@end example + +@item Continuous non interrupted execution with serial output into telnet window +@example +qemu-system-avr -machine mega2560 -bios demo.elf -serial tcp::5678,server,nowait -nographic +@end example +and then in another shell +@example +telnet localhost 5678 +@end example + +@item Debugging wit GDB debugger +@example +qemu-system-avr -machine mega2560 -bios demo.elf -s -S +@end example +and then in another shell +@example +avr-gdb demo.elf +@end example +and then within GDB shell +@example +target remote :1234 +@end example + +@item Print out executed instructions +@example +qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm +@end example + +@end itemize + @node QEMU User space emulator @chapter QEMU User space emulator
Signature · 1 line
2.7.4