QEMU AVR 8 bit cores
PATCH v36 11/17 target/avr: Add limited support for USART and 16 bit timer peripherals
In reply to Michael RolnikQuoted 63 lines · Michael Rolnik
From: Sarah Harris <[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).Signed-off-by Sarah Harris <[email protected]>--- include/hw/char/avr_usart.h | 97 ++++++ include/hw/misc/avr_mask.h | 47 +++ include/hw/timer/avr_timer16.h | 97 ++++++ hw/char/avr_usart.c | 324 ++++++++++++++++++ hw/misc/avr_mask.c | 112 ++++++ hw/timer/avr_timer16.c | 605 +++++++++++++++++++++++++++++++++ hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + 12 files changed, 1296 insertions(+) create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_mask.h create mode 100644 include/hw/timer/avr_timer16.h create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_mask.c create mode 100644 hw/timer/avr_timer16.cinclude/hw/char/avr_usart.h new file +7
-0@@ -0,0 +1,97 @@ +/* +* AVR USART +* +* Copyright (c) 2018 University of Kent +* Author: Sarah Harris +* +* 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
Quoted 8 lines
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.
+ */
+
Sara,
To bring your contribution in line with QEMU overall license, it is necessary to change the preamble to something like in the code excerpt below. Do you agree with that?
Yours, Aleksandar
/*
* QEMU emulation of AVR USART
*
* Copyright (C) 2019 University of Kent * Copyright (C) 2019 Sara Harris * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
Quoted 1,426 lines
include/hw/char/avr_usart.h new file +72
-0+#ifndef HW_AVR_USART_H +#define HW_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_AVR_USART_H */ include/hw/misc/avr_mask.h new file +6
-0@@ -0,0 +1,47 @@ +/* +* AVR Power Reduction +* +* 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.
+ */include/hw/misc/avr_mask.h new file +24
-0+ +#ifndef HW_avr_mask_H +#define HW_avr_mask_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" +#include "hw/hw.h" + + +#define TYPE_AVR_MASK "avr-mask" +#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_avr_mask_H */ include/hw/timer/avr_timer16 renamed from include/hw/timer/avr_timer16.h +0
-0.h
new file mode 100644
index 0000000000..5639074ce5include/hw/timer/avr_timer16.h new file +7
-0@@ -0,0 +1,97 @@ +/* +* AVR 16 bit timer +* +* Copyright (c) 2018 University of Kent +* Author: Ed Robbins +* +* 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.
+ */include/hw/timer/avr_timer16.h new file +5
-0+ +/* +* 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
+ */include/hw/timer/avr_timer16.h new file +67
-0+ +#ifndef AVR_TIMER16_H +#define 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; + +uint64_t cpu_freq_hz; +uint64_t freq_hz; +uint64_t period_ns; +uint64_t reset_time_ns; +enum NextInterrupt next_interrupt; +}AVRTimer16State ; + +#endif /* AVR_TIMER16_H */ hw/char/avr_usart.c new file +7
-0@@ -0,0 +1,324 @@ +/* +* AVR USART +* +* Copyright (c) 2018 University of Kent +* Author: Sarah Harris +* +* 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.
+ */hw/char/avr_usart.c new file +18
-0+ +#include "qemu/osdep.h" +#include "hw/char/avr_usart.h" +#include "qemu/log.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +static int avr_usart_can_receive (void *opaque) +{ +AVRUsartState *usart = opaque; + +if (usart->data_valid || !(usart->csrb &USART_CSRB_RXEN )) { +return 0 ; + } +return 1 ; +} + +static void avr_usart_receive(void *opaque, const uint8_t *buffer, intsize)
hw/char/avr_usart.c new file +69
-0+{ +AVRUsartState *usart = opaque; +assert (size ==1 ); +assert (!usart->data_valid); + usart->data = buffer[0 ]; + usart->data_valid = true; + usart->csra |=USART_CSRA_RXC ; +if (usart->csrb &USART_CSRB_RXCIE ) { +qemu_set_irq (usart->rxc_irq,1 ); + } +} + +static void update_char_mask (AVRUsartState *usart) +{ +uint8_t mode = ((usart->csrc &USART_CSRC_CSZ0 ) ?1 :0 ) | + ((usart->csrc &USART_CSRC_CSZ1 ) ?2 :0 ) | + ((usart->csrb &USART_CSRB_CSZ2 ) ?4 :0 ); +switch (mode) { +case 0 : + usart->char_mask =0b11111 ; +break ; +case 1 : + usart->char_mask =0b111111 ; +break ; +case 2 : + usart->char_mask =0b1111111 ; +break ; +case 3 : + usart->char_mask =0b11111111 ; +break ; +case 4 : +/* Fallthrough. */ +case 5 : +/* Fallthrough. */ +case 6 : +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: Reserved character size 0x%x\n" , + __func__, + mode); +break ; +case 7 : +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: Nine bit character size not supported (forcing eight)\n" , + __func__); + usart->char_mask =0b11111111 ; +break ; +default : +assert (0 ); + } +} + +static void avr_usart_reset (DeviceState *dev) +{ +AVRUsartState *usart =AVR_USART (dev); + usart->data_valid = false; + usart->csra =0b00100000 ; + usart->csrb =0b00000000 ; + usart->csrc =0b00000110 ; + usart->brrl =0 ; + usart->brrh =0 ; +update_char_mask (usart); +qemu_set_irq (usart->rxc_irq,0 ); +qemu_set_irq (usart->txc_irq,0 ); +qemu_set_irq (usart->dre_irq,0 ); +} + +static uint64_t avr_usart_read(void *opaque, hwaddr addr, unsigned intsize)
hw/char/avr_usart.c new file +122
-0+{ +AVRUsartState *usart = opaque; +uint8_t data; +assert (size ==1 ); + +if (!usart->enabled) { +return 0 ; + } + +switch (addr) { +case USART_DR : +if (!(usart->csrb &USART_CSRB_RXEN )) { +/* Receiver disabled, ignore. */ +return 0 ; + } +if (usart->data_valid) { + data = usart->data & usart->char_mask; + usart->data_valid = false; + }else { + data =0 ; + } + usart->csra &=0xff ^USART_CSRA_RXC ; +qemu_set_irq (usart->rxc_irq,0 ); +qemu_chr_fe_accept_input (&usart->chr); +return data; +case USART_CSRA : +return usart->csra; +case USART_CSRB : +return usart->csrb; +case USART_CSRC : +return usart->csrc; +case USART_BRRL : +return usart->brrl; +case USART_BRRH : +return usart->brrh; +default : +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , + __func__, + addr); + } +return 0 ; +} + +static void avr_usart_write (void *opaque,hwaddr addr,uint64_t value, +unsigned int size) +{ +AVRUsartState *usart = opaque; +uint8_t mask; +uint8_t data; +assert ((value &0xff ) == value); +assert (size ==1 ); + +if (!usart->enabled) { +return ; + } + +switch (addr) { +case USART_DR : +if (!(usart->csrb &USART_CSRB_TXEN )) { +/* Transmitter disabled, ignore. */ +return ; + } + usart->csra |=USART_CSRA_TXC ; + usart->csra |=USART_CSRA_DRE ; +if (usart->csrb &USART_CSRB_TXCIE ) { +qemu_set_irq (usart->txc_irq,1 ); + usart->csra &=0xff ^USART_CSRA_TXC ; + } +if (usart->csrb &USART_CSRB_DREIE ) { +qemu_set_irq (usart->dre_irq,1 ); + } + data = value; +qemu_chr_fe_write_all (&usart->chr, &data,1 ); +break ; +case USART_CSRA : + mask =0b01000011 ; +/* Mask read-only bits. */ + value = (value & mask) | (usart->csra & (0xff ^ mask)); + usart->csra = value; +if (value &USART_CSRA_TXC ) { + usart->csra ^=USART_CSRA_TXC ; +qemu_set_irq (usart->txc_irq,0 ); + } +if (value &USART_CSRA_MPCM ) { +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: MPCM not supported by USART\n" , + __func__); + } +break ; +case USART_CSRB : + mask =0b11111101 ; +/* Mask read-only bits. */ + value = (value & mask) | (usart->csrb & (0xff ^ mask)); + usart->csrb = value; +if (!(value &USART_CSRB_RXEN )) { +/* Receiver disabled, flush input buffer. */ + usart->data_valid = false; + } +qemu_set_irq (usart->rxc_irq, + ((value &USART_CSRB_RXCIE ) && + (usart->csra &USART_CSRA_RXC )) ?1 :0 ); +qemu_set_irq (usart->txc_irq, + ((value &USART_CSRB_TXCIE ) && + (usart->csra &USART_CSRA_TXC )) ?1 :0 ); +qemu_set_irq (usart->dre_irq, + ((value &USART_CSRB_DREIE ) && + (usart->csra &USART_CSRA_DRE )) ?1 :0 ); +update_char_mask (usart); +break ; +case USART_CSRC : + usart->csrc = value; +if ((value &USART_CSRC_MSEL1 ) && (value &USART_CSRC_MSEL0 )) { +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: SPI mode not supported by USART\n" , + __func__); + } +if ((value &USART_CSRC_MSEL1 ) && !(value &USART_CSRC_MSEL0 )) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad USART mode\n",
__func__);hw/char/avr_usart.c new file +54
-0+ } +if (!(value &USART_CSRC_PM1 ) && (value &USART_CSRC_PM0 )) { +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: Bad USART parity mode\n" , + __func__); + } +update_char_mask (usart); +break ; +case USART_BRRL : + usart->brrl = value; +break ; +case USART_BRRH : + usart->brrh = value &0b00001111 ; +break ; +default : +qemu_log_mask ( +LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , + __func__, + addr); + } +} + +static const MemoryRegionOps avr_usart_ops = { + .read = avr_usart_read, + .write = avr_usart_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = {.min_access_size =1 , .max_access_size =1 } +}; + +static Property avr_usart_properties[] = { +DEFINE_PROP_CHR ("chardev" , AVRUsartState, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void avr_usart_pr (void *opaque,int irq,int level) +{ +AVRUsartState *s =AVR_USART (opaque); + + s->enabled = !level; + +if (!s->enabled) { +avr_usart_reset (DEVICE (s)); + } +} + +static void avr_usart_init (Object *obj) +{ +AVRUsartState *s =AVR_USART (obj); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->rxc_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->dre_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->txc_irq); + memory_region_init_io(&s->mmio, obj, &avr_usart_ops, s,
TYPE_AVR_USART, 8);hw/char/avr_usart.c new file +37
-0+sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +qdev_init_gpio_in (DEVICE (s), avr_usart_pr,1 ); + s->enabled = true; +} + +static void avr_usart_realize (DeviceState *dev,Error **errp) +{ +AVRUsartState *s =AVR_USART (dev); +qemu_chr_fe_set_handlers (&s->chr, avr_usart_can_receive, + avr_usart_receive,NULL ,NULL , + s,NULL , true); +avr_usart_reset (dev); +} + +static void avr_usart_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = avr_usart_reset; + dc->props = avr_usart_properties; + dc->realize = avr_usart_realize; +} + +static const TypeInfo avr_usart_info = { + .name =TYPE_AVR_USART , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (AVRUsartState), + .instance_init = avr_usart_init, + .class_init = avr_usart_class_init, +}; + +static void avr_usart_register_types (void ) +{ +type_register_static (&avr_usart_info); +} + +type_init (avr_usart_register_types)hw/misc/avr_mask.c new file +6
-0@@ -0,0 +1,112 @@ +/* +* AVR Power Reduction +* +* 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.
+ */hw/misc/avr_mask.c new file +9
-0+ +#include "qemu/osdep.h" +#include "hw/misc/avr_mask.h" +#include "qemu/log.h" +#include "hw/qdev-properties.h" +#include "hw/irq.h" + +#define DB_PRINT(fmt, args...) /* Nothing */ +/*#define DB_PRINT(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)*/
hw/misc/avr_mask.c new file +50
-0+ +static void avr_mask_reset (DeviceState *dev) +{ +AVRMaskState *s =AVR_MASK (dev); + + s->val =0x00 ; + +for (int i =0 ; i <8 ; i++) { +qemu_set_irq (s->irq[i],0 ); + } +} + +static uint64_t avr_mask_read (void *opaque,hwaddr offset,unsigned size) +{ +assert (size ==1 ); +assert (offset ==0 ); +AVRMaskState *s = opaque; + +return (uint64_t )s->val; +} + +static void avr_mask_write (void *opaque,hwaddr offset, +uint64_t val64,unsigned size) +{ +assert (size ==1 ); +assert (offset ==0 ); +AVRMaskState *s = opaque; +uint8_t val8 = val64; + +DB_PRINT ("write %d to offset %d" , val8, (uint8_t )offset); + + s->val = val8; +for (int i =0 ; i <8 ; i++) { +qemu_set_irq (s->irq[i], (val8 & (1 << i)) !=0 ); + } +} + +static const MemoryRegionOps avr_mask_ops = { + .read = avr_mask_read, + .write = avr_mask_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = {.max_access_size =1 } +}; + +static void avr_mask_init (Object *dev) +{ +AVRMaskState *s =AVR_MASK (dev); +SysBusDevice *busdev =SYS_BUS_DEVICE (dev); + + memory_region_init_io(&s->iomem, dev, &avr_mask_ops, s,
TYPE_AVR_MASK,hw/misc/avr_mask.c new file +30
-0+ 0x01); +sysbus_init_mmio (busdev, &s->iomem); + +for (int i =0 ; i <8 ; i++) { +sysbus_init_irq (busdev, &s->irq[i]); + } + s->val =0x00 ; +} + +static void avr_mask_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = avr_mask_reset; +} + +static const TypeInfo avr_mask_info = { + .name =TYPE_AVR_MASK , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (AVRMaskState), + .class_init = avr_mask_class_init, + .instance_init = avr_mask_init, +}; + +static void avr_mask_register_types (void ) +{ +type_register_static (&avr_mask_info); +} + +type_init (avr_mask_register_types)hw/timer/avr_timer16.c new file +7
-0@@ -0,0 +1,605 @@ +/* +* AVR 16 bit timer +* +* Copyright (c) 2018 University of Kent +* Author: Ed Robbins +* +* 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.
+ */hw/timer/avr_timer16.c new file +5
-0+ +/* +* Driver for 16 bit timers on 8 bit AVR devices. +* Note: +* ATmega640/V-1280/V-1281/V-2560/V-2561/V timers 1, 3, 4 and 5 are 16 bit
+ */hw/timer/avr_timer16.c new file +83
-0+ +/* +* XXX TODO: Power Reduction Register support +* prescaler pause support +* PWM modes, GPIO, output capture pins, input compare pin +*/ + +#include "qemu/osdep.h" +#include "hw/timer/avr_timer16.h" +#include "qemu/log.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +/* Register offsets */ +#define T16_CRA 0x0 +#define T16_CRB 0x1 +#define T16_CRC 0x2 +#define T16_CNTL 0x4 +#define T16_CNTH 0x5 +#define T16_ICRL 0x6 +#define T16_ICRH 0x7 +#define T16_OCRAL 0x8 +#define T16_OCRAH 0x9 +#define T16_OCRBL 0xa +#define T16_OCRBH 0xb +#define T16_OCRCL 0xc +#define T16_OCRCH 0xd + +/* Field masks */ +#define T16_CRA_WGM01 0x3 +#define T16_CRA_COMC 0xc +#define T16_CRA_COMB 0x30 +#define T16_CRA_COMA 0xc0 +#define T16_CRA_OC_CONF \ + (T16_CRA_COMA | T16_CRA_COMB | T16_CRA_COMC) + +#define T16_CRB_CS 0x7 +#define T16_CRB_WGM23 0x18 +#define T16_CRB_ICES 0x40 +#define T16_CRB_ICNC 0x80 + +#define T16_CRC_FOCC 0x20 +#define T16_CRC_FOCB 0x40 +#define T16_CRC_FOCA 0x80 + +/* Fields masks both TIMSK and TIFR (interrupt mask/flag registers) */ +#define T16_INT_TOV 0x1/* Timer overflow */ +#define T16_INT_OCA 0x2/* Output compare A */ +#define T16_INT_OCB 0x4/* Output compare B */ +#define T16_INT_OCC 0x8/* Output compare C */ +#define T16_INT_IC 0x20/* Input capture */ + +/* Clock source values */ +#define T16_CLKSRC_STOPPED 0 +#define T16_CLKSRC_DIV1 1 +#define T16_CLKSRC_DIV8 2 +#define T16_CLKSRC_DIV64 3 +#define T16_CLKSRC_DIV256 4 +#define T16_CLKSRC_DIV1024 5 +#define T16_CLKSRC_EXT_FALLING 6 +#define T16_CLKSRC_EXT_RISING 7 + +/* Timer mode values (not including PWM modes) */ +#define T16_MODE_NORMAL 0 +#define T16_MODE_CTC_OCRA 4 +#define T16_MODE_CTC_ICR 12 + +/* Accessors */ +#define CLKSRC (t16) (t16->crb & T16_CRB_CS) +#define MODE (t16) (((t16->crb & T16_CRB_WGM23) >> 1) | \ + (t16->cra & T16_CRA_WGM01)) +#define CNT (t16) VAL16(t16->cntl, t16->cnth) +#define OCRA (t16) VAL16(t16->ocral, t16->ocrah) +#define OCRB (t16) VAL16(t16->ocrbl, t16->ocrbh) +#define OCRC (t16) VAL16(t16->ocrcl, t16->ocrch) +#define ICR (t16) VAL16(t16->icrl, t16->icrh) + +/* Helper macros */ +#define VAL16 (l, h) ((h << 8) | l) +#define ERROR(fmt, args...) \ + qemu_log_mask(LOG_GUEST_ERROR, "%s: " fmt "\n", __func__, ## args) +#define DB_PRINT(fmt, args...) /* Nothing */ +/*#define DB_PRINT(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)*/
hw/timer/avr_timer16.c new file +2
-0+ +static inline int64_t avr_timer16_ns_to_ticks(AVRTimer16State *t16,
int64_tt)hw/timer/avr_timer16.c new file +60
-1+{ +if (t16->period_ns ==0 ) { +return 0 ; + } +return t / t16->period_ns; +} + +static void avr_timer16_update_cnt (AVRTimer16State *t16) +{ +uint16_t cnt; + cnt =avr_timer16_ns_to_ticks (t16,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - + t16->reset_time_ns); + t16->cntl = (uint8_t )(cnt &0xff ); + t16->cnth = (uint8_t )((cnt &0xff00 ) >>8 ); +} + +static inline void avr_timer16_recalc_reset_time (AVRTimer16State *t16) +{ + t16->reset_time_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - +CNT (t16) * t16->period_ns; +} + +static void avr_timer16_clock_reset (AVRTimer16State *t16) +{ + t16->cntl =0 ; + t16->cnth =0 ; + t16->reset_time_ns =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +} + +static void avr_timer16_clksrc_update(AVRTimer16State *t16) +{ + uint16_t divider = 0; + switch (CLKSRC(t16)) { + case T16_CLKSRC_EXT_FALLING: + case T16_CLKSRC_EXT_RISING: + ERROR("external clock source unsupported"); + goto end; + case T16_CLKSRC_STOPPED: + goto end; + case T16_CLKSRC_DIV1: + divider = 1; + break; + case T16_CLKSRC_DIV8: + divider = 8; + break; + case T16_CLKSRC_DIV64: + divider = 64; + break; + case T16_CLKSRC_DIV256: + divider = 256; + break; + case T16_CLKSRC_DIV1024: + divider = 1024; + break; + default: + goto end; + } + t16->freq_hz = t16->cpu_freq_hz / divider; + t16->period_ns = NANOSECONDS_PER_SECOND / t16->freq_hz; + DB_PRINT("Timer frequency %" PRIu64 " hz, period %" PRIu64 " ns (%fs)",
hw/timer/avr_timer16.c new file +11
-0+ t16->freq_hz, t16->period_ns, 1 / (double)t16->freq_hz); +end: +return ; +} + +static void avr_timer16_set_alarm (AVRTimer16State *t16) +{ +if (CLKSRC (t16) ==T16_CLKSRC_EXT_FALLING || +CLKSRC (t16) ==T16_CLKSRC_EXT_RISING || +CLKSRC (t16) ==T16_CLKSRC_STOPPED ) { +/* Timer is disabled or set to external clock source (unsupported) */
hw/timer/avr_timer16.c new file +73
-0+ goto end; + } + +uint64_t alarm_offset =0xffff ; +enum NextInterrupt next_interrupt =OVERFLOW ; + +switch (MODE (t16)) { +case T16_MODE_NORMAL : +/* Normal mode */ +if (OCRA (t16) < alarm_offset &&OCRA (t16) >CNT (t16) && + (t16->imsk &T16_INT_OCA )) { + alarm_offset =OCRA (t16); + next_interrupt =COMPA ; + } +break ; +case T16_MODE_CTC_OCRA : +/* CTC mode, top = ocra */ +if (OCRA (t16) < alarm_offset &&OCRA (t16) >CNT (t16)) { + alarm_offset =OCRA (t16); + next_interrupt =COMPA ; + } +break ; +case T16_MODE_CTC_ICR : +/* CTC mode, top = icr */ +if (ICR (t16) < alarm_offset &&ICR (t16) >CNT (t16)) { + alarm_offset =ICR (t16); + next_interrupt =CAPT ; + } +if (OCRA (t16) < alarm_offset &&OCRA (t16) >CNT (t16) && + (t16->imsk &T16_INT_OCA )) { + alarm_offset =OCRA (t16); + next_interrupt =COMPA ; + } +break ; +default : +ERROR ("pwm modes are unsupported" ); + goto end; + } +if (OCRB (t16) < alarm_offset &&OCRB (t16) >CNT (t16) && + (t16->imsk &T16_INT_OCB )) { + alarm_offset =OCRB (t16); + next_interrupt =COMPB ; + } +if (OCRC (t16) < alarm_offset &&OCRB (t16) >CNT (t16) && + (t16->imsk &T16_INT_OCC )) { + alarm_offset =OCRB (t16); + next_interrupt =COMPC ; + } + alarm_offset -=CNT (t16); + + t16->next_interrupt = next_interrupt; +uint64_t alarm_ns = + t16->reset_time_ns + ((CNT (t16) + alarm_offset) * t16->period_ns); +timer_mod (t16->timer, alarm_ns); + +DB_PRINT ("next alarm %" PRIu64" ns from now" , + alarm_offset * t16->period_ns); + +end: +return ; +} + +static void avr_timer16_interrupt (void *opaque) +{ +AVRTimer16State *t16 = opaque; +uint8_t mode =MODE (t16); + +avr_timer16_update_cnt (t16); + +if (CLKSRC (t16) ==T16_CLKSRC_EXT_FALLING || +CLKSRC (t16) ==T16_CLKSRC_EXT_RISING || +CLKSRC (t16) ==T16_CLKSRC_STOPPED ) { +/* Timer is disabled or set to external clock source (unsupported) */
hw/timer/avr_timer16.c new file +60
-0+return ; + } + +DB_PRINT ("interrupt, cnt = %d" ,CNT (t16)); + +/* Counter overflow */ +if (t16->next_interrupt ==OVERFLOW ) { +DB_PRINT ("0xffff overflow" ); +avr_timer16_clock_reset (t16); +if (t16->imsk &T16_INT_TOV ) { + t16->ifr |=T16_INT_TOV ; +qemu_set_irq (t16->ovf_irq,1 ); + } + } +/* Check for ocra overflow in CTC mode */ +if (mode ==T16_MODE_CTC_OCRA && t16->next_interrupt ==COMPA ) { +DB_PRINT ("CTC OCRA overflow" ); +avr_timer16_clock_reset (t16); + } +/* Check for icr overflow in CTC mode */ +if (mode ==T16_MODE_CTC_ICR && t16->next_interrupt ==CAPT ) { +DB_PRINT ("CTC ICR overflow" ); +avr_timer16_clock_reset (t16); +if (t16->imsk &T16_INT_IC ) { + t16->ifr |=T16_INT_IC ; +qemu_set_irq (t16->capt_irq,1 ); + } + } +/* Check for output compare interrupts */ +if (t16->imsk &T16_INT_OCA && t16->next_interrupt ==COMPA ) { + t16->ifr |=T16_INT_OCA ; +qemu_set_irq (t16->compa_irq,1 ); + } +if (t16->imsk &T16_INT_OCB && t16->next_interrupt ==COMPB ) { + t16->ifr |=T16_INT_OCB ; +qemu_set_irq (t16->compb_irq,1 ); + } +if (t16->imsk &T16_INT_OCC && t16->next_interrupt ==COMPC ) { + t16->ifr |=T16_INT_OCC ; +qemu_set_irq (t16->compc_irq,1 ); + } +avr_timer16_set_alarm (t16); +} + +static void avr_timer16_reset (DeviceState *dev) +{ +AVRTimer16State *t16 =AVR_TIMER16 (dev); + +avr_timer16_clock_reset (t16); +avr_timer16_clksrc_update (t16); +avr_timer16_set_alarm (t16); + +qemu_set_irq (t16->capt_irq,0 ); +qemu_set_irq (t16->compa_irq,0 ); +qemu_set_irq (t16->compb_irq,0 ); +qemu_set_irq (t16->compc_irq,0 ); +qemu_set_irq (t16->ovf_irq,0 ); +} + +static uint64_t avr_timer16_read(void *opaque, hwaddr offset, unsignedsize)
hw/timer/avr_timer16.c new file +89
-0+{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +uint8_t retval =0 ; + +switch (offset) { +case T16_CRA : + retval = t16->cra; +break ; +case T16_CRB : + retval = t16->crb; +break ; +case T16_CRC : + retval = t16->crc; +break ; +case T16_CNTL : +avr_timer16_update_cnt (t16); + t16->rtmp = t16->cnth; + retval = t16->cntl; +break ; +case T16_CNTH : + retval = t16->rtmp; +break ; +case T16_ICRL : +/* +* The timer copies cnt to icr when the input capture pin changes +* state or when the analog comparator has a match. We don't +* emulate this behaviour. We do support it's use for defining a +* TOP value in T16_MODE_CTC_ICR +*/ + t16->rtmp = t16->icrh; + retval = t16->icrl; +break ; +case T16_ICRH : + retval = t16->rtmp; +break ; +case T16_OCRAL : + retval = t16->ocral; +break ; +case T16_OCRAH : + retval = t16->ocrah; +break ; +case T16_OCRBL : + retval = t16->ocrbl; +break ; +case T16_OCRBH : + retval = t16->ocrbh; +break ; +case T16_OCRCL : + retval = t16->ocrcl; +break ; +case T16_OCRCH : + retval = t16->ocrch; +break ; +default : +break ; + } +return (uint64_t )retval; +} + +static void avr_timer16_write (void *opaque,hwaddr offset, +uint64_t val64,unsigned size) +{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +uint8_t val8 = (uint8_t )val64; +uint8_t prev_clk_src =CLKSRC (t16); + +DB_PRINT ("write %d to offset %d" , val8, (uint8_t )offset); + +switch (offset) { +case T16_CRA : + t16->cra = val8; +if (t16->cra &T16_CRA_OC_CONF ) { +ERROR ("output compare pins unsupported" ); + } +break ; +case T16_CRB : + t16->crb = val8; +if (t16->crb &T16_CRB_ICNC ) { +ERROR ("input capture noise canceller unsupported" ); + } +if (t16->crb &T16_CRB_ICES ) { +ERROR ("input capture unsupported" ); + } +if (CLKSRC (t16) != prev_clk_src) { +avr_timer16_clksrc_update (t16); +if (prev_clk_src ==T16_CLKSRC_STOPPED ) { + t16->reset_time_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
hw/timer/avr_timer16.c new file +172
-0+ } + } +break ; +case T16_CRC : + t16->crc = val8; +ERROR ("output compare pins unsupported" ); +break ; +case T16_CNTL : +/* +* CNT is the 16-bit counter value, it must be read/written via +* a temporary register (rtmp) to make the read/write atomic. +*/ +/* ICR also has this behaviour, and shares rtmp */ +/* +* Writing CNT blocks compare matches for one clock cycle. +* Writing CNT to TOP or to an OCR value (if in use) will +* skip the relevant interrupt +*/ + t16->cntl = val8; + t16->cnth = t16->rtmp; +avr_timer16_recalc_reset_time (t16); +break ; +case T16_CNTH : + t16->rtmp = val8; +break ; +case T16_ICRL : +/* ICR can only be written in mode T16_MODE_CTC_ICR */ +if (MODE (t16) ==T16_MODE_CTC_ICR ) { + t16->icrl = val8; + t16->icrh = t16->rtmp; + } +break ; +case T16_ICRH : +if (MODE (t16) ==T16_MODE_CTC_ICR ) { + t16->rtmp = val8; + } +break ; +case T16_OCRAL : +/* +* OCRn cause the relevant output compare flag to be raised, and +* trigger an interrupt, when CNT is equal to the value here +*/ + t16->ocral = val8; +break ; +case T16_OCRAH : + t16->ocrah = val8; +break ; +case T16_OCRBL : + t16->ocrbl = val8; +break ; +case T16_OCRBH : + t16->ocrbh = val8; +break ; +case T16_OCRCL : + t16->ocrcl = val8; +break ; +case T16_OCRCH : + t16->ocrch = val8; +break ; +default : +break ; + } +avr_timer16_set_alarm (t16); +} + +static uint64_t avr_timer16_imsk_read (void *opaque, +hwaddr offset, +unsigned size) +{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +if (offset !=0 ) { +return 0 ; + } +return t16->imsk; +} + +static void avr_timer16_imsk_write (void *opaque,hwaddr offset, +uint64_t val64,unsigned size) +{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +if (offset !=0 ) { +return ; + } + t16->imsk = (uint8_t )val64; +} + +static uint64_t avr_timer16_ifr_read (void *opaque, +hwaddr offset, +unsigned size) +{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +if (offset !=0 ) { +return 0 ; + } +return t16->ifr; +} + +static void avr_timer16_ifr_write (void *opaque,hwaddr offset, +uint64_t val64,unsigned size) +{ +assert (size ==1 ); +AVRTimer16State *t16 = opaque; +if (offset !=0 ) { +return ; + } + t16->ifr = (uint8_t )val64; +} + +static const MemoryRegionOps avr_timer16_ops = { + .read = avr_timer16_read, + .write = avr_timer16_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = {.max_access_size =1 } +}; + +static const MemoryRegionOps avr_timer16_imsk_ops = { + .read = avr_timer16_imsk_read, + .write = avr_timer16_imsk_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = {.max_access_size =1 } +}; + +static const MemoryRegionOps avr_timer16_ifr_ops = { + .read = avr_timer16_ifr_read, + .write = avr_timer16_ifr_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = {.max_access_size =1 } +}; + +static Property avr_timer16_properties[] = { + DEFINE_PROP_UINT64("cpu-frequency-hz", struct AVRTimer16State, + cpu_freq_hz,20000000 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void avr_timer16_pr (void *opaque,int irq,int level) +{ +AVRTimer16State *s =AVR_TIMER16 (opaque); + + s->enabled = !level; + +if (!s->enabled) { +avr_timer16_reset (DEVICE (s)); + } +} + +static void avr_timer16_init (Object *obj) +{ +AVRTimer16State *s =AVR_TIMER16 (obj); + +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->capt_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->compa_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->compb_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->compc_irq); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->ovf_irq); + +memory_region_init_io (&s->iomem, obj, &avr_timer16_ops, + s,TYPE_AVR_TIMER16 ,0xe ); +memory_region_init_io (&s->imsk_iomem, obj, &avr_timer16_imsk_ops, + s,TYPE_AVR_TIMER16 ,0x1 ); +memory_region_init_io (&s->ifr_iomem, obj, &avr_timer16_ifr_ops, + s,TYPE_AVR_TIMER16 ,0x1 ); + +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->imsk_iomem); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->ifr_iomem); +qdev_init_gpio_in (DEVICE (s), avr_timer16_pr,1 ); + + s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, avr_timer16_interrupt,s);
hw/timer/avr_timer16.c new file +25
-0+ s->enabled = true; +} + +static void avr_timer16_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = avr_timer16_reset; + dc->props = avr_timer16_properties; +} + +static const TypeInfo avr_timer16_info = { + .name =TYPE_AVR_TIMER16 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (AVRTimer16State), + .instance_init = avr_timer16_init, + .class_init = avr_timer16_class_init, +}; + +static void avr_timer16_register_types (void ) +{ +type_register_static (&avr_timer16_info); +} + +type_init (avr_timer16_register_types)hw/char/Kconfig +3
-0@@ -46,3 +46,6 @@ config SCLPCONSOLE config TERMINAL3270 bool + +config AVR_USART + boolhw/char/Makefile.objs +1
-0@@ -21,6 +21,7 @@ obj-$(CONFIG_PSERIES) += spapr_vty.o obj-$(CONFIG_DIGIC) += digic-uart.o obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o obj-$(CONFIG_RASPI) += bcm2835_aux.o +common-obj-$(CONFIG_AVR_USART) += avr_usart.o common-obj-$(CONFIG_CMSDK_APB_UART) += cmsdk-apb-uart.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.ohw/misc/Kconfig +3
-0@@ -125,4 +125,7 @@ config MAC_VIA select MOS6522 select ADB +config AVR_MASK + bool + source macio/Kconfighw/misc/Makefile.objs +2
-0@@ -82,3 +82,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_MASK) += avr_mask.ohw/timer/Kconfig +3
-0@@ -34,3 +34,6 @@ config CMSDK_APB_TIMER config CMSDK_APB_DUALTIMER bool select PTIMER + +config AVR_TIMER16 + boolhw/timer/Makefile.objs +0
-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.ohw/timer/Makefile.objs +2
-1+ +obj-$(CONFIG_AVR_TIMER16) += avr_timer16.o --2.17.2 (Apple Git-113)
Re: [PATCH v36 11/17] target/avr: Add limited support for USART and 16 bit timer peripherals
In reply to Michael RolnikQuoted 84 lines · Michael Rolnik
From: Sarah Harris <[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).Signed-off-by Sarah Harris <[email protected]>--- include/hw/char/avr_usart.h | 97 ++++++ include/hw/misc/avr_mask.h | 47 +++ include/hw/timer/avr_timer16.h | 97 ++++++ hw/char/avr_usart.c | 324 ++++++++++++++++++ hw/misc/avr_mask.c | 112 ++++++ hw/timer/avr_timer16.c | 605 +++++++++++++++++++++++++++++++++ hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + 12 files changed, 1296 insertions(+)create mode 100644
include/hw/char/avr_usart.hcreate mode 100644include/hw/misc/avr_mask.hcreate mode 100644include/hw/timer/avr_timer16.hcreate mode 100644hw/char/avr_usart.ccreate mode 100644hw/misc/avr_mask.ccreate mode 100644hw/timer/avr_timer16.cinclude/hw/char/avr_usart.h new file +51
-0@@ -0,0 +1,97 @@ +/* +* AVR USART +* +* Copyright (c) 2018 University of Kent +* Author: Sarah Harris +* +* 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_AVR_USART_H +#define HW_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)
include/hw/char/avr_usart.h line 61
Quoted 10 lines
include/hw/char/avr_usart.h new file +10
-0+#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)
The previous definitions can go into hw/char/avr_usart.c.
Quoted 23 lines
include/hw/char/avr_usart.h new file +23
-0+#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) */
include/hw/char/avr_usart.h line 95
Quoted 10 lines
include/hw/char/avr_usart.h new file +10
-0+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;
Please rename to AvrUsartState (see 'Naming' section of CODING_STYLE.rst).
[...]
Re: [PATCH v36 11/17] target/avr: Add limited support for USART and 16 bit timer peripherals
Quoted 23 lines
Quoted 23 lines
include/hw/char/avr_usart.h new file +23
-0+/* 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) +
Quoted 9 lines
include/hw/char/avr_usart.h line 61
Quoted 6 lines
include/hw/char/avr_usart.h new file +6
-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)The previous definitions can go into
hw/char/avr_usart.c.
Why?
Re: [PATCH v36 11/17] target/avr: Add limited support for USART and 16 bit timer peripherals
too late :)
Quoted 35 lines · Aleksandar Markovic
Quoted 23 lines
Quoted 23 lines
include/hw/char/avr_usart.h new file +23
-0+/* 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) +Quoted 9 lines
include/hw/char/avr_usart.h line 61
Quoted 6 lines
include/hw/char/avr_usart.h new file +6
-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)The previous definitions can go into
hw/char/avr_usart.c.Why?
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [PATCH v36 11/17] target/avr: Add limited support for USART and 16 bit timer peripherals
Quoted 3 lines · Michael Rolnik
too late :)
There will be opportunities in future versions. Whaaat, did you really think you would get away with only 37 versions? ;-)
Re: [PATCH v36 11/17] target/avr: Add limited support for USART and 16 bit timer peripherals
In reply to Aleksandar MarkovicQuoted 34 lines · Aleksandar Markovic
Quoted 24 lines
Quoted 24 lines
include/hw/char/avr_usart.h new file +23
-0+/* 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) +Quoted 9 lines
include/hw/char/avr_usart.h line 61
Quoted 6 lines
include/hw/char/avr_usart.h new file +6
-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)The previous definitions can go into
hw/char/avr_usart.c.
Quoted 1 line
Why?
Seriously, Philippe, why move this from their perfect cosy place in the header?
If the answer is "because most of others in QEMU do", I don't know... I wouldn't consider that a legitimate reason - at least not in this particular case.
Aleksandar
PATCH v36 12/17 target/avr: Add example board configuration
In reply to Michael RolnikA simple board setup that configures an AVR CPU to run a given firmware image.
This is all that's useful to implement without peripheral emulation as AVR CPUs include a lot of on-board peripherals.
NOTE: this is not a real board !!!!
NOTE: it's used for CPU testing!!!!
--- hw/avr/sample.c | 282 +++++++++++++++++++++++++++++++++++++++++++ hw/Kconfig | 1 + hw/avr/Kconfig | 6 + hw/avr/Makefile.objs | 1 + 4 files changed, 290 insertions(+) create mode 100644 hw/avr/sample.c create mode 100644 hw/avr/Kconfig create mode 100644 hw/avr/Makefile.objs
hw/avr/sample.c new file +282 -0
@@ -0,0 +1,282 @@ +/* +* 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> +*/ + +/* +* NOTE: +* This is not a real AVR board, this is an example! +* The CPU is an approximation of an ATmega2560, but is missing various +* built-in peripherals. +* +* This example board loads provided binary file into flash memory and +* executes it from 0x00000000 address in the code memory space. +* +* Currently used for AVR CPU validation +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "sysemu/qtest.h" +#include "ui/console.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "qemu/error-report.h" +#include "exec/address-spaces.h" +#include "include/hw/sysbus.h" +#include "include/hw/char/avr_usart.h" +#include "include/hw/timer/avr_timer16.h" +#include "include/hw/misc/avr_mask.h" +#include "elf.h" +#include "hw/misc/unimp.h" + +#define SIZE_FLASH 0x00040000 +#define SIZE_SRAM 0x00002000 +/* +* Size of additional "external" memory, as if the AVR were configured to use +* an external RAM chip. +* Note that the configuration registers that normally enable this feature are +* unimplemented. +*/ +#define SIZE_EXMEM 0x00000000 + +/* Offsets of peripherals in emulated memory space (i.e. not host addresses) */ +#define PRR0_BASE 0x64 +#define PRR1_BASE 0x65 +#define USART_BASE 0xc0 +#define TIMER1_BASE 0x80 +#define TIMER1_IMSK_BASE 0x6f +#define TIMER1_IFR_BASE 0x36 + +/* Interrupt numbers used by peripherals */ +#define USART_RXC_IRQ 24 +#define USART_DRE_IRQ 25 +#define USART_TXC_IRQ 26 + +#define TIMER1_CAPT_IRQ 15 +#define TIMER1_COMPA_IRQ 16 +#define TIMER1_COMPB_IRQ 17 +#define TIMER1_COMPC_IRQ 18 +#define TIMER1_OVF_IRQ 19 + +/* Power reduction */ +#define PRR1_BIT_PRTIM5 0x05/* Timer/Counter5 */ +#define PRR1_BIT_PRTIM4 0x04/* Timer/Counter4 */ +#define PRR1_BIT_PRTIM3 0x03/* Timer/Counter3 */ +#define PRR1_BIT_PRUSART3 0x02/* USART3 */ +#define PRR1_BIT_PRUSART2 0x01/* USART2 */ +#define PRR1_BIT_PRUSART1 0x00/* USART1 */ + +#define PRR0_BIT_PRTWI 0x06/* TWI */ +#define PRR0_BIT_PRTIM2 0x05/* Timer/Counter2 */ +#define PRR0_BIT_PRTIM0 0x04/* Timer/Counter0 */ +#define PRR0_BIT_PRTIM1 0x03/* Timer/Counter1 */ +#define PRR0_BIT_PRSPI 0x02/* Serial Peripheral Interface */ +#define PRR0_BIT_PRUSART0 0x01/* USART0 */ +#define PRR0_BIT_PRADC 0x00/* ADC */ + +typedef struct { +MachineClass parent; +}SampleMachineClass ; + +typedef struct { +MachineState parent; +MemoryRegion *ram; +MemoryRegion *flash; +AVRUsartState *usart0; +AVRTimer16State *timer1; +AVRMaskState *prr[2 ]; +}SampleMachineState ; + +#define TYPE_SAMPLE_MACHINE MACHINE_TYPE_NAME("sample") + +#define SAMPLE_MACHINE (obj) \ + OBJECT_CHECK(SampleMachineState, obj, TYPE_SAMPLE_MACHINE) +#define SAMPLE_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(SampleMachineClass, obj, TYPE_SAMPLE_MACHINE) +#define SAMPLE_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(SampleMachineClass, klass, TYPE_SAMPLE_MACHINE) + +static void sample_init (MachineState *machine) +{ +SampleMachineState *sms =SAMPLE_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +AVRCPU *cpu; +const char *firmware =NULL ; +const char *filename; +int bytes_loaded; +SysBusDevice *busdev; +DeviceState *cpudev; + + system_memory =get_system_memory (); + sms->ram =g_new (MemoryRegion,1 ); + sms->flash =g_new (MemoryRegion,1 ); + + cpu =AVR_CPU (cpu_create (machine->cpu_type)); + cpudev =DEVICE (cpu); + + +memory_region_init_rom (sms->flash,NULL ,"avr.flash" ,SIZE_FLASH , + &error_fatal); +memory_region_add_subregion (system_memory,OFFSET_CODE , sms->flash); + +/* following are atmel2560 device */ +create_unimplemented_device ("usart 3" ,OFFSET_DATA +0x0130 ,0x0007 ); +create_unimplemented_device ("timer-counter-16bit 5" , +OFFSET_DATA +0x0120 ,0x000e ); +create_unimplemented_device ("gpio L" ,OFFSET_DATA +0x0109 ,0x0003 ); +create_unimplemented_device ("gpio K" ,OFFSET_DATA +0x0106 ,0x0003 ); +create_unimplemented_device ("gpio J" ,OFFSET_DATA +0x0103 ,0x0003 ); +create_unimplemented_device ("gpio H" ,OFFSET_DATA +0x0100 ,0x0003 ); +create_unimplemented_device ("usart 2" ,OFFSET_DATA +0x00d0 ,0x0007 ); +create_unimplemented_device ("usart 1" ,OFFSET_DATA +0x00c8 ,0x0007 ); +create_unimplemented_device ("usart 0" ,OFFSET_DATA +0x00c0 ,0x0007 ); +create_unimplemented_device ("twi" ,OFFSET_DATA +0x00b8 ,0x0006 ); +create_unimplemented_device ("timer-counter-async-8bit 2" , +OFFSET_DATA +0x00b0 ,0x0007 ); +create_unimplemented_device ("timer-counter-16bit 4" , +OFFSET_DATA +0x00a0 ,0x000e ); +create_unimplemented_device ("timer-counter-16bit 3" , +OFFSET_DATA +0x0090 ,0x000e ); +create_unimplemented_device ("timer-counter-16bit 1" , +OFFSET_DATA +0x0080 ,0x000e ); +create_unimplemented_device ("ac / adc" , +OFFSET_DATA +0x0078 ,0x0008 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x0074 ,0x0002 ); +create_unimplemented_device ("int-controller" , +OFFSET_DATA +0x0068 ,0x000c ); +create_unimplemented_device ("sys" , +OFFSET_DATA +0x0060 ,0x0007 ); +create_unimplemented_device ("spi" , +OFFSET_DATA +0x004c ,0x0003 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x004a ,0x0002 ); +create_unimplemented_device ("timer-counter-pwm-8bit 0" , +OFFSET_DATA +0x0043 ,0x0006 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x003e ,0x0005 ); +create_unimplemented_device ("int-controller" , +OFFSET_DATA +0x0035 ,0x0009 ); +create_unimplemented_device ("gpio G" ,OFFSET_DATA +0x0032 ,0x0003 ); +create_unimplemented_device ("gpio F" ,OFFSET_DATA +0x002f ,0x0003 ); +create_unimplemented_device ("gpio E" ,OFFSET_DATA +0x002c ,0x0003 ); +create_unimplemented_device ("gpio D" ,OFFSET_DATA +0x0029 ,0x0003 ); +create_unimplemented_device ("gpio C" ,OFFSET_DATA +0x0026 ,0x0003 ); +create_unimplemented_device ("gpio B" ,OFFSET_DATA +0x0023 ,0x0003 ); +create_unimplemented_device ("gpio A" ,OFFSET_DATA +0x0020 ,0x0003 ); + +memory_region_allocate_system_memory ( + sms->ram,NULL ,"avr.ram" ,SIZE_SRAM +SIZE_EXMEM ); +memory_region_add_subregion (system_memory,OFFSET_DATA +0x200 , sms->ram); + +/* Power Reduction built-in peripheral */ + sms->prr[0 ] =AVR_MASK (sysbus_create_simple (TYPE_AVR_MASK , +OFFSET_DATA +PRR0_BASE ,NULL )); + sms->prr[1 ] =AVR_MASK (sysbus_create_simple (TYPE_AVR_MASK , +OFFSET_DATA +PRR1_BASE ,NULL )); + +/* USART 0 built-in peripheral */ + sms->usart0 =AVR_USART (object_new (TYPE_AVR_USART )); + busdev =SYS_BUS_DEVICE (sms->usart0); +qdev_prop_set_chr (DEVICE (sms->usart0),"chardev" ,serial_hd (0 )); +object_property_set_bool (OBJECT (sms->usart0), true,"realized" , + &error_fatal); +sysbus_mmio_map (busdev,0 ,OFFSET_DATA +USART_BASE ); +/* +* These IRQ numbers don't match the datasheet because we're counting from +* zero and not including reset. +*/ +sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (cpudev,USART_RXC_IRQ )); +sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (cpudev,USART_DRE_IRQ )); +sysbus_connect_irq (busdev,2 ,qdev_get_gpio_in (cpudev,USART_TXC_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (sms->prr[1 ]),PRR1_BIT_PRUSART1 , +qdev_get_gpio_in (DEVICE (sms->usart0),0 )); + +/* Timer 1 built-in periphal */ + sms->timer1 =AVR_TIMER16 (object_new (TYPE_AVR_TIMER16 )); +object_property_set_bool (OBJECT (sms->timer1), true,"realized" , + &error_fatal); + busdev =SYS_BUS_DEVICE (sms->timer1); +sysbus_mmio_map (busdev,0 ,OFFSET_DATA +TIMER1_BASE ); +sysbus_mmio_map (busdev,1 ,OFFSET_DATA +TIMER1_IMSK_BASE ); +sysbus_mmio_map (busdev,2 ,OFFSET_DATA +TIMER1_IFR_BASE ); +sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (cpudev,TIMER1_CAPT_IRQ )); +sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (cpudev,TIMER1_COMPA_IRQ )); +sysbus_connect_irq (busdev,2 ,qdev_get_gpio_in (cpudev,TIMER1_COMPB_IRQ )); +sysbus_connect_irq (busdev,3 ,qdev_get_gpio_in (cpudev,TIMER1_COMPC_IRQ )); +sysbus_connect_irq (busdev,4 ,qdev_get_gpio_in (cpudev,TIMER1_OVF_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (sms->prr[0 ]),PRR0_BIT_PRTIM1 , +qdev_get_gpio_in (DEVICE (sms->timer1),0 )); + +/* Load firmware (contents of flash) trying to auto-detect format */ + firmware = machine->firmware; +if (firmware !=NULL ) { + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf ( + filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys ( + filename,OFFSET_CODE ,SIZE_FLASH ); + } +if (bytes_loaded <0 ) { +error_report ( +"Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } + } +} + +static void sample_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="AVR sample/example board (ATmega2560)" ; + mc->init = sample_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->default_cpu_type ="avr6-avr-cpu" ;/* ATmega2560. */ + mc->is_default =1 ; +} + +static const TypeInfo sample_info = { + .name =TYPE_SAMPLE_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (SampleMachineState), + .class_size =sizeof (SampleMachineClass), + .class_init = sample_class_init, +}; + +static void sample_machine_init (void ) +{ +type_register_static (&sample_info); +} + +type_init (sample_machine_init);
hw/Kconfig +1 -0
@@ -44,6 +44,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 new file +6 -0
@@ -0,0 +1,6 @@ +config AVR_SAMPLE + bool + select AVR_TIMER16 + select AVR_USART + select AVR_MASK + select UNIMP
hw/avr/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +obj-y += sample.o
Signature · 1 line
2.17.2 (Apple Git-113)
Re: [PATCH v36 12/17] target/avr: Add example board configuration
Quoted 10 lines · Michael Rolnik
A simple board setup that configures an AVR CPU to run a given firmware image.
This is all that's useful to implement without peripheral emulation as AVR CPUs include a lot of on-board peripherals.NOTE: this is not a real board !!!!
NOTE: it's used for CPU testing!!!!Signed-off-by Michael Rolnik <[email protected]>---
Given the complexities of peripherals of AVR CPUs, in my opinion it would be overly demanding to the submitters to require a real machine emulation at this point of time. So:
Hopefully this will superceeded with a real board emulation in not so distsnt future.
Philippe, do you have something to add?
Quoted 349 lines
hw/avr/sample.c| 282 +++++++++++++++++++++++++++++++++++++++++++hw/Kconfig | 1 + hw/avr/Kconfig | 6 + hw/avr/Makefile.objs | 1 + 4 files changed, 290 insertions(+) create mode 100644 hw/avr/sample.c create mode 100644 hw/avr/Kconfig create mode 100644 hw/avr/Makefile.objshw/avr/sample.c new file +24
-0@@ -0,0 +1,282 @@ +/* +* 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> +*/ + +/* +* NOTE: +* This is not a real AVR board, this is an example! +* The CPU is an approximation of an ATmega2560, but is missing various
+ * built-in peripherals.
+ *
+ * This example board loads provided binary file into flash memory
and
+ * executes it from0x00000000address in the code memory space.
+ *
+ * Currently used for AVR CPU validation
+ *
+ */hw/avr/sample.c new file +24
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "sysemu/sysemu.h" +#include "sysemu/qtest.h" +#include "ui/console.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "qemu/error-report.h" +#include "exec/address-spaces.h" +#include "include/hw/sysbus.h" +#include "include/hw/char/avr_usart.h" +#include "include/hw/timer/avr_timer16.h" +#include "include/hw/misc/avr_mask.h" +#include "elf.h" +#include "hw/misc/unimp.h" + +#define SIZE_FLASH 0x00040000 +#define SIZE_SRAM 0x00002000 +/* +* Size of additional "external" memory, as if the AVR were configured to use
+ * an external RAM chip.
+ * Note that the configuration registers that normally enable this feature are
+ * unimplemented.
+ */hw/avr/sample.c new file +3
-0+#define SIZE_EXMEM 0x00000000 + +/* Offsets of peripherals in emulated memory space (i.e. not host addresses) */
hw/avr/sample.c new file +128
-0+#define PRR0_BASE 0x64 +#define PRR1_BASE 0x65 +#define USART_BASE 0xc0 +#define TIMER1_BASE 0x80 +#define TIMER1_IMSK_BASE 0x6f +#define TIMER1_IFR_BASE 0x36 + +/* Interrupt numbers used by peripherals */ +#define USART_RXC_IRQ 24 +#define USART_DRE_IRQ 25 +#define USART_TXC_IRQ 26 + +#define TIMER1_CAPT_IRQ 15 +#define TIMER1_COMPA_IRQ 16 +#define TIMER1_COMPB_IRQ 17 +#define TIMER1_COMPC_IRQ 18 +#define TIMER1_OVF_IRQ 19 + +/* Power reduction */ +#define PRR1_BIT_PRTIM5 0x05/* Timer/Counter5 */ +#define PRR1_BIT_PRTIM4 0x04/* Timer/Counter4 */ +#define PRR1_BIT_PRTIM3 0x03/* Timer/Counter3 */ +#define PRR1_BIT_PRUSART3 0x02/* USART3 */ +#define PRR1_BIT_PRUSART2 0x01/* USART2 */ +#define PRR1_BIT_PRUSART1 0x00/* USART1 */ + +#define PRR0_BIT_PRTWI 0x06/* TWI */ +#define PRR0_BIT_PRTIM2 0x05/* Timer/Counter2 */ +#define PRR0_BIT_PRTIM0 0x04/* Timer/Counter0 */ +#define PRR0_BIT_PRTIM1 0x03/* Timer/Counter1 */ +#define PRR0_BIT_PRSPI 0x02/* Serial Peripheral Interface */ +#define PRR0_BIT_PRUSART0 0x01/* USART0 */ +#define PRR0_BIT_PRADC 0x00/* ADC */ + +typedef struct { +MachineClass parent; +}SampleMachineClass ; + +typedef struct { +MachineState parent; +MemoryRegion *ram; +MemoryRegion *flash; +AVRUsartState *usart0; +AVRTimer16State *timer1; +AVRMaskState *prr[2 ]; +}SampleMachineState ; + +#define TYPE_SAMPLE_MACHINE MACHINE_TYPE_NAME("sample") + +#define SAMPLE_MACHINE (obj) \ + OBJECT_CHECK(SampleMachineState, obj, TYPE_SAMPLE_MACHINE) +#define SAMPLE_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(SampleMachineClass, obj, TYPE_SAMPLE_MACHINE) +#define SAMPLE_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(SampleMachineClass, klass, TYPE_SAMPLE_MACHINE) + +static void sample_init (MachineState *machine) +{ +SampleMachineState *sms =SAMPLE_MACHINE (machine); +MemoryRegion *system_memory =get_system_memory (); +AVRCPU *cpu; +const char *firmware =NULL ; +const char *filename; +int bytes_loaded; +SysBusDevice *busdev; +DeviceState *cpudev; + + system_memory =get_system_memory (); + sms->ram =g_new (MemoryRegion,1 ); + sms->flash =g_new (MemoryRegion,1 ); + + cpu =AVR_CPU (cpu_create (machine->cpu_type)); + cpudev =DEVICE (cpu); + + +memory_region_init_rom (sms->flash,NULL ,"avr.flash" ,SIZE_FLASH , + &error_fatal); +memory_region_add_subregion (system_memory,OFFSET_CODE , sms->flash); + +/* following are atmel2560 device */ +create_unimplemented_device ("usart 3" ,OFFSET_DATA +0x0130 ,0x0007 ); +create_unimplemented_device ("timer-counter-16bit 5" , +OFFSET_DATA +0x0120 ,0x000e ); +create_unimplemented_device ("gpio L" ,OFFSET_DATA +0x0109 ,0x0003 ); +create_unimplemented_device ("gpio K" ,OFFSET_DATA +0x0106 ,0x0003 ); +create_unimplemented_device ("gpio J" ,OFFSET_DATA +0x0103 ,0x0003 ); +create_unimplemented_device ("gpio H" ,OFFSET_DATA +0x0100 ,0x0003 ); +create_unimplemented_device ("usart 2" ,OFFSET_DATA +0x00d0 ,0x0007 ); +create_unimplemented_device ("usart 1" ,OFFSET_DATA +0x00c8 ,0x0007 ); +create_unimplemented_device ("usart 0" ,OFFSET_DATA +0x00c0 ,0x0007 ); +create_unimplemented_device ("twi" ,OFFSET_DATA +0x00b8 ,0x0006 ); +create_unimplemented_device ("timer-counter-async-8bit 2" , +OFFSET_DATA +0x00b0 ,0x0007 ); +create_unimplemented_device ("timer-counter-16bit 4" , +OFFSET_DATA +0x00a0 ,0x000e ); +create_unimplemented_device ("timer-counter-16bit 3" , +OFFSET_DATA +0x0090 ,0x000e ); +create_unimplemented_device ("timer-counter-16bit 1" , +OFFSET_DATA +0x0080 ,0x000e ); +create_unimplemented_device ("ac / adc" , +OFFSET_DATA +0x0078 ,0x0008 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x0074 ,0x0002 ); +create_unimplemented_device ("int-controller" , +OFFSET_DATA +0x0068 ,0x000c ); +create_unimplemented_device ("sys" , +OFFSET_DATA +0x0060 ,0x0007 ); +create_unimplemented_device ("spi" , +OFFSET_DATA +0x004c ,0x0003 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x004a ,0x0002 ); +create_unimplemented_device ("timer-counter-pwm-8bit 0" , +OFFSET_DATA +0x0043 ,0x0006 ); +create_unimplemented_device ("ext-mem-iface" , +OFFSET_DATA +0x003e ,0x0005 ); +create_unimplemented_device ("int-controller" , +OFFSET_DATA +0x0035 ,0x0009 ); +create_unimplemented_device ("gpio G" ,OFFSET_DATA +0x0032 ,0x0003 ); +create_unimplemented_device ("gpio F" ,OFFSET_DATA +0x002f ,0x0003 ); +create_unimplemented_device ("gpio E" ,OFFSET_DATA +0x002c ,0x0003 ); +create_unimplemented_device ("gpio D" ,OFFSET_DATA +0x0029 ,0x0003 ); +create_unimplemented_device ("gpio C" ,OFFSET_DATA +0x0026 ,0x0003 ); +create_unimplemented_device ("gpio B" ,OFFSET_DATA +0x0023 ,0x0003 ); +create_unimplemented_device ("gpio A" ,OFFSET_DATA +0x0020 ,0x0003 ); + +memory_region_allocate_system_memory ( + sms->ram,NULL ,"avr.ram" ,SIZE_SRAM +SIZE_EXMEM ); + memory_region_add_subregion(system_memory, OFFSET_DATA + 0x200,
sms->ram);hw/avr/sample.c new file +16
-0+ +/* Power Reduction built-in peripheral */ + sms->prr[0 ] =AVR_MASK (sysbus_create_simple (TYPE_AVR_MASK , +OFFSET_DATA +PRR0_BASE ,NULL )); + sms->prr[1 ] =AVR_MASK (sysbus_create_simple (TYPE_AVR_MASK , +OFFSET_DATA +PRR1_BASE ,NULL )); + +/* USART 0 built-in peripheral */ + sms->usart0 =AVR_USART (object_new (TYPE_AVR_USART )); + busdev =SYS_BUS_DEVICE (sms->usart0); +qdev_prop_set_chr (DEVICE (sms->usart0),"chardev" ,serial_hd (0 )); +object_property_set_bool (OBJECT (sms->usart0), true,"realized" , + &error_fatal); +sysbus_mmio_map (busdev,0 ,OFFSET_DATA +USART_BASE ); +/* +* These IRQ numbers don't match the datasheet because we're counting from
hw/avr/sample.c new file +3
-0+* zero and not including reset. +*/ + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(cpudev,
USART_RXC_IRQ));
+ sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(cpudev,USART_DRE_IRQ));
+ sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(cpudev,USART_TXC_IRQ));hw/avr/sample.c new file +12
-0+sysbus_connect_irq (SYS_BUS_DEVICE (sms->prr[1 ]),PRR1_BIT_PRUSART1 , +qdev_get_gpio_in (DEVICE (sms->usart0),0 )); + +/* Timer 1 built-in periphal */ + sms->timer1 =AVR_TIMER16 (object_new (TYPE_AVR_TIMER16 )); +object_property_set_bool (OBJECT (sms->timer1), true,"realized" , + &error_fatal); + busdev =SYS_BUS_DEVICE (sms->timer1); +sysbus_mmio_map (busdev,0 ,OFFSET_DATA +TIMER1_BASE ); +sysbus_mmio_map (busdev,1 ,OFFSET_DATA +TIMER1_IMSK_BASE ); +sysbus_mmio_map (busdev,2 ,OFFSET_DATA +TIMER1_IFR_BASE ); + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(cpudev,
TIMER1_CAPT_IRQ));
+ sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(cpudev,TIMER1_COMPA_IRQ));
+ sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(cpudev,TIMER1_COMPB_IRQ));
+ sysbus_connect_irq(busdev, 3, qdev_get_gpio_in(cpudev,TIMER1_COMPC_IRQ));
+ sysbus_connect_irq(busdev, 4, qdev_get_gpio_in(cpudev,TIMER1_OVF_IRQ));hw/avr/sample.c new file +14
-0+sysbus_connect_irq (SYS_BUS_DEVICE (sms->prr[0 ]),PRR0_BIT_PRTIM1 , +qdev_get_gpio_in (DEVICE (sms->timer1),0 )); + +/* Load firmware (contents of flash) trying to auto-detect format */ + firmware = machine->firmware; +if (firmware !=NULL ) { + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded = load_elf( + filename, NULL, NULL, NULL, NULL, NULL, NULL, 0, EM_NONE, 0,0);
hw/avr/sample.c new file +40
-0+if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys ( + filename,OFFSET_CODE ,SIZE_FLASH ); + } +if (bytes_loaded <0 ) { +error_report ( +"Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } + } +} + +static void sample_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->desc ="AVR sample/example board (ATmega2560)" ; + mc->init = sample_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->default_cpu_type ="avr6-avr-cpu" ;/* ATmega2560. */ + mc->is_default =1 ; +} + +static const TypeInfo sample_info = { + .name =TYPE_SAMPLE_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (SampleMachineState), + .class_size =sizeof (SampleMachineClass), + .class_init = sample_class_init, +}; + +static void sample_machine_init (void ) +{ +type_register_static (&sample_info); +} + +type_init (sample_machine_init);hw/Kconfig +1
-0@@ -44,6 +44,7 @@ source watchdog/Kconfig # arch Kconfig source arm/Kconfig source alpha/Kconfig +source avr/Kconfig source cris/Kconfig source hppa/Kconfig source i386/Kconfighw/avr/Kconfig new file +6
-0@@ -0,0 +1,6 @@ +config AVR_SAMPLE + bool + select AVR_TIMER16 + select AVR_USART + select AVR_MASK + select UNIMPhw/avr/Makefile.objs new file +1
-1@@ -0,0 +1 @@ +obj-y += sample.o --2.17.2 (Apple Git-113)
Re: [PATCH v36 12/17] target/avr: Add example board configuration
Quoted 15 lines · Aleksandar Markovic
On Sunday, November 24, 2019, Michael Rolnik <[email protected] <mailto:[email protected]>> wrote:
A simple board setup that configures an AVR CPU to run a given firmware image.
This is all that's useful to implement without peripheral emulation as AVR CPUs include a lot of on-board peripherals.NOTE: this is not a real board !!!!
NOTE: it's used for CPU testing!!!!Signed-off-by Michael Rolnik <[email protected]<mailto:[email protected]>>
---
Quoted 7 lines
Given the complexities of peripherals of AVR CPUs, in my opinion it would be overly demanding to the submitters to require a real machine emulation at this point of time. So:
Reviewed-by Aleksandar Markovic <[email protected] <mailto:[email protected]>>Hopefully this will superceeded with a real board emulation in not so distsnt future.
Philippe, do you have something to add?
Joaquin started to work on the Arduino Mini board, with a ATmega168.
I'd prefer to not introduce the 'sample' board and directly use his work, because we have datasheet and schematics to match, and Michael/Sarah can use it to test their CPU the same way.
So since this series is blocked by QEMU 5.0 still closed anyway,
If we get no news from Joaquin when 5.0 opens, then feel free to remove this Nack tag.
Quoted 366 lines
hw/avr/sample.c | 282 +++++++++++++++++++++++++++++++++++++++++++
hw/Kconfig | 1 +
hw/avr/Kconfig | 6 +
hw/avr/Makefile.objs | 1 +
4 files changed, 290 insertions(+)
create mode 100644 hw/avr/sample.c
create mode 100644 hw/avr/Kconfig
create mode 100644 hw/avr/Makefile.objs
diff --git a/hw/avr/sample.c b/hw/avr/sample.c
new file mode 100644
index 0000000000..2295ec1b79
--- /dev/null
+++ b/hw/avr/sample.c
@@ -0,0 +1,282 @@
+/*
+ * 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
<http://www.gnu.org/licenses/lgpl-2.1.html>>
+ */
+
+/*
+ * NOTE:
+ * This is not a real AVR board, this is an example!
+ * The CPU is an approximation of an ATmega2560, but is
missing various
+ * built-in peripherals.
+ *
+ * This example board loads provided binary file into flash
memory and
+ * executes it from 0x00000000 address in the code memory space.
+ *
+ * Currently used for AVR CPU validation
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "cpu.h"
+#include "hw/hw.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/qtest.h"
+#include "ui/console.h"
+#include "hw/boards.h"
+#include "hw/loader.h"
+#include "qemu/error-report.h"
+#include "exec/address-spaces.h"
+#include "include/hw/sysbus.h"
+#include "include/hw/char/avr_usart.h"
+#include "include/hw/timer/avr_timer16.h"
+#include "include/hw/misc/avr_mask.h"
+#include "elf.h"
+#include "hw/misc/unimp.h"
+
+#define SIZE_FLASH 0x00040000
+#define SIZE_SRAM 0x00002000
+/*
+ * Size of additional "external" memory, as if the AVR were
configured to use
+ * an external RAM chip.
+ * Note that the configuration registers that normally enable this
feature are
+ * unimplemented.
+ */
+#define SIZE_EXMEM 0x00000000
+
+/* Offsets of peripherals in emulated memory space (i.e. not host
addresses) */
+#define PRR0_BASE 0x64
+#define PRR1_BASE 0x65
+#define USART_BASE 0xc0
+#define TIMER1_BASE 0x80
+#define TIMER1_IMSK_BASE 0x6f
+#define TIMER1_IFR_BASE 0x36
+
+/* Interrupt numbers used by peripherals */
+#define USART_RXC_IRQ 24
+#define USART_DRE_IRQ 25
+#define USART_TXC_IRQ 26
+
+#define TIMER1_CAPT_IRQ 15
+#define TIMER1_COMPA_IRQ 16
+#define TIMER1_COMPB_IRQ 17
+#define TIMER1_COMPC_IRQ 18
+#define TIMER1_OVF_IRQ 19
+
+/* Power reduction */
+#define PRR1_BIT_PRTIM5 0x05 /* Timer/Counter5 */
+#define PRR1_BIT_PRTIM4 0x04 /* Timer/Counter4 */
+#define PRR1_BIT_PRTIM3 0x03 /* Timer/Counter3 */
+#define PRR1_BIT_PRUSART3 0x02 /* USART3 */
+#define PRR1_BIT_PRUSART2 0x01 /* USART2 */
+#define PRR1_BIT_PRUSART1 0x00 /* USART1 */
+
+#define PRR0_BIT_PRTWI 0x06 /* TWI */
+#define PRR0_BIT_PRTIM2 0x05 /* Timer/Counter2 */
+#define PRR0_BIT_PRTIM0 0x04 /* Timer/Counter0 */
+#define PRR0_BIT_PRTIM1 0x03 /* Timer/Counter1 */
+#define PRR0_BIT_PRSPI 0x02 /* Serial Peripheral Interface */
+#define PRR0_BIT_PRUSART0 0x01 /* USART0 */
+#define PRR0_BIT_PRADC 0x00 /* ADC */
+
+typedef struct {
+ MachineClass parent;
+} SampleMachineClass;
+
+typedef struct {
+ MachineState parent;
+ MemoryRegion *ram;
+ MemoryRegion *flash;
+ AVRUsartState *usart0;
+ AVRTimer16State *timer1;
+ AVRMaskState *prr[2];
+} SampleMachineState;
+
+#define TYPE_SAMPLE_MACHINE MACHINE_TYPE_NAME("sample")
+
+#define SAMPLE_MACHINE(obj) \
+ OBJECT_CHECK(SampleMachineState, obj, TYPE_SAMPLE_MACHINE)
+#define SAMPLE_MACHINE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(SampleMachineClass, obj, TYPE_SAMPLE_MACHINE)
+#define SAMPLE_MACHINE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(SampleMachineClass, klass, TYPE_SAMPLE_MACHINE)
+
+static void sample_init(MachineState *machine)
+{
+ SampleMachineState *sms = SAMPLE_MACHINE(machine);
+ MemoryRegion *system_memory = get_system_memory();
+ AVRCPU *cpu;
+ const char *firmware = NULL;
+ const char *filename;
+ int bytes_loaded;
+ SysBusDevice *busdev;
+ DeviceState *cpudev;
+
+ system_memory = get_system_memory();
+ sms->ram = g_new(MemoryRegion, 1);
+ sms->flash = g_new(MemoryRegion, 1);
+
+ cpu = AVR_CPU(cpu_create(machine->cpu_type));
+ cpudev = DEVICE(cpu);
+
+
+ memory_region_init_rom(sms->flash, NULL, "avr.flash", SIZE_FLASH,
+ &error_fatal);
+ memory_region_add_subregion(system_memory, OFFSET_CODE,
sms->flash);
+
+ /* following are atmel2560 device */
+ create_unimplemented_device("usart 3", OFFSET_DATA + 0x0130,
0x0007);
+ create_unimplemented_device("timer-counter-16bit 5",
+ OFFSET_DATA + 0x0120, 0x000e);
+ create_unimplemented_device("gpio L", OFFSET_DATA + 0x0109,
0x0003);
+ create_unimplemented_device("gpio K", OFFSET_DATA + 0x0106,
0x0003);
+ create_unimplemented_device("gpio J", OFFSET_DATA + 0x0103,
0x0003);
+ create_unimplemented_device("gpio H", OFFSET_DATA + 0x0100,
0x0003);
+ create_unimplemented_device("usart 2", OFFSET_DATA + 0x00d0,
0x0007);
+ create_unimplemented_device("usart 1", OFFSET_DATA + 0x00c8,
0x0007);
+ create_unimplemented_device("usart 0", OFFSET_DATA + 0x00c0,
0x0007);
+ create_unimplemented_device("twi", OFFSET_DATA + 0x00b8, 0x0006);
+ create_unimplemented_device("timer-counter-async-8bit 2",
+ OFFSET_DATA + 0x00b0, 0x0007);
+ create_unimplemented_device("timer-counter-16bit 4",
+ OFFSET_DATA + 0x00a0, 0x000e);
+ create_unimplemented_device("timer-counter-16bit 3",
+ OFFSET_DATA + 0x0090, 0x000e);
+ create_unimplemented_device("timer-counter-16bit 1",
+ OFFSET_DATA + 0x0080, 0x000e);
+ create_unimplemented_device("ac / adc",
+ OFFSET_DATA + 0x0078, 0x0008);
+ create_unimplemented_device("ext-mem-iface",
+ OFFSET_DATA + 0x0074, 0x0002);
+ create_unimplemented_device("int-controller",
+ OFFSET_DATA + 0x0068, 0x000c);
+ create_unimplemented_device("sys",
+ OFFSET_DATA + 0x0060, 0x0007);
+ create_unimplemented_device("spi",
+ OFFSET_DATA + 0x004c, 0x0003);
+ create_unimplemented_device("ext-mem-iface",
+ OFFSET_DATA + 0x004a, 0x0002);
+ create_unimplemented_device("timer-counter-pwm-8bit 0",
+ OFFSET_DATA + 0x0043, 0x0006);
+ create_unimplemented_device("ext-mem-iface",
+ OFFSET_DATA + 0x003e, 0x0005);
+ create_unimplemented_device("int-controller",
+ OFFSET_DATA + 0x0035, 0x0009);
+ create_unimplemented_device("gpio G", OFFSET_DATA + 0x0032,
0x0003);
+ create_unimplemented_device("gpio F", OFFSET_DATA + 0x002f,
0x0003);
+ create_unimplemented_device("gpio E", OFFSET_DATA + 0x002c,
0x0003);
+ create_unimplemented_device("gpio D", OFFSET_DATA + 0x0029,
0x0003);
+ create_unimplemented_device("gpio C", OFFSET_DATA + 0x0026,
0x0003);
+ create_unimplemented_device("gpio B", OFFSET_DATA + 0x0023,
0x0003);
+ create_unimplemented_device("gpio A", OFFSET_DATA + 0x0020,
0x0003);
+
+ memory_region_allocate_system_memory(
+ sms->ram, NULL, "avr.ram", SIZE_SRAM + SIZE_EXMEM);
+ memory_region_add_subregion(system_memory, OFFSET_DATA + 0x200,
sms->ram);
+
+ /* Power Reduction built-in peripheral */
+ sms->prr[0] = AVR_MASK(sysbus_create_simple(TYPE_AVR_MASK,
+ OFFSET_DATA + PRR0_BASE, NULL));
+ sms->prr[1] = AVR_MASK(sysbus_create_simple(TYPE_AVR_MASK,
+ OFFSET_DATA + PRR1_BASE, NULL));
+
+ /* USART 0 built-in peripheral */
+ sms->usart0 = AVR_USART(object_new(TYPE_AVR_USART));
+ busdev = SYS_BUS_DEVICE(sms->usart0);
+ qdev_prop_set_chr(DEVICE(sms->usart0), "chardev", serial_hd(0));
+ object_property_set_bool(OBJECT(sms->usart0), true, "realized",
+ &error_fatal);
+ sysbus_mmio_map(busdev, 0, OFFSET_DATA + USART_BASE);
+ /*
+ * These IRQ numbers don't match the datasheet because we're
counting from
+ * zero and not including reset.
+ */
+ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(cpudev,
USART_RXC_IRQ));
+ sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(cpudev,
USART_DRE_IRQ));
+ sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(cpudev,
USART_TXC_IRQ));
+ sysbus_connect_irq(SYS_BUS_DEVICE(sms->prr[1]), PRR1_BIT_PRUSART1,
+ qdev_get_gpio_in(DEVICE(sms->usart0), 0));
+
+ /* Timer 1 built-in periphal */
+ sms->timer1 = AVR_TIMER16(object_new(TYPE_AVR_TIMER16));
+ object_property_set_bool(OBJECT(sms->timer1), true, "realized",
+ &error_fatal);
+ busdev = SYS_BUS_DEVICE(sms->timer1);
+ sysbus_mmio_map(busdev, 0, OFFSET_DATA + TIMER1_BASE);
+ sysbus_mmio_map(busdev, 1, OFFSET_DATA + TIMER1_IMSK_BASE);
+ sysbus_mmio_map(busdev, 2, OFFSET_DATA + TIMER1_IFR_BASE);
+ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(cpudev,
TIMER1_CAPT_IRQ));
+ sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(cpudev,
TIMER1_COMPA_IRQ));
+ sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(cpudev,
TIMER1_COMPB_IRQ));
+ sysbus_connect_irq(busdev, 3, qdev_get_gpio_in(cpudev,
TIMER1_COMPC_IRQ));
+ sysbus_connect_irq(busdev, 4, qdev_get_gpio_in(cpudev,
TIMER1_OVF_IRQ));
+ sysbus_connect_irq(SYS_BUS_DEVICE(sms->prr[0]), PRR0_BIT_PRTIM1,
+ qdev_get_gpio_in(DEVICE(sms->timer1), 0));
+
+ /* Load firmware (contents of flash) trying to auto-detect
format */
+ firmware = machine->firmware;
+ if (firmware != NULL) {
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+ if (filename == NULL) {
+ error_report("Unable to find %s", firmware);
+ exit(1);
+ }
+
+ bytes_loaded = load_elf(
+ filename, NULL, NULL, NULL, NULL, NULL, NULL, 0,
EM_NONE, 0, 0);
+ if (bytes_loaded < 0) {
+ bytes_loaded = load_image_targphys(
+ filename, OFFSET_CODE, SIZE_FLASH);
+ }
+ if (bytes_loaded < 0) {
+ error_report(
+ "Unable to load firmware image %s as ELF or raw
binary",
+ firmware);
+ exit(1);
+ }
+ }
+}
+
+static void sample_class_init(ObjectClass *oc, void *data)
+{
+ MachineClass *mc = MACHINE_CLASS(oc);
+
+ mc->desc = "AVR sample/example board (ATmega2560)";
+ mc->init = sample_init;
+ mc->default_cpus = 1;
+ mc->min_cpus = mc->default_cpus;
+ mc->max_cpus = mc->default_cpus;
+ mc->default_cpu_type = "avr6-avr-cpu"; /* ATmega2560. */
+ mc->is_default = 1;
+}
+
+static const TypeInfo sample_info = {
+ .name = TYPE_SAMPLE_MACHINE,
+ .parent = TYPE_MACHINE,
+ .instance_size = sizeof(SampleMachineState),
+ .class_size = sizeof(SampleMachineClass),
+ .class_init = sample_class_init,
+};
+
+static void sample_machine_init(void)
+{
+ type_register_static(&sample_info);
+}
+
+type_init(sample_machine_init);
diff --git a/hw/Kconfig b/hw/Kconfig
index b9685b3944..07b8abb342 100644
--- a/hw/Kconfig
+++ b/hw/Kconfig
@@ -44,6 +44,7 @@ source watchdog/Kconfig
# arch Kconfig
source arm/Kconfig
source alpha/Kconfig
+source avr/Kconfig
source cris/Kconfig
source hppa/Kconfig
source i386/Kconfig
diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig
new file mode 100644
index 0000000000..92aa1e6afb
--- /dev/null
+++ b/hw/avr/Kconfig
@@ -0,0 +1,6 @@
+config AVR_SAMPLE
+ bool
+ select AVR_TIMER16
+ select AVR_USART
+ select AVR_MASK
+ select UNIMP
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
new file mode 100644
index 0000000000..626b7064b3
--- /dev/null
+++ b/hw/avr/Makefile.objs
@@ -0,0 +1 @@
+obj-y += sample.o
--
2.17.2 (Apple Git-113)PATCH v36 13/17 target/avr: Register AVR support with the rest of QEMU
In reply to Michael RolnikAdd AVR related definitions into QEMU
--- qapi/machine.json | 3 ++- include/disas/dis-asm.h | 6 ++++++ include/sysemu/arch_init.h | 1 + arch_init.c | 2 ++ tests/machine-none-test.c | 1 + 5 files changed, 12 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 +6 -0
@@ -211,6 +211,12 @@ enum bfd_architecture#define bfd_mach_m32r 0/* backwards compatibility */ bfd_arch_mn10200, /* Matsushita MN10200 */ bfd_arch_mn10300, /* Matsushita MN10300 */ + bfd_arch_avr, /* Atmel AVR microcontrollers. */ +#define bfd_mach_avr1 1 +#define bfd_mach_avr2 2 +#define bfd_mach_avr3 3 +#define bfd_mach_avr4 4 +#define bfd_mach_avr5 5 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 ;
tests/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.17.2 (Apple Git-113)
PATCH v36 14/17 target/avr: Update build system
In reply to Michael RolnikMake AVR support buildable
--- configure | 7 +++++++ default-configs/avr-softmmu.mak | 5 +++++ target/avr/Makefile.objs | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 target/avr/Makefile.objs
configure +7 -0
@@ -7649,6 +7649,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)
@@ -7868,6 +7872,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_AVR_SAMPLE=y
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.17.2 (Apple Git-113)
PATCH v36 15/17 target/avr: Add boot serial test
In reply to Michael RolnikPrint out 'T' through serial port
--- tests/boot-serial-test.c | 10 ++++++++++ tests/Makefile.include | 2 ++ 2 files changed, 12 insertions(+)
tests/boot-serial-test.c +10 -0
@@ -16,6 +16,15 @@#include "qemu/osdep.h" #include "libqtest.h" +static const uint8_t bios_avr[] = { +0x88 ,0xe0 ,/* ldi r24, 0x08 */ +0x80 ,0x93 ,0xc1 ,0x00 ,/* sts 0x00C1, r24 ; Enable tx */ +0x86 ,0xe0 ,/* ldi r24, 0x06 */ +0x80 ,0x93 ,0xc2 ,0x00 ,/* sts 0x00C2, r24 ; Set the data bits to 8 */ +0x84 ,0xe5 ,/* ldi r24, 0x54 */ +0x80 ,0x93 ,0xc6 ,0x00 ,/* sts 0x00C6, r24 ; Output 'T' */ +}; +static const uint8_t kernel_mcf5208[] = {0x41 ,0xf9 ,0xfc ,0x06 ,0x00 ,0x00 ,/* lea 0xfc060000,%a0 */ 0x10 ,0x3c ,0x00 ,0x54 ,/* move.b #'T',%d0 */
@@ -103,6 +112,7 @@ typedef struct testdef {static testdef_t tests[] = { {"alpha" ,"clipper" ,"" ,"PCI:" }, + {"avr" ,"sample" ,"" ,"T" ,sizeof (bios_avr),NULL , bios_avr }, {"ppc" ,"ppce500" ,"" ,"U-Boot" }, {"ppc" ,"40p" ,"-vga none -boot d" ,"Trying cd:," }, {"ppc" ,"g3beige" ,"" ,"PowerPC,750" },
tests/Makefile.include +2 -0
@@ -208,6 +208,8 @@ check-qtest-i386-y += tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y += tests/numa-test$(EXESUF) check-qtest-x86_64-y += $(check-qtest-i386-y) +check-qtest-avr-y += tests/boot-serial-test$(EXESUF) + check-qtest-alpha-y += tests/boot-serial-test$(EXESUF) check-qtest-alpha-$(CONFIG_VGA) += tests/display-vga-test$(EXESUF)
Signature · 1 line
2.17.2 (Apple Git-113)
PATCH v36 16/17 target/avr: Add Avocado test
In reply to Michael RolnikThe 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
--- tests/acceptance/machine_avr6.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/acceptance/machine_avr6.py
tests/acceptance/machine_avr6.py new file +36 -0
@@ -0,0 +1,36 @@ +import logging +import time +import distutils.spawn + +from avocado import skipUnless +from avocado_qemu import Test +from avocado.utils import process + +class AVR6Machine(Test): + timeout = 5 + + def test_freertos(self): + """ + :avocado: tags=arch:avr + :avocado: tags=machine:sample + """ + """ + https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf + constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' + """ + rom_url = 'https://github.com/seharris/qemu-avr-tests' + rom_url += '/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf' + rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' + rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) + + self.vm.set_machine('sample') + self.vm.add_args('-bios', rom_path) + self.vm.add_args('-nographic') + self.vm.launch() + + time.sleep(2) + self.vm.shutdown() + + match = 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' + + self.assertIn(match, self.vm.get_log())
Signature · 1 line
2.17.2 (Apple Git-113)
Re: [PATCH v36 16/17] target/avr: Add Avocado test
Quoted 10 lines · Michael Rolnik
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 workingSigned-off-by Michael Rolnik <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Acked-by Thomas Huth <[email protected]>---
License preamble missing.
Quoted 54 lines
tests/acceptance/machine_avr6.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/acceptance/machine_avr6.pytests/acceptance/machine_ renamed from tests/acceptance/machine_avr6.py +0
-0
avr6.py
new file mode 100644
index 0000000000..0601080b01tests/acceptance/machine_avr6.py new file +18
-0@@ -0,0 +1,36 @@ +import logging +import time +import distutils.spawn + +from avocado import skipUnless +from avocado_qemu import Test +from avocado.utils import process + +class AVR6Machine(Test): + timeout = 5 + + def test_freertos(self): + """ + :avocado: tags=arch:avr + :avocado: tags=machine:sample + """ + """ + https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf
+ constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEF
GHIJKLMNOPQRSTUVWX'tests/acceptance/machine_avr6.py new file +3
-0+ """ + rom_url = 'https://github.com/seharris/qemu-avr-tests' + rom_url += '/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf'
tests/acceptance/machine_avr6.py new file +14
-1+ rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' + rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) + + self.vm.set_machine('sample') + self.vm.add_args('-bios', rom_path) + self.vm.add_args('-nographic') + self.vm.launch() + + time.sleep(2) + self.vm.shutdown() + + match = 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' + + self.assertIn(match, self.vm.get_log()) --2.17.2 (Apple Git-113)
Re: [PATCH v36 16/17] target/avr: Add Avocado test
In reply to Michael RolnikHi Michael,
Quoted 20 lines · Michael Rolnik
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 workingSigned-off-by Michael Rolnik <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Acked-by Thomas Huth <[email protected]>--- tests/acceptance/machine_avr6.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)create mode 100644
tests/acceptance/machine_avr6.pytests/acceptance/machine_avr6.py new file +0
-0
tests/acceptance/machine_avr6.py line 5
Quoted 5 lines
tests/acceptance/machine_avr6.py new file +5
-0@@ -0,0 +1,36 @@ +import logging +import time +import distutils.spawn + +from avocado import skipUnless
^ not used, can be dropped
tests/acceptance/machine_avr6.py line 6
Quoted 1 line
tests/acceptance/machine_avr6.py new file +1
-0+from avocado_qemu import Test
^ OK
tests/acceptance/machine_avr6.py line 7
Quoted 1 line
tests/acceptance/machine_avr6.py new file +1
-0+from avocado.utils import process
^ not used, can be dropped
tests/acceptance/machine_avr6.py line 18
Quoted 11 lines
tests/acceptance/machine_avr6.py new file +11
-0+ +class AVR6Machine(Test): + timeout = 5 + + def test_freertos(self): + """ + :avocado: tags=arch:avr + :avocado: tags=machine:sample + """ + """ + https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf
As a short documentation, maybe refer to the main.c file instead?
tests/acceptance/machine_avr6.py line 22
Quoted 4 lines
tests/acceptance/machine_avr6.py new file +4
-0+ constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' + """ + rom_url = 'https://github.com/seharris/qemu-avr-tests' + rom_url += '/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf'
Please use the commit sha1 instead of 'master', because Sarah might push a new reference to /master, while the commit sha1 stays constant:
rom_url = ('https://github.com/seharris/qemu-avr-tests'
'/raw/36c3e67b8755dcf/free-rtos/Demo'
'/AVR_ATMega2560_GCC/demo.elf')Quoted 15 lines
tests/acceptance/machine_avr6.py new file +14
-0+ rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' + rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) + + self.vm.set_machine('sample') + self.vm.add_args('-bios', rom_path) + self.vm.add_args('-nographic') + self.vm.launch() + + time.sleep(2) + self.vm.shutdown() + + match = 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' + + self.assertIn(match, self.vm.get_log())
PATCH v36 17/17 target/avr: Update MAINTAINERS file
In reply to Michael RolnikInclude AVR maintaners in MAINTAINERS file
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu* +AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ + CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained
Signature · 1 line
2.17.2 (Apple Git-113)
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
Quoted 14 lines · Michael Rolnik
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*
MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +
If Cleber and Eduardo don't object, please add file:
tests/acceptance/machine_avr6.py
to the list. This means that the file would have a sort of "dual"
maintainrship: Cleber and Eduardo would take care of Python/Avocado/test harness aspects, while you and Sarah would take care of AVR aspects.
Cleber and Eduardo, please note that AVR target will be significantly different than others, since these CPUs are not meant to work with Linux kernel, and there are other idiosyncracies where AVR folks would be really needed. There is also a case of MIPS-specific Avocado test where, at least from my point of view, dual maintainership worked well, so I think this one would work well too.
With or without that file addition:
Quoted 7 lines
MAINTAINERS +0
-1CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
----- Original Message -----
Quoted 37 lines
From: "Aleksandar Markovic" <[email protected]>
To: "Michael Rolnik" <[email protected]>, "Cleber Rosa" <[email protected]>, "Eduardo Habkost" <[email protected]>
Cc: [email protected], "richard henderson" <[email protected]>, [email protected], [email protected], [email protected], [email protected]
Sent: Monday, November 25, 2019 6:49:40 PM
Subject: Re: [PATCH v36 17/17] target/avr: UpdateMAINTAINERSfileQuoted 14 lines · Michael Rolnik
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +If Cleber and Eduardo don't object, please add file:
Quoted 6 lines
tests/acceptance/machine_avr6.pyto the list. This means that the file would have a sort of "dual"
maintainrship: Cleber and Eduardo would take care of Python/Avocado/test harness aspects, while you and Sarah would take care of AVR aspects.
No objections, quite the contrary, I'd happy to be CC'd when such code changes.
Thanks,
- Cleber.
Quoted 21 lines
Cleber and Eduardo, please note that AVR target will be significantly different than others, since these CPUs are not meant to work with Linux kernel, and there are other idiosyncracies where AVR folks would be really needed. There is also a case of MIPS-specific Avocado test where, at least from my point of view, dual maintainership worked well, so I think this one would work well too.
With or without that file addition:
Reviewed-by Aleksandar Markovic <[email protected]>Quoted 7 lines
MAINTAINERS +0
-1CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
In reply to Aleksandar MarkovicQuoted 30 lines · Aleksandar Markovic
Quoted 14 lines · Michael Rolnik
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +If Cleber and Eduardo don't object, please add file:
Quoted 5 lines
tests/acceptance/machine_avr6.pyto the list. This means that the file would have a sort of "dual"
maintainrship: Cleber and Eduardo would take care of Python/Avocado/test harness aspects, while you and Sarah would take care of AVR aspects.
No objections. Thanks!
Quoted 11 lines
Cleber and Eduardo, please note that AVR target will be significantly different than others, since these CPUs are not meant to work with Linux kernel, and there are other idiosyncracies where AVR folks would be really needed. There is also a case of MIPS-specific Avocado test where, at least from my point of view, dual maintainership worked well, so I think this one would work well too.
With or without that file addition:
Reviewed-by Aleksandar Markovic <[email protected]>
Signature · 1 line
Eduardo
PATCH v36 17/17 target/avr: Update MAINTAINERS file
In reply to Michael RolnikQuoted 14 lines · Michael Rolnik
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*
MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +
I had a strange feeling that something is missing here, and I finally realized what that was:
R: Sarah Harris <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-10/msg04225.html
CRIS TCG CPUs
Quoted 6 lines
MAINTAINERS +0
-1M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
Aleksandar,
there was an email from Sarah, stating that she does not want to be a maintainer.
Quoted 46 lines · Aleksandar Markovic
Quoted 14 lines · Michael Rolnik
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +I had a strange feeling that something is missing here, and I finally realized what that was:
R: Sarah Harris <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-10/msg04225.html
CRIS TCG CPUs
Quoted 6 lines
MAINTAINERS +0
-1M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
Quoted 5 lines · Michael Rolnik
Aleksandar,
there was an email from Sarah, stating that she does not want to be a maintainer.
But this is for "reviewer" role, not "maintainer".
Sarah?
Quoted 51 lines · Aleksandar Markovic
Quoted 33 lines · Michael Rolnik
Quoted 15 lines
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*MAINTAINERS S: Maintained · line 174
Quoted 10 lines
MAINTAINERS +9
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/ +F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +I had a strange feeling that something is missing here, and I finally realized what that was:
Quoted 12 lines
R: Sarah Harris <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-10/msg04225.html
Quoted 6 lines
MAINTAINERS +0
-1CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
--
Best Regards,
Michael Rolnik
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
Ah. I think Sarah was ok with reviewer role.
Quoted 66 lines · Aleksandar Markovic
Quoted 4 lines · Michael Rolnik
Aleksandar,
there was an email from Sarah, stating that she does not want to be a
maintainer.
Quoted 1 line
But this is for "reviewer" role, not "maintainer".
Sarah?
Quoted 1 line
On Tue, Nov 26, 2019 at 5:17 AM Aleksandar Markovic <
Quoted 20 lines · [email protected]> wrote:
Quoted 20 lines · Michael Rolnik
Quoted 16 lines
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
MAINTAINERS +4
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/Quoted 8 lines
MAINTAINERS S: Maintained · line 174
Quoted 5 lines
MAINTAINERS +5
-0+F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +I had a strange feeling that something is missing here, and I finally
realized what that was:
Quoted 18 lines
Quoted 13 lines
R: Sarah Harris <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-10/msg04225.html
Quoted 6 lines
MAINTAINERS +0
-1CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
--
Best Regards,
Michael Rolnik
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [PATCH v36 17/17] target/avr: Update MAINTAINERS file
Yes, I don't have time to do maintenance, but I can manage reviewing.
Kind regards,
Sarah Harris
Quoted 76 lines · On Tue, 26 Nov 2019 22:41:32 +0200 Michael Rolnik <[email protected]> wrote:
Ah. I think Sarah was ok with reviewer role.
Quoted 66 lines · Aleksandar Markovic
Quoted 4 lines · Michael Rolnik
Aleksandar,
there was an email from Sarah, stating that she does not want to be a
maintainer.
Quoted 1 line
But this is for "reviewer" role, not "maintainer".
Sarah?
Quoted 1 line
On Tue, Nov 26, 2019 at 5:17 AM Aleksandar Markovic <
Quoted 20 lines · [email protected]> wrote:
Quoted 20 lines · Michael Rolnik
Quoted 16 lines
Include AVR maintaners in
MAINTAINERSfileSigned-off-by Michael Rolnik <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0@@ -163,6 +163,15 @@ S: Maintained F: hw/arm/smmu* F: include/hw/arm/smmu*Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
MAINTAINERS +4
-0+AVR TCG CPUs +M: Michael Rolnik <[email protected]> +S: Maintained +F: target/avr/Quoted 8 lines
MAINTAINERS S: Maintained · line 174
Quoted 5 lines
MAINTAINERS +5
-0+F: hw/misc/avr_mask.c +F: hw/char/avr_usart.c +F: hw/timer/avr_timer16.c +F: hw/avr/ +I had a strange feeling that something is missing here, and I finally
realized what that was:
Quoted 18 lines
Quoted 13 lines
R: Sarah Harris <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-10/msg04225.html
Quoted 6 lines
MAINTAINERS +0
-1CRIS TCG CPUs M: Edgar E. Iglesias <[email protected]> S: Maintained --2.17.2 (Apple Git-113)
--
Best Regards,
Michael RolnikSignature · 2 lines
Best Regards, Michael Rolnik
Cc'ing Joaquin who is implementing the ATmega328.
Quoted 246 lines · Michael Rolnik
This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested yet. However I was able to execute simple code with functions. e.g fibonacci calculation. This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.the patches include the following
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR coresavr1 avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 xmega2 xmega4 xmega5 xmega6 xmega73. a definition of sample machine with SRAM, FLASH and CPU which allows to execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features togetherchanges since v3
1. rampD/X/Y/Z registers are encoded as0x00ff0000(instead of0x000000ff) for faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed atavr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7.tcg_const_local_i32->tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of0xff- r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCHchanges since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifyinggen_goto_tbas there is no real paging
5.env->pc->env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removingavr_set_feature
10. SPL/SPH set bug fix
11. switchingstb_phystocpu_stb_data
12. cleaning upavr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)changes since v5
1. BLD bug fix
2. decoder generator is addedchages since v6
1. using cpu_get_sreg/cpu_set_sreg in avr_cpu_gdb_read_register/avr_cpu_gdb_write_register
2. configure the target as little endian because otherwise GDB does not work
3. fixing and testing gen_push_ret/gen_pop_retchanges since v7
1. folding back v6
2. logging athelper_outbandhelper_inbare done for non supported yet registers only
3.MAINTAINERSupdatedchanges since v8
1. removing hw/avr from hw/Makefile.obj as it should not be built for all
2. making linux compilable
3. testing ona. Mac, Apple LLVM version 7.0.0 b. Ubuntu 12.04, gcc 4.9.2 c. Fedora 23, gcc 5.3.14. folding back some patches
5. translation bug fixes for ORI, CPI, XOR instructions
6. propper handling of cpu register writes though memorychanges since v9
1. removing forward declarations of static functions
2. disabling debug prints
3. switching to case range instead of if else if ...
4. LD/ST IN/OUT accessing CPU maintainder registers are not routed to any device
5. commenst about sample board and sample IO device added
6. sample board description is more descriptive now
7.memory_region_allocate_system_memoryis used to create RAM
8. now there arehelper_fullrd&helper_fullwrwhen LD/ST try to access registerschanges since v10
1. movig back fullwr & fullrd into the commit where outb and inb were introduced
2. changingtlb_fillfunction signature
3. adding empty line between functions
4. adding newline on the last line of the file
5. usingtb->flagsto generae full access ST/LD instructions
6. fixing SBRC bug
7. folding back 10th commit
8. whenever a new file is introduced it's added to Makefile.objschanges since v11
1. updating to v2.7.0-rc
2. removing assignment toenv->fullaccfromgen_intermediate_codechanges since v12
1. fixing spacing
2. fixing get/put_segment functions
3. removingtarget-avr/machine.hfile
4.VMSTATE_SINGLE_TEST->VMSTATE_SINGLE
5. comment spelling
6. removinghw/avr/sample_io.c
7. char const* -> const char*
8. proper ram allocation
9. fixing breakpoint functionality.
10.env1 -> env
11.fixingavr_cpu_gdb_write_register&avr_cpu_gdb_read_registerfunctions 12.any cpu is removed
12.feature bits are not saved into vm statechanges since v13
1. rebasing to v2.7.0-rc1changes since v14
1. I made self review with git gui tool. (I did not know such a thing exists)
2. removing all double/tripple spaces
3. removing comment reference to SampleIO
4. folding back some changes, so there is not deleted lines in my code
5. moving avr configuration, within configure file, before chrischanges since v15
1. removing IO registers cache from CPU
2. implementing CBI/SBI asread(helper_inb), modify,write(helper_outb)
3. implementing CBIC/SBIC asread(helper_inb), check, branch
4. adding missingtcg_temp_free_i32fortcg_const_i32changes since v16
1. removing EXT IO registers knoledge from CPU. These registers are accessible by LD/ST only. CPU has no interest in themchanges since v17 (by Richard Henderson)
This is Michael's v17, with some adjustments of my own:1. Fix the whitespace errors reported by "git am",
2. Replace the utf-8 characters with normal ascii,
3. Ditch the separate compilation oftranslate.c.I retained the two separate files that could be regenerated from the included cpugen program, but merged in
translate-insn.c. Not that it matters, but the code generated is about 3k smaller.changes since v18
1. moving target-avr into target/avr 2. do not call cpu_exec_initfn function from avr_cpu_initfn 3. call cpu_exec_realizefn avr_cpu_realizefn 4. do not fail sample machine creation if no rom is suplied 5. add tcg_gen_exit_tb(0) for BS_BRANCH in gen_intermediate_code 6. fix a register getters/setters in machine.c 7. changing QEMU_ARCH_AVR from 1<<17 to 1<<18changes since v19
1. use decodetree.py tool to decode instructions 2. adding USART 3. adding 16 bit timer peripherals 4. changing QEMU_ARCH_AVR from 1<<18 to 1<<20 5. renaming tlb_fill to avr_cpu_tlb_fillchanges since v20
1. use one CPU naming convention 2. merging insn16.decode & insn32.decode files 3. modifying skip next instruction mechanizm 4. translate BREAK as NOP for nowchanges since v21
1. Reorganize bstate.
This will make transition to <exec/translator.h> easier, and fixes a couple of bugs wrt single stepping by [email protected]
2. Drop cpc and fix page cross condition.
by [email protected]
3. Refactor checking supported/unsupported instructions
4. Addgdb-xml/avr-cpu.xmlchanges since v22
1. Rebase
2. Split long commentchanges since v23
1. remove avr_cpu_list_compare function 2. modify avr_cpu_class_by_name function 3. modify avr_cpu_list_entry function 4. modify avr_cpu_list functionchanges since v24
1. removeAVR_CPU_TYPE_NAMEmacrochanges since v25
1. fix patches. every file belong to one patch only 2. change copyright year from 2016 to 2019 3. create mask device to emulate prr0/prr1changes since v26
1. add avocado acceptence test
2. add boot serial testchanges since v27
1. list atmel2560 devices as unimplemented
2. fix sram base/sizechanges since v28
1. rebase
2. fix includes & buildchanges since v29
1. fixing ownership
2. using 'since' instread of 'added in'changes since v30
1. rebasechanges since v31
1. splitting 'Add instruction translation' commit 2. fixing typo in qapi/machine.json sicne -> since 3. removing unintended changes in configure file 4. adding Richard Henderson as a co developer to 'Add instruction translation - CPU main translation funcions' commitchanges since v32
1. modifycpu_get_sregto treat sreg C as other flags, except sreg Zchanges since v33
1. ensure flag C is always calculated as one bit
2. calculate flag Z as one bit, without using inverse logicchanges since v34
1. rebasechanges since v35
1. rebase 2. use NANOSECONDS_PER_SECOND instead of 1000000000 in avr_timer16.c 3. split "target/avr: Register AVR support with the rest of QEMU" into three patches 1. "target/avr: Register AVR support with the rest of QEMU" 2. "target/avr: Update build system" 3. "target/avr: Update MAINTAINERS file"4. split "target/avr: Add tests" patch into two patches
1. "target/avr: Add Avocado test"
2. "target/avr: Add boot serial test"
5. Add instruction disassembly function
6. change "since 4.2" to "since 5.0"
Quoted 18 lines · Michael Rolnik
This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested yet.
However I was able to execute simple code with functions. e.g fibonacci calculation.
This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.the patches include the following
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR coresavr1 avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 xmega2 xmega4 xmega5 xmega6 xmega7
Quoted 10 lines
3. a definition of sample machine with SRAM, FLASH and CPU which allows to execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features together
Michael,
Please do persist.
In next version, please add to the cover letter, right at this place:
1) An example of invoking QEMU for AVR, and doing some simple stuff with such virtual machine
2) An example of debugging QEMU-powered AVR vurtual machine with GDB
3) (optional) Some other interesting example.
This is needed so that more people get interested in your series, try the things out, convince themself in the value of this series (without digging into individual patches searching fir examples).
Regards,
Aleksandar
Quoted 330 lines
changes since v3
1. rampD/X/Y/Z registers are encoded as0x00ff0000(instead of0x000000ff) for faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed atavr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7.tcg_const_local_i32->tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of0xff- r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCHchanges since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifyinggen_goto_tbas there is no real paging
5.env->pc->env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removingavr_set_feature
10. SPL/SPH set bug fix
11. switchingstb_phystocpu_stb_data
12. cleaning upavr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)changes since v5
1. BLD bug fix
2. decoder generator is addedchages since v6
1. using cpu_get_sreg/cpu_set_sreg in avr_cpu_gdb_read_register/avr_cpu_gdb_write_register
2. configure the target as little endian because otherwise GDB does not work
3. fixing and testing gen_push_ret/gen_pop_retchanges since v7
1. folding back v6
2. logging athelper_outbandhelper_inbare done for non supported yet registers only
3.MAINTAINERSupdatedchanges since v8
1. removing hw/avr from hw/Makefile.obj as it should not be built for all
2. making linux compilable
3. testing ona. Mac, Apple LLVM version 7.0.0 b. Ubuntu 12.04, gcc 4.9.2 c. Fedora 23, gcc 5.3.14. folding back some patches
5. translation bug fixes for ORI, CPI, XOR instructions
6. propper handling of cpu register writes though memorychanges since v9
1. removing forward declarations of static functions
2. disabling debug prints
3. switching to case range instead of if else if ...
4. LD/ST IN/OUT accessing CPU maintainder registers are not routed to any device
5. commenst about sample board and sample IO device added
6. sample board description is more descriptive now
7.memory_region_allocate_system_memoryis used to create RAM
8. now there arehelper_fullrd&helper_fullwrwhen LD/ST try to access registerschanges since v10
1. movig back fullwr & fullrd into the commit where outb and inb were introduced
2. changingtlb_fillfunction signature
3. adding empty line between functions
4. adding newline on the last line of the file
5. usingtb->flagsto generae full access ST/LD instructions
6. fixing SBRC bug
7. folding back 10th commit
8. whenever a new file is introduced it's added to Makefile.objschanges since v11
1. updating to v2.7.0-rc
2. removing assignment toenv->fullaccfromgen_intermediate_codechanges since v12
1. fixing spacing
2. fixing get/put_segment functions
3. removingtarget-avr/machine.hfile
4.VMSTATE_SINGLE_TEST->VMSTATE_SINGLE
5. comment spelling
6. removinghw/avr/sample_io.c
7. char const* -> const char*
8. proper ram allocation
9. fixing breakpoint functionality.
10.env1 -> env
11.fixingavr_cpu_gdb_write_register&avr_cpu_gdb_read_registerfunctions 12.any cpu is removed
12.feature bits are not saved into vm statechanges since v13
1. rebasing to v2.7.0-rc1changes since v14
1. I made self review with git gui tool. (I did not know such a thing exists)
2. removing all double/tripple spaces
3. removing comment reference to SampleIO
4. folding back some changes, so there is not deleted lines in my code
5. moving avr configuration, within configure file, before chrischanges since v15
1. removing IO registers cache from CPU
2. implementing CBI/SBI asread(helper_inb), modify,write(helper_outb)
3. implementing CBIC/SBIC asread(helper_inb), check, branch
4. adding missingtcg_temp_free_i32fortcg_const_i32changes since v16
1. removing EXT IO registers knoledge from CPU. These registers are accessible
by LD/ST only. CPU has no interest in themchanges since v17 (by Richard Henderson)
This is Michael's v17, with some adjustments of my own:1. Fix the whitespace errors reported by "git am",
2. Replace the utf-8 characters with normal ascii,
3. Ditch the separate compilation oftranslate.c.I retained the two separate files that could be regenerated from the included cpugen program, but merged in
translate-insn.c. Not that it matters, but the code generated is about 3k smaller.changes since v18
1. moving target-avr into target/avr 2. do not call cpu_exec_initfn function from avr_cpu_initfn 3. call cpu_exec_realizefn avr_cpu_realizefn 4. do not fail sample machine creation if no rom is suplied 5. add tcg_gen_exit_tb(0) for BS_BRANCH in gen_intermediate_code 6. fix a register getters/setters in machine.c 7. changing QEMU_ARCH_AVR from 1<<17 to 1<<18changes since v19
1. use decodetree.py tool to decode instructions 2. adding USART 3. adding 16 bit timer peripherals 4. changing QEMU_ARCH_AVR from 1<<18 to 1<<20 5. renaming tlb_fill to avr_cpu_tlb_fillchanges since v20
1. use one CPU naming convention 2. merging insn16.decode & insn32.decode files 3. modifying skip next instruction mechanizm 4. translate BREAK as NOP for nowchanges since v21
1. Reorganize bstate.
This will make transition to <exec/translator.h> easier, and fixes a
couple of bugs wrt single stepping
by [email protected]
2. Drop cpc and fix page cross condition.
by [email protected]
3. Refactor checking supported/unsupported instructions
4. Addgdb-xml/avr-cpu.xmlchanges since v22
1. Rebase
2. Split long commentchanges since v23
1. remove avr_cpu_list_compare function 2. modify avr_cpu_class_by_name function 3. modify avr_cpu_list_entry function 4. modify avr_cpu_list functionchanges since v24
1. removeAVR_CPU_TYPE_NAMEmacrochanges since v25
1. fix patches. every file belong to one patch only 2. change copyright year from 2016 to 2019 3. create mask device to emulate prr0/prr1changes since v26
1. add avocado acceptence test
2. add boot serial testchanges since v27
1. list atmel2560 devices as unimplemented
2. fix sram base/sizechanges since v28
1. rebase
2. fix includes & buildchanges since v29
1. fixing ownership
2. using 'since' instread of 'added in'changes since v30
1. rebasechanges since v31
1. splitting 'Add instruction translation' commit 2. fixing typo in qapi/machine.json sicne -> since 3. removing unintended changes in configure file 4. adding Richard Henderson as a co developer to 'Add instructiontranslation - CPU main translation funcions' commit
changes since v32
1. modifycpu_get_sregto treat sreg C as other flags, except sreg Zchanges since v33
1. ensure flag C is always calculated as one bit
2. calculate flag Z as one bit, without using inverse logicchanges since v34
1. rebasechanges since v35
1. rebase 2. use NANOSECONDS_PER_SECOND instead of 1000000000 in avr_timer16.c 3. split "target/avr: Register AVR support with the rest of QEMU" into three patches 1. "target/avr: Register AVR support with the rest of QEMU" 2. "target/avr: Update build system" 3. "target/avr: Update MAINTAINERS file"4. split "target/avr: Add tests" patch into two patches
1. "target/avr: Add Avocado test"
2. "target/avr: Add boot serial test"
5. Add instruction disassembly function
6. change "since 4.2" to "since 5.0"Michael Rolnik (16):
target/avr: Add outward facing interfaces and core CPU logic target/avr: Add instruction helpers
target/avr: Add instruction decoding
target/avr: Add instruction translation - Registers definition target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function target/avr: Add example board configuration
target/avr: Register AVR support with the rest of QEMU target/avr: Update build system
target/avr: Add boot serial test
target/avr: Add Avocado test
target/avr: UpdateMAINTAINERSfileSarah Harris (1):
target/avr: Add limited support for USART and 16 bit timer peripheralsconfigure | 7 + default-configs/avr-softmmu.mak | 5 + qapi/machine.json | 3 +- include/disas/dis-asm.h | 6 + include/hw/char/avr_usart.h | 97 + include/hw/misc/avr_mask.h | 47 + include/hw/timer/avr_timer16.h | 97 + include/sysemu/arch_init.h | 1 + target/avr/cpu-param.h | 37 + target/avr/cpu-qom.h | 54 + target/avr/cpu.h | 254 +++ target/avr/helper.h | 29 + arch_init.c | 2 + hw/avr/sample.c | 282 +++ hw/char/avr_usart.c | 324 ++++ hw/misc/avr_mask.c | 112 ++ hw/timer/avr_timer16.c | 605 ++++++ target/avr/cpu.c | 576 ++++++ target/avr/disas.c | 214 +++ target/avr/gdbstub.c | 85 + target/avr/helper.c | 354 ++++ target/avr/machine.c | 121 ++ target/avr/translate.c | 3039 ++++++++++++++++++++++++++++++ tests/boot-serial-test.c | 10 + tests/machine-none-test.c | 1 + MAINTAINERS | 9 + gdb-xml/avr-cpu.xml | 49 + hw/Kconfig | 1 + hw/avr/Kconfig | 6 + hw/avr/Makefile.objs | 1 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + target/avr/Makefile.objs | 34 + target/avr/insn.decode | 175 ++ tests/Makefile.include | 2 + tests/acceptance/machine_avr6.py | 36 + 40 files changed, 6688 insertions(+), 1 deletion(-) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_mask.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 hw/avr/sample.c create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_mask.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 target/avr/insn.decode create mode 100644 tests/acceptance/machine_avr6.py--
2.17.2 (Apple Git-113)
Quoted 9 lines · Michael Rolnik
This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested yet.
However I was able to execute simple code with functions. e.g fibonacci calculation.
This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.
Michael,
Please, in the next version, add or clean up licence preambles in ALL added files. It looks the most suitable license for you is LPGL 2.1 with "or later (at your option)" wording, like you already have in some (but not all) files, but it is your choice. If possible, make it consistent throughout the series. Sarah indicated to me she agreed with GPL-like license, but she will certainly have the chance to speak up if something is not right in her view. Don't misspell her name (as I did in one of my responses). All this license thing is important so that one more item of the series is resolved, and after that you don't need to think about it anymore.
Regards,
Aleksandar
Quoted 349 lines
the patches include the following
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR coresavr1 avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 xmega2 xmega4 xmega5 xmega6 xmega73. a definition of sample machine with SRAM, FLASH and CPU which allows to execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features togetherchanges since v3
1. rampD/X/Y/Z registers are encoded as0x00ff0000(instead of0x000000ff) for faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed atavr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7.tcg_const_local_i32->tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of0xff- r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCHchanges since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifyinggen_goto_tbas there is no real paging
5.env->pc->env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removingavr_set_feature
10. SPL/SPH set bug fix
11. switchingstb_phystocpu_stb_data
12. cleaning upavr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)changes since v5
1. BLD bug fix
2. decoder generator is addedchages since v6
1. using cpu_get_sreg/cpu_set_sreg in avr_cpu_gdb_read_register/avr_cpu_gdb_write_register
2. configure the target as little endian because otherwise GDB does not work
3. fixing and testing gen_push_ret/gen_pop_retchanges since v7
1. folding back v6
2. logging athelper_outbandhelper_inbare done for non supported yet registers only
3.MAINTAINERSupdatedchanges since v8
1. removing hw/avr from hw/Makefile.obj as it should not be built for all
2. making linux compilable
3. testing ona. Mac, Apple LLVM version 7.0.0 b. Ubuntu 12.04, gcc 4.9.2 c. Fedora 23, gcc 5.3.14. folding back some patches
5. translation bug fixes for ORI, CPI, XOR instructions
6. propper handling of cpu register writes though memorychanges since v9
1. removing forward declarations of static functions
2. disabling debug prints
3. switching to case range instead of if else if ...
4. LD/ST IN/OUT accessing CPU maintainder registers are not routed to any device
5. commenst about sample board and sample IO device added
6. sample board description is more descriptive now
7.memory_region_allocate_system_memoryis used to create RAM
8. now there arehelper_fullrd&helper_fullwrwhen LD/ST try to access registerschanges since v10
1. movig back fullwr & fullrd into the commit where outb and inb were introduced
2. changingtlb_fillfunction signature
3. adding empty line between functions
4. adding newline on the last line of the file
5. usingtb->flagsto generae full access ST/LD instructions
6. fixing SBRC bug
7. folding back 10th commit
8. whenever a new file is introduced it's added to Makefile.objschanges since v11
1. updating to v2.7.0-rc
2. removing assignment toenv->fullaccfromgen_intermediate_codechanges since v12
1. fixing spacing
2. fixing get/put_segment functions
3. removingtarget-avr/machine.hfile
4.VMSTATE_SINGLE_TEST->VMSTATE_SINGLE
5. comment spelling
6. removinghw/avr/sample_io.c
7. char const* -> const char*
8. proper ram allocation
9. fixing breakpoint functionality.
10.env1 -> env
11.fixingavr_cpu_gdb_write_register&avr_cpu_gdb_read_registerfunctions 12.any cpu is removed
12.feature bits are not saved into vm statechanges since v13
1. rebasing to v2.7.0-rc1changes since v14
1. I made self review with git gui tool. (I did not know such a thing exists)
2. removing all double/tripple spaces
3. removing comment reference to SampleIO
4. folding back some changes, so there is not deleted lines in my code
5. moving avr configuration, within configure file, before chrischanges since v15
1. removing IO registers cache from CPU
2. implementing CBI/SBI asread(helper_inb), modify,write(helper_outb)
3. implementing CBIC/SBIC asread(helper_inb), check, branch
4. adding missingtcg_temp_free_i32fortcg_const_i32changes since v16
1. removing EXT IO registers knoledge from CPU. These registers are accessible
by LD/ST only. CPU has no interest in themchanges since v17 (by Richard Henderson)
This is Michael's v17, with some adjustments of my own:1. Fix the whitespace errors reported by "git am",
2. Replace the utf-8 characters with normal ascii,
3. Ditch the separate compilation oftranslate.c.I retained the two separate files that could be regenerated from the included cpugen program, but merged in
translate-insn.c. Not that it matters, but the code generated is about 3k smaller.changes since v18
1. moving target-avr into target/avr 2. do not call cpu_exec_initfn function from avr_cpu_initfn 3. call cpu_exec_realizefn avr_cpu_realizefn 4. do not fail sample machine creation if no rom is suplied 5. add tcg_gen_exit_tb(0) for BS_BRANCH in gen_intermediate_code 6. fix a register getters/setters in machine.c 7. changing QEMU_ARCH_AVR from 1<<17 to 1<<18changes since v19
1. use decodetree.py tool to decode instructions 2. adding USART 3. adding 16 bit timer peripherals 4. changing QEMU_ARCH_AVR from 1<<18 to 1<<20 5. renaming tlb_fill to avr_cpu_tlb_fillchanges since v20
1. use one CPU naming convention 2. merging insn16.decode & insn32.decode files 3. modifying skip next instruction mechanizm 4. translate BREAK as NOP for nowchanges since v21
1. Reorganize bstate.
This will make transition to <exec/translator.h> easier, and fixes a
couple of bugs wrt single stepping
by [email protected]
2. Drop cpc and fix page cross condition.
by [email protected]
3. Refactor checking supported/unsupported instructions
4. Addgdb-xml/avr-cpu.xmlchanges since v22
1. Rebase
2. Split long commentchanges since v23
1. remove avr_cpu_list_compare function 2. modify avr_cpu_class_by_name function 3. modify avr_cpu_list_entry function 4. modify avr_cpu_list functionchanges since v24
1. removeAVR_CPU_TYPE_NAMEmacrochanges since v25
1. fix patches. every file belong to one patch only 2. change copyright year from 2016 to 2019 3. create mask device to emulate prr0/prr1changes since v26
1. add avocado acceptence test
2. add boot serial testchanges since v27
1. list atmel2560 devices as unimplemented
2. fix sram base/sizechanges since v28
1. rebase
2. fix includes & buildchanges since v29
1. fixing ownership
2. using 'since' instread of 'added in'changes since v30
1. rebasechanges since v31
1. splitting 'Add instruction translation' commit 2. fixing typo in qapi/machine.json sicne -> since 3. removing unintended changes in configure file 4. adding Richard Henderson as a co developer to 'Add instructiontranslation - CPU main translation funcions' commit
changes since v32
1. modifycpu_get_sregto treat sreg C as other flags, except sreg Zchanges since v33
1. ensure flag C is always calculated as one bit
2. calculate flag Z as one bit, without using inverse logicchanges since v34
1. rebasechanges since v35
1. rebase 2. use NANOSECONDS_PER_SECOND instead of 1000000000 in avr_timer16.c 3. split "target/avr: Register AVR support with the rest of QEMU" into three patches 1. "target/avr: Register AVR support with the rest of QEMU" 2. "target/avr: Update build system" 3. "target/avr: Update MAINTAINERS file"4. split "target/avr: Add tests" patch into two patches
1. "target/avr: Add Avocado test"
2. "target/avr: Add boot serial test"
5. Add instruction disassembly function
6. change "since 4.2" to "since 5.0"Michael Rolnik (16):
target/avr: Add outward facing interfaces and core CPU logic target/avr: Add instruction helpers
target/avr: Add instruction decoding
target/avr: Add instruction translation - Registers definition target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function target/avr: Add example board configuration
target/avr: Register AVR support with the rest of QEMU target/avr: Update build system
target/avr: Add boot serial test
target/avr: Add Avocado test
target/avr: UpdateMAINTAINERSfileSarah Harris (1):
target/avr: Add limited support for USART and 16 bit timer peripheralsconfigure | 7 + default-configs/avr-softmmu.mak | 5 + qapi/machine.json | 3 +- include/disas/dis-asm.h | 6 + include/hw/char/avr_usart.h | 97 + include/hw/misc/avr_mask.h | 47 + include/hw/timer/avr_timer16.h | 97 + include/sysemu/arch_init.h | 1 + target/avr/cpu-param.h | 37 + target/avr/cpu-qom.h | 54 + target/avr/cpu.h | 254 +++ target/avr/helper.h | 29 + arch_init.c | 2 + hw/avr/sample.c | 282 +++ hw/char/avr_usart.c | 324 ++++ hw/misc/avr_mask.c | 112 ++ hw/timer/avr_timer16.c | 605 ++++++ target/avr/cpu.c | 576 ++++++ target/avr/disas.c | 214 +++ target/avr/gdbstub.c | 85 + target/avr/helper.c | 354 ++++ target/avr/machine.c | 121 ++ target/avr/translate.c | 3039 ++++++++++++++++++++++++++++++ tests/boot-serial-test.c | 10 + tests/machine-none-test.c | 1 + MAINTAINERS | 9 + gdb-xml/avr-cpu.xml | 49 + hw/Kconfig | 1 + hw/avr/Kconfig | 6 + hw/avr/Makefile.objs | 1 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + target/avr/Makefile.objs | 34 + target/avr/insn.decode | 175 ++ tests/Makefile.include | 2 + tests/acceptance/machine_avr6.py | 36 + 40 files changed, 6688 insertions(+), 1 deletion(-) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_mask.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 hw/avr/sample.c create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_mask.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 target/avr/insn.decode create mode 100644 tests/acceptance/machine_avr6.py--
2.17.2 (Apple Git-113)
Quoted 9 lines · Michael Rolnik
This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested yet.
However I was able to execute simple code with functions. e.g fibonacci calculation.
This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.
You used to complain why nobody is reviewing your code, now you will start complaining that there are too many reviewes. ;-) Good sign if that happens!!
the patches include the following
Quoted 348 lines
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR coresavr1 avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 xmega2 xmega4 xmega5 xmega6 xmega73. a definition of sample machine with SRAM, FLASH and CPU which allows to execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features togetherchanges since v3
1. rampD/X/Y/Z registers are encoded as0x00ff0000(instead of0x000000ff) for faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed atavr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7.tcg_const_local_i32->tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of0xff- r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCHchanges since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifyinggen_goto_tbas there is no real paging
5.env->pc->env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removingavr_set_feature
10. SPL/SPH set bug fix
11. switchingstb_phystocpu_stb_data
12. cleaning upavr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)changes since v5
1. BLD bug fix
2. decoder generator is addedchages since v6
1. using cpu_get_sreg/cpu_set_sreg in avr_cpu_gdb_read_register/avr_cpu_gdb_write_register
2. configure the target as little endian because otherwise GDB does not work
3. fixing and testing gen_push_ret/gen_pop_retchanges since v7
1. folding back v6
2. logging athelper_outbandhelper_inbare done for non supported yet registers only
3.MAINTAINERSupdatedchanges since v8
1. removing hw/avr from hw/Makefile.obj as it should not be built for all
2. making linux compilable
3. testing ona. Mac, Apple LLVM version 7.0.0 b. Ubuntu 12.04, gcc 4.9.2 c. Fedora 23, gcc 5.3.14. folding back some patches
5. translation bug fixes for ORI, CPI, XOR instructions
6. propper handling of cpu register writes though memorychanges since v9
1. removing forward declarations of static functions
2. disabling debug prints
3. switching to case range instead of if else if ...
4. LD/ST IN/OUT accessing CPU maintainder registers are not routed to any device
5. commenst about sample board and sample IO device added
6. sample board description is more descriptive now
7.memory_region_allocate_system_memoryis used to create RAM
8. now there arehelper_fullrd&helper_fullwrwhen LD/ST try to access registerschanges since v10
1. movig back fullwr & fullrd into the commit where outb and inb were introduced
2. changingtlb_fillfunction signature
3. adding empty line between functions
4. adding newline on the last line of the file
5. usingtb->flagsto generae full access ST/LD instructions
6. fixing SBRC bug
7. folding back 10th commit
8. whenever a new file is introduced it's added to Makefile.objschanges since v11
1. updating to v2.7.0-rc
2. removing assignment toenv->fullaccfromgen_intermediate_codechanges since v12
1. fixing spacing
2. fixing get/put_segment functions
3. removingtarget-avr/machine.hfile
4.VMSTATE_SINGLE_TEST->VMSTATE_SINGLE
5. comment spelling
6. removinghw/avr/sample_io.c
7. char const* -> const char*
8. proper ram allocation
9. fixing breakpoint functionality.
10.env1 -> env
11.fixingavr_cpu_gdb_write_register&avr_cpu_gdb_read_registerfunctions 12.any cpu is removed
12.feature bits are not saved into vm statechanges since v13
1. rebasing to v2.7.0-rc1changes since v14
1. I made self review with git gui tool. (I did not know such a thing exists)
2. removing all double/tripple spaces
3. removing comment reference to SampleIO
4. folding back some changes, so there is not deleted lines in my code
5. moving avr configuration, within configure file, before chrischanges since v15
1. removing IO registers cache from CPU
2. implementing CBI/SBI asread(helper_inb), modify,write(helper_outb)
3. implementing CBIC/SBIC asread(helper_inb), check, branch
4. adding missingtcg_temp_free_i32fortcg_const_i32changes since v16
1. removing EXT IO registers knoledge from CPU. These registers are accessible
by LD/ST only. CPU has no interest in themchanges since v17 (by Richard Henderson)
This is Michael's v17, with some adjustments of my own:1. Fix the whitespace errors reported by "git am",
2. Replace the utf-8 characters with normal ascii,
3. Ditch the separate compilation oftranslate.c.I retained the two separate files that could be regenerated from the included cpugen program, but merged in
translate-insn.c. Not that it matters, but the code generated is about 3k smaller.changes since v18
1. moving target-avr into target/avr 2. do not call cpu_exec_initfn function from avr_cpu_initfn 3. call cpu_exec_realizefn avr_cpu_realizefn 4. do not fail sample machine creation if no rom is suplied 5. add tcg_gen_exit_tb(0) for BS_BRANCH in gen_intermediate_code 6. fix a register getters/setters in machine.c 7. changing QEMU_ARCH_AVR from 1<<17 to 1<<18changes since v19
1. use decodetree.py tool to decode instructions 2. adding USART 3. adding 16 bit timer peripherals 4. changing QEMU_ARCH_AVR from 1<<18 to 1<<20 5. renaming tlb_fill to avr_cpu_tlb_fillchanges since v20
1. use one CPU naming convention 2. merging insn16.decode & insn32.decode files 3. modifying skip next instruction mechanizm 4. translate BREAK as NOP for nowchanges since v21
1. Reorganize bstate.
This will make transition to <exec/translator.h> easier, and fixes a
couple of bugs wrt single stepping
by [email protected]
2. Drop cpc and fix page cross condition.
by [email protected]
3. Refactor checking supported/unsupported instructions
4. Addgdb-xml/avr-cpu.xmlchanges since v22
1. Rebase
2. Split long commentchanges since v23
1. remove avr_cpu_list_compare function 2. modify avr_cpu_class_by_name function 3. modify avr_cpu_list_entry function 4. modify avr_cpu_list functionchanges since v24
1. removeAVR_CPU_TYPE_NAMEmacrochanges since v25
1. fix patches. every file belong to one patch only 2. change copyright year from 2016 to 2019 3. create mask device to emulate prr0/prr1changes since v26
1. add avocado acceptence test
2. add boot serial testchanges since v27
1. list atmel2560 devices as unimplemented
2. fix sram base/sizechanges since v28
1. rebase
2. fix includes & buildchanges since v29
1. fixing ownership
2. using 'since' instread of 'added in'changes since v30
1. rebasechanges since v31
1. splitting 'Add instruction translation' commit 2. fixing typo in qapi/machine.json sicne -> since 3. removing unintended changes in configure file 4. adding Richard Henderson as a co developer to 'Add instructiontranslation - CPU main translation funcions' commit
changes since v32
1. modifycpu_get_sregto treat sreg C as other flags, except sreg Zchanges since v33
1. ensure flag C is always calculated as one bit
2. calculate flag Z as one bit, without using inverse logicchanges since v34
1. rebasechanges since v35
1. rebase 2. use NANOSECONDS_PER_SECOND instead of 1000000000 in avr_timer16.c 3. split "target/avr: Register AVR support with the rest of QEMU" into three patches 1. "target/avr: Register AVR support with the rest of QEMU" 2. "target/avr: Update build system" 3. "target/avr: Update MAINTAINERS file"4. split "target/avr: Add tests" patch into two patches
1. "target/avr: Add Avocado test"
2. "target/avr: Add boot serial test"
5. Add instruction disassembly function
6. change "since 4.2" to "since 5.0"Michael Rolnik (16):
target/avr: Add outward facing interfaces and core CPU logic target/avr: Add instruction helpers
target/avr: Add instruction decoding
target/avr: Add instruction translation - Registers definition target/avr: Add instruction translation - Arithmetic and Logic
Instructions
target/avr: Add instruction translation - Branch Instructions target/avr: Add instruction translation - Bit and Bit-test
Instructions
target/avr: Add instruction translation - MCU Control Instructions target/avr: Add instruction translation - CPU main translation
function
target/avr: Add instruction disassembly function target/avr: Add example board configuration
target/avr: Register AVR support with the rest of QEMU target/avr: Update build system
target/avr: Add boot serial test
target/avr: Add Avocado test
target/avr: UpdateMAINTAINERSfileSarah Harris (1):
target/avr: Add limited support for USART and 16 bit timer peripheralsconfigure | 7 + default-configs/avr-softmmu.mak | 5 + qapi/machine.json | 3 +- include/disas/dis-asm.h | 6 + include/hw/char/avr_usart.h | 97 + include/hw/misc/avr_mask.h | 47 + include/hw/timer/avr_timer16.h | 97 + include/sysemu/arch_init.h | 1 + target/avr/cpu-param.h | 37 + target/avr/cpu-qom.h | 54 + target/avr/cpu.h | 254 +++ target/avr/helper.h | 29 + arch_init.c | 2 + hw/avr/sample.c | 282 +++ hw/char/avr_usart.c | 324 ++++ hw/misc/avr_mask.c | 112 ++ hw/timer/avr_timer16.c | 605 ++++++ target/avr/cpu.c | 576 ++++++ target/avr/disas.c | 214 +++ target/avr/gdbstub.c | 85 + target/avr/helper.c | 354 ++++ target/avr/machine.c | 121 ++ target/avr/translate.c | 3039 ++++++++++++++++++++++++++++++ tests/boot-serial-test.c | 10 + tests/machine-none-test.c | 1 + MAINTAINERS | 9 + gdb-xml/avr-cpu.xml | 49 + hw/Kconfig | 1 + hw/avr/Kconfig | 6 + hw/avr/Makefile.objs | 1 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 1 + hw/misc/Kconfig | 3 + hw/misc/Makefile.objs | 2 + hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + target/avr/Makefile.objs | 34 + target/avr/insn.decode | 175 ++ tests/Makefile.include | 2 + tests/acceptance/machine_avr6.py | 36 + 40 files changed, 6688 insertions(+), 1 deletion(-) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 include/hw/char/avr_usart.h create mode 100644 include/hw/misc/avr_mask.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 hw/avr/sample.c create mode 100644 hw/char/avr_usart.c create mode 100644 hw/misc/avr_mask.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 target/avr/insn.decode create mode 100644 tests/acceptance/machine_avr6.py--
2.17.2 (Apple Git-113)